Skip to content

feat(trace): add coinbase account_proof #58

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

Merged
merged 1 commit into from
Mar 30, 2022
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
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