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

replace the state debug tx to execute just the tx that needs the trace #1994

Merged
merged 2 commits into from
Apr 5, 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
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ services:
zkevm-prover:
container_name: zkevm-prover
restart: unless-stopped
image: hermeznetwork/zkevm-prover:9e70a64
image: hermeznetwork/zkevm-prover:6d6e3aa
depends_on:
zkevm-state-db:
condition: service_healthy
Expand Down
70 changes: 35 additions & 35 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,39 +851,50 @@ func (s *State) GetLastBatch(ctx context.Context, dbTx pgx.Tx) (*Batch, error) {
func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Hash, traceConfig TraceConfig, dbTx pgx.Tx) (*runtime.ExecutionResult, error) {
result := new(runtime.ExecutionResult)

// Get the transaction
// gets the transaction
tx, err := s.GetTransactionByHash(ctx, transactionHash, dbTx)
if err != nil {
return nil, err
}

// Get batch including the transaction
batch, err := s.GetBatchByTxHash(ctx, transactionHash, dbTx)
// gets the tx receipt
receipt, err := s.GetTransactionReceipt(ctx, transactionHash, dbTx)
if err != nil {
return nil, err
}

// The previous batch to get OldStateRoot and globalExitRoot
pBatch, err := s.GetBatchByNumber(ctx, batch.BatchNumber-1, dbTx)
// gets the l2 block including the transaction
block, err := s.GetL2BlockByNumber(ctx, receipt.BlockNumber.Uint64(), dbTx)
if err != nil {
return nil, err
}

batchL2Data := batch.BatchL2Data
if batchL2Data == nil {
txs, err := s.GetTransactionsByBatchNumber(ctx, batch.BatchNumber, dbTx)
if err != nil {
return nil, err
}
// get the previous L2 Block
previousBlockNumber := uint64(0)
if receipt.BlockNumber.Uint64() > 0 {
previousBlockNumber = receipt.BlockNumber.Uint64() - 1
}
previousBlock, err := s.GetL2BlockByNumber(ctx, previousBlockNumber, dbTx)
if err != nil {
return nil, err
}

for _, tx := range txs {
log.Debugf(tx.Hash().String())
}
// generate batch l2 data for the transaction
batchL2Data, err := EncodeTransactions([]types.Transaction{*tx})
if err != nil {
return nil, err
}

batchL2Data, err = EncodeTransactions(txs)
if err != nil {
return nil, err
}
// gets batch that including the l2 block
batch, err := s.GetBatchByL2BlockNumber(ctx, block.NumberU64(), dbTx)
if err != nil {
return nil, err
}

// gets batch that including the previous l2 block
previousBatch, err := s.GetBatchByL2BlockNumber(ctx, previousBlock.NumberU64(), dbTx)
if err != nil {
return nil, err
}

forkId := s.GetForkIdByBatchNumber(batch.BatchNumber)
Expand All @@ -908,11 +919,12 @@ func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Has
}

processBatchRequest := &pb.ProcessBatchRequest{
OldBatchNum: batch.BatchNumber - 1,
OldBatchNum: batch.BatchNumber - 1,
OldStateRoot: previousBlock.Root().Bytes(),
OldAccInputHash: previousBatch.AccInputHash.Bytes(),

BatchL2Data: batchL2Data,
OldStateRoot: pBatch.StateRoot.Bytes(),
GlobalExitRoot: batch.GlobalExitRoot.Bytes(),
OldAccInputHash: pBatch.AccInputHash.Bytes(),
EthTimestamp: uint64(batch.Timestamp.Unix()),
Coinbase: batch.Coinbase.String(),
UpdateMerkleTree: cFalse,
Expand Down Expand Up @@ -944,10 +956,6 @@ func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Has
// return nil, err
// }

for _, response := range processBatchResponse.Responses {
log.Debugf(string(response.TxHash))
}

txs, _, err := DecodeTxs(batchL2Data)
if err != nil && !errors.Is(err, InvalidData) {
return nil, err
Expand All @@ -962,17 +970,9 @@ func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Has
return nil, err
}

var response *ProcessTransactionResponse

// Get the response for the tx
for _, response = range convertedResponse.Responses {
log.Debugf(response.TxHash.String())
if response.TxHash == transactionHash {
break
}
}

// Sanity check
response := convertedResponse.Responses[0]
log.Debugf(response.TxHash.String())
if response.TxHash != transactionHash {
return nil, fmt.Errorf("tx hash not found in executor response")
}
Expand Down
4 changes: 2 additions & 2 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ services:

zkevm-prover:
container_name: zkevm-prover
image: hermeznetwork/zkevm-prover:9e70a64
image: hermeznetwork/zkevm-prover:6d6e3aa
ports:
# - 50051:50051 # Prover
- 50052:50052 # Mock prover
Expand Down Expand Up @@ -423,7 +423,7 @@ services:

zkevm-permissionless-prover:
container_name: zkevm-permissionless-prover
image: hermeznetwork/zkevm-prover:9e70a64
image: hermeznetwork/zkevm-prover:6d6e3aa
ports:
# - 50058:50058 # Prover
- 50059:50052 # Mock prover
Expand Down