Skip to content

Commit

Permalink
feat(trace): add coinbase account_proof (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmountaintop authored Mar 30, 2022
1 parent 5128154 commit 8ccc105
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 17 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
6 changes: 3 additions & 3 deletions core/types/l2trace_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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)
Expand All @@ -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,
}
Expand Down

0 comments on commit 8ccc105

Please sign in to comment.