Skip to content

Commit

Permalink
fix deltaTimestamp when debug tx (#3291)
Browse files Browse the repository at this point in the history
* fix deltaTimestamp when debug tx

* fix deltaTimeStamp for unsigned txs execution for specific block

* fix deltaTimeStamp for unsigned txs execution for specific block

* Revert "fix deltaTimeStamp for unsigned txs execution for specific block"

This reverts commit eb77e04.

* Revert "fix deltaTimeStamp for unsigned txs execution for specific block"

This reverts commit d2cfa78.

* fix debug trace l1 info tree index and add l1 info tree data

* move MockL1InfoRoot from sequencer to state to allow multiple components to use the same value

---------

Co-authored-by: agnusmor <agnusmor@gmail.com>
  • Loading branch information
tclemos and agnusmor committed Feb 22, 2024
1 parent 906f527 commit 595eb8a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
2 changes: 1 addition & 1 deletion sequencer/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (f *finalizer) batchSanityCheck(ctx context.Context, batchNum uint64, initi

batchRequest := state.ProcessRequest{
BatchNumber: batch.BatchNumber,
L1InfoRoot_V2: mockL1InfoRoot,
L1InfoRoot_V2: state.GetMockL1InfoRoot(),
OldStateRoot: initialStateRoot,
Transactions: batch.BatchL2Data,
Coinbase: batch.Coinbase,
Expand Down
10 changes: 2 additions & 8 deletions sequencer/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ const (
)

var (
now = time.Now
mockL1InfoRoot = common.Hash{}
now = time.Now
)

// finalizer represents the finalizer component of the sequencer.
Expand Down Expand Up @@ -138,11 +137,6 @@ func newFinalizer(

// Start starts the finalizer.
func (f *finalizer) Start(ctx context.Context) {
// Init mockL1InfoRoot to a mock value since it must be different to {0,0,...,0}
for i := 0; i < len(mockL1InfoRoot); i++ {
mockL1InfoRoot[i] = byte(i)
}

// Do sanity check for batches closed but pending to be checked
f.processBatchesPendingtoCheck(ctx)

Expand Down Expand Up @@ -350,7 +344,7 @@ func (f *finalizer) processTransaction(ctx context.Context, tx *TxTracker, first
BatchNumber: f.wipBatch.batchNumber,
OldStateRoot: f.wipBatch.imStateRoot,
Coinbase: f.wipBatch.coinbase,
L1InfoRoot_V2: mockL1InfoRoot,
L1InfoRoot_V2: state.GetMockL1InfoRoot(),
TimestampLimit_V2: f.wipL2Block.timestamp,
Caller: stateMetrics.SequencerCallerLabel,
ForkID: f.stateIntf.GetForkIDByBatchNumber(f.wipBatch.batchNumber),
Expand Down
4 changes: 2 additions & 2 deletions sequencer/l2block.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (f *finalizer) executeL2Block(ctx context.Context, initialStateRoot common.
BatchNumber: f.wipBatch.batchNumber,
OldStateRoot: initialStateRoot,
Coinbase: f.wipBatch.coinbase,
L1InfoRoot_V2: mockL1InfoRoot,
L1InfoRoot_V2: state.GetMockL1InfoRoot(),
TimestampLimit_V2: l2Block.timestamp,
Transactions: batchL2Data,
SkipFirstChangeL2Block_V2: false,
Expand Down Expand Up @@ -534,7 +534,7 @@ func (f *finalizer) executeNewWIPL2Block(ctx context.Context) (*state.ProcessBat
BatchNumber: f.wipBatch.batchNumber,
OldStateRoot: f.wipBatch.imStateRoot,
Coinbase: f.wipBatch.coinbase,
L1InfoRoot_V2: mockL1InfoRoot,
L1InfoRoot_V2: state.GetMockL1InfoRoot(),
TimestampLimit_V2: f.wipL2Block.timestamp,
Caller: stateMetrics.SequencerCallerLabel,
ForkID: f.stateIntf.GetForkIDByBatchNumber(f.wipBatch.batchNumber),
Expand Down
17 changes: 17 additions & 0 deletions state/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ const (
cFalse = 0
noFlushID uint64 = 0
noProverID string = ""

// MockL1InfoRootHex is used to send batches to the Executor
// the number below represents this formula:
//
// mockL1InfoRoot := common.Hash{}
// for i := 0; i < len(mockL1InfoRoot); i++ {
// mockL1InfoRoot[i] = byte(i)
// }
MockL1InfoRootHex = "0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
)

// Batch struct
Expand Down Expand Up @@ -632,3 +641,11 @@ func findMax(blocks []L2BlockRaw) uint32 {
}
return maxIndex
}

var mockL1InfoRoot = common.HexToHash(MockL1InfoRootHex)

// GetMockL1InfoRoot returns an instance of common.Hash set
// with the value provided by the const MockL1InfoRootHex
func GetMockL1InfoRoot() common.Hash {
return mockL1InfoRoot
}
49 changes: 46 additions & 3 deletions state/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,33 @@ func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Has
traceConfigRequestV2.EnableReturnData = cFalse
}
}
deltaTimestamp := uint32(uint64(time.Now().Unix()) - l2Block.Time())
transactions := s.BuildChangeL2Block(deltaTimestamp, uint32(0))

// build the raw batch so we can get the index l1 info tree for the l2 block
rawBatch, err := DecodeBatchV2(batch.BatchL2Data)
if err != nil {
log.Errorf("error decoding BatchL2Data for batch %d, error: %v", batch.BatchNumber, err)
return nil, err
}

// identify the first l1 block number so we can identify the
// current l2 block index in the block array
firstBlockNumberForBatch, err := s.GetFirstL2BlockNumberForBatchNumber(ctx, batch.BatchNumber, dbTx)
if err != nil {
log.Errorf("failed to get first l2 block number for batch %v: %v ", batch.BatchNumber, err)
return nil, err
}

// computes the l2 block index
rawL2BlockIndex := l2Block.NumberU64() - firstBlockNumberForBatch
if rawL2BlockIndex > uint64(len(rawBatch.Blocks)-1) {
log.Errorf("computed rawL2BlockIndex is greater than the number of blocks we have in the batch %v: %v ", batch.BatchNumber, err)
return nil, err
}

// builds the ChangeL2Block transaction with the correct timestamp and IndexL1InfoTree
rawL2Block := rawBatch.Blocks[rawL2BlockIndex]
deltaTimestamp := uint32(l2Block.Time() - previousL2Block.Time())
transactions := s.BuildChangeL2Block(deltaTimestamp, rawL2Block.IndexL1InfoTree)

batchL2Data, err := EncodeTransactions(txsToEncode, effectivePercentage, forkId)
if err != nil {
Expand All @@ -213,7 +238,7 @@ func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Has
ContextId: uuid.NewString(),

// v2 fields
L1InfoRoot: l2Block.BlockInfoRoot().Bytes(),
L1InfoRoot: GetMockL1InfoRoot().Bytes(),
TimestampLimit: uint64(time.Now().Unix()),
SkipFirstChangeL2Block: cFalse,
SkipWriteBlockInfoRoot: cTrue,
Expand All @@ -238,6 +263,24 @@ func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Has
}
}

// gets the L1InfoTreeData for the transactions
l1InfoTreeData, _, _, err := s.GetL1InfoTreeDataFromBatchL2Data(ctx, transactions, dbTx)
if err != nil {
return nil, err
}

// In case we have any l1InfoTreeData, add them to the request
if len(l1InfoTreeData) > 0 {
processBatchRequestV2.L1InfoTreeData = map[uint32]*executor.L1DataV2{}
for k, v := range l1InfoTreeData {
processBatchRequestV2.L1InfoTreeData[k] = &executor.L1DataV2{
GlobalExitRoot: v.GlobalExitRoot.Bytes(),
BlockHashL1: v.BlockHashL1.Bytes(),
MinTimestamp: v.MinTimestamp,
}
}
}

// Send Batch to the Executor
startTime = time.Now()
processBatchResponseV2, err := s.executorClient.ProcessBatchV2(ctx, processBatchRequestV2)
Expand Down

0 comments on commit 595eb8a

Please sign in to comment.