Skip to content

Commit

Permalink
add flags for configurable hours of blob data
Browse files Browse the repository at this point in the history
  • Loading branch information
fahimahmedx committed Jun 17, 2024
1 parent 9c07467 commit f5e4671
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
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.BlocksPerMinuteConfig*cfg.HoursOfBlobDataConfig*60), nil
}
}
18 changes: 15 additions & 3 deletions validator/flags/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
)

type ValidatorConfig struct {
LogConfig oplog.CLIConfig
BeaconConfig common.BeaconConfig
BlobConfig common.BeaconConfig
LogConfig oplog.CLIConfig
BeaconConfig common.BeaconConfig
BlobConfig common.BeaconConfig
BlocksPerMinuteConfig int
HoursOfBlobDataConfig int
}

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

if c.BlocksPerMinuteConfig <= 0 {
return fmt.Errorf("blocks per minute must be greater than 0")
}

if c.HoursOfBlobDataConfig <= 0 {
return fmt.Errorf("hours of blob data must be greater than 0")
}

return nil
}

Expand All @@ -40,5 +50,7 @@ func ReadConfig(cliCtx *cli.Context) ValidatorConfig {
BeaconURL: cliCtx.String(BlobApiClientUrlFlag.Name),
BeaconClientTimeout: timeout,
},
BlocksPerMinuteConfig: cliCtx.Int(BeaconClientTimeoutFlag.Name),
HoursOfBlobDataConfig: cliCtx.Int(HoursOfBlobDataClientFlag.Name),
}
}
14 changes: 14 additions & 0 deletions validator/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ var (
Required: true,
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "BLOB_API_HTTP"),
}
BlocksPerMinuteClientFlag = &cli.IntFlag{
Name: "blocks-per-minute",
Usage: "The number of blocks per minute",
Value: 5,
Required: true,
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "BLOCKS_PER_MINUTE"),
}
HoursOfBlobDataClientFlag = &cli.IntFlag{
Name: "hours-of-blob-data",
Usage: "The number of hours of blob data to fetch",
Value: 2,
Required: true,
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "HOURS_OF_BLOB_DATA"),
}
)

func init() {
Expand Down
30 changes: 15 additions & 15 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,23 +29,25 @@ 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, hoursOfBlocks int) *ValidatorService {
return &ValidatorService{
log: l,
headerClient: headerClient,
beaconAPI: beaconAPI,
blobAPI: blobAPI,
closeApp: app,
log: l,
headerClient: headerClient,
beaconAPI: beaconAPI,
blobAPI: blobAPI,
closeApp: app,
hoursOfBlocks: hoursOfBlocks,
}
}

type ValidatorService struct {
stopped atomic.Bool
log log.Logger
headerClient client.BeaconBlockHeadersProvider
beaconAPI BlobSidecarClient
blobAPI BlobSidecarClient
closeApp context.CancelCauseFunc
stopped atomic.Bool
log log.Logger
headerClient client.BeaconBlockHeadersProvider
beaconAPI BlobSidecarClient
blobAPI BlobSidecarClient
closeApp context.CancelCauseFunc
hoursOfBlocks 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.hoursOfBlocks)

go a.checkBlobs(ctx, start, end)

Expand Down

0 comments on commit f5e4671

Please sign in to comment.