Skip to content

Commit a1681ab

Browse files
authoredJul 10, 2024··
Merge pull request #32 from base-org/setting-for-json-validation-only
chore: allow validation service to process subset of formats
2 parents 988d545 + ec43e60 commit a1681ab

File tree

6 files changed

+54
-18
lines changed

6 files changed

+54
-18
lines changed
 

‎archiver/service/archiver.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (a *Archiver) backfillBlobs(ctx context.Context, latest *v1.BeaconBlockHead
199199
a.log.Crit("failed to read backfill_processes", "err", err)
200200
}
201201
backfillProcesses[common.Hash(latest.Root)] = storage.BackfillProcess{Start: *latest, Current: *latest}
202-
a.dataStoreClient.WriteBackfillProcesses(ctx, backfillProcesses)
202+
_ = a.dataStoreClient.WriteBackfillProcesses(ctx, backfillProcesses)
203203

204204
backfillLoop := func(start *v1.BeaconBlockHeader, current *v1.BeaconBlockHeader) {
205205
curr, alreadyExists, err := current, false, error(nil)
@@ -219,7 +219,7 @@ func (a *Archiver) backfillBlobs(ctx context.Context, latest *v1.BeaconBlockHead
219219
"startSlot", start.Header.Message.Slot,
220220
)
221221
delete(backfillProcesses, common.Hash(start.Root))
222-
a.dataStoreClient.WriteBackfillProcesses(ctx, backfillProcesses)
222+
_ = a.dataStoreClient.WriteBackfillProcesses(ctx, backfillProcesses)
223223
}()
224224

225225
for !alreadyExists {
@@ -246,7 +246,7 @@ func (a *Archiver) backfillBlobs(ctx context.Context, latest *v1.BeaconBlockHead
246246
count++
247247
if count%10 == 0 {
248248
backfillProcesses[common.Hash(start.Root)] = storage.BackfillProcess{Start: *start, Current: *curr}
249-
a.dataStoreClient.WriteBackfillProcesses(ctx, backfillProcesses)
249+
_ = a.dataStoreClient.WriteBackfillProcesses(ctx, backfillProcesses)
250250
}
251251
}
252252
}

‎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, cfg.NumBlocks), nil
62+
return service.NewValidator(l, headerClient, beaconClient, blobClient, closeApp, cfg), nil
6363
}
6464
}

‎validator/flags/config.go

+22-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010
)
1111

1212
type ValidatorConfig struct {
13-
LogConfig oplog.CLIConfig
14-
BeaconConfig common.BeaconConfig
15-
BlobConfig common.BeaconConfig
16-
NumBlocks int
13+
LogConfig oplog.CLIConfig
14+
BeaconConfig common.BeaconConfig
15+
BlobConfig common.BeaconConfig
16+
ValidateFormats []string
17+
NumBlocks int
1718
}
1819

1920
func (c ValidatorConfig) Check() error {
@@ -29,6 +30,21 @@ func (c ValidatorConfig) Check() error {
2930
return fmt.Errorf("number of blocks must be greater than 0")
3031
}
3132

33+
if len(c.ValidateFormats) == 0 || len(c.ValidateFormats) > 2 {
34+
return fmt.Errorf("no formats to validate, please specify formats [json,ssz]")
35+
}
36+
37+
seen := make(map[string]struct{})
38+
for _, format := range c.ValidateFormats {
39+
if format != "json" && format != "ssz" {
40+
return fmt.Errorf("invalid format %v, please specify formats [json,ssz]", format)
41+
}
42+
if _, ok := seen[format]; ok {
43+
return fmt.Errorf("duplicate format %v", format)
44+
}
45+
seen[format] = struct{}{}
46+
}
47+
3248
return nil
3349
}
3450

@@ -45,6 +61,7 @@ func ReadConfig(cliCtx *cli.Context) ValidatorConfig {
4561
BeaconURL: cliCtx.String(BlobApiClientUrlFlag.Name),
4662
BeaconClientTimeout: timeout,
4763
},
48-
NumBlocks: cliCtx.Int(NumBlocksClientFlag.Name),
64+
NumBlocks: cliCtx.Int(NumBlocksClientFlag.Name),
65+
ValidateFormats: cliCtx.StringSlice(ValidateFormatsFlag.Name),
4966
}
5067
}

‎validator/flags/flags.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@ var (
3434
Required: true,
3535
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "NUM_BLOCKS"),
3636
}
37+
ValidateFormatsFlag = &cli.StringSliceFlag{
38+
Name: "validate-formats",
39+
Usage: "The formats to validate [json, ssz]",
40+
Value: cli.NewStringSlice("json", "ssz"),
41+
Required: true,
42+
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "VALIDATE_FORMATS"),
43+
}
3744
)
3845

