Skip to content

Commit

Permalink
Cherry-pick 0xPolygonHermez#2658: feature: storing LER in state.batch…
Browse files Browse the repository at this point in the history
… on successful transaction processing (0xPolygonHermez#2821)

* feature: storing LER in state.batch on successful transaction processing (0xPolygonHermez#2658)

Signed-off-by: Nikolay Nedkov <[email protected]>

* fix doc

---------

Signed-off-by: Nikolay Nedkov <[email protected]>
Co-authored-by: Nikolay Nedkov <[email protected]>
  • Loading branch information
agnusmor and Psykepro authored Nov 23, 2023
1 parent 837a78a commit 84ac067
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sequencer/dbmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,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 {
Expand Down
1 change: 1 addition & 0 deletions sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions sequencer/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type storage interface {
GetLastClosedBatch(ctx context.Context, dbTx pgx.Tx) (*Batch, error)
GetLastClosedBatchNumber(ctx context.Context, dbTx pgx.Tx) (uint64, 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
AddAccumulatedInputHash(ctx context.Context, batchNum uint64, accInputHash common.Hash, dbTx pgx.Tx) error
GetLastTrustedForcedBatchNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
AddTrustedReorg(ctx context.Context, reorg *TrustedReorg, dbTx pgx.Tx) error
Expand Down
9 changes: 9 additions & 0 deletions state/pgstatestorage/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,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"
Expand Down

0 comments on commit 84ac067

Please sign in to comment.