diff --git a/validator/cmd/main.go b/validator/cmd/main.go index 0e9b270..7c4c492 100644 --- a/validator/cmd/main.go +++ b/validator/cmd/main.go @@ -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 } } diff --git a/validator/flags/config.go b/validator/flags/config.go index ea6144c..b600f27 100644 --- a/validator/flags/config.go +++ b/validator/flags/config.go @@ -13,6 +13,7 @@ type ValidatorConfig struct { LogConfig oplog.CLIConfig BeaconConfig common.BeaconConfig BlobConfig common.BeaconConfig + NumBlocks int } func (c ValidatorConfig) Check() error { @@ -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 } @@ -40,5 +45,6 @@ func ReadConfig(cliCtx *cli.Context) ValidatorConfig { BeaconURL: cliCtx.String(BlobApiClientUrlFlag.Name), BeaconClientTimeout: timeout, }, + NumBlocks: cliCtx.Int(NumBlocksClientFlag.Name), } } diff --git a/validator/flags/flags.go b/validator/flags/flags.go index befb67b..5fd4bbc 100644 --- a/validator/flags/flags.go +++ b/validator/flags/flags.go @@ -27,11 +27,18 @@ 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() { Flags = append(Flags, oplog.CLIFlags(EnvVarPrefix)...) - Flags = append(Flags, BeaconClientTimeoutFlag, L1BeaconClientUrlFlag, BlobApiClientUrlFlag) + Flags = append(Flags, BeaconClientTimeoutFlag, L1BeaconClientUrlFlag, BlobApiClientUrlFlag, NumBlocksClientFlag) } // Flags contains the list of configuration options available to the binary. diff --git a/validator/service/service.go b/validator/service/service.go index 4137a59..adefc36 100644 --- a/validator/service/service.go +++ b/validator/service/service.go @@ -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 @@ -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, } } @@ -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 @@ -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) diff --git a/validator/service/service_test.go b/validator/service/service_test.go index 33de554..1454bf2 100644 --- a/validator/service/service_test.go +++ b/validator/service/service_test.go @@ -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) {