Skip to content

Commit

Permalink
expose new V2 executor fields (0xPolygonHermez#2944)
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniRamirezM authored Dec 19, 2023
1 parent e74fd67 commit f341155
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 37 deletions.
2 changes: 1 addition & 1 deletion sequencer/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func (f *finalizer) reprocessFullBatch(ctx context.Context, batchNum uint64, ini
SkipVerifyL1InfoRoot_V2: true,
Caller: caller,
}
executorBatchRequest.L1InfoTree_V2.L1InfoTreeRoot = mockL1InfoRoot
executorBatchRequest.L1InfoRoot_V2 = mockL1InfoRoot

var result *state.ProcessBatchResponse

Expand Down
17 changes: 10 additions & 7 deletions sequencer/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,19 @@ func (f *finalizer) processTransaction(ctx context.Context, tx *TxTracker, first
}()

executorBatchRequest := state.ProcessRequest{
BatchNumber: f.wipBatch.batchNumber,
OldStateRoot: f.wipBatch.imStateRoot,
OldAccInputHash: f.wipBatch.imAccInputHash,
Coinbase: f.wipBatch.coinbase,
L1InfoTree_V2: f.wipL2Block.l1InfoTreeExitRoot,
BatchNumber: f.wipBatch.batchNumber,
OldStateRoot: f.wipBatch.imStateRoot,
OldAccInputHash: f.wipBatch.imAccInputHash,
Coinbase: f.wipBatch.coinbase,
// TODO: FRAN REVIEW
// L1InfoTree_V2: f.wipL2Block.l1InfoTreeExitRoot,
TimestampLimit_V2: uint64(f.wipL2Block.timestamp.Unix()),
Caller: stateMetrics.SequencerCallerLabel,
ForkID: f.state.GetForkIDByBatchNumber(f.wipBatch.batchNumber),
SkipVerifyL1InfoRoot_V2: true,
}
executorBatchRequest.L1InfoTree_V2.L1InfoTreeRoot = mockL1InfoRoot
// TODO: FRAN REVIEW
// executorBatchRequest.L1InfoTree_V2.L1InfoTreeRoot = mockL1InfoRoot
if f.wipBatch.isEmpty() {
executorBatchRequest.Transactions = f.state.BuildChangeL2Block(f.wipL2Block.deltaTimestamp, f.wipL2Block.l1InfoTreeExitRoot.L1InfoTreeIndex)
executorBatchRequest.SkipFirstChangeL2Block_V2 = false
Expand Down Expand Up @@ -549,7 +551,8 @@ func (f *finalizer) processTransaction(ctx context.Context, tx *TxTracker, first
executorBatchRequest.Transactions = append(executorBatchRequest.Transactions, effectivePercentageAsDecodedHex...)
}

log.Infof("processing tx: %s. Batch.BatchNumber: %d, batchNumber: %d, oldStateRoot: %s, txHash: %s, L1InfoRoot: %s", hashStr, f.wipBatch.batchNumber, executorBatchRequest.BatchNumber, executorBatchRequest.OldStateRoot, hashStr, executorBatchRequest.L1InfoTree_V2.L1InfoTreeRoot.String())
// TODO: FRAN REVIEW
// log.Infof("processing tx: %s. Batch.BatchNumber: %d, batchNumber: %d, oldStateRoot: %s, txHash: %s, L1InfoRoot: %s", hashStr, f.wipBatch.batchNumber, executorBatchRequest.BatchNumber, executorBatchRequest.OldStateRoot, hashStr, executorBatchRequest.L1InfoTree_V2.L1InfoTreeRoot.String())
processBatchResponse, err := f.state.ProcessBatchV2(ctx, executorBatchRequest, false)
if err != nil && errors.Is(err, runtime.ErrExecutorDBError) {
log.Errorf("failed to process transaction: %s", err)
Expand Down
12 changes: 6 additions & 6 deletions sequencer/l2block.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ func (f *finalizer) processL2Block(ctx context.Context, l2Block *L2Block) (*stat

// TODO: review this request
executorBatchRequest := state.ProcessRequest{
BatchNumber: f.wipBatch.batchNumber,
OldStateRoot: l2Block.initialStateRoot,
OldAccInputHash: l2Block.initialAccInputHash,
Coinbase: f.wipBatch.coinbase,
L1InfoTree_V2: l2Block.l1InfoTreeExitRoot,
BatchNumber: f.wipBatch.batchNumber,
OldStateRoot: l2Block.initialStateRoot,
OldAccInputHash: l2Block.initialAccInputHash,
Coinbase: f.wipBatch.coinbase,
// L1InfoTree_V2: l2Block.l1InfoTreeExitRoot,
TimestampLimit_V2: uint64(l2Block.timestamp.Unix()),
Transactions: batchL2Data,
SkipFirstChangeL2Block_V2: false,
Expand All @@ -246,7 +246,7 @@ func (f *finalizer) processL2Block(ctx context.Context, l2Block *L2Block) (*stat
ForkID: f.state.GetForkIDByBatchNumber(f.wipBatch.batchNumber),
SkipVerifyL1InfoRoot_V2: true,
}
executorBatchRequest.L1InfoTree_V2.L1InfoTreeRoot = mockL1InfoRoot
// executorBatchRequest.L1InfoTree_V2.L1InfoTreeRoot = mockL1InfoRoot

var (
err error
Expand Down
39 changes: 23 additions & 16 deletions state/batchV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,31 @@ func (s *State) ProcessBatchV2(ctx context.Context, request ProcessRequest, upda
updateMT = cTrue
}

l1InfoTreeData := make(map[uint32]*executor.L1DataV2)

for k, v := range request.L1InfoTreeData_V2 {
l1InfoTreeData[k] = &executor.L1DataV2{
GlobalExitRoot: v.GlobalExitRoot.Bytes(),
BlockHashL1: v.BlockHashL1.Bytes(),
MinTimestamp: v.MinTimestamp,
}
}

// Create Batch
var processBatchRequest = &executor.ProcessBatchRequestV2{
OldBatchNum: request.BatchNumber - 1,
Coinbase: request.Coinbase.String(),
BatchL2Data: request.Transactions,
OldStateRoot: request.OldStateRoot.Bytes(),
L1InfoRoot: request.L1InfoTree_V2.L1InfoTreeRoot.Bytes(),
OldAccInputHash: request.OldAccInputHash.Bytes(),
TimestampLimit: request.TimestampLimit_V2,
UpdateMerkleTree: updateMT,
ChainId: s.cfg.ChainID,
ForkId: request.ForkID,
ContextId: uuid.NewString(),
L1InfoTreeData: map[uint32]*executor.L1DataV2{request.L1InfoTree_V2.L1InfoTreeIndex: {
GlobalExitRoot: request.L1InfoTree_V2.L1InfoTreeLeaf.GlobalExitRoot.GlobalExitRoot.Bytes(),
BlockHashL1: request.L1InfoTree_V2.L1InfoTreeLeaf.PreviousBlockHash.Bytes(),
MinTimestamp: uint64(request.L1InfoTree_V2.L1InfoTreeLeaf.GlobalExitRoot.Timestamp.Unix()),
}},
OldBatchNum: request.BatchNumber - 1,
Coinbase: request.Coinbase.String(),
ForcedBlockhashL1: request.ForcedBlockHashL1.Bytes(),
BatchL2Data: request.Transactions,
OldStateRoot: request.OldStateRoot.Bytes(),
L1InfoRoot: request.L1InfoRoot_V2.Bytes(),
L1InfoTreeData: l1InfoTreeData,
OldAccInputHash: request.OldAccInputHash.Bytes(),
TimestampLimit: request.TimestampLimit_V2,
UpdateMerkleTree: updateMT,
ChainId: s.cfg.ChainID,
ForkId: request.ForkID,
ContextId: uuid.NewString(),
}

if request.SkipFirstChangeL2Block_V2 {
Expand Down
8 changes: 3 additions & 5 deletions state/test/forkid_etrog/etrog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,9 @@ func TestStateTransition(t *testing.T) {
}

processRequest := state.ProcessRequest{
BatchNumber: uint64(i + 1),
L1InfoTree_V2: state.L1InfoTreeExitRootStorageEntry{
L1InfoTreeRoot: common.HexToHash(testCase.L1InfoRoot),
L1InfoTreeIndex: 0,
},
BatchNumber: uint64(i + 1),
L1InfoRoot_V2: common.HexToHash(testCase.L1InfoRoot),
L1InfoTreeData_V2: map[uint32]state.L1DataV2{},
OldStateRoot: stateRoot,
OldAccInputHash: common.HexToHash(testCase.OldAccInputHash),
Transactions: common.FromHex(testCase.BatchL2Data),
Expand Down
11 changes: 10 additions & 1 deletion state/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import (
type ProcessRequest struct {
BatchNumber uint64
GlobalExitRoot_V1 common.Hash
L1InfoTree_V2 L1InfoTreeExitRootStorageEntry
L1InfoRoot_V2 common.Hash
L1InfoTreeData_V2 map[uint32]L1DataV2
OldStateRoot common.Hash
OldAccInputHash common.Hash
Transactions []byte
Coinbase common.Address
ForcedBlockHashL1 common.Hash
Timestamp_V1 time.Time
TimestampLimit_V2 uint64
Caller metrics.CallerLabel
Expand All @@ -32,6 +34,13 @@ type ProcessRequest struct {
ForkID uint64
}

type L1DataV2 struct {
GlobalExitRoot common.Hash
BlockHashL1 common.Hash
MinTimestamp uint64
SmtProof [][]byte
}

// ProcessBatchResponse represents the response of a batch process.
type ProcessBatchResponse struct {
NewStateRoot common.Hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ func (b *SyncTrustedBatchExecutorForEtrog) getProcessRequest(data *l2_shared.Pro
OldStateRoot: data.OldStateRoot,
OldAccInputHash: data.OldAccInputHash,
Coinbase: common.HexToAddress(data.TrustedBatch.Coinbase.String()),
L1InfoTree_V2: l1InfoTree,
L1InfoRoot_V2: l1InfoTree.L1InfoTreeRoot,
L1InfoTreeData_V2: map[uint32]state.L1DataV2{0: {GlobalExitRoot: l1InfoTree.L1InfoTreeRoot}},
TimestampLimit_V2: uint64(data.TrustedBatch.Timestamp),
Transactions: data.TrustedBatch.BatchL2Data,
ForkID: b.state.GetForkIDByBatchNumber(uint64(data.TrustedBatch.Number)),
Expand Down

0 comments on commit f341155

Please sign in to comment.