From 8ccc10541dd49d52c70230cc0f8210d5da64248b Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Wed, 30 Mar 2022 13:46:16 +0800 Subject: [PATCH] feat(trace): add coinbase account_proof (#58) --- core/blockchain.go | 18 +++++++++++++++++- core/types/l2trace_block.go | 6 +++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index cbf6fc446b51..ef97c9cebacb 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1346,7 +1346,23 @@ 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) { - blockResult.BlockTrace = types.NewTraceBlock(bc.chainConfig, block) + coinbase := types.AccountProofWrapper{ + Address: block.Coinbase(), + Nonce: state.GetNonce(block.Coinbase()), + Balance: state.GetBalance(block.Coinbase()), + } + // Get coinbase address's account proof. + proof, err := state.GetProof(block.Coinbase()) + if err != nil { + log.Error("Failed to get proof", "blockNumber", block.NumberU64(), "address", block.Coinbase().String(), "err", err) + } else { + coinbase.Proof = make([]string, len(proof)) + for i := range proof { + coinbase.Proof[i] = hexutil.Encode(proof[i]) + } + } + + blockResult.BlockTrace = types.NewTraceBlock(bc.chainConfig, block, coinbase) for i, tx := range block.Transactions() { evmTrace := blockResult.ExecutionResults[i] diff --git a/core/types/l2trace_block.go b/core/types/l2trace_block.go index 02e7ce121cf4..50d1983171fe 100644 --- a/core/types/l2trace_block.go +++ b/core/types/l2trace_block.go @@ -14,7 +14,7 @@ type BlockTrace struct { GasLimit uint64 `json:"gasLimit"` Difficulty *big.Int `json:"difficulty"` BaseFee *big.Int `json:"baseFee"` - Coinbase common.Address `json:"coinbase"` + Coinbase AccountProofWrapper `json:"coinbase"` Time uint64 `json:"time"` Transactions []*TransactionTrace `json:"transactions"` } @@ -36,7 +36,7 @@ type TransactionTrace struct { } // NewTraceBlock supports necessary fields for roller. -func NewTraceBlock(config *params.ChainConfig, block *Block) *BlockTrace { +func NewTraceBlock(config *params.ChainConfig, block *Block, coinbase AccountProofWrapper) *BlockTrace { txs := make([]*TransactionTrace, block.Transactions().Len()) for i, tx := range block.Transactions() { txs[i] = newTraceTransaction(tx, block.NumberU64(), config) @@ -47,7 +47,7 @@ func NewTraceBlock(config *params.ChainConfig, block *Block) *BlockTrace { GasLimit: block.GasLimit(), Difficulty: block.Difficulty(), BaseFee: block.BaseFee(), - Coinbase: block.Coinbase(), + Coinbase: coinbase, Time: block.Time(), Transactions: txs, }