Skip to content

Commit

Permalink
reduce interval to search forkID events
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR552 committed May 4, 2023
1 parent e3cd4ff commit 0c75fba
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func start(cliCtx *cli.Context) error {
log.Fatal(err)
}
// Read Fork ID FROM POE SC
forkIDIntervals, err := etherman.GetForks(cliCtx.Context)
forkIDIntervals, err := etherman.GetForks(cliCtx.Context, c.NetworkConfig.Genesis.GenesisBlockNum)
if err != nil || len(forkIDIntervals) == 0 {
log.Fatal("error getting forks: ", err)
}
Expand Down
4 changes: 2 additions & 2 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ func (etherMan *Client) VerifyGenBlockNumber(ctx context.Context, genBlockNumber
}

// GetForks returns fork information
func (etherMan *Client) GetForks(ctx context.Context) ([]state.ForkIDInterval, error) {
func (etherMan *Client) GetForks(ctx context.Context, genBlockNumber uint64) ([]state.ForkIDInterval, error) {
// Filter query
query := ethereum.FilterQuery{
FromBlock: new(big.Int).SetUint64(1),
FromBlock: new(big.Int).SetUint64(genBlockNumber),
Addresses: etherMan.SCAddresses,
Topics: [][]common.Hash{{updateZkEVMVersionSignatureHash}},
}
Expand Down
2 changes: 1 addition & 1 deletion etherman/etherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func TestGetForks(t *testing.T) {
// Set up testing environment
etherman, _, _, _, _ := newTestingEnv()
ctx := context.Background()
forks, err := etherman.GetForks(ctx)
forks, err := etherman.GetForks(ctx, 0)
require.NoError(t, err)
assert.Equal(t, 1, len(forks))
assert.Equal(t, uint64(1), forks[0].ForkId)
Expand Down
2 changes: 1 addition & 1 deletion synchronizer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ethermanInterface interface {
GetLatestBatchNumber() (uint64, error)
GetTrustedSequencerURL() (string, error)
VerifyGenBlockNumber(ctx context.Context, genBlockNumber uint64) (bool, error)
GetForks(ctx context.Context) ([]state.ForkIDInterval, error)
GetForks(ctx context.Context, genBlockNumber uint64) ([]state.ForkIDInterval, error)
}

// stateInterface gathers the methods required to interact with the state.
Expand Down
18 changes: 9 additions & 9 deletions synchronizer/mock_etherman.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ func (s *ClientSynchronizer) processForkID(forkID etherman.ForkID, blockNumber u
}
if latestBatchNumber < forkID.BatchNumber { //If the forkID will start in a future batch
// Read Fork ID FROM POE SC
forkIDIntervals, err := s.etherMan.GetForks(s.ctx)
forkIDIntervals, err := s.etherMan.GetForks(s.ctx, s.genesis.GenesisBlockNum)
if err != nil || len(forkIDIntervals) == 0 {
log.Error("error getting all forkIDs: ", err)
rollbackErr := dbTx.Rollback(s.ctx)
Expand Down Expand Up @@ -597,7 +597,7 @@ func (s *ClientSynchronizer) processForkID(forkID etherman.ForkID, blockNumber u
}

// Read Fork ID FROM POE SC
forkIDIntervals, err := s.etherMan.GetForks(s.ctx)
forkIDIntervals, err := s.etherMan.GetForks(s.ctx, s.genesis.GenesisBlockNum)
if err != nil || len(forkIDIntervals) == 0 {
log.Error("error getting all forkIDs: ", err)
rollbackErr := dbTx.Rollback(s.ctx)
Expand Down

0 comments on commit 0c75fba

Please sign in to comment.