From 2eee781561298f6dbb3612c3a8852630fa2c7126 Mon Sep 17 00:00:00 2001 From: Joan Esteban <129153821+joanestebanr@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:21:58 +0200 Subject: [PATCH] fix: 127. Convert warning to error if L1InfoTreeUpdateV2 doesnt pass sanity check (#128) --- state/entities/l1_info_tree_leaf.go | 14 + state/mocks/storer.go | 58 ++ state/mocks/tx.go | 631 ++++++++++++++++++ state/mocks/virtual_batch_storer.go | 58 ++ state/model/l1infotree_state.go | 4 + state/storage/mocks/exec_querier.go | 185 ++--- state/storage/mocks/storer.go | 58 ++ state/storage/mocks/virtual_batch_storer.go | 58 ++ .../processor_update_l1_info_tree_v2.go | 12 +- .../syncinterfaces/mocks/state_interface.go | 59 ++ .../mocks/storage_virtual_batch_interface.go | 18 +- synchronizer/syncinterfaces/state.go | 1 + version.go | 2 +- 13 files changed, 1023 insertions(+), 135 deletions(-) diff --git a/state/entities/l1_info_tree_leaf.go b/state/entities/l1_info_tree_leaf.go index a16d8ff..e7a457d 100644 --- a/state/entities/l1_info_tree_leaf.go +++ b/state/entities/l1_info_tree_leaf.go @@ -1,6 +1,7 @@ package entities import ( + "fmt" "time" "github.com/ethereum/go-ethereum/common" @@ -16,3 +17,16 @@ type L1InfoTreeLeaf struct { RollupExitRoot common.Hash GlobalExitRoot common.Hash } + +func (l *L1InfoTreeLeaf) String() string { + + if l == nil { + return "nil" + } + return fmt.Sprintf("L1InfoTreeRoot:%s L1InfoTreeIndex:%d PreviousBlockHash:%s "+ + "BlockNumber:%d Timestamp:%s MainnetExitRoot:%s RollupExitRoot:%s GlobalExitRoot:%s", + l.L1InfoTreeRoot.String(), l.L1InfoTreeIndex, l.PreviousBlockHash.String(), + l.BlockNumber, l.Timestamp.String(), l.MainnetExitRoot.String(), + l.RollupExitRoot.String(), l.GlobalExitRoot.String()) + +} diff --git a/state/mocks/storer.go b/state/mocks/storer.go index 846d36f..8a5a70a 100644 --- a/state/mocks/storer.go +++ b/state/mocks/storer.go @@ -824,6 +824,64 @@ func (_c *Storer_GetLastBlock_Call) RunAndReturn(run func(context.Context, entit return _c } +// GetLastestVirtualBatchNumber provides a mock function with given fields: ctx, constrains, dbTx +func (_m *Storer) GetLastestVirtualBatchNumber(ctx context.Context, constrains *entities.VirtualBatchConstraints, dbTx entities.Tx) (uint64, error) { + ret := _m.Called(ctx, constrains, dbTx) + + if len(ret) == 0 { + panic("no return value specified for GetLastestVirtualBatchNumber") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) (uint64, error)); ok { + return rf(ctx, constrains, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) uint64); ok { + r0 = rf(ctx, constrains, dbTx) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) error); ok { + r1 = rf(ctx, constrains, dbTx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Storer_GetLastestVirtualBatchNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLastestVirtualBatchNumber' +type Storer_GetLastestVirtualBatchNumber_Call struct { + *mock.Call +} + +// GetLastestVirtualBatchNumber is a helper method to define mock.On call +// - ctx context.Context +// - constrains *entities.VirtualBatchConstraints +// - dbTx entities.Tx +func (_e *Storer_Expecter) GetLastestVirtualBatchNumber(ctx interface{}, constrains interface{}, dbTx interface{}) *Storer_GetLastestVirtualBatchNumber_Call { + return &Storer_GetLastestVirtualBatchNumber_Call{Call: _e.mock.On("GetLastestVirtualBatchNumber", ctx, constrains, dbTx)} +} + +func (_c *Storer_GetLastestVirtualBatchNumber_Call) Run(run func(ctx context.Context, constrains *entities.VirtualBatchConstraints, dbTx entities.Tx)) *Storer_GetLastestVirtualBatchNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*entities.VirtualBatchConstraints), args[2].(entities.Tx)) + }) + return _c +} + +func (_c *Storer_GetLastestVirtualBatchNumber_Call) Return(_a0 uint64, _a1 error) *Storer_GetLastestVirtualBatchNumber_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Storer_GetLastestVirtualBatchNumber_Call) RunAndReturn(run func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) (uint64, error)) *Storer_GetLastestVirtualBatchNumber_Call { + _c.Call.Return(run) + return _c +} + // GetLatestL1InfoTreeLeaf provides a mock function with given fields: ctx, dbTx func (_m *Storer) GetLatestL1InfoTreeLeaf(ctx context.Context, dbTx entities.Tx) (*entities.L1InfoTreeLeaf, error) { ret := _m.Called(ctx, dbTx) diff --git a/state/mocks/tx.go b/state/mocks/tx.go index 1bf620d..214916c 100644 --- a/state/mocks/tx.go +++ b/state/mocks/tx.go @@ -7,6 +7,10 @@ import ( entities "github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities" mock "github.com/stretchr/testify/mock" + + pgconn "github.com/jackc/pgconn" + + pgx "github.com/jackc/pgx/v4" ) // Tx is an autogenerated mock type for the Tx type @@ -88,6 +92,111 @@ func (_c *Tx_AddRollbackCallback_Call) RunAndReturn(run func(entities.TxCallback return _c } +// Begin provides a mock function with given fields: ctx +func (_m *Tx) Begin(ctx context.Context) (pgx.Tx, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Begin") + } + + var r0 pgx.Tx + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (pgx.Tx, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) pgx.Tx); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(pgx.Tx) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Tx_Begin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Begin' +type Tx_Begin_Call struct { + *mock.Call +} + +// Begin is a helper method to define mock.On call +// - ctx context.Context +func (_e *Tx_Expecter) Begin(ctx interface{}) *Tx_Begin_Call { + return &Tx_Begin_Call{Call: _e.mock.On("Begin", ctx)} +} + +func (_c *Tx_Begin_Call) Run(run func(ctx context.Context)) *Tx_Begin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *Tx_Begin_Call) Return(_a0 pgx.Tx, _a1 error) *Tx_Begin_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Tx_Begin_Call) RunAndReturn(run func(context.Context) (pgx.Tx, error)) *Tx_Begin_Call { + _c.Call.Return(run) + return _c +} + +// BeginFunc provides a mock function with given fields: ctx, f +func (_m *Tx) BeginFunc(ctx context.Context, f func(pgx.Tx) error) error { + ret := _m.Called(ctx, f) + + if len(ret) == 0 { + panic("no return value specified for BeginFunc") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, func(pgx.Tx) error) error); ok { + r0 = rf(ctx, f) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Tx_BeginFunc_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BeginFunc' +type Tx_BeginFunc_Call struct { + *mock.Call +} + +// BeginFunc is a helper method to define mock.On call +// - ctx context.Context +// - f func(pgx.Tx) error +func (_e *Tx_Expecter) BeginFunc(ctx interface{}, f interface{}) *Tx_BeginFunc_Call { + return &Tx_BeginFunc_Call{Call: _e.mock.On("BeginFunc", ctx, f)} +} + +func (_c *Tx_BeginFunc_Call) Run(run func(ctx context.Context, f func(pgx.Tx) error)) *Tx_BeginFunc_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(func(pgx.Tx) error)) + }) + return _c +} + +func (_c *Tx_BeginFunc_Call) Return(err error) *Tx_BeginFunc_Call { + _c.Call.Return(err) + return _c +} + +func (_c *Tx_BeginFunc_Call) RunAndReturn(run func(context.Context, func(pgx.Tx) error) error) *Tx_BeginFunc_Call { + _c.Call.Return(run) + return _c +} + // Commit provides a mock function with given fields: ctx func (_m *Tx) Commit(ctx context.Context) error { ret := _m.Called(ctx) @@ -134,6 +243,479 @@ func (_c *Tx_Commit_Call) RunAndReturn(run func(context.Context) error) *Tx_Comm return _c } +// Conn provides a mock function with given fields: +func (_m *Tx) Conn() *pgx.Conn { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Conn") + } + + var r0 *pgx.Conn + if rf, ok := ret.Get(0).(func() *pgx.Conn); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*pgx.Conn) + } + } + + return r0 +} + +// Tx_Conn_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Conn' +type Tx_Conn_Call struct { + *mock.Call +} + +// Conn is a helper method to define mock.On call +func (_e *Tx_Expecter) Conn() *Tx_Conn_Call { + return &Tx_Conn_Call{Call: _e.mock.On("Conn")} +} + +func (_c *Tx_Conn_Call) Run(run func()) *Tx_Conn_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Tx_Conn_Call) Return(_a0 *pgx.Conn) *Tx_Conn_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Tx_Conn_Call) RunAndReturn(run func() *pgx.Conn) *Tx_Conn_Call { + _c.Call.Return(run) + return _c +} + +// CopyFrom provides a mock function with given fields: ctx, tableName, columnNames, rowSrc +func (_m *Tx) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error) { + ret := _m.Called(ctx, tableName, columnNames, rowSrc) + + if len(ret) == 0 { + panic("no return value specified for CopyFrom") + } + + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, pgx.Identifier, []string, pgx.CopyFromSource) (int64, error)); ok { + return rf(ctx, tableName, columnNames, rowSrc) + } + if rf, ok := ret.Get(0).(func(context.Context, pgx.Identifier, []string, pgx.CopyFromSource) int64); ok { + r0 = rf(ctx, tableName, columnNames, rowSrc) + } else { + r0 = ret.Get(0).(int64) + } + + if rf, ok := ret.Get(1).(func(context.Context, pgx.Identifier, []string, pgx.CopyFromSource) error); ok { + r1 = rf(ctx, tableName, columnNames, rowSrc) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Tx_CopyFrom_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CopyFrom' +type Tx_CopyFrom_Call struct { + *mock.Call +} + +// CopyFrom is a helper method to define mock.On call +// - ctx context.Context +// - tableName pgx.Identifier +// - columnNames []string +// - rowSrc pgx.CopyFromSource +func (_e *Tx_Expecter) CopyFrom(ctx interface{}, tableName interface{}, columnNames interface{}, rowSrc interface{}) *Tx_CopyFrom_Call { + return &Tx_CopyFrom_Call{Call: _e.mock.On("CopyFrom", ctx, tableName, columnNames, rowSrc)} +} + +func (_c *Tx_CopyFrom_Call) Run(run func(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource)) *Tx_CopyFrom_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(pgx.Identifier), args[2].([]string), args[3].(pgx.CopyFromSource)) + }) + return _c +} + +func (_c *Tx_CopyFrom_Call) Return(_a0 int64, _a1 error) *Tx_CopyFrom_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Tx_CopyFrom_Call) RunAndReturn(run func(context.Context, pgx.Identifier, []string, pgx.CopyFromSource) (int64, error)) *Tx_CopyFrom_Call { + _c.Call.Return(run) + return _c +} + +// Exec provides a mock function with given fields: ctx, sql, arguments +func (_m *Tx) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error) { + var _ca []interface{} + _ca = append(_ca, ctx, sql) + _ca = append(_ca, arguments...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Exec") + } + + var r0 pgconn.CommandTag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) (pgconn.CommandTag, error)); ok { + return rf(ctx, sql, arguments...) + } + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) pgconn.CommandTag); ok { + r0 = rf(ctx, sql, arguments...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(pgconn.CommandTag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, ...interface{}) error); ok { + r1 = rf(ctx, sql, arguments...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Tx_Exec_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Exec' +type Tx_Exec_Call struct { + *mock.Call +} + +// Exec is a helper method to define mock.On call +// - ctx context.Context +// - sql string +// - arguments ...interface{} +func (_e *Tx_Expecter) Exec(ctx interface{}, sql interface{}, arguments ...interface{}) *Tx_Exec_Call { + return &Tx_Exec_Call{Call: _e.mock.On("Exec", + append([]interface{}{ctx, sql}, arguments...)...)} +} + +func (_c *Tx_Exec_Call) Run(run func(ctx context.Context, sql string, arguments ...interface{})) *Tx_Exec_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(context.Context), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *Tx_Exec_Call) Return(commandTag pgconn.CommandTag, err error) *Tx_Exec_Call { + _c.Call.Return(commandTag, err) + return _c +} + +func (_c *Tx_Exec_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (pgconn.CommandTag, error)) *Tx_Exec_Call { + _c.Call.Return(run) + return _c +} + +// LargeObjects provides a mock function with given fields: +func (_m *Tx) LargeObjects() pgx.LargeObjects { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for LargeObjects") + } + + var r0 pgx.LargeObjects + if rf, ok := ret.Get(0).(func() pgx.LargeObjects); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(pgx.LargeObjects) + } + + return r0 +} + +// Tx_LargeObjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LargeObjects' +type Tx_LargeObjects_Call struct { + *mock.Call +} + +// LargeObjects is a helper method to define mock.On call +func (_e *Tx_Expecter) LargeObjects() *Tx_LargeObjects_Call { + return &Tx_LargeObjects_Call{Call: _e.mock.On("LargeObjects")} +} + +func (_c *Tx_LargeObjects_Call) Run(run func()) *Tx_LargeObjects_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Tx_LargeObjects_Call) Return(_a0 pgx.LargeObjects) *Tx_LargeObjects_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Tx_LargeObjects_Call) RunAndReturn(run func() pgx.LargeObjects) *Tx_LargeObjects_Call { + _c.Call.Return(run) + return _c +} + +// Prepare provides a mock function with given fields: ctx, name, sql +func (_m *Tx) Prepare(ctx context.Context, name string, sql string) (*pgconn.StatementDescription, error) { + ret := _m.Called(ctx, name, sql) + + if len(ret) == 0 { + panic("no return value specified for Prepare") + } + + var r0 *pgconn.StatementDescription + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*pgconn.StatementDescription, error)); ok { + return rf(ctx, name, sql) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) *pgconn.StatementDescription); ok { + r0 = rf(ctx, name, sql) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*pgconn.StatementDescription) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, name, sql) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Tx_Prepare_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Prepare' +type Tx_Prepare_Call struct { + *mock.Call +} + +// Prepare is a helper method to define mock.On call +// - ctx context.Context +// - name string +// - sql string +func (_e *Tx_Expecter) Prepare(ctx interface{}, name interface{}, sql interface{}) *Tx_Prepare_Call { + return &Tx_Prepare_Call{Call: _e.mock.On("Prepare", ctx, name, sql)} +} + +func (_c *Tx_Prepare_Call) Run(run func(ctx context.Context, name string, sql string)) *Tx_Prepare_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *Tx_Prepare_Call) Return(_a0 *pgconn.StatementDescription, _a1 error) *Tx_Prepare_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Tx_Prepare_Call) RunAndReturn(run func(context.Context, string, string) (*pgconn.StatementDescription, error)) *Tx_Prepare_Call { + _c.Call.Return(run) + return _c +} + +// Query provides a mock function with given fields: ctx, sql, args +func (_m *Tx) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error) { + var _ca []interface{} + _ca = append(_ca, ctx, sql) + _ca = append(_ca, args...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Query") + } + + var r0 pgx.Rows + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) (pgx.Rows, error)); ok { + return rf(ctx, sql, args...) + } + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) pgx.Rows); ok { + r0 = rf(ctx, sql, args...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(pgx.Rows) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, ...interface{}) error); ok { + r1 = rf(ctx, sql, args...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Tx_Query_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Query' +type Tx_Query_Call struct { + *mock.Call +} + +// Query is a helper method to define mock.On call +// - ctx context.Context +// - sql string +// - args ...interface{} +func (_e *Tx_Expecter) Query(ctx interface{}, sql interface{}, args ...interface{}) *Tx_Query_Call { + return &Tx_Query_Call{Call: _e.mock.On("Query", + append([]interface{}{ctx, sql}, args...)...)} +} + +func (_c *Tx_Query_Call) Run(run func(ctx context.Context, sql string, args ...interface{})) *Tx_Query_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(context.Context), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *Tx_Query_Call) Return(_a0 pgx.Rows, _a1 error) *Tx_Query_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Tx_Query_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (pgx.Rows, error)) *Tx_Query_Call { + _c.Call.Return(run) + return _c +} + +// QueryFunc provides a mock function with given fields: ctx, sql, args, scans, f +func (_m *Tx) QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error) { + ret := _m.Called(ctx, sql, args, scans, f) + + if len(ret) == 0 { + panic("no return value specified for QueryFunc") + } + + var r0 pgconn.CommandTag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, []interface{}, []interface{}, func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error)); ok { + return rf(ctx, sql, args, scans, f) + } + if rf, ok := ret.Get(0).(func(context.Context, string, []interface{}, []interface{}, func(pgx.QueryFuncRow) error) pgconn.CommandTag); ok { + r0 = rf(ctx, sql, args, scans, f) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(pgconn.CommandTag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, []interface{}, []interface{}, func(pgx.QueryFuncRow) error) error); ok { + r1 = rf(ctx, sql, args, scans, f) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Tx_QueryFunc_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryFunc' +type Tx_QueryFunc_Call struct { + *mock.Call +} + +// QueryFunc is a helper method to define mock.On call +// - ctx context.Context +// - sql string +// - args []interface{} +// - scans []interface{} +// - f func(pgx.QueryFuncRow) error +func (_e *Tx_Expecter) QueryFunc(ctx interface{}, sql interface{}, args interface{}, scans interface{}, f interface{}) *Tx_QueryFunc_Call { + return &Tx_QueryFunc_Call{Call: _e.mock.On("QueryFunc", ctx, sql, args, scans, f)} +} + +func (_c *Tx_QueryFunc_Call) Run(run func(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(pgx.QueryFuncRow) error)) *Tx_QueryFunc_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].([]interface{}), args[3].([]interface{}), args[4].(func(pgx.QueryFuncRow) error)) + }) + return _c +} + +func (_c *Tx_QueryFunc_Call) Return(_a0 pgconn.CommandTag, _a1 error) *Tx_QueryFunc_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Tx_QueryFunc_Call) RunAndReturn(run func(context.Context, string, []interface{}, []interface{}, func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error)) *Tx_QueryFunc_Call { + _c.Call.Return(run) + return _c +} + +// QueryRow provides a mock function with given fields: ctx, sql, args +func (_m *Tx) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row { + var _ca []interface{} + _ca = append(_ca, ctx, sql) + _ca = append(_ca, args...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for QueryRow") + } + + var r0 pgx.Row + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) pgx.Row); ok { + r0 = rf(ctx, sql, args...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(pgx.Row) + } + } + + return r0 +} + +// Tx_QueryRow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryRow' +type Tx_QueryRow_Call struct { + *mock.Call +} + +// QueryRow is a helper method to define mock.On call +// - ctx context.Context +// - sql string +// - args ...interface{} +func (_e *Tx_Expecter) QueryRow(ctx interface{}, sql interface{}, args ...interface{}) *Tx_QueryRow_Call { + return &Tx_QueryRow_Call{Call: _e.mock.On("QueryRow", + append([]interface{}{ctx, sql}, args...)...)} +} + +func (_c *Tx_QueryRow_Call) Run(run func(ctx context.Context, sql string, args ...interface{})) *Tx_QueryRow_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(context.Context), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *Tx_QueryRow_Call) Return(_a0 pgx.Row) *Tx_QueryRow_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Tx_QueryRow_Call) RunAndReturn(run func(context.Context, string, ...interface{}) pgx.Row) *Tx_QueryRow_Call { + _c.Call.Return(run) + return _c +} + // Rollback provides a mock function with given fields: ctx func (_m *Tx) Rollback(ctx context.Context) error { ret := _m.Called(ctx) @@ -180,6 +762,55 @@ func (_c *Tx_Rollback_Call) RunAndReturn(run func(context.Context) error) *Tx_Ro return _c } +// SendBatch provides a mock function with given fields: ctx, b +func (_m *Tx) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults { + ret := _m.Called(ctx, b) + + if len(ret) == 0 { + panic("no return value specified for SendBatch") + } + + var r0 pgx.BatchResults + if rf, ok := ret.Get(0).(func(context.Context, *pgx.Batch) pgx.BatchResults); ok { + r0 = rf(ctx, b) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(pgx.BatchResults) + } + } + + return r0 +} + +// Tx_SendBatch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendBatch' +type Tx_SendBatch_Call struct { + *mock.Call +} + +// SendBatch is a helper method to define mock.On call +// - ctx context.Context +// - b *pgx.Batch +func (_e *Tx_Expecter) SendBatch(ctx interface{}, b interface{}) *Tx_SendBatch_Call { + return &Tx_SendBatch_Call{Call: _e.mock.On("SendBatch", ctx, b)} +} + +func (_c *Tx_SendBatch_Call) Run(run func(ctx context.Context, b *pgx.Batch)) *Tx_SendBatch_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*pgx.Batch)) + }) + return _c +} + +func (_c *Tx_SendBatch_Call) Return(_a0 pgx.BatchResults) *Tx_SendBatch_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Tx_SendBatch_Call) RunAndReturn(run func(context.Context, *pgx.Batch) pgx.BatchResults) *Tx_SendBatch_Call { + _c.Call.Return(run) + return _c +} + // NewTx creates a new instance of Tx. 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 NewTx(t interface { diff --git a/state/mocks/virtual_batch_storer.go b/state/mocks/virtual_batch_storer.go index b627590..dfc253b 100644 --- a/state/mocks/virtual_batch_storer.go +++ b/state/mocks/virtual_batch_storer.go @@ -70,6 +70,64 @@ func (_c *virtualBatchStorer_AddVirtualBatch_Call) RunAndReturn(run func(context return _c } +// GetLastestVirtualBatchNumber provides a mock function with given fields: ctx, constrains, dbTx +func (_m *virtualBatchStorer) GetLastestVirtualBatchNumber(ctx context.Context, constrains *entities.VirtualBatchConstraints, dbTx entities.Tx) (uint64, error) { + ret := _m.Called(ctx, constrains, dbTx) + + if len(ret) == 0 { + panic("no return value specified for GetLastestVirtualBatchNumber") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) (uint64, error)); ok { + return rf(ctx, constrains, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) uint64); ok { + r0 = rf(ctx, constrains, dbTx) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) error); ok { + r1 = rf(ctx, constrains, dbTx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// virtualBatchStorer_GetLastestVirtualBatchNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLastestVirtualBatchNumber' +type virtualBatchStorer_GetLastestVirtualBatchNumber_Call struct { + *mock.Call +} + +// GetLastestVirtualBatchNumber is a helper method to define mock.On call +// - ctx context.Context +// - constrains *entities.VirtualBatchConstraints +// - dbTx entities.Tx +func (_e *virtualBatchStorer_Expecter) GetLastestVirtualBatchNumber(ctx interface{}, constrains interface{}, dbTx interface{}) *virtualBatchStorer_GetLastestVirtualBatchNumber_Call { + return &virtualBatchStorer_GetLastestVirtualBatchNumber_Call{Call: _e.mock.On("GetLastestVirtualBatchNumber", ctx, constrains, dbTx)} +} + +func (_c *virtualBatchStorer_GetLastestVirtualBatchNumber_Call) Run(run func(ctx context.Context, constrains *entities.VirtualBatchConstraints, dbTx entities.Tx)) *virtualBatchStorer_GetLastestVirtualBatchNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*entities.VirtualBatchConstraints), args[2].(entities.Tx)) + }) + return _c +} + +func (_c *virtualBatchStorer_GetLastestVirtualBatchNumber_Call) Return(_a0 uint64, _a1 error) *virtualBatchStorer_GetLastestVirtualBatchNumber_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *virtualBatchStorer_GetLastestVirtualBatchNumber_Call) RunAndReturn(run func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) (uint64, error)) *virtualBatchStorer_GetLastestVirtualBatchNumber_Call { + _c.Call.Return(run) + return _c +} + // GetVirtualBatchByBatchNumber provides a mock function with given fields: ctx, batchNumber, dbTx func (_m *virtualBatchStorer) GetVirtualBatchByBatchNumber(ctx context.Context, batchNumber uint64, dbTx entities.Tx) (*entities.VirtualBatch, error) { ret := _m.Called(ctx, batchNumber, dbTx) diff --git a/state/model/l1infotree_state.go b/state/model/l1infotree_state.go index 33b0163..d58c446 100644 --- a/state/model/l1infotree_state.go +++ b/state/model/l1infotree_state.go @@ -165,3 +165,7 @@ func (s *L1InfoTreeState) GetLeafsByL1InfoRoot(ctx context.Context, l1InfoRoot c func (s *L1InfoTreeState) GetL1InfoLeafPerIndex(ctx context.Context, L1InfoTreeIndex uint32, dbTx stateTxType) (*L1InfoTreeLeaf, error) { return s.storage.GetL1InfoLeafPerIndex(ctx, L1InfoTreeIndex, dbTx) } + +func (s *L1InfoTreeState) GetLatestL1InfoTreeLeaf(ctx context.Context, dbTx stateTxType) (*L1InfoTreeLeaf, error) { + return s.storage.GetLatestL1InfoTreeLeaf(ctx, dbTx) +} diff --git a/state/storage/mocks/exec_querier.go b/state/storage/mocks/exec_querier.go index b6dd007..94a7ebe 100644 --- a/state/storage/mocks/exec_querier.go +++ b/state/storage/mocks/exec_querier.go @@ -4,11 +4,9 @@ package mock_storage import ( context "context" + sql "database/sql" - pgconn "github.com/jackc/pgconn" mock "github.com/stretchr/testify/mock" - - pgx "github.com/jackc/pgx/v4" ) // execQuerier is an autogenerated mock type for the execQuerier type @@ -24,91 +22,32 @@ func (_m *execQuerier) EXPECT() *execQuerier_Expecter { return &execQuerier_Expecter{mock: &_m.Mock} } -// CopyFrom provides a mock function with given fields: ctx, tableName, columnNames, rowSrc -func (_m *execQuerier) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error) { - ret := _m.Called(ctx, tableName, columnNames, rowSrc) - - if len(ret) == 0 { - panic("no return value specified for CopyFrom") - } - - var r0 int64 - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, pgx.Identifier, []string, pgx.CopyFromSource) (int64, error)); ok { - return rf(ctx, tableName, columnNames, rowSrc) - } - if rf, ok := ret.Get(0).(func(context.Context, pgx.Identifier, []string, pgx.CopyFromSource) int64); ok { - r0 = rf(ctx, tableName, columnNames, rowSrc) - } else { - r0 = ret.Get(0).(int64) - } - - if rf, ok := ret.Get(1).(func(context.Context, pgx.Identifier, []string, pgx.CopyFromSource) error); ok { - r1 = rf(ctx, tableName, columnNames, rowSrc) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// execQuerier_CopyFrom_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CopyFrom' -type execQuerier_CopyFrom_Call struct { - *mock.Call -} - -// CopyFrom is a helper method to define mock.On call -// - ctx context.Context -// - tableName pgx.Identifier -// - columnNames []string -// - rowSrc pgx.CopyFromSource -func (_e *execQuerier_Expecter) CopyFrom(ctx interface{}, tableName interface{}, columnNames interface{}, rowSrc interface{}) *execQuerier_CopyFrom_Call { - return &execQuerier_CopyFrom_Call{Call: _e.mock.On("CopyFrom", ctx, tableName, columnNames, rowSrc)} -} - -func (_c *execQuerier_CopyFrom_Call) Run(run func(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource)) *execQuerier_CopyFrom_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(pgx.Identifier), args[2].([]string), args[3].(pgx.CopyFromSource)) - }) - return _c -} - -func (_c *execQuerier_CopyFrom_Call) Return(_a0 int64, _a1 error) *execQuerier_CopyFrom_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *execQuerier_CopyFrom_Call) RunAndReturn(run func(context.Context, pgx.Identifier, []string, pgx.CopyFromSource) (int64, error)) *execQuerier_CopyFrom_Call { - _c.Call.Return(run) - return _c -} - -// Exec provides a mock function with given fields: ctx, sql, arguments -func (_m *execQuerier) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error) { +// ExecContext provides a mock function with given fields: ctx, _a1, arguments +func (_m *execQuerier) ExecContext(ctx context.Context, _a1 string, arguments ...interface{}) (sql.Result, error) { var _ca []interface{} - _ca = append(_ca, ctx, sql) + _ca = append(_ca, ctx, _a1) _ca = append(_ca, arguments...) ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for Exec") + panic("no return value specified for ExecContext") } - var r0 pgconn.CommandTag + var r0 sql.Result var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) (pgconn.CommandTag, error)); ok { - return rf(ctx, sql, arguments...) + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) (sql.Result, error)); ok { + return rf(ctx, _a1, arguments...) } - if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) pgconn.CommandTag); ok { - r0 = rf(ctx, sql, arguments...) + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) sql.Result); ok { + r0 = rf(ctx, _a1, arguments...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(pgconn.CommandTag) + r0 = ret.Get(0).(sql.Result) } } if rf, ok := ret.Get(1).(func(context.Context, string, ...interface{}) error); ok { - r1 = rf(ctx, sql, arguments...) + r1 = rf(ctx, _a1, arguments...) } else { r1 = ret.Error(1) } @@ -116,21 +55,21 @@ func (_m *execQuerier) Exec(ctx context.Context, sql string, arguments ...interf return r0, r1 } -// execQuerier_Exec_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Exec' -type execQuerier_Exec_Call struct { +// execQuerier_ExecContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ExecContext' +type execQuerier_ExecContext_Call struct { *mock.Call } -// Exec is a helper method to define mock.On call +// ExecContext is a helper method to define mock.On call // - ctx context.Context -// - sql string +// - _a1 string // - arguments ...interface{} -func (_e *execQuerier_Expecter) Exec(ctx interface{}, sql interface{}, arguments ...interface{}) *execQuerier_Exec_Call { - return &execQuerier_Exec_Call{Call: _e.mock.On("Exec", - append([]interface{}{ctx, sql}, arguments...)...)} +func (_e *execQuerier_Expecter) ExecContext(ctx interface{}, _a1 interface{}, arguments ...interface{}) *execQuerier_ExecContext_Call { + return &execQuerier_ExecContext_Call{Call: _e.mock.On("ExecContext", + append([]interface{}{ctx, _a1}, arguments...)...)} } -func (_c *execQuerier_Exec_Call) Run(run func(ctx context.Context, sql string, arguments ...interface{})) *execQuerier_Exec_Call { +func (_c *execQuerier_ExecContext_Call) Run(run func(ctx context.Context, _a1 string, arguments ...interface{})) *execQuerier_ExecContext_Call { _c.Call.Run(func(args mock.Arguments) { variadicArgs := make([]interface{}, len(args)-2) for i, a := range args[2:] { @@ -143,42 +82,42 @@ func (_c *execQuerier_Exec_Call) Run(run func(ctx context.Context, sql string, a return _c } -func (_c *execQuerier_Exec_Call) Return(commandTag pgconn.CommandTag, err error) *execQuerier_Exec_Call { - _c.Call.Return(commandTag, err) +func (_c *execQuerier_ExecContext_Call) Return(_a0 sql.Result, _a1 error) *execQuerier_ExecContext_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *execQuerier_Exec_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (pgconn.CommandTag, error)) *execQuerier_Exec_Call { +func (_c *execQuerier_ExecContext_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (sql.Result, error)) *execQuerier_ExecContext_Call { _c.Call.Return(run) return _c } -// Query provides a mock function with given fields: ctx, sql, args -func (_m *execQuerier) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error) { +// QueryContext provides a mock function with given fields: ctx, _a1, args +func (_m *execQuerier) QueryContext(ctx context.Context, _a1 string, args ...interface{}) (*sql.Rows, error) { var _ca []interface{} - _ca = append(_ca, ctx, sql) + _ca = append(_ca, ctx, _a1) _ca = append(_ca, args...) ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for Query") + panic("no return value specified for QueryContext") } - var r0 pgx.Rows + var r0 *sql.Rows var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) (pgx.Rows, error)); ok { - return rf(ctx, sql, args...) + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) (*sql.Rows, error)); ok { + return rf(ctx, _a1, args...) } - if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) pgx.Rows); ok { - r0 = rf(ctx, sql, args...) + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) *sql.Rows); ok { + r0 = rf(ctx, _a1, args...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(pgx.Rows) + r0 = ret.Get(0).(*sql.Rows) } } if rf, ok := ret.Get(1).(func(context.Context, string, ...interface{}) error); ok { - r1 = rf(ctx, sql, args...) + r1 = rf(ctx, _a1, args...) } else { r1 = ret.Error(1) } @@ -186,21 +125,21 @@ func (_m *execQuerier) Query(ctx context.Context, sql string, args ...interface{ return r0, r1 } -// execQuerier_Query_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Query' -type execQuerier_Query_Call struct { +// execQuerier_QueryContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryContext' +type execQuerier_QueryContext_Call struct { *mock.Call } -// Query is a helper method to define mock.On call +// QueryContext is a helper method to define mock.On call // - ctx context.Context -// - sql string +// - _a1 string // - args ...interface{} -func (_e *execQuerier_Expecter) Query(ctx interface{}, sql interface{}, args ...interface{}) *execQuerier_Query_Call { - return &execQuerier_Query_Call{Call: _e.mock.On("Query", - append([]interface{}{ctx, sql}, args...)...)} +func (_e *execQuerier_Expecter) QueryContext(ctx interface{}, _a1 interface{}, args ...interface{}) *execQuerier_QueryContext_Call { + return &execQuerier_QueryContext_Call{Call: _e.mock.On("QueryContext", + append([]interface{}{ctx, _a1}, args...)...)} } -func (_c *execQuerier_Query_Call) Run(run func(ctx context.Context, sql string, args ...interface{})) *execQuerier_Query_Call { +func (_c *execQuerier_QueryContext_Call) Run(run func(ctx context.Context, _a1 string, args ...interface{})) *execQuerier_QueryContext_Call { _c.Call.Run(func(args mock.Arguments) { variadicArgs := make([]interface{}, len(args)-2) for i, a := range args[2:] { @@ -213,54 +152,54 @@ func (_c *execQuerier_Query_Call) Run(run func(ctx context.Context, sql string, return _c } -func (_c *execQuerier_Query_Call) Return(_a0 pgx.Rows, _a1 error) *execQuerier_Query_Call { +func (_c *execQuerier_QueryContext_Call) Return(_a0 *sql.Rows, _a1 error) *execQuerier_QueryContext_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *execQuerier_Query_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (pgx.Rows, error)) *execQuerier_Query_Call { +func (_c *execQuerier_QueryContext_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (*sql.Rows, error)) *execQuerier_QueryContext_Call { _c.Call.Return(run) return _c } -// QueryRow provides a mock function with given fields: ctx, sql, args -func (_m *execQuerier) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row { +// QueryRowContext provides a mock function with given fields: ctx, _a1, args +func (_m *execQuerier) QueryRowContext(ctx context.Context, _a1 string, args ...interface{}) *sql.Row { var _ca []interface{} - _ca = append(_ca, ctx, sql) + _ca = append(_ca, ctx, _a1) _ca = append(_ca, args...) ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for QueryRow") + panic("no return value specified for QueryRowContext") } - var r0 pgx.Row - if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) pgx.Row); ok { - r0 = rf(ctx, sql, args...) + var r0 *sql.Row + if rf, ok := ret.Get(0).(func(context.Context, string, ...interface{}) *sql.Row); ok { + r0 = rf(ctx, _a1, args...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(pgx.Row) + r0 = ret.Get(0).(*sql.Row) } } return r0 } -// execQuerier_QueryRow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryRow' -type execQuerier_QueryRow_Call struct { +// execQuerier_QueryRowContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryRowContext' +type execQuerier_QueryRowContext_Call struct { *mock.Call } -// QueryRow is a helper method to define mock.On call +// QueryRowContext is a helper method to define mock.On call // - ctx context.Context -// - sql string +// - _a1 string // - args ...interface{} -func (_e *execQuerier_Expecter) QueryRow(ctx interface{}, sql interface{}, args ...interface{}) *execQuerier_QueryRow_Call { - return &execQuerier_QueryRow_Call{Call: _e.mock.On("QueryRow", - append([]interface{}{ctx, sql}, args...)...)} +func (_e *execQuerier_Expecter) QueryRowContext(ctx interface{}, _a1 interface{}, args ...interface{}) *execQuerier_QueryRowContext_Call { + return &execQuerier_QueryRowContext_Call{Call: _e.mock.On("QueryRowContext", + append([]interface{}{ctx, _a1}, args...)...)} } -func (_c *execQuerier_QueryRow_Call) Run(run func(ctx context.Context, sql string, args ...interface{})) *execQuerier_QueryRow_Call { +func (_c *execQuerier_QueryRowContext_Call) Run(run func(ctx context.Context, _a1 string, args ...interface{})) *execQuerier_QueryRowContext_Call { _c.Call.Run(func(args mock.Arguments) { variadicArgs := make([]interface{}, len(args)-2) for i, a := range args[2:] { @@ -273,12 +212,12 @@ func (_c *execQuerier_QueryRow_Call) Run(run func(ctx context.Context, sql strin return _c } -func (_c *execQuerier_QueryRow_Call) Return(_a0 pgx.Row) *execQuerier_QueryRow_Call { +func (_c *execQuerier_QueryRowContext_Call) Return(_a0 *sql.Row) *execQuerier_QueryRowContext_Call { _c.Call.Return(_a0) return _c } -func (_c *execQuerier_QueryRow_Call) RunAndReturn(run func(context.Context, string, ...interface{}) pgx.Row) *execQuerier_QueryRow_Call { +func (_c *execQuerier_QueryRowContext_Call) RunAndReturn(run func(context.Context, string, ...interface{}) *sql.Row) *execQuerier_QueryRowContext_Call { _c.Call.Return(run) return _c } diff --git a/state/storage/mocks/storer.go b/state/storage/mocks/storer.go index 9ee31b4..67e4260 100644 --- a/state/storage/mocks/storer.go +++ b/state/storage/mocks/storer.go @@ -824,6 +824,64 @@ func (_c *Storer_GetLastBlock_Call) RunAndReturn(run func(context.Context, entit return _c } +// GetLastestVirtualBatchNumber provides a mock function with given fields: ctx, constrains, dbTx +func (_m *Storer) GetLastestVirtualBatchNumber(ctx context.Context, constrains *entities.VirtualBatchConstraints, dbTx entities.Tx) (uint64, error) { + ret := _m.Called(ctx, constrains, dbTx) + + if len(ret) == 0 { + panic("no return value specified for GetLastestVirtualBatchNumber") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) (uint64, error)); ok { + return rf(ctx, constrains, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) uint64); ok { + r0 = rf(ctx, constrains, dbTx) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) error); ok { + r1 = rf(ctx, constrains, dbTx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Storer_GetLastestVirtualBatchNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLastestVirtualBatchNumber' +type Storer_GetLastestVirtualBatchNumber_Call struct { + *mock.Call +} + +// GetLastestVirtualBatchNumber is a helper method to define mock.On call +// - ctx context.Context +// - constrains *entities.VirtualBatchConstraints +// - dbTx entities.Tx +func (_e *Storer_Expecter) GetLastestVirtualBatchNumber(ctx interface{}, constrains interface{}, dbTx interface{}) *Storer_GetLastestVirtualBatchNumber_Call { + return &Storer_GetLastestVirtualBatchNumber_Call{Call: _e.mock.On("GetLastestVirtualBatchNumber", ctx, constrains, dbTx)} +} + +func (_c *Storer_GetLastestVirtualBatchNumber_Call) Run(run func(ctx context.Context, constrains *entities.VirtualBatchConstraints, dbTx entities.Tx)) *Storer_GetLastestVirtualBatchNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*entities.VirtualBatchConstraints), args[2].(entities.Tx)) + }) + return _c +} + +func (_c *Storer_GetLastestVirtualBatchNumber_Call) Return(_a0 uint64, _a1 error) *Storer_GetLastestVirtualBatchNumber_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Storer_GetLastestVirtualBatchNumber_Call) RunAndReturn(run func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) (uint64, error)) *Storer_GetLastestVirtualBatchNumber_Call { + _c.Call.Return(run) + return _c +} + // GetLatestL1InfoTreeLeaf provides a mock function with given fields: ctx, dbTx func (_m *Storer) GetLatestL1InfoTreeLeaf(ctx context.Context, dbTx entities.Tx) (*entities.L1InfoTreeLeaf, error) { ret := _m.Called(ctx, dbTx) diff --git a/state/storage/mocks/virtual_batch_storer.go b/state/storage/mocks/virtual_batch_storer.go index 588d7e8..a27bef0 100644 --- a/state/storage/mocks/virtual_batch_storer.go +++ b/state/storage/mocks/virtual_batch_storer.go @@ -70,6 +70,64 @@ func (_c *virtualBatchStorer_AddVirtualBatch_Call) RunAndReturn(run func(context return _c } +// GetLastestVirtualBatchNumber provides a mock function with given fields: ctx, constrains, dbTx +func (_m *virtualBatchStorer) GetLastestVirtualBatchNumber(ctx context.Context, constrains *entities.VirtualBatchConstraints, dbTx entities.Tx) (uint64, error) { + ret := _m.Called(ctx, constrains, dbTx) + + if len(ret) == 0 { + panic("no return value specified for GetLastestVirtualBatchNumber") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) (uint64, error)); ok { + return rf(ctx, constrains, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) uint64); ok { + r0 = rf(ctx, constrains, dbTx) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) error); ok { + r1 = rf(ctx, constrains, dbTx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// virtualBatchStorer_GetLastestVirtualBatchNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLastestVirtualBatchNumber' +type virtualBatchStorer_GetLastestVirtualBatchNumber_Call struct { + *mock.Call +} + +// GetLastestVirtualBatchNumber is a helper method to define mock.On call +// - ctx context.Context +// - constrains *entities.VirtualBatchConstraints +// - dbTx entities.Tx +func (_e *virtualBatchStorer_Expecter) GetLastestVirtualBatchNumber(ctx interface{}, constrains interface{}, dbTx interface{}) *virtualBatchStorer_GetLastestVirtualBatchNumber_Call { + return &virtualBatchStorer_GetLastestVirtualBatchNumber_Call{Call: _e.mock.On("GetLastestVirtualBatchNumber", ctx, constrains, dbTx)} +} + +func (_c *virtualBatchStorer_GetLastestVirtualBatchNumber_Call) Run(run func(ctx context.Context, constrains *entities.VirtualBatchConstraints, dbTx entities.Tx)) *virtualBatchStorer_GetLastestVirtualBatchNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*entities.VirtualBatchConstraints), args[2].(entities.Tx)) + }) + return _c +} + +func (_c *virtualBatchStorer_GetLastestVirtualBatchNumber_Call) Return(_a0 uint64, _a1 error) *virtualBatchStorer_GetLastestVirtualBatchNumber_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *virtualBatchStorer_GetLastestVirtualBatchNumber_Call) RunAndReturn(run func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) (uint64, error)) *virtualBatchStorer_GetLastestVirtualBatchNumber_Call { + _c.Call.Return(run) + return _c +} + // GetVirtualBatchByBatchNumber provides a mock function with given fields: ctx, batchNumber, dbTx func (_m *virtualBatchStorer) GetVirtualBatchByBatchNumber(ctx context.Context, batchNumber uint64, dbTx entities.Tx) (*entities.VirtualBatch, error) { ret := _m.Called(ctx, batchNumber, dbTx) diff --git a/synchronizer/actions/banana/processor_update_l1_info_tree_v2.go b/synchronizer/actions/banana/processor_update_l1_info_tree_v2.go index 8be5d28..6840bcd 100644 --- a/synchronizer/actions/banana/processor_update_l1_info_tree_v2.go +++ b/synchronizer/actions/banana/processor_update_l1_info_tree_v2.go @@ -13,6 +13,7 @@ import ( type stateVerifyL1InfoTreeInterface interface { GetL1InfoLeafPerIndex(ctx context.Context, L1InfoTreeIndex uint32, dbTx stateTxType) (*L1InfoTreeLeaf, error) + GetLatestL1InfoTreeLeaf(ctx context.Context, dbTx stateTxType) (*L1InfoTreeLeaf, error) } type ProcessorUpdateL1InfoTreeV2 struct { @@ -55,7 +56,16 @@ func (p *ProcessorUpdateL1InfoTreeV2) ProcessUpdateL1InfoTreeV2(ctx context.Cont } log.Infof("L1InfoTreeLeafV2 sanity check OK: %s", data.String()) } else { - log.Warnf("this l1nfotree is not stored on local DB. So can't check it: data:%s ", data.String()) + responseErr := fmt.Sprintf("this l1nfotree is not stored on local DB. So it's likely that is desynced : incomming data:%s ", data.String()) + lastLeafOnDb, err := p.state.GetLatestL1InfoTreeLeaf(ctx, dbTx) + if err == nil && lastLeafOnDb != nil { + responseErr += fmt.Sprintf(" Latest leaf on DB: %s", lastLeafOnDb.String()) + } else { + responseErr += fmt.Sprintf(" Error getting latest leaf on DB: %v", err) + } + log.Error(responseErr) + return fmt.Errorf(responseErr) + } return nil } diff --git a/synchronizer/syncinterfaces/mocks/state_interface.go b/synchronizer/syncinterfaces/mocks/state_interface.go index 723b163..ee0289b 100644 --- a/synchronizer/syncinterfaces/mocks/state_interface.go +++ b/synchronizer/syncinterfaces/mocks/state_interface.go @@ -870,6 +870,65 @@ func (_c *StateInterface_GetLastBlock_Call) RunAndReturn(run func(context.Contex return _c } +// GetLatestL1InfoTreeLeaf provides a mock function with given fields: ctx, dbTx +func (_m *StateInterface) GetLatestL1InfoTreeLeaf(ctx context.Context, dbTx entities.Tx) (*entities.L1InfoTreeLeaf, error) { + ret := _m.Called(ctx, dbTx) + + if len(ret) == 0 { + panic("no return value specified for GetLatestL1InfoTreeLeaf") + } + + var r0 *entities.L1InfoTreeLeaf + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, entities.Tx) (*entities.L1InfoTreeLeaf, error)); ok { + return rf(ctx, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, entities.Tx) *entities.L1InfoTreeLeaf); ok { + r0 = rf(ctx, dbTx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*entities.L1InfoTreeLeaf) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, entities.Tx) error); ok { + r1 = rf(ctx, dbTx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// StateInterface_GetLatestL1InfoTreeLeaf_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLatestL1InfoTreeLeaf' +type StateInterface_GetLatestL1InfoTreeLeaf_Call struct { + *mock.Call +} + +// GetLatestL1InfoTreeLeaf is a helper method to define mock.On call +// - ctx context.Context +// - dbTx entities.Tx +func (_e *StateInterface_Expecter) GetLatestL1InfoTreeLeaf(ctx interface{}, dbTx interface{}) *StateInterface_GetLatestL1InfoTreeLeaf_Call { + return &StateInterface_GetLatestL1InfoTreeLeaf_Call{Call: _e.mock.On("GetLatestL1InfoTreeLeaf", ctx, dbTx)} +} + +func (_c *StateInterface_GetLatestL1InfoTreeLeaf_Call) Run(run func(ctx context.Context, dbTx entities.Tx)) *StateInterface_GetLatestL1InfoTreeLeaf_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(entities.Tx)) + }) + return _c +} + +func (_c *StateInterface_GetLatestL1InfoTreeLeaf_Call) Return(_a0 *entities.L1InfoTreeLeaf, _a1 error) *StateInterface_GetLatestL1InfoTreeLeaf_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *StateInterface_GetLatestL1InfoTreeLeaf_Call) RunAndReturn(run func(context.Context, entities.Tx) (*entities.L1InfoTreeLeaf, error)) *StateInterface_GetLatestL1InfoTreeLeaf_Call { + _c.Call.Return(run) + return _c +} + // GetLeafsByL1InfoRoot provides a mock function with given fields: ctx, l1InfoRoot, dbTx func (_m *StateInterface) GetLeafsByL1InfoRoot(ctx context.Context, l1InfoRoot common.Hash, dbTx entities.Tx) ([]entities.L1InfoTreeLeaf, error) { ret := _m.Called(ctx, l1InfoRoot, dbTx) diff --git a/synchronizer/syncinterfaces/mocks/storage_virtual_batch_interface.go b/synchronizer/syncinterfaces/mocks/storage_virtual_batch_interface.go index 0bb6bfa..e513177 100644 --- a/synchronizer/syncinterfaces/mocks/storage_virtual_batch_interface.go +++ b/synchronizer/syncinterfaces/mocks/storage_virtual_batch_interface.go @@ -7,8 +7,6 @@ import ( entities "github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities" mock "github.com/stretchr/testify/mock" - - pgstorage "github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/storage/pgstorage" ) // StorageVirtualBatchInterface is an autogenerated mock type for the StorageVirtualBatchInterface type @@ -25,7 +23,7 @@ func (_m *StorageVirtualBatchInterface) EXPECT() *StorageVirtualBatchInterface_E } // GetLastestVirtualBatchNumber provides a mock function with given fields: ctx, constrains, dbTx -func (_m *StorageVirtualBatchInterface) GetLastestVirtualBatchNumber(ctx context.Context, constrains *pgstorage.VirtualBatchConstraints, dbTx entities.Tx) (uint64, error) { +func (_m *StorageVirtualBatchInterface) GetLastestVirtualBatchNumber(ctx context.Context, constrains *entities.VirtualBatchConstraints, dbTx entities.Tx) (uint64, error) { ret := _m.Called(ctx, constrains, dbTx) if len(ret) == 0 { @@ -34,16 +32,16 @@ func (_m *StorageVirtualBatchInterface) GetLastestVirtualBatchNumber(ctx context var r0 uint64 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *pgstorage.VirtualBatchConstraints, entities.Tx) (uint64, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) (uint64, error)); ok { return rf(ctx, constrains, dbTx) } - if rf, ok := ret.Get(0).(func(context.Context, *pgstorage.VirtualBatchConstraints, entities.Tx) uint64); ok { + if rf, ok := ret.Get(0).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) uint64); ok { r0 = rf(ctx, constrains, dbTx) } else { r0 = ret.Get(0).(uint64) } - if rf, ok := ret.Get(1).(func(context.Context, *pgstorage.VirtualBatchConstraints, entities.Tx) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) error); ok { r1 = rf(ctx, constrains, dbTx) } else { r1 = ret.Error(1) @@ -59,15 +57,15 @@ type StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call struct { // GetLastestVirtualBatchNumber is a helper method to define mock.On call // - ctx context.Context -// - constrains *pgstorage.VirtualBatchConstraints +// - constrains *entities.VirtualBatchConstraints // - dbTx entities.Tx func (_e *StorageVirtualBatchInterface_Expecter) GetLastestVirtualBatchNumber(ctx interface{}, constrains interface{}, dbTx interface{}) *StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call { return &StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call{Call: _e.mock.On("GetLastestVirtualBatchNumber", ctx, constrains, dbTx)} } -func (_c *StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call) Run(run func(ctx context.Context, constrains *pgstorage.VirtualBatchConstraints, dbTx entities.Tx)) *StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call { +func (_c *StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call) Run(run func(ctx context.Context, constrains *entities.VirtualBatchConstraints, dbTx entities.Tx)) *StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*pgstorage.VirtualBatchConstraints), args[2].(entities.Tx)) + run(args[0].(context.Context), args[1].(*entities.VirtualBatchConstraints), args[2].(entities.Tx)) }) return _c } @@ -77,7 +75,7 @@ func (_c *StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call) Return return _c } -func (_c *StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call) RunAndReturn(run func(context.Context, *pgstorage.VirtualBatchConstraints, entities.Tx) (uint64, error)) *StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call { +func (_c *StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call) RunAndReturn(run func(context.Context, *entities.VirtualBatchConstraints, entities.Tx) (uint64, error)) *StorageVirtualBatchInterface_GetLastestVirtualBatchNumber_Call { _c.Call.Return(run) return _c } diff --git a/synchronizer/syncinterfaces/state.go b/synchronizer/syncinterfaces/state.go index 357510b..121fd0d 100644 --- a/synchronizer/syncinterfaces/state.go +++ b/synchronizer/syncinterfaces/state.go @@ -43,6 +43,7 @@ type StateInterface interface { GetL1InfoRootPerLeafIndex(ctx context.Context, L1InfoTreeIndex uint32, dbTx stateTxType) (common.Hash, error) GetL1InfoLeafPerIndex(ctx context.Context, L1InfoTreeIndex uint32, dbTx stateTxType) (*entities.L1InfoTreeLeaf, error) GetL1InfoTreeLeaves(ctx context.Context, indexLeaves []uint32, dbTx stateTxType) (map[uint32]entities.L1InfoTreeLeaf, error) + GetLatestL1InfoTreeLeaf(ctx context.Context, dbTx stateTxType) (*entities.L1InfoTreeLeaf, error) AddForkID(ctx context.Context, newForkID entities.ForkIDInterval, dbTx stateTxType) error diff --git a/version.go b/version.go index af2f88c..a762f5b 100644 --- a/version.go +++ b/version.go @@ -7,7 +7,7 @@ import ( ) var ( - Version = "v1.0.3" + Version = "v1.0.4" ) // PrintVersion prints version info into the provided io.Writer.