Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR552 authored Jan 3, 2024
1 parent 35e208e commit 2e584e7
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 33 deletions.
4 changes: 4 additions & 0 deletions jsonrpc/mocks/mock_pool.go

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

4 changes: 4 additions & 0 deletions jsonrpc/mocks/mock_state.go

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

2 changes: 1 addition & 1 deletion sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type stateInterface interface {
OpenWIPBatch(ctx context.Context, batch state.Batch, dbTx pgx.Tx) error
GetWIPBatch(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.Batch, error)
GetLastNBatches(ctx context.Context, numBatches uint, dbTx pgx.Tx) ([]*state.Batch, error)
StoreTransaction(ctx context.Context, batchNumber uint64, processedTx *state.ProcessTransactionResponse, coinbase common.Address, timestamp uint64, egpLog *state.EffectiveGasPriceLog, dbTx pgx.Tx) (*state.L2Header, error)
StoreTransaction(ctx context.Context, batchNumber uint64, processedTx *state.ProcessTransactionResponse, coinbase common.Address, timestamp uint64, egpLog *state.EffectiveGasPriceLog, globalExitRoot, blockInfoRoot common.Hash, dbTx pgx.Tx) (*state.L2Header, error)
GetLastClosedBatch(ctx context.Context, dbTx pgx.Tx) (*state.Batch, error)
GetLastL2Block(ctx context.Context, dbTx pgx.Tx) (*state.L2Block, error)
GetLastBlock(ctx context.Context, dbTx pgx.Tx) (*state.Block, error)
Expand Down
18 changes: 9 additions & 9 deletions sequencer/mock_state.go

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

12 changes: 7 additions & 5 deletions state/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ func RlpFieldsToLegacyTx(fields [][]byte, v, r, s []byte) (tx *types.LegacyTx, e
}, nil
}

