diff --git a/cmd/run.go b/cmd/run.go index d86e25ddce..26f91208f1 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -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) } diff --git a/etherman/etherman.go b/etherman/etherman.go index 71e71ce3d2..27560d9a69 100644 --- a/etherman/etherman.go +++ b/etherman/etherman.go @@ -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}}, } diff --git a/etherman/etherman_test.go b/etherman/etherman_test.go index 7c3712e0be..8985bb2b1e 100644 --- a/etherman/etherman_test.go +++ b/etherman/etherman_test.go @@ -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) diff --git a/synchronizer/interfaces.go b/synchronizer/interfaces.go index 2045b1564e..3c707dd7c9 100644 --- a/synchronizer/interfaces.go +++ b/synchronizer/interfaces.go @@ -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. diff --git a/synchronizer/mock_etherman.go b/synchronizer/mock_etherman.go index 036a115fed..fceda51564 100644 --- a/synchronizer/mock_etherman.go +++ b/synchronizer/mock_etherman.go @@ -48,25 +48,25 @@ func (_m *ethermanMock) EthBlockByNumber(ctx context.Context, blockNumber uint64 return r0, r1 } -// GetForks provides a mock function with given fields: ctx -func (_m *ethermanMock) GetForks(ctx context.Context) ([]state.ForkIDInterval, error) { - ret := _m.Called(ctx) +// GetForks provides a mock function with given fields: ctx, genBlockNumber +func (_m *ethermanMock) GetForks(ctx context.Context, genBlockNumber uint64) ([]state.ForkIDInterval, error) { + ret := _m.Called(ctx, genBlockNumber) var r0 []state.ForkIDInterval var r1 error - if rf, ok := ret.Get(0).(func(context.Context) ([]state.ForkIDInterval, error)); ok { - return rf(ctx) + if rf, ok := ret.Get(0).(func(context.Context, uint64) ([]state.ForkIDInterval, error)); ok { + return rf(ctx, genBlockNumber) } - if rf, ok := ret.Get(0).(func(context.Context) []state.ForkIDInterval); ok { - r0 = rf(ctx) + if rf, ok := ret.Get(0).(func(context.Context, uint64) []state.ForkIDInterval); ok { + r0 = rf(ctx, genBlockNumber) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]state.ForkIDInterval) } } - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) + if rf, ok := ret.Get(1).(func(context.Context, uint64) error); ok { + r1 = rf(ctx, genBlockNumber) } else { r1 = ret.Error(1) } diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index 93641e20c5..7884792414 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -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) @@ -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)