Skip to content

Commit 1ef67f6

Browse files
authored
Merge pull request #30 from base-org/add-blocks-per-minute-flag
Add validator flags for configurable hours of blob data
2 parents 9c07467 + a85fee2 commit 1ef67f6

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

validator/cmd/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ func Main() cliapp.LifecycleAction {
5959
beaconClient := service.NewBlobSidecarClient(cfg.BeaconConfig.BeaconURL)
6060
blobClient := service.NewBlobSidecarClient(cfg.BlobConfig.BeaconURL)
6161

62-
return service.NewValidator(l, headerClient, beaconClient, blobClient, closeApp), nil
62+
return service.NewValidator(l, headerClient, beaconClient, blobClient, closeApp, cfg.NumBlocks), nil
6363
}
6464
}

validator/flags/config.go

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type ValidatorConfig struct {
1313
LogConfig oplog.CLIConfig
1414
BeaconConfig common.BeaconConfig
1515
BlobConfig common.BeaconConfig
16+
NumBlocks int
1617
}
1718

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

28+
if c.NumBlocks <= 0 {
29+
return fmt.Errorf("number of blocks must be greater than 0")
30+
}
31+
2732
return nil
2833
}
2934

@@ -40,5 +45,6 @@ func ReadConfig(cliCtx *cli.Context) ValidatorConfig {
4045
BeaconURL: cliCtx.String(BlobApiClientUrlFlag.Name),
4146
BeaconClientTimeout: timeout,
4247
},
48+
NumBlocks: cliCtx.Int(NumBlocksClientFlag.Name),
4349
}
4450
}

validator/flags/flags.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ var (
2727
Required: true,
2828
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "BLOB_API_HTTP"),
2929
}
30+
NumBlocksClientFlag = &cli.IntFlag{
31+
Name: "num-blocks",
32+
Usage: "The number of blocks to read blob data for",
33+
Value: 600,
34+
Required: true,
35+
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "NUM_BLOCKS"),
36+
}
3037
)
3138

3239
func init() {
3340
Flags = append(Flags, oplog.CLIFlags(EnvVarPrefix)...)
34-
Flags = append(Flags, BeaconClientTimeoutFlag, L1BeaconClientUrlFlag, BlobApiClientUrlFlag)
41+
Flags = append(Flags, BeaconClientTimeoutFlag, L1BeaconClientUrlFlag, BlobApiClientUrlFlag, NumBlocksClientFlag)
3542
}
3643

3744
// Flags contains the list of configuration options available to the binary.

validator/service/service.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
var ErrAlreadyStopped = errors.New("already stopped")
2222

2323
const (
24-
// 5 blocks per minute, 120 minutes
25-
twoHoursOfBlocks = 5 * 120
2624
// finalized l1 offset
2725
finalizedL1Offset = 64
2826
// Known log for any validation errors
@@ -31,13 +29,14 @@ const (
3129
retryAttempts = 10
3230
)
3331

34-
func NewValidator(l log.Logger, headerClient client.BeaconBlockHeadersProvider, beaconAPI BlobSidecarClient, blobAPI BlobSidecarClient, app context.CancelCauseFunc) *ValidatorService {
32+
func NewValidator(l log.Logger, headerClient client.BeaconBlockHeadersProvider, beaconAPI BlobSidecarClient, blobAPI BlobSidecarClient, app context.CancelCauseFunc, numBlocks int) *ValidatorService {
3533
return &ValidatorService{
3634
log: l,
3735
headerClient: headerClient,
3836
beaconAPI: beaconAPI,
3937
blobAPI: blobAPI,
4038
closeApp: app,
39+
numBlocks: numBlocks,
4140
}
4241
}
4342

@@ -48,6 +47,7 @@ type ValidatorService struct {
4847
beaconAPI BlobSidecarClient
4948
blobAPI BlobSidecarClient
5049
closeApp context.CancelCauseFunc
50+
numBlocks int
5151
}
5252

5353
// 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 {
6464
}
6565

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

6969
go a.checkBlobs(ctx, start, end)
7070

validator/service/service_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ func setup(t *testing.T) (*ValidatorService, *beacontest.StubBeaconClient, *stub
7171
data: make(map[string]response),
7272
}
7373

74-
return NewValidator(l, headerClient, beacon, blob, cancel), headerClient, beacon, blob
74+
numBlocks := 600
75+
76+
return NewValidator(l, headerClient, beacon, blob, cancel, numBlocks), headerClient, beacon, blob
7577
}
7678

7779
func TestValidatorService_OnFetchError(t *testing.T) {

0 commit comments

Comments
 (0)