// StoreTransactions is used by the sequencer to add processed transactions into
// an open batch. If the batch already has txs, the processedTxs must be a super
// set of the existing ones, preserving order.
// StoreTransactions is used by the synchronizer through the method ProcessAndStoreClosedBatch.
func (s *State) StoreTransactions(ctx context.Context, batchNumber uint64, processedBlocks []*ProcessBlockResponse, txsEGPLog []*EffectiveGasPriceLog, dbTx pgx.Tx) error {
if dbTx == nil {
return ErrDBTxNil
Expand Down Expand Up @@ -230,6 +228,8 @@ func (s *State) StoreTransactions(ctx context.Context, batchNumber uint64, proce
GasLimit: s.cfg.MaxCumulativeGasUsed,
Time: uint64(processingContext.Timestamp.Unix()),
})
header.GlobalExitRoot = processedBlock.GlobalExitRoot
header.BlockInfoRoot = processedBlock.BlockInfoRoot
transactions := []*types.Transaction{&processedTx.Tx}

receipt := GenerateReceipt(header.Number, processedTx)
Expand Down Expand Up @@ -653,8 +653,8 @@ func (s *State) isContractCreation(tx *types.Transaction) bool {
return tx.To() == nil && len(tx.Data()) > 0
}

// StoreTransaction is used by the sequencer and trusted state synchronizer to add process a transaction.
func (s *State) StoreTransaction(ctx context.Context, batchNumber uint64, processedTx *ProcessTransactionResponse, coinbase common.Address, timestamp uint64, egpLog *EffectiveGasPriceLog, dbTx pgx.Tx) (*L2Header, error) {
// StoreTransaction is used by the trusted state synchronizer to add process a transaction.
func (s *State) StoreTransaction(ctx context.Context, batchNumber uint64, processedTx *ProcessTransactionResponse, coinbase common.Address, timestamp uint64, egpLog *EffectiveGasPriceLog, globalExitRoot, blockInfoRoot common.Hash, dbTx pgx.Tx) (*L2Header, error) {
if dbTx == nil {
return nil, ErrDBTxNil
}
Expand All @@ -679,6 +679,8 @@ func (s *State) StoreTransaction(ctx context.Context, batchNumber uint64, proces
GasLimit: s.cfg.MaxCumulativeGasUsed,
Time: timestamp,
})
header.GlobalExitRoot = globalExitRoot
header.BlockInfoRoot = blockInfoRoot
transactions := []*types.Transaction{&processedTx.Tx}

receipt := GenerateReceipt(header.Number, processedTx)
Expand Down
2 changes: 1 addition & 1 deletion synchronizer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type stateInterface interface {
CloseBatch(ctx context.Context, receipt state.ProcessingReceipt, dbTx pgx.Tx) error
ProcessBatch(ctx context.Context, request state.ProcessRequest, updateMerkleTree bool) (*state.ProcessBatchResponse, error)
ProcessBatchV2(ctx context.Context, request state.ProcessRequest, updateMerkleTree bool) (*state.ProcessBatchResponse, error)
StoreTransaction(ctx context.Context, batchNumber uint64, processedTx *state.ProcessTransactionResponse, coinbase common.Address, timestamp uint64, egpLog *state.EffectiveGasPriceLog, dbTx pgx.Tx) (*state.L2Header, error)
StoreTransaction(ctx context.Context, batchNumber uint64, processedTx *state.ProcessTransactionResponse, coinbase common.Address, timestamp uint64, egpLog *state.EffectiveGasPriceLog, globalExitRoot, blockInfoRoot common.Hash, dbTx pgx.Tx) (*state.L2Header, error)
GetStateRootByBatchNumber(ctx context.Context, batchNum uint64, dbTx pgx.Tx) (common.Hash, error)
ExecuteBatch(ctx context.Context, batch state.Batch, updateMerkleTree bool, dbTx pgx.Tx) (*executor.ProcessBatchResponse, error)
ExecuteBatchV2(ctx context.Context, batch state.Batch, l1InfoTree state.L1InfoTreeExitRootStorageEntry, timestampLimit time.Time, updateMerkleTree bool, skipVerifyL1InfoRoot uint32, forcedBlockHashL1 *common.Hash, dbTx pgx.Tx) (*executor.ProcessBatchResponseV2, error)
Expand Down
4 changes: 2 additions & 2 deletions synchronizer/l2_sync/l2_sync_incaberry/sync_trusted_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type syncTrustedBatchesStateInterface interface {
OpenBatch(ctx context.Context, processingContext state.ProcessingContext, dbTx pgx.Tx) error
CloseBatch(ctx context.Context, receipt state.ProcessingReceipt, dbTx pgx.Tx) error
ProcessBatch(ctx context.Context, request state.ProcessRequest, updateMerkleTree bool) (*state.ProcessBatchResponse, error)
StoreTransaction(ctx context.Context, batchNumber uint64, processedTx *state.ProcessTransactionResponse, coinbase common.Address, timestamp uint64, egpLog *state.EffectiveGasPriceLog, dbTx pgx.Tx) (*state.L2Header, error)
StoreTransaction(ctx context.Context, batchNumber uint64, processedTx *state.ProcessTransactionResponse, coinbase common.Address, timestamp uint64, egpLog *state.EffectiveGasPriceLog, globalExitRoot, blockInfoRoot common.Hash, dbTx pgx.Tx) (*state.L2Header, error)
GetBatchByNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.Batch, error)
GetForkIDByBatchNumber(batchNumber uint64) uint64
ResetTrustedState(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) error
Expand Down Expand Up @@ -449,7 +449,7 @@ func (s *SyncTrustedBatchesAction) processAndStoreTxs(ctx context.Context, trust
if state.IsStateRootChanged(executor.RomErrorCode(tx.RomError)) {
log.Infof("TrustedBatch info: %+v", processBatchResp)
log.Infof("Storing trusted tx %+v", tx)
if _, err = s.state.StoreTransaction(ctx, uint64(trustedBatch.Number), tx, trustedBatch.Coinbase, uint64(trustedBatch.Timestamp), nil, dbTx); err != nil {
if _, err = s.state.StoreTransaction(ctx, uint64(trustedBatch.Number), tx, trustedBatch.Coinbase, uint64(trustedBatch.Timestamp), nil, block.GlobalExitRoot, block.BlockInfoRoot, dbTx); err != nil {
log.Errorf("failed to store transactions for batch: %v. Tx: %s", trustedBatch.Number, tx.TxHash.String())
return nil, err
}
Expand Down
30 changes: 16 additions & 14 deletions synchronizer/mock_state.go

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

2 changes: 1 addition & 1 deletion synchronizer/synchronizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ func expectedCallsForsyncTrustedState(t *testing.T, m *mocks, sync *ClientSynchr
Once()

m.State.
On("StoreTransaction", sync.ctx, stateBatchInTrustedNode.BatchNumber, mock.Anything, stateBatchInTrustedNode.Coinbase, uint64(batchInTrustedNode.Timestamp), mock.Anything, m.DbTx).
On("StoreTransaction", sync.ctx, stateBatchInTrustedNode.BatchNumber, mock.Anything, stateBatchInTrustedNode.Coinbase, uint64(batchInTrustedNode.Timestamp), common.Hash{}, common.Hash{}, mock.Anything, m.DbTx).
Return(&state.L2Header{}, nil).
Once()

Expand Down

0 comments on commit 2e584e7

Please sign in to comment.