From 360115e61fb33aee60e02d7a907a2f0e79935ee2 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Wed, 30 Mar 2022 15:17:57 +0800 Subject: [PATCH] add code_hash to trace --- core/blockchain.go | 14 ++++++++------ core/types/l2trace.go | 11 ++++++----- core/vm/logger_trace.go | 18 ++++++++++-------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index ef97c9cebacb..8fa121a78536 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1347,9 +1347,10 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. // Fill blockResult content func (bc *BlockChain) writeBlockResult(state *state.StateDB, block *types.Block, blockResult *types.BlockResult) { coinbase := types.AccountProofWrapper{ - Address: block.Coinbase(), - Nonce: state.GetNonce(block.Coinbase()), - Balance: state.GetBalance(block.Coinbase()), + Address: block.Coinbase(), + Nonce: state.GetNonce(block.Coinbase()), + Balance: state.GetBalance(block.Coinbase()), + CodeHash: state.GetCodeHash(block.Coinbase()), } // Get coinbase address's account proof. proof, err := state.GetProof(block.Coinbase()) @@ -1369,9 +1370,10 @@ func (bc *BlockChain) writeBlockResult(state *state.StateDB, block *types.Block, // Get sender's address. from, _ := types.Sender(types.MakeSigner(bc.chainConfig, block.Number()), tx) evmTrace.Sender = &types.AccountProofWrapper{ - Address: from, - Nonce: state.GetNonce(from), - Balance: state.GetBalance(from), + Address: from, + Nonce: state.GetNonce(from), + Balance: state.GetBalance(from), + CodeHash: state.GetCodeHash(from), } // Get sender's account proof. proof, err := state.GetProof(from) diff --git a/core/types/l2trace.go b/core/types/l2trace.go index beea08907b57..7a2f3d0f3140 100644 --- a/core/types/l2trace.go +++ b/core/types/l2trace.go @@ -56,11 +56,12 @@ type ExtraData struct { } type AccountProofWrapper struct { - Address common.Address `json:"address,omitempty"` - Nonce uint64 `json:"nonce,omitempty"` - Balance *big.Int `json:"balance,omitempty"` - Proof []string `json:"proof,omitempty"` - Storage *StorageProofWrapper `json:"storage,omitempty"` // StorageProofWrapper can be empty if irrelated to storage operation + Address common.Address `json:"address,omitempty"` + Nonce uint64 `json:"nonce,omitempty"` + Balance *big.Int `json:"balance,omitempty"` + CodeHash common.Hash `json:"code_hash,omitempty"` + Proof []string `json:"proof,omitempty"` + Storage *StorageProofWrapper `json:"storage,omitempty"` // StorageProofWrapper can be empty if irrelated to storage operation } // while key & value can also be retrieved from StructLogRes.Storage, diff --git a/core/vm/logger_trace.go b/core/vm/logger_trace.go index dfb75de4b349..736e36743a70 100644 --- a/core/vm/logger_trace.go +++ b/core/vm/logger_trace.go @@ -128,10 +128,11 @@ func getWrappedProofForAddr(l *StructLogger, address common.Address) (*types.Acc } return &types.AccountProofWrapper{ - Address: address, - Nonce: l.env.StateDB.GetNonce(address), - Balance: l.env.StateDB.GetBalance(address), - Proof: encodeProof(proof), + Address: address, + Nonce: l.env.StateDB.GetNonce(address), + Balance: l.env.StateDB.GetBalance(address), + CodeHash: l.env.StateDB.GetCodeHash(address), + Proof: encodeProof(proof), }, nil } @@ -147,10 +148,11 @@ func getWrappedProofForStorage(l *StructLogger, address common.Address, key comm } return &types.AccountProofWrapper{ - Address: address, - Nonce: l.env.StateDB.GetNonce(address), - Balance: l.env.StateDB.GetBalance(address), - Proof: encodeProof(proof), + Address: address, + Nonce: l.env.StateDB.GetNonce(address), + Balance: l.env.StateDB.GetBalance(address), + CodeHash: l.env.StateDB.GetCodeHash(address), + Proof: encodeProof(proof), Storage: &types.StorageProofWrapper{ Key: key.String(), Value: l.env.StateDB.GetState(address, key).String(),