Skip to content

Commit e33d203

Browse files
committed
Add sync start block number config parameter
1 parent b0142ea commit e33d203

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

rolling-shutter/keyperimpl/gnosis/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ type GnosisConfig struct {
106106
SecondsPerSlot uint64 `shconfig:",required"`
107107
SlotsPerEpoch uint64 `shconfig:",required"`
108108
GenesisSlotTimestamp uint64 `shconfig:",required"`
109+
SyncStartBlockNumber uint64 `shconfig:",required"`
109110
}
110111

111112
func NewGnosisConfig() *GnosisConfig {
@@ -118,6 +119,7 @@ func NewGnosisConfig() *GnosisConfig {
118119
SecondsPerSlot: 0,
119120
SlotsPerEpoch: 0,
120121
GenesisSlotTimestamp: 0,
122+
SyncStartBlockNumber: 0,
121123
}
122124
c.Init()
123125
return c
@@ -153,6 +155,7 @@ func (c *GnosisConfig) SetExampleValues() error {
153155
c.SecondsPerSlot = 5
154156
c.SlotsPerEpoch = 16
155157
c.GenesisSlotTimestamp = 1665410700
158+
c.SyncStartBlockNumber = 0
156159
return nil
157160
}
158161

rolling-shutter/keyperimpl/gnosis/keyper.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func (kpr *Keyper) initSequencerSyncer(ctx context.Context) error {
201201
ExecutionClient: client,
202202
GenesisSlotTimestamp: kpr.config.Gnosis.GenesisSlotTimestamp,
203203
SecondsPerSlot: kpr.config.Gnosis.SecondsPerSlot,
204+
SyncStartBlockNumber: kpr.config.Gnosis.SyncStartBlockNumber,
204205
}
205206

206207
// Perform an initial sync now because it might take some time and doing so during regular
@@ -234,11 +235,12 @@ func (kpr *Keyper) initValidatorSyncer(ctx context.Context) error {
234235
return errors.Wrap(err, "failed to instantiate validator registry contract")
235236
}
236237
kpr.validatorSyncer = &ValidatorSyncer{
237-
Contract: validatorRegistryContract,
238-
DBPool: kpr.dbpool,
239-
BeaconAPIClient: kpr.beaconAPIClient,
240-
ExecutionClient: validatorSyncerClient,
241-
ChainID: chainID.Uint64(),
238+
Contract: validatorRegistryContract,
239+
DBPool: kpr.dbpool,
240+
BeaconAPIClient: kpr.beaconAPIClient,
241+
ExecutionClient: validatorSyncerClient,
242+
ChainID: chainID.Uint64(),
243+
SyncStartBlockNumber: kpr.config.Gnosis.SyncStartBlockNumber,
242244
}
243245

244246
// Perform an initial sync now because it might take some time and doing so during regular

rolling-shutter/keyperimpl/gnosis/sequencersyncer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type SequencerSyncer struct {
2626
ExecutionClient *ethclient.Client
2727
GenesisSlotTimestamp uint64
2828
SecondsPerSlot uint64
29+
SyncStartBlockNumber uint64
2930
}
3031

3132
// Sync fetches transaction submitted events from the sequencer contract and inserts them into the
@@ -39,7 +40,7 @@ func (s *SequencerSyncer) Sync(ctx context.Context, header *types.Header) error
3940
}
4041
var start uint64
4142
if err == pgx.ErrNoRows {
42-
start = 0
43+
start = s.SyncStartBlockNumber
4344
} else {
4445
start = uint64(syncedUntil.BlockNumber + 1)
4546
}

rolling-shutter/keyperimpl/gnosis/validatorsyncer.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ const (
2929
)
3030

3131
type ValidatorSyncer struct {
32-
Contract *validatorRegistryBindings.Validatorregistry
33-
DBPool *pgxpool.Pool
34-
BeaconAPIClient *beaconapiclient.Client
35-
ExecutionClient *ethclient.Client
36-
ChainID uint64
32+
Contract *validatorRegistryBindings.Validatorregistry
33+
DBPool *pgxpool.Pool
34+
BeaconAPIClient *beaconapiclient.Client
35+
ExecutionClient *ethclient.Client
36+
ChainID uint64
37+
SyncStartBlockNumber uint64
3738
}
3839

3940
func (v *ValidatorSyncer) Sync(ctx context.Context, header *types.Header) error {
@@ -44,7 +45,7 @@ func (v *ValidatorSyncer) Sync(ctx context.Context, header *types.Header) error
4445
}
4546
var start uint64
4647
if err == pgx.ErrNoRows {
47-
start = 0
48+
start = v.SyncStartBlockNumber
4849
} else {
4950
start = uint64(syncedUntil.BlockNumber + 1)
5051
}

0 commit comments

Comments
 (0)