Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store batchL2Data when the batch is opened #2358

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions state/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ProcessingContext struct {
Timestamp time.Time
GlobalExitRoot common.Hash
ForcedBatchNum *uint64
BatchL2Data *[]byte
}

// ClosingReason represents the reason why a batch is closed.
Expand Down
3 changes: 2 additions & 1 deletion state/pgstatestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ func (p *PostgresStorage) storeGenesisBatch(ctx context.Context, batch Batch, db
// in this batch yet. In other words it's the creation of a WIP batch.
// Note that this will add a batch with batch number N + 1, where N it's the greatest batch number on the state.
func (p *PostgresStorage) openBatch(ctx context.Context, batchContext ProcessingContext, dbTx pgx.Tx) error {
const openBatchSQL = "INSERT INTO state.batch (batch_num, global_exit_root, timestamp, coinbase, forced_batch_num) VALUES ($1, $2, $3, $4, $5)"
const openBatchSQL = "INSERT INTO state.batch (batch_num, global_exit_root, timestamp, coinbase, forced_batch_num, raw_txs_data) VALUES ($1, $2, $3, $4, $5, $6)"

e := p.getExecQuerier(dbTx)
_, err := e.Exec(
Expand All @@ -974,6 +974,7 @@ func (p *PostgresStorage) openBatch(ctx context.Context, batchContext Processing
batchContext.Timestamp.UTC(),
batchContext.Coinbase.String(),
batchContext.ForcedBatchNum,
batchContext.BatchL2Data,
)
return err
}
Expand Down
2 changes: 2 additions & 0 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1455,11 +1455,13 @@ func (s *ClientSynchronizer) processAndStoreTxs(trustedBatch *types.Batch, reque

func (s *ClientSynchronizer) openBatch(trustedBatch *types.Batch, dbTx pgx.Tx) error {
log.Debugf("Opening batch %d", trustedBatch.Number)
var batchL2Data []byte = trustedBatch.BatchL2Data
processCtx := state.ProcessingContext{
BatchNumber: uint64(trustedBatch.Number),
Coinbase: common.HexToAddress(trustedBatch.Coinbase.String()),
Timestamp: time.Unix(int64(trustedBatch.Timestamp), 0),
GlobalExitRoot: trustedBatch.GlobalExitRoot,
BatchL2Data: &batchL2Data,
}
if trustedBatch.ForcedBatchNumber != nil {
fb := uint64(*trustedBatch.ForcedBatchNumber)
Expand Down
1 change: 1 addition & 0 deletions synchronizer/synchronizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ func expectedCallsForsyncTrustedState(t *testing.T, m *mocks, sync *ClientSynchr
Coinbase: common.HexToAddress(batchInTrustedNode.Coinbase.String()),
Timestamp: time.Unix(int64(batchInTrustedNode.Timestamp), 0),
GlobalExitRoot: batchInTrustedNode.GlobalExitRoot,
BatchL2Data: (*[]byte)(&batchInTrustedNode.BatchL2Data),
}
m.State.
On("OpenBatch", sync.ctx, processCtx, m.DbTx).
Expand Down