diff --git a/sequencer/dbmanager.go b/sequencer/dbmanager.go index 987d61f034..7d172ef94f 100644 --- a/sequencer/dbmanager.go +++ b/sequencer/dbmanager.go @@ -292,7 +292,7 @@ func (d *dbManager) StoreProcessedTxAndDeleteFromPool(ctx context.Context, tx tr batch.BatchL2Data = append(batch.BatchL2Data, txData...) if !tx.isForcedBatch { - err = d.state.UpdateBatchL2Data(ctx, tx.batchNumber, batch.BatchL2Data, dbTx) + err = d.state.UpdateBatchL2DataAndLER(ctx, tx.batchNumber, batch.BatchL2Data, tx.batchResponse.NewLocalExitRoot, dbTx) if err != nil { err2 := dbTx.Rollback(ctx) if err2 != nil { diff --git a/sequencer/interfaces.go b/sequencer/interfaces.go index 32bf0c1ce7..2dfc818823 100644 --- a/sequencer/interfaces.go +++ b/sequencer/interfaces.go @@ -72,6 +72,7 @@ type stateInterface interface { GetLatestGlobalExitRoot(ctx context.Context, maxBlockNumber uint64, dbTx pgx.Tx) (state.GlobalExitRoot, time.Time, error) GetLastL2BlockHeader(ctx context.Context, dbTx pgx.Tx) (*types.Header, error) UpdateBatchL2Data(ctx context.Context, batchNumber uint64, batchL2Data []byte, dbTx pgx.Tx) error + UpdateBatchL2DataAndLER(ctx context.Context, batchNumber uint64, batchL2Data []byte, localExitRoot common.Hash, dbTx pgx.Tx) error ProcessSequencerBatch(ctx context.Context, batchNumber uint64, batchL2Data []byte, caller metrics.CallerLabel, dbTx pgx.Tx) (*state.ProcessBatchResponse, error) GetForcedBatchesSince(ctx context.Context, forcedBatchNumber, maxBlockNumber uint64, dbTx pgx.Tx) ([]*state.ForcedBatch, error) GetLastTrustedForcedBatchNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error) diff --git a/sequencer/mock_state.go b/sequencer/mock_state.go index 4c75ede79d..95af2e78d2 100644 --- a/sequencer/mock_state.go +++ b/sequencer/mock_state.go @@ -966,6 +966,20 @@ func (_m *StateMock) UpdateBatchL2Data(ctx context.Context, batchNumber uint64, return r0 } +// UpdateBatchL2DataAndLER provides a mock function with given fields: ctx, batchNumber, batchL2Data, localExitRoot, dbTx +func (_m *StateMock) UpdateBatchL2DataAndLER(ctx context.Context, batchNumber uint64, batchL2Data []byte, localExitRoot common.Hash, dbTx pgx.Tx) error { + ret := _m.Called(ctx, batchNumber, batchL2Data, localExitRoot, dbTx) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, []byte, common.Hash, pgx.Tx) error); ok { + r0 = rf(ctx, batchNumber, batchL2Data, localExitRoot, dbTx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + // NewStateMock creates a new instance of StateMock. 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 NewStateMock(t interface { diff --git a/state/pgstatestorage.go b/state/pgstatestorage.go index 1c394a8c71..4f96861a35 100644 --- a/state/pgstatestorage.go +++ b/state/pgstatestorage.go @@ -2438,6 +2438,15 @@ func (p *PostgresStorage) UpdateBatchL2Data(ctx context.Context, batchNumber uin return err } +// UpdateBatchL2DataAndLER updates data tx data in a batch and the local exit root +func (p *PostgresStorage) UpdateBatchL2DataAndLER(ctx context.Context, batchNumber uint64, batchL2Data []byte, localExitRoot common.Hash, dbTx pgx.Tx) error { + const updateL2DataSQL = "UPDATE state.batch SET raw_txs_data = $2, local_exit_root = $3 WHERE batch_num = $1" + + e := p.getExecQuerier(dbTx) + _, err := e.Exec(ctx, updateL2DataSQL, batchNumber, batchL2Data, localExitRoot.String()) + return err +} + // AddAccumulatedInputHash adds the accumulated input hash func (p *PostgresStorage) AddAccumulatedInputHash(ctx context.Context, batchNum uint64, accInputHash common.Hash, dbTx pgx.Tx) error { const addAccInputHashBatchSQL = "UPDATE state.batch SET acc_input_hash = $1 WHERE batch_num = $2"