diff --git a/db/migrations/state/0018.sql b/db/migrations/state/0018.sql new file mode 100644 index 0000000000..3d9db107c1 --- /dev/null +++ b/db/migrations/state/0018.sql @@ -0,0 +1,11 @@ +-- +migrate Up +ALTER TABLE state.block + ADD COLUMN IF NOT EXISTS checked BOOL NOT NULL DEFAULT FALSE; + +-- set block.checked to true for all blocks below max - 100 +UPDATE state.block SET checked = true WHERE block_num <= (SELECT MAX(block_num) - 1000 FROM state.block); + +-- +migrate Down +ALTER TABLE state.block + DROP COLUMN IF EXISTS checked; + diff --git a/db/migrations/state/0018_test.go b/db/migrations/state/0018_test.go new file mode 100644 index 0000000000..b8a51dbb49 --- /dev/null +++ b/db/migrations/state/0018_test.go @@ -0,0 +1,69 @@ +package migrations_test + +import ( + "database/sql" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +type migrationTest0018 struct{} + +func (m migrationTest0018) InsertData(db *sql.DB) error { + const addBlock = "INSERT INTO state.block (block_num, received_at, block_hash) VALUES ($1, $2, $3)" + if _, err := db.Exec(addBlock, 1, time.Now(), "0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1"); err != nil { + return err + } + if _, err := db.Exec(addBlock, 50, time.Now(), "0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1"); err != nil { + return err + } + if _, err := db.Exec(addBlock, 1050, time.Now(), "0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1"); err != nil { + return err + } + return nil +} + +func (m migrationTest0018) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB) { + var checked bool + row := db.QueryRow("SELECT checked FROM state.block WHERE block_num = $1", 1) + assert.NoError(t, row.Scan(&checked)) + assert.Equal(t, true, checked) + row = db.QueryRow("SELECT checked FROM state.block WHERE block_num = $1", 50) + assert.NoError(t, row.Scan(&checked)) + assert.Equal(t, true, checked) + row = db.QueryRow("SELECT checked FROM state.block WHERE block_num = $1", 1050) + assert.NoError(t, row.Scan(&checked)) + assert.Equal(t, false, checked) + + const addBlock = "INSERT INTO state.block (block_num, received_at, block_hash, checked) VALUES ($1, $2, $3, $4)" + _, err := db.Exec(addBlock, 2, time.Now(), "0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1", true) + assert.NoError(t, err) + _, err = db.Exec(addBlock, 3, time.Now(), "0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1", false) + assert.NoError(t, err) + const sql = `SELECT count(*) FROM state.block WHERE checked = true` + row = db.QueryRow(sql) + var result int + assert.NoError(t, row.Scan(&result)) + assert.Equal(t, 3, result, "must be 1,50 per migration and 2 by insert") + + const sqlCheckedFalse = `SELECT count(*) FROM state.block WHERE checked = false` + row = db.QueryRow(sqlCheckedFalse) + + assert.NoError(t, row.Scan(&result)) + assert.Equal(t, 2, result, "must be 150 by migration, and 3 by insert") +} + +func (m migrationTest0018) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB) { + var result int + + // Check column wip doesn't exists in state.batch table + const sql = `SELECT count(*) FROM state.block` + row := db.QueryRow(sql) + assert.NoError(t, row.Scan(&result)) + assert.Equal(t, 5, result) +} + +func TestMigration0018(t *testing.T) { + runMigrationTest(t, 18, migrationTest0018{}) +} diff --git a/state/block.go b/state/block.go index c5c9fbb1a2..7883770249 100644 --- a/state/block.go +++ b/state/block.go @@ -12,6 +12,7 @@ type Block struct { BlockHash common.Hash ParentHash common.Hash ReceivedAt time.Time + Checked bool } // NewBlock creates a block with the given data. diff --git a/state/interfaces.go b/state/interfaces.go index ac9c2a0a67..dfde07d8ce 100644 --- a/state/interfaces.go +++ b/state/interfaces.go @@ -24,6 +24,8 @@ type storage interface { GetTxsOlderThanNL1BlocksUntilTxHash(ctx context.Context, nL1Blocks uint64, earliestTxHash common.Hash, dbTx pgx.Tx) ([]common.Hash, error) GetLastBlock(ctx context.Context, dbTx pgx.Tx) (*Block, error) GetPreviousBlock(ctx context.Context, offset uint64, dbTx pgx.Tx) (*Block, error) + GetFirstUncheckedBlock(ctx context.Context, fromBlockNumber uint64, dbTx pgx.Tx) (*Block, error) + UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx pgx.Tx) error AddGlobalExitRoot(ctx context.Context, exitRoot *GlobalExitRoot, dbTx pgx.Tx) error GetLatestGlobalExitRoot(ctx context.Context, maxBlockNumber uint64, dbTx pgx.Tx) (GlobalExitRoot, time.Time, error) GetNumberOfBlocksSinceLastGERUpdate(ctx context.Context, dbTx pgx.Tx) (uint64, error) diff --git a/state/mocks/mock_storage.go b/state/mocks/mock_storage.go index d47b4524bd..2b03479dee 100644 --- a/state/mocks/mock_storage.go +++ b/state/mocks/mock_storage.go @@ -2380,6 +2380,66 @@ func (_c *StorageMock_GetFirstL2BlockNumberForBatchNumber_Call) RunAndReturn(run return _c } +// GetFirstUncheckedBlock provides a mock function with given fields: ctx, fromBlockNumber, dbTx +func (_m *StorageMock) GetFirstUncheckedBlock(ctx context.Context, fromBlockNumber uint64, dbTx pgx.Tx) (*state.Block, error) { + ret := _m.Called(ctx, fromBlockNumber, dbTx) + + if len(ret) == 0 { + panic("no return value specified for GetFirstUncheckedBlock") + } + + var r0 *state.Block + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, pgx.Tx) (*state.Block, error)); ok { + return rf(ctx, fromBlockNumber, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, uint64, pgx.Tx) *state.Block); ok { + r0 = rf(ctx, fromBlockNumber, dbTx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*state.Block) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, uint64, pgx.Tx) error); ok { + r1 = rf(ctx, fromBlockNumber, dbTx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// StorageMock_GetFirstUncheckedBlock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetFirstUncheckedBlock' +type StorageMock_GetFirstUncheckedBlock_Call struct { + *mock.Call +} + +// GetFirstUncheckedBlock is a helper method to define mock.On call +// - ctx context.Context +// - fromBlockNumber uint64 +// - dbTx pgx.Tx +func (_e *StorageMock_Expecter) GetFirstUncheckedBlock(ctx interface{}, fromBlockNumber interface{}, dbTx interface{}) *StorageMock_GetFirstUncheckedBlock_Call { + return &StorageMock_GetFirstUncheckedBlock_Call{Call: _e.mock.On("GetFirstUncheckedBlock", ctx, fromBlockNumber, dbTx)} +} + +func (_c *StorageMock_GetFirstUncheckedBlock_Call) Run(run func(ctx context.Context, fromBlockNumber uint64, dbTx pgx.Tx)) *StorageMock_GetFirstUncheckedBlock_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(pgx.Tx)) + }) + return _c +} + +func (_c *StorageMock_GetFirstUncheckedBlock_Call) Return(_a0 *state.Block, _a1 error) *StorageMock_GetFirstUncheckedBlock_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *StorageMock_GetFirstUncheckedBlock_Call) RunAndReturn(run func(context.Context, uint64, pgx.Tx) (*state.Block, error)) *StorageMock_GetFirstUncheckedBlock_Call { + _c.Call.Return(run) + return _c +} + // GetForcedBatch provides a mock function with given fields: ctx, forcedBatchNumber, dbTx func (_m *StorageMock) GetForcedBatch(ctx context.Context, forcedBatchNumber uint64, dbTx pgx.Tx) (*state.ForcedBatch, error) { ret := _m.Called(ctx, forcedBatchNumber, dbTx) @@ -8152,6 +8212,55 @@ func (_c *StorageMock_UpdateBatchL2Data_Call) RunAndReturn(run func(context.Cont return _c } +// UpdateCheckedBlockByNumber provides a mock function with given fields: ctx, blockNumber, newCheckedStatus, dbTx +func (_m *StorageMock) UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx pgx.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, pgx.Tx) error); ok { + r0 = rf(ctx, blockNumber, newCheckedStatus, dbTx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// StorageMock_UpdateCheckedBlockByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateCheckedBlockByNumber' +type StorageMock_UpdateCheckedBlockByNumber_Call struct { + *mock.Call +} + +// UpdateCheckedBlockByNumber is a helper method to define mock.On call +// - ctx context.Context +// - blockNumber uint64 +// - newCheckedStatus bool +// - dbTx pgx.Tx +func (_e *StorageMock_Expecter) UpdateCheckedBlockByNumber(ctx interface{}, blockNumber interface{}, newCheckedStatus interface{}, dbTx interface{}) *StorageMock_UpdateCheckedBlockByNumber_Call { + return &StorageMock_UpdateCheckedBlockByNumber_Call{Call: _e.mock.On("UpdateCheckedBlockByNumber", ctx, blockNumber, newCheckedStatus, dbTx)} +} + +func (_c *StorageMock_UpdateCheckedBlockByNumber_Call) Run(run func(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx pgx.Tx)) *StorageMock_UpdateCheckedBlockByNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(bool), args[3].(pgx.Tx)) + }) + return _c +} + +func (_c *StorageMock_UpdateCheckedBlockByNumber_Call) Return(_a0 error) *StorageMock_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *StorageMock_UpdateCheckedBlockByNumber_Call) RunAndReturn(run func(context.Context, uint64, bool, pgx.Tx) error) *StorageMock_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(run) + return _c +} + // UpdateForkIDBlockNumber provides a mock function with given fields: ctx, forkdID, newBlockNumber, updateMemCache, dbTx func (_m *StorageMock) UpdateForkIDBlockNumber(ctx context.Context, forkdID uint64, newBlockNumber uint64, updateMemCache bool, dbTx pgx.Tx) error { ret := _m.Called(ctx, forkdID, newBlockNumber, updateMemCache, dbTx) diff --git a/state/pgstatestorage/block.go b/state/pgstatestorage/block.go index f2ae7abd17..768b384df1 100644 --- a/state/pgstatestorage/block.go +++ b/state/pgstatestorage/block.go @@ -16,10 +16,10 @@ const ( // AddBlock adds a new block to the State Store func (p *PostgresStorage) AddBlock(ctx context.Context, block *state.Block, dbTx pgx.Tx) error { - const addBlockSQL = "INSERT INTO state.block (block_num, block_hash, parent_hash, received_at) VALUES ($1, $2, $3, $4)" + const addBlockSQL = "INSERT INTO state.block (block_num, block_hash, parent_hash, received_at, checked) VALUES ($1, $2, $3, $4, $5)" e := p.getExecQuerier(dbTx) - _, err := e.Exec(ctx, addBlockSQL, block.BlockNumber, block.BlockHash.String(), block.ParentHash.String(), block.ReceivedAt) + _, err := e.Exec(ctx, addBlockSQL, block.BlockNumber, block.BlockHash.String(), block.ParentHash.String(), block.ReceivedAt, block.Checked) return err } @@ -30,11 +30,11 @@ func (p *PostgresStorage) GetLastBlock(ctx context.Context, dbTx pgx.Tx) (*state parentHash string block state.Block ) - const getLastBlockSQL = "SELECT block_num, block_hash, parent_hash, received_at FROM state.block ORDER BY block_num DESC LIMIT 1" + const getLastBlockSQL = "SELECT block_num, block_hash, parent_hash, received_at, checked FROM state.block ORDER BY block_num DESC LIMIT 1" q := p.getExecQuerier(dbTx) - err := q.QueryRow(ctx, getLastBlockSQL).Scan(&block.BlockNumber, &blockHash, &parentHash, &block.ReceivedAt) + err := q.QueryRow(ctx, getLastBlockSQL).Scan(&block.BlockNumber, &blockHash, &parentHash, &block.ReceivedAt, &block.Checked) if errors.Is(err, pgx.ErrNoRows) { return nil, state.ErrStateNotSynchronized } @@ -43,6 +43,26 @@ func (p *PostgresStorage) GetLastBlock(ctx context.Context, dbTx pgx.Tx) (*state return &block, err } +// 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 pgx.Tx) (*state.Block, error) { + var ( + blockHash string + parentHash string + block state.Block + ) + const getLastBlockSQL = "SELECT block_num, block_hash, parent_hash, received_at, checked FROM state.block WHERE block_num>=$1 AND checked=false ORDER BY block_num LIMIT 1" + + q := p.getExecQuerier(dbTx) + + err := q.QueryRow(ctx, getLastBlockSQL, fromBlockNumber).Scan(&block.BlockNumber, &blockHash, &parentHash, &block.ReceivedAt, &block.Checked) + if errors.Is(err, pgx.ErrNoRows) { + return nil, state.ErrNotFound + } + block.BlockHash = common.HexToHash(blockHash) + block.ParentHash = common.HexToHash(parentHash) + return &block, err +} + // GetPreviousBlock gets the offset previous L1 block respect to latest. func (p *PostgresStorage) GetPreviousBlock(ctx context.Context, offset uint64, dbTx pgx.Tx) (*state.Block, error) { var ( @@ -50,11 +70,11 @@ func (p *PostgresStorage) GetPreviousBlock(ctx context.Context, offset uint64, d parentHash string block state.Block ) - const getPreviousBlockSQL = "SELECT block_num, block_hash, parent_hash, received_at FROM state.block ORDER BY block_num DESC LIMIT 1 OFFSET $1" + const getPreviousBlockSQL = "SELECT block_num, block_hash, parent_hash, received_at,checked FROM state.block ORDER BY block_num DESC LIMIT 1 OFFSET $1" q := p.getExecQuerier(dbTx) - err := q.QueryRow(ctx, getPreviousBlockSQL, offset).Scan(&block.BlockNumber, &blockHash, &parentHash, &block.ReceivedAt) + err := q.QueryRow(ctx, getPreviousBlockSQL, offset).Scan(&block.BlockNumber, &blockHash, &parentHash, &block.ReceivedAt, &block.Checked) if errors.Is(err, pgx.ErrNoRows) { return nil, state.ErrNotFound } @@ -70,11 +90,11 @@ func (p *PostgresStorage) GetBlockByNumber(ctx context.Context, blockNumber uint parentHash string block state.Block ) - const getBlockByNumberSQL = "SELECT block_num, block_hash, parent_hash, received_at FROM state.block WHERE block_num = $1" + const getBlockByNumberSQL = "SELECT block_num, block_hash, parent_hash, received_at,checked FROM state.block WHERE block_num = $1" q := p.getExecQuerier(dbTx) - err := q.QueryRow(ctx, getBlockByNumberSQL, blockNumber).Scan(&block.BlockNumber, &blockHash, &parentHash, &block.ReceivedAt) + err := q.QueryRow(ctx, getBlockByNumberSQL, blockNumber).Scan(&block.BlockNumber, &blockHash, &parentHash, &block.ReceivedAt, &block.Checked) if errors.Is(err, pgx.ErrNoRows) { return nil, state.ErrNotFound } @@ -82,3 +102,14 @@ func (p *PostgresStorage) GetBlockByNumber(ctx context.Context, blockNumber uint block.ParentHash = common.HexToHash(parentHash) return &block, err } + +// UpdateCheckedBlockByNumber update checked flag for a block +func (p *PostgresStorage) UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx pgx.Tx) error { + const query = ` + UPDATE state.block + SET checked = $1 WHERE block_num = $2` + + e := p.getExecQuerier(dbTx) + _, err := e.Exec(ctx, query, newCheckedStatus, blockNumber) + return err +} diff --git a/state/pgstatestorage/pgstatestorage_test.go b/state/pgstatestorage/pgstatestorage_test.go index 7d934f029e..416b21b47b 100644 --- a/state/pgstatestorage/pgstatestorage_test.go +++ b/state/pgstatestorage/pgstatestorage_test.go @@ -1650,3 +1650,40 @@ func TestGetLastGER(t *testing.T) { require.Equal(t, common.HexToHash("0x2").String(), ger.String()) } + +func TestGetFirstUncheckedBlock(t *testing.T) { + var err error + blockNumber := uint64(51001) + err = testState.AddBlock(context.Background(), &state.Block{BlockNumber: blockNumber, Checked: true}, nil) + require.NoError(t, err) + err = testState.AddBlock(context.Background(), &state.Block{BlockNumber: blockNumber + 1, Checked: false}, nil) + require.NoError(t, err) + err = testState.AddBlock(context.Background(), &state.Block{BlockNumber: blockNumber + 2, Checked: true}, nil) + require.NoError(t, err) + + block, err := testState.GetFirstUncheckedBlock(context.Background(), blockNumber, nil) + require.NoError(t, err) + require.Equal(t, uint64(blockNumber+1), block.BlockNumber) +} + +func TestUpdateCheckedBlockByNumber(t *testing.T) { + var err error + blockNumber := uint64(54001) + err = testState.AddBlock(context.Background(), &state.Block{BlockNumber: blockNumber, Checked: true}, nil) + require.NoError(t, err) + err = testState.AddBlock(context.Background(), &state.Block{BlockNumber: blockNumber + 1, Checked: false}, nil) + require.NoError(t, err) + err = testState.AddBlock(context.Background(), &state.Block{BlockNumber: blockNumber + 2, Checked: true}, nil) + require.NoError(t, err) + + b1, err := testState.GetBlockByNumber(context.Background(), uint64(blockNumber), nil) + require.NoError(t, err) + require.True(t, b1.Checked) + + err = testState.UpdateCheckedBlockByNumber(context.Background(), uint64(blockNumber), false, nil) + require.NoError(t, err) + + b1, err = testState.GetBlockByNumber(context.Background(), uint64(blockNumber), nil) + require.NoError(t, err) + require.False(t, b1.Checked) +} diff --git a/synchronizer/common/syncinterfaces/mocks/state_full_interface.go b/synchronizer/common/syncinterfaces/mocks/state_full_interface.go index 1559654641..f4790bc695 100644 --- a/synchronizer/common/syncinterfaces/mocks/state_full_interface.go +++ b/synchronizer/common/syncinterfaces/mocks/state_full_interface.go @@ -881,6 +881,66 @@ func (_c *StateFullInterface_GetExitRootByGlobalExitRoot_Call) RunAndReturn(run return _c } +// GetFirstUncheckedBlock provides a mock function with given fields: ctx, fromBlockNumber, dbTx +func (_m *StateFullInterface) GetFirstUncheckedBlock(ctx context.Context, fromBlockNumber uint64, dbTx pgx.Tx) (*state.Block, error) { + ret := _m.Called(ctx, fromBlockNumber, dbTx) + + if len(ret) == 0 { + panic("no return value specified for GetFirstUncheckedBlock") + } + + var r0 *state.Block + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, pgx.Tx) (*state.Block, error)); ok { + return rf(ctx, fromBlockNumber, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, uint64, pgx.Tx) *state.Block); ok { + r0 = rf(ctx, fromBlockNumber, dbTx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*state.Block) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, uint64, pgx.Tx) error); ok { + r1 = rf(ctx, fromBlockNumber, dbTx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// StateFullInterface_GetFirstUncheckedBlock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetFirstUncheckedBlock' +type StateFullInterface_GetFirstUncheckedBlock_Call struct { + *mock.Call +} + +// GetFirstUncheckedBlock is a helper method to define mock.On call +// - ctx context.Context +// - fromBlockNumber uint64 +// - dbTx pgx.Tx +func (_e *StateFullInterface_Expecter) GetFirstUncheckedBlock(ctx interface{}, fromBlockNumber interface{}, dbTx interface{}) *StateFullInterface_GetFirstUncheckedBlock_Call { + return &StateFullInterface_GetFirstUncheckedBlock_Call{Call: _e.mock.On("GetFirstUncheckedBlock", ctx, fromBlockNumber, dbTx)} +} + +func (_c *StateFullInterface_GetFirstUncheckedBlock_Call) Run(run func(ctx context.Context, fromBlockNumber uint64, dbTx pgx.Tx)) *StateFullInterface_GetFirstUncheckedBlock_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(pgx.Tx)) + }) + return _c +} + +func (_c *StateFullInterface_GetFirstUncheckedBlock_Call) Return(_a0 *state.Block, _a1 error) *StateFullInterface_GetFirstUncheckedBlock_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *StateFullInterface_GetFirstUncheckedBlock_Call) RunAndReturn(run func(context.Context, uint64, pgx.Tx) (*state.Block, error)) *StateFullInterface_GetFirstUncheckedBlock_Call { + _c.Call.Return(run) + return _c +} + // GetForkIDByBatchNumber provides a mock function with given fields: batchNumber func (_m *StateFullInterface) GetForkIDByBatchNumber(batchNumber uint64) uint64 { ret := _m.Called(batchNumber) @@ -2343,53 +2403,6 @@ func (_c *StateFullInterface_ResetForkID_Call) RunAndReturn(run func(context.Con return _c } -// ResetL1InfoTree provides a mock function with given fields: ctx, dbTx -func (_m *StateFullInterface) ResetL1InfoTree(ctx context.Context, dbTx pgx.Tx) error { - ret := _m.Called(ctx, dbTx) - - if len(ret) == 0 { - panic("no return value specified for ResetL1InfoTree") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, pgx.Tx) error); ok { - r0 = rf(ctx, dbTx) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// StateFullInterface_ResetL1InfoTree_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ResetL1InfoTree' -type StateFullInterface_ResetL1InfoTree_Call struct { - *mock.Call -} - -// ResetL1InfoTree is a helper method to define mock.On call -// - ctx context.Context -// - dbTx pgx.Tx -func (_e *StateFullInterface_Expecter) ResetL1InfoTree(ctx interface{}, dbTx interface{}) *StateFullInterface_ResetL1InfoTree_Call { - return &StateFullInterface_ResetL1InfoTree_Call{Call: _e.mock.On("ResetL1InfoTree", ctx, dbTx)} -} - -func (_c *StateFullInterface_ResetL1InfoTree_Call) Run(run func(ctx context.Context, dbTx pgx.Tx)) *StateFullInterface_ResetL1InfoTree_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(pgx.Tx)) - }) - return _c -} - -func (_c *StateFullInterface_ResetL1InfoTree_Call) Return(_a0 error) *StateFullInterface_ResetL1InfoTree_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *StateFullInterface_ResetL1InfoTree_Call) RunAndReturn(run func(context.Context, pgx.Tx) error) *StateFullInterface_ResetL1InfoTree_Call { - _c.Call.Return(run) - return _c -} - // ResetTrustedState provides a mock function with given fields: ctx, batchNumber, dbTx func (_m *StateFullInterface) ResetTrustedState(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) error { ret := _m.Called(ctx, batchNumber, dbTx) @@ -2762,6 +2775,55 @@ func (_c *StateFullInterface_UpdateBatchL2Data_Call) RunAndReturn(run func(conte return _c } +// UpdateCheckedBlockByNumber provides a mock function with given fields: ctx, blockNumber, newCheckedStatus, dbTx +func (_m *StateFullInterface) UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx pgx.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, pgx.Tx) error); ok { + r0 = rf(ctx, blockNumber, newCheckedStatus, dbTx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// StateFullInterface_UpdateCheckedBlockByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateCheckedBlockByNumber' +type StateFullInterface_UpdateCheckedBlockByNumber_Call struct { + *mock.Call +} + +// UpdateCheckedBlockByNumber is a helper method to define mock.On call +// - ctx context.Context +// - blockNumber uint64 +// - newCheckedStatus bool +// - dbTx pgx.Tx +func (_e *StateFullInterface_Expecter) UpdateCheckedBlockByNumber(ctx interface{}, blockNumber interface{}, newCheckedStatus interface{}, dbTx interface{}) *StateFullInterface_UpdateCheckedBlockByNumber_Call { + return &StateFullInterface_UpdateCheckedBlockByNumber_Call{Call: _e.mock.On("UpdateCheckedBlockByNumber", ctx, blockNumber, newCheckedStatus, dbTx)} +} + +func (_c *StateFullInterface_UpdateCheckedBlockByNumber_Call) Run(run func(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx pgx.Tx)) *StateFullInterface_UpdateCheckedBlockByNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64), args[2].(bool), args[3].(pgx.Tx)) + }) + return _c +} + +func (_c *StateFullInterface_UpdateCheckedBlockByNumber_Call) Return(_a0 error) *StateFullInterface_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *StateFullInterface_UpdateCheckedBlockByNumber_Call) RunAndReturn(run func(context.Context, uint64, bool, pgx.Tx) error) *StateFullInterface_UpdateCheckedBlockByNumber_Call { + _c.Call.Return(run) + return _c +} + // UpdateForkIDBlockNumber provides a mock function with given fields: ctx, forkdID, newBlockNumber, updateMemCache, dbTx func (_m *StateFullInterface) UpdateForkIDBlockNumber(ctx context.Context, forkdID uint64, newBlockNumber uint64, updateMemCache bool, dbTx pgx.Tx) error { ret := _m.Called(ctx, forkdID, newBlockNumber, updateMemCache, dbTx) diff --git a/synchronizer/common/syncinterfaces/state.go b/synchronizer/common/syncinterfaces/state.go index 2895eb0903..0aff583319 100644 --- a/synchronizer/common/syncinterfaces/state.go +++ b/synchronizer/common/syncinterfaces/state.go @@ -29,6 +29,8 @@ type StateFullInterface interface { AddBlock(ctx context.Context, block *state.Block, dbTx pgx.Tx) error Reset(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) error GetPreviousBlock(ctx context.Context, offset uint64, dbTx pgx.Tx) (*state.Block, error) + GetFirstUncheckedBlock(ctx context.Context, fromBlockNumber uint64, dbTx pgx.Tx) (*state.Block, error) + UpdateCheckedBlockByNumber(ctx context.Context, blockNumber uint64, newCheckedStatus bool, dbTx pgx.Tx) error GetLastBatchNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error) GetBatchByNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.Batch, error) ResetTrustedState(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) error