From 8543669f8ec1ea5e79d6dfc15945ddd04945f635 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Thu, 9 May 2024 17:39:35 +0200 Subject: [PATCH] add check_l1_block synchronusly before start sync from L1 --- state/entities/mocks/tx_callback_type.go | 69 ++++ state/mocks/block_storer.go | 49 +++ state/mocks/reorg_storer.go | 85 +++++ state/mocks/storage_reorg_interface.go | 85 +++++ state/mocks/storer.go | 49 +++ state/mocks/tx_callback_type.go | 69 ++++ state/model/mocks/storage_reorg_interface.go | 85 +++++ state/storage/interface.go | 1 + state/storage/pgstorage/block.go | 16 +- state/storage/pgstorage/block_test.go | 95 +++-- synchronizer/common/syncinterfaces/storage.go | 2 + synchronizer/l1_sync/l1_sequential_sync.go | 14 + .../l1_sync/l1_sequential_sync_test.go | 2 +- synchronizer/l1_sync/mocks/block_checker.go | 82 +++++ synchronizer/mocks/block_checker.go | 82 +++++ synchronizer/mocks/etherman_interface.go | 339 ------------------ synchronizer/mocks/state_reorg_manager.go | 120 +++++++ .../mocks/storage_block_reader_interface.go | 60 ++++ .../mocks/storage_block_writer_interface.go | 49 +++ synchronizer/mocks/storage_interface.go | 109 ++++++ synchronizer/mocks/storage_sync_queries.go | 60 ++++ synchronizer/synchronizer_impl.go | 10 +- 22 files changed, 1150 insertions(+), 382 deletions(-) create mode 100644 state/entities/mocks/tx_callback_type.go create mode 100644 state/mocks/reorg_storer.go create mode 100644 state/mocks/storage_reorg_interface.go create mode 100644 state/mocks/tx_callback_type.go create mode 100644 state/model/mocks/storage_reorg_interface.go create mode 100644 synchronizer/l1_sync/mocks/block_checker.go create mode 100644 synchronizer/mocks/block_checker.go create mode 100644 synchronizer/mocks/state_reorg_manager.go diff --git a/state/entities/mocks/tx_callback_type.go b/state/entities/mocks/tx_callback_type.go new file mode 100644 index 0000000..a19b1fa --- /dev/null +++ b/state/entities/mocks/tx_callback_type.go @@ -0,0 +1,69 @@ +// Code generated by mockery. DO NOT EDIT. + +package mock_entities + +import ( + entities "github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities" + mock "github.com/stretchr/testify/mock" +) + +// TxCallbackType is an autogenerated mock type for the TxCallbackType type +type TxCallbackType struct { + mock.Mock +} + +type TxCallbackType_Expecter struct { + mock *mock.Mock +} + +func (_m *TxCallbackType) EXPECT() *TxCallbackType_Expecter { + return &TxCallbackType_Expecter{mock: &_m.Mock} +} + +// Execute provides a mock function with given fields: _a0, _a1 +func (_m *TxCallbackType) Execute(_a0 entities.Tx, _a1 error) { + _m.Called(_a0, _a1) +} + +// TxCallbackType_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' +type TxCallbackType_Execute_Call struct { + *mock.Call +} + +// Execute is a helper method to define mock.On call +// - _a0 entities.Tx +// - _a1 error +func (_e *TxCallbackType_Expecter) Execute(_a0 interface{}, _a1 interface{}) *TxCallbackType_Execute_Call { + return &TxCallbackType_Execute_Call{Call: _e.mock.On("Execute", _a0, _a1)} +} + +func (_c *TxCallbackType_Execute_Call) Run(run func(_a0 entities.Tx, _a1 error)) *TxCallbackType_Execute_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(entities.Tx), args[1].(error)) + }) + return _c +} + +func (_c *TxCallbackType_Execute_Call) Return() *TxCallbackType_Execute_Call { + _c.Call.Return() + return _c +} + +func (_c *TxCallbackType_Execute_Call) RunAndReturn(run func(entities.Tx, error)) *TxCallbackType_Execute_Call { + _c.Call.Return(run) + return _c +} + +// NewTxCallbackType creates a new instance of TxCallbackType. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTxCallbackType(t interface { + mock.TestingT + Cleanup(func()) +}) *TxCallbackType { + mock := &TxCallbackType{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/state/mocks/block_storer.go b/state/mocks/block_storer.go index 0fd4a59..9a5cfcb 100644 --- a/state/mocks/block_storer.go +++ b/state/mocks/block_storer.go @@ -371,6 +371,55 @@ func (_c *BlockStorer_GetUncheckedBlocks_Call) RunAndReturn(run func(context.Con return _c } +// UpdateCheckedBlockByNumber provides a mock function with given fields: ctx, blockNumber, newCheckedStatus, dbTx +func (_m *BlockStorer) UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx entities.Tx) error { + ret := _m.Called(ctx, blockNumber, newCheckedStatus, dbTx) + + if len(ret) == 0 { + panic("no return value specified for UpdateCheckedBlockByNumber") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, bool, entities.Tx) error); ok { + r0 = rf(ctx, blockNumber, newCheckedStatus, dbTx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// BlockStorer_UpdateCheckedBlockByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateCheckedBlockByNumber' +type BlockStorer_UpdateCheckedBlockByNumber_Call struct { + *mock.Call +} + +// UpdateCheckedBlockByNumber is a helper method to define mock.On call +// - ctx context.Context +// - blockNumber uint64 +// - newCheckedStatus bool +// - dbTx entities.Tx +func (_e *BlockStorer_Expecter) UpdateCheckedBlockByNumber(ctx interface{}, blockNumber interface{}, newCheckedStatus interface{}, dbTx interface{}) *BlockStorer_UpdateCheckedBlockByNumber_Call { + return &BlockStorer_UpdateCheckedBlockByNumber_Call{Call: _e.mock.On("UpdateCheckedBlockByNumber", ctx, blockNumber, newCheckedStatus, dbTx)} +} + +func (_c *BlockStorer_UpdateCheckedBlockByNumber_Call) Run(run func(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx entities.Tx)) *BlockStorer_UpdateCheckedBlockByNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(bool), args[3].(entities.Tx)) + }) + return _c +} + +func (_c *BlockStorer_UpdateCheckedBlockByNumber_Call) Return(_a0 error) *BlockStorer_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *BlockStorer_UpdateCheckedBlockByNumber_Call) RunAndReturn(run func(context.Context, uint64, bool, entities.Tx) error) *BlockStorer_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(run) + return _c +} + // NewBlockStorer creates a new instance of BlockStorer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewBlockStorer(t interface { diff --git a/state/mocks/reorg_storer.go b/state/mocks/reorg_storer.go new file mode 100644 index 0000000..1fc5265 --- /dev/null +++ b/state/mocks/reorg_storer.go @@ -0,0 +1,85 @@ +// Code generated by mockery. DO NOT EDIT. + +package mock_state + +import ( + context "context" + + entities "github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities" + mock "github.com/stretchr/testify/mock" +) + +// reorgStorer is an autogenerated mock type for the reorgStorer type +type reorgStorer struct { + mock.Mock +} + +type reorgStorer_Expecter struct { + mock *mock.Mock +} + +func (_m *reorgStorer) EXPECT() *reorgStorer_Expecter { + return &reorgStorer_Expecter{mock: &_m.Mock} +} + +// ResetToL1BlockNumber provides a mock function with given fields: ctx, firstBlockNumberToKeep, dbTx +func (_m *reorgStorer) ResetToL1BlockNumber(ctx context.Context, firstBlockNumberToKeep uint64, dbTx entities.Tx) error { + ret := _m.Called(ctx, firstBlockNumberToKeep, dbTx) + + if len(ret) == 0 { + panic("no return value specified for ResetToL1BlockNumber") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, entities.Tx) error); ok { + r0 = rf(ctx, firstBlockNumberToKeep, dbTx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// reorgStorer_ResetToL1BlockNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ResetToL1BlockNumber' +type reorgStorer_ResetToL1BlockNumber_Call struct { + *mock.Call +} + +// ResetToL1BlockNumber is a helper method to define mock.On call +// - ctx context.Context +// - firstBlockNumberToKeep uint64 +// - dbTx entities.Tx +func (_e *reorgStorer_Expecter) ResetToL1BlockNumber(ctx interface{}, firstBlockNumberToKeep interface{}, dbTx interface{}) *reorgStorer_ResetToL1BlockNumber_Call { + return &reorgStorer_ResetToL1BlockNumber_Call{Call: _e.mock.On("ResetToL1BlockNumber", ctx, firstBlockNumberToKeep, dbTx)} +} + +func (_c *reorgStorer_ResetToL1BlockNumber_Call) Run(run func(ctx context.Context, firstBlockNumberToKeep uint64, dbTx entities.Tx)) *reorgStorer_ResetToL1BlockNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(entities.Tx)) + }) + return _c +} + +func (_c *reorgStorer_ResetToL1BlockNumber_Call) Return(_a0 error) *reorgStorer_ResetToL1BlockNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *reorgStorer_ResetToL1BlockNumber_Call) RunAndReturn(run func(context.Context, uint64, entities.Tx) error) *reorgStorer_ResetToL1BlockNumber_Call { + _c.Call.Return(run) + return _c +} + +// newReorgStorer creates a new instance of reorgStorer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newReorgStorer(t interface { + mock.TestingT + Cleanup(func()) +}) *reorgStorer { + mock := &reorgStorer{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/state/mocks/storage_reorg_interface.go b/state/mocks/storage_reorg_interface.go new file mode 100644 index 0000000..27709a4 --- /dev/null +++ b/state/mocks/storage_reorg_interface.go @@ -0,0 +1,85 @@ +// Code generated by mockery. DO NOT EDIT. + +package mock_state + +import ( + context "context" + + entities "github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities" + mock "github.com/stretchr/testify/mock" +) + +// StorageReorgInterface is an autogenerated mock type for the StorageReorgInterface type +type StorageReorgInterface struct { + mock.Mock +} + +type StorageReorgInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *StorageReorgInterface) EXPECT() *StorageReorgInterface_Expecter { + return &StorageReorgInterface_Expecter{mock: &_m.Mock} +} + +// ResetToL1BlockNumber provides a mock function with given fields: ctx, firstBlockNumberToKeep, dbTx +func (_m *StorageReorgInterface) ResetToL1BlockNumber(ctx context.Context, firstBlockNumberToKeep uint64, dbTx entities.Tx) error { + ret := _m.Called(ctx, firstBlockNumberToKeep, dbTx) + + if len(ret) == 0 { + panic("no return value specified for ResetToL1BlockNumber") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, entities.Tx) error); ok { + r0 = rf(ctx, firstBlockNumberToKeep, dbTx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// StorageReorgInterface_ResetToL1BlockNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ResetToL1BlockNumber' +type StorageReorgInterface_ResetToL1BlockNumber_Call struct { + *mock.Call +} + +// ResetToL1BlockNumber is a helper method to define mock.On call +// - ctx context.Context +// - firstBlockNumberToKeep uint64 +// - dbTx entities.Tx +func (_e *StorageReorgInterface_Expecter) ResetToL1BlockNumber(ctx interface{}, firstBlockNumberToKeep interface{}, dbTx interface{}) *StorageReorgInterface_ResetToL1BlockNumber_Call { + return &StorageReorgInterface_ResetToL1BlockNumber_Call{Call: _e.mock.On("ResetToL1BlockNumber", ctx, firstBlockNumberToKeep, dbTx)} +} + +func (_c *StorageReorgInterface_ResetToL1BlockNumber_Call) Run(run func(ctx context.Context, firstBlockNumberToKeep uint64, dbTx entities.Tx)) *StorageReorgInterface_ResetToL1BlockNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(entities.Tx)) + }) + return _c +} + +func (_c *StorageReorgInterface_ResetToL1BlockNumber_Call) Return(_a0 error) *StorageReorgInterface_ResetToL1BlockNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *StorageReorgInterface_ResetToL1BlockNumber_Call) RunAndReturn(run func(context.Context, uint64, entities.Tx) error) *StorageReorgInterface_ResetToL1BlockNumber_Call { + _c.Call.Return(run) + return _c +} + +// NewStorageReorgInterface creates a new instance of StorageReorgInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewStorageReorgInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *StorageReorgInterface { + mock := &StorageReorgInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/state/mocks/storer.go b/state/mocks/storer.go index f61f51e..d1d1925 100644 --- a/state/mocks/storer.go +++ b/state/mocks/storer.go @@ -1137,6 +1137,55 @@ func (_c *Storer_ResetToL1BlockNumber_Call) RunAndReturn(run func(context.Contex return _c } +// UpdateCheckedBlockByNumber provides a mock function with given fields: ctx, blockNumber, newCheckedStatus, dbTx +func (_m *Storer) UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx entities.Tx) error { + ret := _m.Called(ctx, blockNumber, newCheckedStatus, dbTx) + + if len(ret) == 0 { + panic("no return value specified for UpdateCheckedBlockByNumber") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, bool, entities.Tx) error); ok { + r0 = rf(ctx, blockNumber, newCheckedStatus, dbTx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Storer_UpdateCheckedBlockByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateCheckedBlockByNumber' +type Storer_UpdateCheckedBlockByNumber_Call struct { + *mock.Call +} + +// UpdateCheckedBlockByNumber is a helper method to define mock.On call +// - ctx context.Context +// - blockNumber uint64 +// - newCheckedStatus bool +// - dbTx entities.Tx +func (_e *Storer_Expecter) UpdateCheckedBlockByNumber(ctx interface{}, blockNumber interface{}, newCheckedStatus interface{}, dbTx interface{}) *Storer_UpdateCheckedBlockByNumber_Call { + return &Storer_UpdateCheckedBlockByNumber_Call{Call: _e.mock.On("UpdateCheckedBlockByNumber", ctx, blockNumber, newCheckedStatus, dbTx)} +} + +func (_c *Storer_UpdateCheckedBlockByNumber_Call) Run(run func(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx entities.Tx)) *Storer_UpdateCheckedBlockByNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(bool), args[3].(entities.Tx)) + }) + return _c +} + +func (_c *Storer_UpdateCheckedBlockByNumber_Call) Return(_a0 error) *Storer_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Storer_UpdateCheckedBlockByNumber_Call) RunAndReturn(run func(context.Context, uint64, bool, entities.Tx) error) *Storer_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(run) + return _c +} + // UpdateForkID provides a mock function with given fields: ctx, forkID, dbTx func (_m *Storer) UpdateForkID(ctx context.Context, forkID entities.ForkIDInterval, dbTx entities.Tx) error { ret := _m.Called(ctx, forkID, dbTx) diff --git a/state/mocks/tx_callback_type.go b/state/mocks/tx_callback_type.go new file mode 100644 index 0000000..f04bb30 --- /dev/null +++ b/state/mocks/tx_callback_type.go @@ -0,0 +1,69 @@ +// Code generated by mockery. DO NOT EDIT. + +package mock_state + +import ( + entities "github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities" + mock "github.com/stretchr/testify/mock" +) + +// TxCallbackType is an autogenerated mock type for the TxCallbackType type +type TxCallbackType struct { + mock.Mock +} + +type TxCallbackType_Expecter struct { + mock *mock.Mock +} + +func (_m *TxCallbackType) EXPECT() *TxCallbackType_Expecter { + return &TxCallbackType_Expecter{mock: &_m.Mock} +} + +// Execute provides a mock function with given fields: _a0, _a1 +func (_m *TxCallbackType) Execute(_a0 entities.Tx, _a1 error) { + _m.Called(_a0, _a1) +} + +// TxCallbackType_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' +type TxCallbackType_Execute_Call struct { + *mock.Call +} + +// Execute is a helper method to define mock.On call +// - _a0 entities.Tx +// - _a1 error +func (_e *TxCallbackType_Expecter) Execute(_a0 interface{}, _a1 interface{}) *TxCallbackType_Execute_Call { + return &TxCallbackType_Execute_Call{Call: _e.mock.On("Execute", _a0, _a1)} +} + +func (_c *TxCallbackType_Execute_Call) Run(run func(_a0 entities.Tx, _a1 error)) *TxCallbackType_Execute_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(entities.Tx), args[1].(error)) + }) + return _c +} + +func (_c *TxCallbackType_Execute_Call) Return() *TxCallbackType_Execute_Call { + _c.Call.Return() + return _c +} + +func (_c *TxCallbackType_Execute_Call) RunAndReturn(run func(entities.Tx, error)) *TxCallbackType_Execute_Call { + _c.Call.Return(run) + return _c +} + +// NewTxCallbackType creates a new instance of TxCallbackType. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTxCallbackType(t interface { + mock.TestingT + Cleanup(func()) +}) *TxCallbackType { + mock := &TxCallbackType{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/state/model/mocks/storage_reorg_interface.go b/state/model/mocks/storage_reorg_interface.go new file mode 100644 index 0000000..a57f07f --- /dev/null +++ b/state/model/mocks/storage_reorg_interface.go @@ -0,0 +1,85 @@ +// Code generated by mockery. DO NOT EDIT. + +package mock_model + +import ( + context "context" + + entities "github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities" + mock "github.com/stretchr/testify/mock" +) + +// StorageReorgInterface is an autogenerated mock type for the StorageReorgInterface type +type StorageReorgInterface struct { + mock.Mock +} + +type StorageReorgInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *StorageReorgInterface) EXPECT() *StorageReorgInterface_Expecter { + return &StorageReorgInterface_Expecter{mock: &_m.Mock} +} + +// ResetToL1BlockNumber provides a mock function with given fields: ctx, firstBlockNumberToKeep, dbTx +func (_m *StorageReorgInterface) ResetToL1BlockNumber(ctx context.Context, firstBlockNumberToKeep uint64, dbTx entities.Tx) error { + ret := _m.Called(ctx, firstBlockNumberToKeep, dbTx) + + if len(ret) == 0 { + panic("no return value specified for ResetToL1BlockNumber") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, entities.Tx) error); ok { + r0 = rf(ctx, firstBlockNumberToKeep, dbTx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// StorageReorgInterface_ResetToL1BlockNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ResetToL1BlockNumber' +type StorageReorgInterface_ResetToL1BlockNumber_Call struct { + *mock.Call +} + +// ResetToL1BlockNumber is a helper method to define mock.On call +// - ctx context.Context +// - firstBlockNumberToKeep uint64 +// - dbTx entities.Tx +func (_e *StorageReorgInterface_Expecter) ResetToL1BlockNumber(ctx interface{}, firstBlockNumberToKeep interface{}, dbTx interface{}) *StorageReorgInterface_ResetToL1BlockNumber_Call { + return &StorageReorgInterface_ResetToL1BlockNumber_Call{Call: _e.mock.On("ResetToL1BlockNumber", ctx, firstBlockNumberToKeep, dbTx)} +} + +func (_c *StorageReorgInterface_ResetToL1BlockNumber_Call) Run(run func(ctx context.Context, firstBlockNumberToKeep uint64, dbTx entities.Tx)) *StorageReorgInterface_ResetToL1BlockNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(entities.Tx)) + }) + return _c +} + +func (_c *StorageReorgInterface_ResetToL1BlockNumber_Call) Return(_a0 error) *StorageReorgInterface_ResetToL1BlockNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *StorageReorgInterface_ResetToL1BlockNumber_Call) RunAndReturn(run func(context.Context, uint64, entities.Tx) error) *StorageReorgInterface_ResetToL1BlockNumber_Call { + _c.Call.Return(run) + return _c +} + +// NewStorageReorgInterface creates a new instance of StorageReorgInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewStorageReorgInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *StorageReorgInterface { + mock := &StorageReorgInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/state/storage/interface.go b/state/storage/interface.go index 4e614ac..27ffb94 100644 --- a/state/storage/interface.go +++ b/state/storage/interface.go @@ -16,6 +16,7 @@ type storageTxType = entities.Tx type BlockStorer interface { AddBlock(ctx context.Context, block *L1Block, dbTx storageTxType) error + UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx storageTxType) error GetLastBlock(ctx context.Context, dbTx storageTxType) (*L1Block, error) GetBlockByNumber(ctx context.Context, blockNumber uint64, dbTx storageTxType) (*L1Block, error) GetPreviousBlock(ctx context.Context, offset uint64, fromBlockNumber *uint64, dbTx storageTxType) (*L1Block, error) diff --git a/state/storage/pgstorage/block.go b/state/storage/pgstorage/block.go index e3dec51..108dbee 100644 --- a/state/storage/pgstorage/block.go +++ b/state/storage/pgstorage/block.go @@ -17,6 +17,19 @@ func (p *PostgresStorage) AddBlock(ctx context.Context, block *L1Block, dbTx dbT return translatePgxError(err, fmt.Sprintf("AddBlock %d", block.Key())) } +// UpdateCheckedBlockByNumber update checked flag for a block +func (p *PostgresStorage) UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx dbTxType) error { + const query = ` + UPDATE sync.block + SET checked = $1 WHERE block_num = $2` + + e := p.getExecQuerier(getPgTx(dbTx)) + _, err := e.Exec(ctx, query, newCheckedStatus, blockNumber) + return err +} + +// -- READ FUNCTIONS --------------------------------- + // GetLastBlock returns the last L1 block. func (p *PostgresStorage) GetLastBlock(ctx context.Context, dbTx dbTxType) (*L1Block, error) { const getLastBlockSQL = "SELECT block_num, block_hash, parent_hash, received_at,checked, has_events,sync_version FROM sync.block ORDER BY block_num DESC LIMIT 1" @@ -44,7 +57,7 @@ func (p *PostgresStorage) GetPreviousBlock(ctx context.Context, offset uint64, f // GetFirstUncheckedBlock returns the first L1 block that has not been checked from a given block number. func (p *PostgresStorage) GetFirstUncheckedBlock(ctx context.Context, fromBlockNumber uint64, dbTx dbTxType) (*L1Block, error) { - const getLastBlockSQL = "SELECT block_num, block_hash, parent_hash, received_at, has_events,checked FROM sync.block WHERE block_num>=$1 AND checked=false ORDER BY block_num LIMIT 1" + const getLastBlockSQL = "SELECT block_num, block_hash, parent_hash, received_at,checked,has_events,sync_version FROM sync.block WHERE block_num>=$1 AND checked=false ORDER BY block_num LIMIT 1" return p.queryBlock(ctx, "GetFirstUncheckedBlock", getLastBlockSQL, dbTx, fromBlockNumber) } @@ -53,6 +66,7 @@ func (p *PostgresStorage) GetUncheckedBlocks(ctx context.Context, fromBlockNumbe const getUncheckedBlocksSQL = "SELECT block_num, block_hash, parent_hash, received_at,has_events, checked FROM sync.block WHERE block_num>=$1 AND block_num<=$2 AND checked=false ORDER BY block_num" return p.queryBlocks(ctx, "GetUncheckedBlocks", getUncheckedBlocksSQL, getPgTx(dbTx), fromBlockNumber, toBlockNumber) } + func (p *PostgresStorage) queryBlocks(ctx context.Context, desc string, sql string, dbTx pgx.Tx, args ...interface{}) (*[]L1Block, error) { q := p.getExecQuerier(dbTx) rows, err := q.Query(ctx, sql, args...) diff --git a/state/storage/pgstorage/block_test.go b/state/storage/pgstorage/block_test.go index 5ca4c8e..fb4881b 100644 --- a/state/storage/pgstorage/block_test.go +++ b/state/storage/pgstorage/block_test.go @@ -11,18 +11,8 @@ import ( "github.com/stretchr/testify/require" ) -func TestBlockAddAndGets(t *testing.T) { - skipDatabaseTestIfNeeded(t) - ctx := context.TODO() - dbConfig := getStorageConfig() - err := pgstorage.ResetDB(dbConfig) - require.NoError(t, err) - storage, err := pgstorage.NewPostgresStorage(dbConfig) - require.NoError(t, err) - dbTx, err := storage.BeginTransaction(ctx) - require.NoError(t, err) - defer func() { _ = dbTx.Commit(ctx) }() - block300 := pgstorage.L1Block{ +var ( + block300 = pgstorage.L1Block{ BlockNumber: 300, BlockHash: common.HexToHash("0x1234567890123456789012345678901234567890123456789012345678901234"), ParentHash: common.HexToHash("0x1234567890123456789012345678901234567890123456789012345678906789"), @@ -30,7 +20,7 @@ func TestBlockAddAndGets(t *testing.T) { Checked: false, SyncVersion: "test", } - block301 := pgstorage.L1Block{ + block301 = pgstorage.L1Block{ BlockNumber: 301, BlockHash: common.HexToHash("0x00"), ParentHash: common.HexToHash("0x12"), @@ -38,6 +28,27 @@ func TestBlockAddAndGets(t *testing.T) { Checked: true, SyncVersion: "test_2", } + block310 = pgstorage.L1Block{ + BlockNumber: 310, + BlockHash: common.HexToHash("0x00"), + ParentHash: common.HexToHash("0x12"), + ReceivedAt: time.Now().Truncate(time.Second), + Checked: true, + SyncVersion: "test_2", + } +) + +func TestBlockAddAndGets(t *testing.T) { + skipDatabaseTestIfNeeded(t) + ctx := context.TODO() + dbConfig := getStorageConfig() + err := pgstorage.ResetDB(dbConfig) + require.NoError(t, err) + storage, err := pgstorage.NewPostgresStorage(dbConfig) + require.NoError(t, err) + dbTx, err := storage.BeginTransaction(ctx) + require.NoError(t, err) + defer func() { _ = dbTx.Commit(ctx) }() tests := []struct { addBlock *pgstorage.L1Block queryLastBlock *pgstorage.L1Block @@ -78,30 +89,7 @@ func TestGetPreviousBlockFromBlock(t *testing.T) { dbTx, err := storage.BeginTransaction(ctx) require.NoError(t, err) defer func() { _ = dbTx.Commit(ctx) }() - block300 := pgstorage.L1Block{ - BlockNumber: 300, - BlockHash: common.HexToHash("0x1234567890123456789012345678901234567890123456789012345678901234"), - ParentHash: common.HexToHash("0x1234567890123456789012345678901234567890123456789012345678906789"), - ReceivedAt: time.Now().Truncate(time.Second), - Checked: false, - SyncVersion: "test", - } - block301 := pgstorage.L1Block{ - BlockNumber: 301, - BlockHash: common.HexToHash("0x00"), - ParentHash: common.HexToHash("0x12"), - ReceivedAt: time.Now().Truncate(time.Second), - Checked: true, - SyncVersion: "test_2", - } - block310 := pgstorage.L1Block{ - BlockNumber: 310, - BlockHash: common.HexToHash("0x00"), - ParentHash: common.HexToHash("0x12"), - ReceivedAt: time.Now().Truncate(time.Second), - Checked: true, - SyncVersion: "test_2", - } + err = storage.AddBlock(ctx, &block300, dbTx) require.NoError(t, err) err = storage.AddBlock(ctx, &block301, dbTx) @@ -128,3 +116,36 @@ func TestGetPreviousBlockFromBlock(t *testing.T) { require.Equal(t, block300.String(), block.String(), "offset 1 and fromBlock latest-1 must return 2 before to latest") } + +func TestUpdateCheckedBlockByNumber(t *testing.T) { + skipDatabaseTestIfNeeded(t) + ctx := context.TODO() + dbConfig := getStorageConfig() + err := pgstorage.ResetDB(dbConfig) + require.NoError(t, err) + storage, err := pgstorage.NewPostgresStorage(dbConfig) + require.NoError(t, err) + dbTx, err := storage.BeginTransaction(ctx) + require.NoError(t, err) + defer func() { _ = dbTx.Commit(ctx) }() + block := block300 + block.Checked = true + err = storage.AddBlock(ctx, &block, dbTx) + require.NoError(t, err) + err = storage.UpdateCheckedBlockByNumber(ctx, 300, false, dbTx) + require.NoError(t, err) + blockRead, err := storage.GetBlockByNumber(ctx, 300, dbTx) + require.NoError(t, err) + require.False(t, blockRead.Checked) + err = storage.UpdateCheckedBlockByNumber(ctx, 300, true, dbTx) + require.NoError(t, err) + blockRead, err = storage.GetBlockByNumber(ctx, 300, dbTx) + require.NoError(t, err) + require.True(t, blockRead.Checked) + err = storage.UpdateCheckedBlockByNumber(ctx, 300, false, dbTx) + require.NoError(t, err) + + blockRead, err = storage.GetFirstUncheckedBlock(ctx, 0, dbTx) + require.NoError(t, err) + require.Equal(t, block300.String(), blockRead.String()) +} diff --git a/synchronizer/common/syncinterfaces/storage.go b/synchronizer/common/syncinterfaces/storage.go index 9e7ba29..73295cb 100644 --- a/synchronizer/common/syncinterfaces/storage.go +++ b/synchronizer/common/syncinterfaces/storage.go @@ -10,12 +10,14 @@ import ( type StorageBlockWriterInterface interface { AddBlock(ctx context.Context, block *entities.L1Block, dbTx stateTxType) error + UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx stateTxType) error } type StorageBlockReaderInterface interface { GetLastBlock(ctx context.Context, dbTx stateTxType) (*entities.L1Block, error) AddBlock(ctx context.Context, block *entities.L1Block, dbTx stateTxType) error GetPreviousBlock(ctx context.Context, offset uint64, fromBlockNumber *uint64, dbTx stateTxType) (*entities.L1Block, error) + GetFirstUncheckedBlock(ctx context.Context, fromBlockNumber uint64, dbTx stateTxType) (*entities.L1Block, error) } type StorageForkIDInterface interface { diff --git a/synchronizer/l1_sync/l1_sequential_sync.go b/synchronizer/l1_sync/l1_sequential_sync.go index f65b7d8..6cbe67e 100644 --- a/synchronizer/l1_sync/l1_sequential_sync.go +++ b/synchronizer/l1_sync/l1_sequential_sync.go @@ -40,6 +40,9 @@ type ReorgManager interface { CheckReorg(latestBlock *stateBlockType, syncedBlock *etherman.Block) (*stateBlockType, uint64, error) } +type BlockChecker interface { + Step(ctx context.Context) error +} type L1SequentialSync struct { blockPointsRetriever BlockPointsRetriever etherMan EthermanInterface @@ -48,6 +51,7 @@ type L1SequentialSync struct { blockRangeProcessor BlockRangeProcessor reorgManager ReorgManager cfg L1SequentialSyncConfig + blockChecker BlockChecker } type L1SequentialSyncConfig struct { @@ -61,6 +65,7 @@ func NewL1SequentialSync(blockPointsRetriever BlockPointsRetriever, state StateL1SeqInterface, blockRangeProcessor BlockRangeProcessor, reorgManager ReorgManager, + blockChecker BlockChecker, cfg L1SequentialSyncConfig) *L1SequentialSync { return &L1SequentialSync{ blockPointsRetriever: blockPointsRetriever, @@ -68,6 +73,7 @@ func NewL1SequentialSync(blockPointsRetriever BlockPointsRetriever, state: state, blockRangeProcessor: blockRangeProcessor, reorgManager: reorgManager, + blockChecker: blockChecker, cfg: cfg, } } @@ -108,6 +114,14 @@ func (s *BlockPointsRetrieverImplementation) GetL1BlockPoints(ctx context.Contex // returns true if the sync is completed func (s *L1SequentialSync) SyncBlocksSequential(ctx context.Context, lastEthBlockSynced *stateBlockType) (*stateBlockType, bool, error) { // Call the blockchain to retrieve data + + if s.blockChecker != nil { + err := s.blockChecker.Step(ctx) + if err != nil { + return lastEthBlockSynced, false, err + } + } + blockPoints, err := s.blockPointsRetriever.GetL1BlockPoints(ctx) if err != nil { return lastEthBlockSynced, false, err diff --git a/synchronizer/l1_sync/l1_sequential_sync_test.go b/synchronizer/l1_sync/l1_sequential_sync_test.go index 7e1ca10..7b21175 100644 --- a/synchronizer/l1_sync/l1_sequential_sync_test.go +++ b/synchronizer/l1_sync/l1_sequential_sync_test.go @@ -67,7 +67,7 @@ func newL1SyncData(t *testing.T) *testL1SyncData { mockState := mock_l1sync.NewStateL1SeqInterface(t) mockBlockProcessor := mock_l1sync.NewBlockRangeProcessor(t) mockReorg := mock_l1sync.NewReorgManager(t) - sut := l1sync.NewL1SequentialSync(mockBlock, mockEth, mockState, mockBlockProcessor, mockReorg, l1sync.L1SequentialSyncConfig{ + sut := l1sync.NewL1SequentialSync(mockBlock, mockEth, mockState, mockBlockProcessor, mockReorg, nil, l1sync.L1SequentialSyncConfig{ SyncChunkSize: 100, GenesisBlockNumber: 123, }) diff --git a/synchronizer/l1_sync/mocks/block_checker.go b/synchronizer/l1_sync/mocks/block_checker.go new file mode 100644 index 0000000..b2550b6 --- /dev/null +++ b/synchronizer/l1_sync/mocks/block_checker.go @@ -0,0 +1,82 @@ +// Code generated by mockery. DO NOT EDIT. + +package mock_l1sync + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// BlockChecker is an autogenerated mock type for the BlockChecker type +type BlockChecker struct { + mock.Mock +} + +type BlockChecker_Expecter struct { + mock *mock.Mock +} + +func (_m *BlockChecker) EXPECT() *BlockChecker_Expecter { + return &BlockChecker_Expecter{mock: &_m.Mock} +} + +// Step provides a mock function with given fields: ctx +func (_m *BlockChecker) Step(ctx context.Context) error { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Step") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// BlockChecker_Step_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Step' +type BlockChecker_Step_Call struct { + *mock.Call +} + +// Step is a helper method to define mock.On call +// - ctx context.Context +func (_e *BlockChecker_Expecter) Step(ctx interface{}) *BlockChecker_Step_Call { + return &BlockChecker_Step_Call{Call: _e.mock.On("Step", ctx)} +} + +func (_c *BlockChecker_Step_Call) Run(run func(ctx context.Context)) *BlockChecker_Step_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *BlockChecker_Step_Call) Return(_a0 error) *BlockChecker_Step_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *BlockChecker_Step_Call) RunAndReturn(run func(context.Context) error) *BlockChecker_Step_Call { + _c.Call.Return(run) + return _c +} + +// NewBlockChecker creates a new instance of BlockChecker. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewBlockChecker(t interface { + mock.TestingT + Cleanup(func()) +}) *BlockChecker { + mock := &BlockChecker{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/synchronizer/mocks/block_checker.go b/synchronizer/mocks/block_checker.go new file mode 100644 index 0000000..9bf83cd --- /dev/null +++ b/synchronizer/mocks/block_checker.go @@ -0,0 +1,82 @@ +// Code generated by mockery. DO NOT EDIT. + +package mock_synchronizer + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// BlockChecker is an autogenerated mock type for the BlockChecker type +type BlockChecker struct { + mock.Mock +} + +type BlockChecker_Expecter struct { + mock *mock.Mock +} + +func (_m *BlockChecker) EXPECT() *BlockChecker_Expecter { + return &BlockChecker_Expecter{mock: &_m.Mock} +} + +// Step provides a mock function with given fields: ctx +func (_m *BlockChecker) Step(ctx context.Context) error { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Step") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// BlockChecker_Step_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Step' +type BlockChecker_Step_Call struct { + *mock.Call +} + +// Step is a helper method to define mock.On call +// - ctx context.Context +func (_e *BlockChecker_Expecter) Step(ctx interface{}) *BlockChecker_Step_Call { + return &BlockChecker_Step_Call{Call: _e.mock.On("Step", ctx)} +} + +func (_c *BlockChecker_Step_Call) Run(run func(ctx context.Context)) *BlockChecker_Step_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *BlockChecker_Step_Call) Return(_a0 error) *BlockChecker_Step_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *BlockChecker_Step_Call) RunAndReturn(run func(context.Context) error) *BlockChecker_Step_Call { + _c.Call.Return(run) + return _c +} + +// NewBlockChecker creates a new instance of BlockChecker. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewBlockChecker(t interface { + mock.TestingT + Cleanup(func()) +}) *BlockChecker { + mock := &BlockChecker{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/synchronizer/mocks/etherman_interface.go b/synchronizer/mocks/etherman_interface.go index 424e9b6..64677ff 100644 --- a/synchronizer/mocks/etherman_interface.go +++ b/synchronizer/mocks/etherman_interface.go @@ -4,15 +4,12 @@ package mock_synchronizer import ( context "context" - big "math/big" common "github.com/ethereum/go-ethereum/common" etherman "github.com/0xPolygonHermez/zkevm-synchronizer-l1/etherman" mock "github.com/stretchr/testify/mock" - - types "github.com/ethereum/go-ethereum/core/types" ) // EthermanInterface is an autogenerated mock type for the EthermanInterface type @@ -28,181 +25,6 @@ func (_m *EthermanInterface) EXPECT() *EthermanInterface_Expecter { return &EthermanInterface_Expecter{mock: &_m.Mock} } -// EthBlockByNumber provides a mock function with given fields: ctx, blockNumber -func (_m *EthermanInterface) EthBlockByNumber(ctx context.Context, blockNumber uint64) (*types.Block, error) { - ret := _m.Called(ctx, blockNumber) - - if len(ret) == 0 { - panic("no return value specified for EthBlockByNumber") - } - - var r0 *types.Block - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, uint64) (*types.Block, error)); ok { - return rf(ctx, blockNumber) - } - if rf, ok := ret.Get(0).(func(context.Context, uint64) *types.Block); ok { - r0 = rf(ctx, blockNumber) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Block) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, uint64) error); ok { - r1 = rf(ctx, blockNumber) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// EthermanInterface_EthBlockByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'EthBlockByNumber' -type EthermanInterface_EthBlockByNumber_Call struct { - *mock.Call -} - -// EthBlockByNumber is a helper method to define mock.On call -// - ctx context.Context -// - blockNumber uint64 -func (_e *EthermanInterface_Expecter) EthBlockByNumber(ctx interface{}, blockNumber interface{}) *EthermanInterface_EthBlockByNumber_Call { - return &EthermanInterface_EthBlockByNumber_Call{Call: _e.mock.On("EthBlockByNumber", ctx, blockNumber)} -} - -func (_c *EthermanInterface_EthBlockByNumber_Call) Run(run func(ctx context.Context, blockNumber uint64)) *EthermanInterface_EthBlockByNumber_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(uint64)) - }) - return _c -} - -func (_c *EthermanInterface_EthBlockByNumber_Call) Return(_a0 *types.Block, _a1 error) *EthermanInterface_EthBlockByNumber_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *EthermanInterface_EthBlockByNumber_Call) RunAndReturn(run func(context.Context, uint64) (*types.Block, error)) *EthermanInterface_EthBlockByNumber_Call { - _c.Call.Return(run) - return _c -} - -// GetFinalizedBlockNumber provides a mock function with given fields: ctx -func (_m *EthermanInterface) GetFinalizedBlockNumber(ctx context.Context) (uint64, error) { - ret := _m.Called(ctx) - - if len(ret) == 0 { - panic("no return value specified for GetFinalizedBlockNumber") - } - - var r0 uint64 - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { - return rf(ctx) - } - if rf, ok := ret.Get(0).(func(context.Context) uint64); ok { - r0 = rf(ctx) - } else { - r0 = ret.Get(0).(uint64) - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// EthermanInterface_GetFinalizedBlockNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetFinalizedBlockNumber' -type EthermanInterface_GetFinalizedBlockNumber_Call struct { - *mock.Call -} - -// GetFinalizedBlockNumber is a helper method to define mock.On call -// - ctx context.Context -func (_e *EthermanInterface_Expecter) GetFinalizedBlockNumber(ctx interface{}) *EthermanInterface_GetFinalizedBlockNumber_Call { - return &EthermanInterface_GetFinalizedBlockNumber_Call{Call: _e.mock.On("GetFinalizedBlockNumber", ctx)} -} - -func (_c *EthermanInterface_GetFinalizedBlockNumber_Call) Run(run func(ctx context.Context)) *EthermanInterface_GetFinalizedBlockNumber_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context)) - }) - return _c -} - -func (_c *EthermanInterface_GetFinalizedBlockNumber_Call) Return(_a0 uint64, _a1 error) *EthermanInterface_GetFinalizedBlockNumber_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *EthermanInterface_GetFinalizedBlockNumber_Call) RunAndReturn(run func(context.Context) (uint64, error)) *EthermanInterface_GetFinalizedBlockNumber_Call { - _c.Call.Return(run) - return _c -} - -// GetForks provides a mock function with given fields: ctx, genBlockNumber, lastL1BlockSynced -func (_m *EthermanInterface) GetForks(ctx context.Context, genBlockNumber uint64, lastL1BlockSynced uint64) ([]etherman.ForkIDInterval, error) { - ret := _m.Called(ctx, genBlockNumber, lastL1BlockSynced) - - if len(ret) == 0 { - panic("no return value specified for GetForks") - } - - var r0 []etherman.ForkIDInterval - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) ([]etherman.ForkIDInterval, error)); ok { - return rf(ctx, genBlockNumber, lastL1BlockSynced) - } - if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) []etherman.ForkIDInterval); ok { - r0 = rf(ctx, genBlockNumber, lastL1BlockSynced) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]etherman.ForkIDInterval) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, uint64, uint64) error); ok { - r1 = rf(ctx, genBlockNumber, lastL1BlockSynced) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// EthermanInterface_GetForks_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetForks' -type EthermanInterface_GetForks_Call struct { - *mock.Call -} - -// GetForks is a helper method to define mock.On call -// - ctx context.Context -// - genBlockNumber uint64 -// - lastL1BlockSynced uint64 -func (_e *EthermanInterface_Expecter) GetForks(ctx interface{}, genBlockNumber interface{}, lastL1BlockSynced interface{}) *EthermanInterface_GetForks_Call { - return &EthermanInterface_GetForks_Call{Call: _e.mock.On("GetForks", ctx, genBlockNumber, lastL1BlockSynced)} -} - -func (_c *EthermanInterface_GetForks_Call) Run(run func(ctx context.Context, genBlockNumber uint64, lastL1BlockSynced uint64)) *EthermanInterface_GetForks_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(uint64), args[2].(uint64)) - }) - return _c -} - -func (_c *EthermanInterface_GetForks_Call) Return(_a0 []etherman.ForkIDInterval, _a1 error) *EthermanInterface_GetForks_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *EthermanInterface_GetForks_Call) RunAndReturn(run func(context.Context, uint64, uint64) ([]etherman.ForkIDInterval, error)) *EthermanInterface_GetForks_Call { - _c.Call.Return(run) - return _c -} - // GetL1BlockByNumber provides a mock function with given fields: ctx, blockNumber func (_m *EthermanInterface) GetL1BlockByNumber(ctx context.Context, blockNumber uint64) (*etherman.Block, error) { ret := _m.Called(ctx, blockNumber) @@ -262,108 +84,6 @@ func (_c *EthermanInterface_GetL1BlockByNumber_Call) RunAndReturn(run func(conte return _c } -// GetL1BlockUpgradeLxLy provides a mock function with given fields: ctx, genesisBlock -func (_m *EthermanInterface) GetL1BlockUpgradeLxLy(ctx context.Context, genesisBlock *uint64) (uint64, error) { - ret := _m.Called(ctx, genesisBlock) - - if len(ret) == 0 { - panic("no return value specified for GetL1BlockUpgradeLxLy") - } - - var r0 uint64 - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *uint64) (uint64, error)); ok { - return rf(ctx, genesisBlock) - } - if rf, ok := ret.Get(0).(func(context.Context, *uint64) uint64); ok { - r0 = rf(ctx, genesisBlock) - } else { - r0 = ret.Get(0).(uint64) - } - - if rf, ok := ret.Get(1).(func(context.Context, *uint64) error); ok { - r1 = rf(ctx, genesisBlock) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// EthermanInterface_GetL1BlockUpgradeLxLy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetL1BlockUpgradeLxLy' -type EthermanInterface_GetL1BlockUpgradeLxLy_Call struct { - *mock.Call -} - -// GetL1BlockUpgradeLxLy is a helper method to define mock.On call -// - ctx context.Context -// - genesisBlock *uint64 -func (_e *EthermanInterface_Expecter) GetL1BlockUpgradeLxLy(ctx interface{}, genesisBlock interface{}) *EthermanInterface_GetL1BlockUpgradeLxLy_Call { - return &EthermanInterface_GetL1BlockUpgradeLxLy_Call{Call: _e.mock.On("GetL1BlockUpgradeLxLy", ctx, genesisBlock)} -} - -func (_c *EthermanInterface_GetL1BlockUpgradeLxLy_Call) Run(run func(ctx context.Context, genesisBlock *uint64)) *EthermanInterface_GetL1BlockUpgradeLxLy_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*uint64)) - }) - return _c -} - -func (_c *EthermanInterface_GetL1BlockUpgradeLxLy_Call) Return(_a0 uint64, _a1 error) *EthermanInterface_GetL1BlockUpgradeLxLy_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *EthermanInterface_GetL1BlockUpgradeLxLy_Call) RunAndReturn(run func(context.Context, *uint64) (uint64, error)) *EthermanInterface_GetL1BlockUpgradeLxLy_Call { - _c.Call.Return(run) - return _c -} - -// GetRollupID provides a mock function with given fields: -func (_m *EthermanInterface) GetRollupID() uint { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for GetRollupID") - } - - var r0 uint - if rf, ok := ret.Get(0).(func() uint); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(uint) - } - - return r0 -} - -// EthermanInterface_GetRollupID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRollupID' -type EthermanInterface_GetRollupID_Call struct { - *mock.Call -} - -// GetRollupID is a helper method to define mock.On call -func (_e *EthermanInterface_Expecter) GetRollupID() *EthermanInterface_GetRollupID_Call { - return &EthermanInterface_GetRollupID_Call{Call: _e.mock.On("GetRollupID")} -} - -func (_c *EthermanInterface_GetRollupID_Call) Run(run func()) *EthermanInterface_GetRollupID_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *EthermanInterface_GetRollupID_Call) Return(_a0 uint) *EthermanInterface_GetRollupID_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *EthermanInterface_GetRollupID_Call) RunAndReturn(run func() uint) *EthermanInterface_GetRollupID_Call { - _c.Call.Return(run) - return _c -} - // GetRollupInfoByBlockRange provides a mock function with given fields: ctx, fromBlock, toBlock func (_m *EthermanInterface) GetRollupInfoByBlockRange(ctx context.Context, fromBlock uint64, toBlock *uint64) ([]etherman.Block, map[common.Hash][]etherman.Order, error) { ret := _m.Called(ctx, fromBlock, toBlock) @@ -433,65 +153,6 @@ func (_c *EthermanInterface_GetRollupInfoByBlockRange_Call) RunAndReturn(run fun return _c } -// HeaderByNumber provides a mock function with given fields: ctx, number -func (_m *EthermanInterface) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { - ret := _m.Called(ctx, number) - - if len(ret) == 0 { - panic("no return value specified for HeaderByNumber") - } - - var r0 *types.Header - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*types.Header, error)); ok { - return rf(ctx, number) - } - if rf, ok := ret.Get(0).(func(context.Context, *big.Int) *types.Header); ok { - r0 = rf(ctx, number) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Header) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, *big.Int) error); ok { - r1 = rf(ctx, number) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// EthermanInterface_HeaderByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HeaderByNumber' -type EthermanInterface_HeaderByNumber_Call struct { - *mock.Call -} - -// HeaderByNumber is a helper method to define mock.On call -// - ctx context.Context -// - number *big.Int -func (_e *EthermanInterface_Expecter) HeaderByNumber(ctx interface{}, number interface{}) *EthermanInterface_HeaderByNumber_Call { - return &EthermanInterface_HeaderByNumber_Call{Call: _e.mock.On("HeaderByNumber", ctx, number)} -} - -func (_c *EthermanInterface_HeaderByNumber_Call) Run(run func(ctx context.Context, number *big.Int)) *EthermanInterface_HeaderByNumber_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*big.Int)) - }) - return _c -} - -func (_c *EthermanInterface_HeaderByNumber_Call) Return(_a0 *types.Header, _a1 error) *EthermanInterface_HeaderByNumber_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *EthermanInterface_HeaderByNumber_Call) RunAndReturn(run func(context.Context, *big.Int) (*types.Header, error)) *EthermanInterface_HeaderByNumber_Call { - _c.Call.Return(run) - return _c -} - // NewEthermanInterface creates a new instance of EthermanInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewEthermanInterface(t interface { diff --git a/synchronizer/mocks/state_reorg_manager.go b/synchronizer/mocks/state_reorg_manager.go new file mode 100644 index 0000000..52718b7 --- /dev/null +++ b/synchronizer/mocks/state_reorg_manager.go @@ -0,0 +1,120 @@ +// Code generated by mockery. DO NOT EDIT. + +package mock_synchronizer + +import ( + context "context" + + entities "github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities" + mock "github.com/stretchr/testify/mock" + + model "github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/model" +) + +// stateReorgManager is an autogenerated mock type for the stateReorgManager type +type stateReorgManager struct { + mock.Mock +} + +type stateReorgManager_Expecter struct { + mock *mock.Mock +} + +func (_m *stateReorgManager) EXPECT() *stateReorgManager_Expecter { + return &stateReorgManager_Expecter{mock: &_m.Mock} +} + +// AddOnReorgCallback provides a mock function with given fields: f +func (_m *stateReorgManager) AddOnReorgCallback(f func(model.ReorgExecutionResult)) { + _m.Called(f) +} + +// stateReorgManager_AddOnReorgCallback_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddOnReorgCallback' +type stateReorgManager_AddOnReorgCallback_Call struct { + *mock.Call +} + +// AddOnReorgCallback is a helper method to define mock.On call +// - f func(model.ReorgExecutionResult) +func (_e *stateReorgManager_Expecter) AddOnReorgCallback(f interface{}) *stateReorgManager_AddOnReorgCallback_Call { + return &stateReorgManager_AddOnReorgCallback_Call{Call: _e.mock.On("AddOnReorgCallback", f)} +} + +func (_c *stateReorgManager_AddOnReorgCallback_Call) Run(run func(f func(model.ReorgExecutionResult))) *stateReorgManager_AddOnReorgCallback_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(func(model.ReorgExecutionResult))) + }) + return _c +} + +func (_c *stateReorgManager_AddOnReorgCallback_Call) Return() *stateReorgManager_AddOnReorgCallback_Call { + _c.Call.Return() + return _c +} + +func (_c *stateReorgManager_AddOnReorgCallback_Call) RunAndReturn(run func(func(model.ReorgExecutionResult))) *stateReorgManager_AddOnReorgCallback_Call { + _c.Call.Return(run) + return _c +} + +// ExecuteReorg provides a mock function with given fields: ctx, reorgRequest, dbTx +func (_m *stateReorgManager) ExecuteReorg(ctx context.Context, reorgRequest model.ReorgRequest, dbTx entities.Tx) model.ReorgExecutionResult { + ret := _m.Called(ctx, reorgRequest, dbTx) + + if len(ret) == 0 { + panic("no return value specified for ExecuteReorg") + } + + var r0 model.ReorgExecutionResult + if rf, ok := ret.Get(0).(func(context.Context, model.ReorgRequest, entities.Tx) model.ReorgExecutionResult); ok { + r0 = rf(ctx, reorgRequest, dbTx) + } else { + r0 = ret.Get(0).(model.ReorgExecutionResult) + } + + return r0 +} + +// stateReorgManager_ExecuteReorg_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ExecuteReorg' +type stateReorgManager_ExecuteReorg_Call struct { + *mock.Call +} + +// ExecuteReorg is a helper method to define mock.On call +// - ctx context.Context +// - reorgRequest model.ReorgRequest +// - dbTx entities.Tx +func (_e *stateReorgManager_Expecter) ExecuteReorg(ctx interface{}, reorgRequest interface{}, dbTx interface{}) *stateReorgManager_ExecuteReorg_Call { + return &stateReorgManager_ExecuteReorg_Call{Call: _e.mock.On("ExecuteReorg", ctx, reorgRequest, dbTx)} +} + +func (_c *stateReorgManager_ExecuteReorg_Call) Run(run func(ctx context.Context, reorgRequest model.ReorgRequest, dbTx entities.Tx)) *stateReorgManager_ExecuteReorg_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(model.ReorgRequest), args[2].(entities.Tx)) + }) + return _c +} + +func (_c *stateReorgManager_ExecuteReorg_Call) Return(_a0 model.ReorgExecutionResult) *stateReorgManager_ExecuteReorg_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *stateReorgManager_ExecuteReorg_Call) RunAndReturn(run func(context.Context, model.ReorgRequest, entities.Tx) model.ReorgExecutionResult) *stateReorgManager_ExecuteReorg_Call { + _c.Call.Return(run) + return _c +} + +// newStateReorgManager creates a new instance of stateReorgManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newStateReorgManager(t interface { + mock.TestingT + Cleanup(func()) +}) *stateReorgManager { + mock := &stateReorgManager{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/synchronizer/mocks/storage_block_reader_interface.go b/synchronizer/mocks/storage_block_reader_interface.go index e3168d1..6e1d2c8 100644 --- a/synchronizer/mocks/storage_block_reader_interface.go +++ b/synchronizer/mocks/storage_block_reader_interface.go @@ -70,6 +70,66 @@ func (_c *StorageBlockReaderInterface_AddBlock_Call) RunAndReturn(run func(conte return _c } +// GetFirstUncheckedBlock provides a mock function with given fields: ctx, fromBlockNumber, dbTx +func (_m *StorageBlockReaderInterface) GetFirstUncheckedBlock(ctx context.Context, fromBlockNumber uint64, dbTx entities.Tx) (*entities.L1Block, error) { + ret := _m.Called(ctx, fromBlockNumber, dbTx) + + if len(ret) == 0 { + panic("no return value specified for GetFirstUncheckedBlock") + } + + var r0 *entities.L1Block + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, entities.Tx) (*entities.L1Block, error)); ok { + return rf(ctx, fromBlockNumber, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, uint64, entities.Tx) *entities.L1Block); ok { + r0 = rf(ctx, fromBlockNumber, dbTx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*entities.L1Block) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, uint64, entities.Tx) error); ok { + r1 = rf(ctx, fromBlockNumber, dbTx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// StorageBlockReaderInterface_GetFirstUncheckedBlock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetFirstUncheckedBlock' +type StorageBlockReaderInterface_GetFirstUncheckedBlock_Call struct { + *mock.Call +} + +// GetFirstUncheckedBlock is a helper method to define mock.On call +// - ctx context.Context +// - fromBlockNumber uint64 +// - dbTx entities.Tx +func (_e *StorageBlockReaderInterface_Expecter) GetFirstUncheckedBlock(ctx interface{}, fromBlockNumber interface{}, dbTx interface{}) *StorageBlockReaderInterface_GetFirstUncheckedBlock_Call { + return &StorageBlockReaderInterface_GetFirstUncheckedBlock_Call{Call: _e.mock.On("GetFirstUncheckedBlock", ctx, fromBlockNumber, dbTx)} +} + +func (_c *StorageBlockReaderInterface_GetFirstUncheckedBlock_Call) Run(run func(ctx context.Context, fromBlockNumber uint64, dbTx entities.Tx)) *StorageBlockReaderInterface_GetFirstUncheckedBlock_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(entities.Tx)) + }) + return _c +} + +func (_c *StorageBlockReaderInterface_GetFirstUncheckedBlock_Call) Return(_a0 *entities.L1Block, _a1 error) *StorageBlockReaderInterface_GetFirstUncheckedBlock_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *StorageBlockReaderInterface_GetFirstUncheckedBlock_Call) RunAndReturn(run func(context.Context, uint64, entities.Tx) (*entities.L1Block, error)) *StorageBlockReaderInterface_GetFirstUncheckedBlock_Call { + _c.Call.Return(run) + return _c +} + // GetLastBlock provides a mock function with given fields: ctx, dbTx func (_m *StorageBlockReaderInterface) GetLastBlock(ctx context.Context, dbTx entities.Tx) (*entities.L1Block, error) { ret := _m.Called(ctx, dbTx) diff --git a/synchronizer/mocks/storage_block_writer_interface.go b/synchronizer/mocks/storage_block_writer_interface.go index fe000d3..9346e2a 100644 --- a/synchronizer/mocks/storage_block_writer_interface.go +++ b/synchronizer/mocks/storage_block_writer_interface.go @@ -70,6 +70,55 @@ func (_c *StorageBlockWriterInterface_AddBlock_Call) RunAndReturn(run func(conte return _c } +// UpdateCheckedBlockByNumber provides a mock function with given fields: ctx, blockNumber, newCheckedStatus, dbTx +func (_m *StorageBlockWriterInterface) UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx entities.Tx) error { + ret := _m.Called(ctx, blockNumber, newCheckedStatus, dbTx) + + if len(ret) == 0 { + panic("no return value specified for UpdateCheckedBlockByNumber") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, bool, entities.Tx) error); ok { + r0 = rf(ctx, blockNumber, newCheckedStatus, dbTx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// StorageBlockWriterInterface_UpdateCheckedBlockByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateCheckedBlockByNumber' +type StorageBlockWriterInterface_UpdateCheckedBlockByNumber_Call struct { + *mock.Call +} + +// UpdateCheckedBlockByNumber is a helper method to define mock.On call +// - ctx context.Context +// - blockNumber uint64 +// - newCheckedStatus bool +// - dbTx entities.Tx +func (_e *StorageBlockWriterInterface_Expecter) UpdateCheckedBlockByNumber(ctx interface{}, blockNumber interface{}, newCheckedStatus interface{}, dbTx interface{}) *StorageBlockWriterInterface_UpdateCheckedBlockByNumber_Call { + return &StorageBlockWriterInterface_UpdateCheckedBlockByNumber_Call{Call: _e.mock.On("UpdateCheckedBlockByNumber", ctx, blockNumber, newCheckedStatus, dbTx)} +} + +func (_c *StorageBlockWriterInterface_UpdateCheckedBlockByNumber_Call) Run(run func(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx entities.Tx)) *StorageBlockWriterInterface_UpdateCheckedBlockByNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(bool), args[3].(entities.Tx)) + }) + return _c +} + +func (_c *StorageBlockWriterInterface_UpdateCheckedBlockByNumber_Call) Return(_a0 error) *StorageBlockWriterInterface_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *StorageBlockWriterInterface_UpdateCheckedBlockByNumber_Call) RunAndReturn(run func(context.Context, uint64, bool, entities.Tx) error) *StorageBlockWriterInterface_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(run) + return _c +} + // NewStorageBlockWriterInterface creates a new instance of StorageBlockWriterInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewStorageBlockWriterInterface(t interface { diff --git a/synchronizer/mocks/storage_interface.go b/synchronizer/mocks/storage_interface.go index 452fd73..6c481f1 100644 --- a/synchronizer/mocks/storage_interface.go +++ b/synchronizer/mocks/storage_interface.go @@ -276,6 +276,66 @@ func (_c *StorageInterface_GetAllL1InfoTreeLeaves_Call) RunAndReturn(run func(co return _c } +// GetFirstUncheckedBlock provides a mock function with given fields: ctx, fromBlockNumber, dbTx +func (_m *StorageInterface) GetFirstUncheckedBlock(ctx context.Context, fromBlockNumber uint64, dbTx entities.Tx) (*entities.L1Block, error) { + ret := _m.Called(ctx, fromBlockNumber, dbTx) + + if len(ret) == 0 { + panic("no return value specified for GetFirstUncheckedBlock") + } + + var r0 *entities.L1Block + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, entities.Tx) (*entities.L1Block, error)); ok { + return rf(ctx, fromBlockNumber, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, uint64, entities.Tx) *entities.L1Block); ok { + r0 = rf(ctx, fromBlockNumber, dbTx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*entities.L1Block) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, uint64, entities.Tx) error); ok { + r1 = rf(ctx, fromBlockNumber, dbTx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// StorageInterface_GetFirstUncheckedBlock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetFirstUncheckedBlock' +type StorageInterface_GetFirstUncheckedBlock_Call struct { + *mock.Call +} + +// GetFirstUncheckedBlock is a helper method to define mock.On call +// - ctx context.Context +// - fromBlockNumber uint64 +// - dbTx entities.Tx +func (_e *StorageInterface_Expecter) GetFirstUncheckedBlock(ctx interface{}, fromBlockNumber interface{}, dbTx interface{}) *StorageInterface_GetFirstUncheckedBlock_Call { + return &StorageInterface_GetFirstUncheckedBlock_Call{Call: _e.mock.On("GetFirstUncheckedBlock", ctx, fromBlockNumber, dbTx)} +} + +func (_c *StorageInterface_GetFirstUncheckedBlock_Call) Run(run func(ctx context.Context, fromBlockNumber uint64, dbTx entities.Tx)) *StorageInterface_GetFirstUncheckedBlock_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(entities.Tx)) + }) + return _c +} + +func (_c *StorageInterface_GetFirstUncheckedBlock_Call) Return(_a0 *entities.L1Block, _a1 error) *StorageInterface_GetFirstUncheckedBlock_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *StorageInterface_GetFirstUncheckedBlock_Call) RunAndReturn(run func(context.Context, uint64, entities.Tx) (*entities.L1Block, error)) *StorageInterface_GetFirstUncheckedBlock_Call { + _c.Call.Return(run) + return _c +} + // GetForkIDs provides a mock function with given fields: ctx, dbTx func (_m *StorageInterface) GetForkIDs(ctx context.Context, dbTx entities.Tx) ([]entities.ForkIDInterval, error) { ret := _m.Called(ctx, dbTx) @@ -694,6 +754,55 @@ func (_c *StorageInterface_GetSequenceByBatchNumber_Call) RunAndReturn(run func( return _c } +// UpdateCheckedBlockByNumber provides a mock function with given fields: ctx, blockNumber, newCheckedStatus, dbTx +func (_m *StorageInterface) UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx entities.Tx) error { + ret := _m.Called(ctx, blockNumber, newCheckedStatus, dbTx) + + if len(ret) == 0 { + panic("no return value specified for UpdateCheckedBlockByNumber") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, bool, entities.Tx) error); ok { + r0 = rf(ctx, blockNumber, newCheckedStatus, dbTx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// StorageInterface_UpdateCheckedBlockByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateCheckedBlockByNumber' +type StorageInterface_UpdateCheckedBlockByNumber_Call struct { + *mock.Call +} + +// UpdateCheckedBlockByNumber is a helper method to define mock.On call +// - ctx context.Context +// - blockNumber uint64 +// - newCheckedStatus bool +// - dbTx entities.Tx +func (_e *StorageInterface_Expecter) UpdateCheckedBlockByNumber(ctx interface{}, blockNumber interface{}, newCheckedStatus interface{}, dbTx interface{}) *StorageInterface_UpdateCheckedBlockByNumber_Call { + return &StorageInterface_UpdateCheckedBlockByNumber_Call{Call: _e.mock.On("UpdateCheckedBlockByNumber", ctx, blockNumber, newCheckedStatus, dbTx)} +} + +func (_c *StorageInterface_UpdateCheckedBlockByNumber_Call) Run(run func(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx entities.Tx)) *StorageInterface_UpdateCheckedBlockByNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(bool), args[3].(entities.Tx)) + }) + return _c +} + +func (_c *StorageInterface_UpdateCheckedBlockByNumber_Call) Return(_a0 error) *StorageInterface_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *StorageInterface_UpdateCheckedBlockByNumber_Call) RunAndReturn(run func(context.Context, uint64, bool, entities.Tx) error) *StorageInterface_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(run) + return _c +} + // UpdateForkID provides a mock function with given fields: ctx, forkID, dbTx func (_m *StorageInterface) UpdateForkID(ctx context.Context, forkID entities.ForkIDInterval, dbTx entities.Tx) error { ret := _m.Called(ctx, forkID, dbTx) diff --git a/synchronizer/mocks/storage_sync_queries.go b/synchronizer/mocks/storage_sync_queries.go index 3e5db86..31a8346 100644 --- a/synchronizer/mocks/storage_sync_queries.go +++ b/synchronizer/mocks/storage_sync_queries.go @@ -120,6 +120,66 @@ func (_c *storageSyncQueries_AddSequencedBatches_Call) RunAndReturn(run func(con return _c } +// GetFirstUncheckedBlock provides a mock function with given fields: ctx, fromBlockNumber, dbTx +func (_m *storageSyncQueries) GetFirstUncheckedBlock(ctx context.Context, fromBlockNumber uint64, dbTx entities.Tx) (*entities.L1Block, error) { + ret := _m.Called(ctx, fromBlockNumber, dbTx) + + if len(ret) == 0 { + panic("no return value specified for GetFirstUncheckedBlock") + } + + var r0 *entities.L1Block + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, entities.Tx) (*entities.L1Block, error)); ok { + return rf(ctx, fromBlockNumber, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, uint64, entities.Tx) *entities.L1Block); ok { + r0 = rf(ctx, fromBlockNumber, dbTx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*entities.L1Block) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, uint64, entities.Tx) error); ok { + r1 = rf(ctx, fromBlockNumber, dbTx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// storageSyncQueries_GetFirstUncheckedBlock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetFirstUncheckedBlock' +type storageSyncQueries_GetFirstUncheckedBlock_Call struct { + *mock.Call +} + +// GetFirstUncheckedBlock is a helper method to define mock.On call +// - ctx context.Context +// - fromBlockNumber uint64 +// - dbTx entities.Tx +func (_e *storageSyncQueries_Expecter) GetFirstUncheckedBlock(ctx interface{}, fromBlockNumber interface{}, dbTx interface{}) *storageSyncQueries_GetFirstUncheckedBlock_Call { + return &storageSyncQueries_GetFirstUncheckedBlock_Call{Call: _e.mock.On("GetFirstUncheckedBlock", ctx, fromBlockNumber, dbTx)} +} + +func (_c *storageSyncQueries_GetFirstUncheckedBlock_Call) Run(run func(ctx context.Context, fromBlockNumber uint64, dbTx entities.Tx)) *storageSyncQueries_GetFirstUncheckedBlock_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(entities.Tx)) + }) + return _c +} + +func (_c *storageSyncQueries_GetFirstUncheckedBlock_Call) Return(_a0 *entities.L1Block, _a1 error) *storageSyncQueries_GetFirstUncheckedBlock_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *storageSyncQueries_GetFirstUncheckedBlock_Call) RunAndReturn(run func(context.Context, uint64, entities.Tx) (*entities.L1Block, error)) *storageSyncQueries_GetFirstUncheckedBlock_Call { + _c.Call.Return(run) + return _c +} + // GetLastBlock provides a mock function with given fields: ctx, dbTx func (_m *storageSyncQueries) GetLastBlock(ctx context.Context, dbTx entities.Tx) (*entities.L1Block, error) { ret := _m.Called(ctx, dbTx) diff --git a/synchronizer/synchronizer_impl.go b/synchronizer/synchronizer_impl.go index 08bc5de..1e8c4df 100644 --- a/synchronizer/synchronizer_impl.go +++ b/synchronizer/synchronizer_impl.go @@ -78,16 +78,18 @@ func NewSynchronizerImpl( log.Infof("First block from the blockchain: %d (ETROG)", firstBlock) sync.genBlockNumber = firstBlock } - //TODO: Add blockRetriever - // TODO: Add Reorg object + finalizedBlockNumberFetcher := l1_check_block.NewSafeL1BlockNumberFetch(l1_check_block.FinalizedBlockNumber, 0) reorgManager := l1sync.NewCheckReorgManager(ctx, ethMan, state, nil, sync.genBlockNumber) blocksRetriever := l1sync.NewBlockPointsRetriever( - l1_check_block.NewSafeL1BlockNumberFetch(l1_check_block.FinalizedBlockNumber, 0), + finalizedBlockNumberFetcher, l1_check_block.NewSafeL1BlockNumberFetch(l1_check_block.SafeBlockNumber, 0), ethMan, ) + checkl1blocks := l1_check_block.NewCheckL1BlockHash(ethMan, storage, finalizedBlockNumberFetcher) - sync.l1Sync = l1sync.NewL1SequentialSync(blocksRetriever, ethMan, state, sync.blockRangeProcessor, reorgManager, + sync.l1Sync = l1sync.NewL1SequentialSync(blocksRetriever, ethMan, state, + sync.blockRangeProcessor, reorgManager, + checkl1blocks, l1sync.L1SequentialSyncConfig{ SyncChunkSize: cfg.SyncChunkSize, GenesisBlockNumber: sync.genBlockNumber,