3946
func init() {
4047
Flags = append(Flags, oplog.CLIFlags(EnvVarPrefix)...)
41-
Flags = append(Flags, BeaconClientTimeoutFlag, L1BeaconClientUrlFlag, BlobApiClientUrlFlag, NumBlocksClientFlag)
48+
Flags = append(Flags, BeaconClientTimeoutFlag, L1BeaconClientUrlFlag, BlobApiClientUrlFlag, NumBlocksClientFlag, ValidateFormatsFlag)
4249
}
4350

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

‎validator/service/service.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
v1 "github.com/attestantio/go-eth2-client/api/v1"
1515
"github.com/attestantio/go-eth2-client/spec/phase0"
1616
"github.com/base-org/blob-archiver/common/storage"
17+
"github.com/base-org/blob-archiver/validator/flags"
1718
"github.com/ethereum-optimism/optimism/op-service/retry"
1819
"github.com/ethereum/go-ethereum/log"
1920
)
@@ -29,14 +30,21 @@ const (
2930
retryAttempts = 10
3031
)
3132

32-
func NewValidator(l log.Logger, headerClient client.BeaconBlockHeadersProvider, beaconAPI BlobSidecarClient, blobAPI BlobSidecarClient, app context.CancelCauseFunc, numBlocks int) *ValidatorService {
33+
var (
34+
formatSettingToHeader = map[string]Format{
35+
"json": FormatJson,
36+
"ssz": FormatSSZ,
37+
}
38+
)
39+
40+
func NewValidator(l log.Logger, headerClient client.BeaconBlockHeadersProvider, beaconAPI BlobSidecarClient, blobAPI BlobSidecarClient, app context.CancelCauseFunc, cfg flags.ValidatorConfig) *ValidatorService {
3341
return &ValidatorService{
3442
log: l,
3543
headerClient: headerClient,
3644
beaconAPI: beaconAPI,
3745
blobAPI: blobAPI,
3846
closeApp: app,
39-
numBlocks: numBlocks,
47+
cfg: cfg,
4048
}
4149
}
4250

@@ -47,7 +55,7 @@ type ValidatorService struct {
4755
beaconAPI BlobSidecarClient
4856
blobAPI BlobSidecarClient
4957
closeApp context.CancelCauseFunc
50-
numBlocks int
58+
cfg flags.ValidatorConfig
5159
}
5260

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

6674
end := header.Data.Header.Message.Slot - finalizedL1Offset
67-
start := end - phase0.Slot(a.numBlocks)
75+
start := end - phase0.Slot(a.cfg.NumBlocks)
6876

6977
go a.checkBlobs(ctx, start, end)
7078

@@ -126,7 +134,9 @@ func (a *ValidatorService) checkBlobs(ctx context.Context, start phase0.Slot, en
126134
var result CheckBlobResult
127135

128136
for slot := start; slot <= end; slot++ {
129-
for _, format := range []Format{FormatJson, FormatSSZ} {
137+
for _, setting := range a.cfg.ValidateFormats {
138+
format := formatSettingToHeader[setting]
139+
130140
id := strconv.FormatUint(uint64(slot), 10)
131141

132142
l := a.log.New("format", format, "slot", slot)

‎validator/service/service_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/base-org/blob-archiver/common/beacon/beacontest"
1313
"github.com/base-org/blob-archiver/common/blobtest"
1414
"github.com/base-org/blob-archiver/common/storage"
15+
"github.com/base-org/blob-archiver/validator/flags"
1516
"github.com/ethereum-optimism/optimism/op-service/testlog"
1617
"github.com/ethereum/go-ethereum/log"
1718
"github.com/stretchr/testify/require"
@@ -71,9 +72,10 @@ func setup(t *testing.T) (*ValidatorService, *beacontest.StubBeaconClient, *stub
7172
data: make(map[string]response),
7273
}
7374

74-
numBlocks := 600
75-
76-
return NewValidator(l, headerClient, beacon, blob, cancel, numBlocks), headerClient, beacon, blob
75+
return NewValidator(l, headerClient, beacon, blob, cancel, flags.ValidatorConfig{
76+
ValidateFormats: []string{"json", "ssz"},
77+
NumBlocks: 600,
78+
}), headerClient, beacon, blob
7779
}
7880

7981
func TestValidatorService_OnFetchError(t *testing.T) {

0 commit comments

Comments
 (0)
Please sign in to comment.