Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validator flags for configurable hours of blob data #30

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion validator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ func Main() cliapp.LifecycleAction {
beaconClient := service.NewBlobSidecarClient(cfg.BeaconConfig.BeaconURL)
blobClient := service.NewBlobSidecarClient(cfg.BlobConfig.BeaconURL)

return service.NewValidator(l, headerClient, beaconClient, blobClient, closeApp), nil
return service.NewValidator(l, headerClient, beaconClient, blobClient, closeApp, cfg.NumBlocks), nil
}
}
6 changes: 6 additions & 0 deletions validator/flags/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ValidatorConfig struct {
LogConfig oplog.CLIConfig
BeaconConfig common.BeaconConfig
BlobConfig common.BeaconConfig
NumBlocks int
}

func (c ValidatorConfig) Check() error {
Expand All @@ -24,6 +25,10 @@ func (c ValidatorConfig) Check() error {
return fmt.Errorf("blob config check failed: %w", err)
}

if c.NumBlocks <= 0 {
return fmt.Errorf("number of blocks must be greater than 0")
}

return nil
}

Expand All @@ -40,5 +45,6 @@ func ReadConfig(cliCtx *cli.Context) ValidatorConfig {
BeaconURL: cliCtx.String(BlobApiClientUrlFlag.Name),
BeaconClientTimeout: timeout,
},
NumBlocks: cliCtx.Int(NumBlocksClientFlag.Name),
}
}
7 changes: 7 additions & 0 deletions validator/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ var (
Required: true,
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "BLOB_API_HTTP"),
}
NumBlocksClientFlag = &cli.IntFlag{
Name: "num-blocks",
Usage: "The number of blocks to read blob data for",
Value: 600,
Required: true,
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "NUM_BLOCKS"),
}
)

func init() {
Expand Down
8 changes: 4 additions & 4 deletions validator/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
var ErrAlreadyStopped = errors.New("already stopped")

const (
// 5 blocks per minute, 120 minutes
twoHoursOfBlocks = 5 * 120
// finalized l1 offset
finalizedL1Offset = 64
// Known log for any validation errors
Expand All @@ -31,13 +29,14 @@ const (
retryAttempts = 10
)

func NewValidator(l log.Logger, headerClient client.BeaconBlockHeadersProvider, beaconAPI BlobSidecarClient, blobAPI BlobSidecarClient, app context.CancelCauseFunc) *ValidatorService {
func NewValidator(l log.Logger, headerClient client.BeaconBlockHeadersProvider, beaconAPI BlobSidecarClient, blobAPI BlobSidecarClient, app context.CancelCauseFunc, numBlocks int) *ValidatorService {
return &ValidatorService{
log: l,
headerClient: headerClient,
beaconAPI: beaconAPI,
blobAPI: blobAPI,
closeApp: app,
numBlocks: numBlocks,
}
}

Expand All @@ -48,6 +47,7 @@ type ValidatorService struct {
beaconAPI BlobSidecarClient
blobAPI BlobSidecarClient
closeApp context.CancelCauseFunc
numBlocks int
}

// Start starts the validator service. This will fetch the current range of blocks to validate and start the validation
Expand All @@ -64,7 +64,7 @@ func (a *ValidatorService) Start(ctx context.Context) error {
}

end := header.Data.Header.Message.Slot - finalizedL1Offset
start := end - twoHoursOfBlocks
start := end - phase0.Slot(a.numBlocks)

go a.checkBlobs(ctx, start, end)

Expand Down
4 changes: 3 additions & 1 deletion validator/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func setup(t *testing.T) (*ValidatorService, *beacontest.StubBeaconClient, *stub
data: make(map[string]response),
}

return NewValidator(l, headerClient, beacon, blob, cancel), headerClient, beacon, blob
numBlocks := 600

return NewValidator(l, headerClient, beacon, blob, cancel, numBlocks), headerClient, beacon, blob
}

func TestValidatorService_OnFetchError(t *testing.T) {
Expand Down