Skip to content

Commit

Permalink
feat: add to AccountProof to trace (ethereum#98)
Browse files Browse the repository at this point in the history
* init to

* update

* fix `to` address

* fix

* fix

* refactor
  • Loading branch information
0xmountaintop authored May 17, 2022
1 parent 6e872d0 commit 571dcad
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
20 changes: 17 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1375,16 +1375,30 @@ func (bc *BlockChain) writeBlockResult(state *state.StateDB, block *types.Block,
blockResult.BlockTrace = types.NewTraceBlock(bc.chainConfig, block, &coinbase)
for i, tx := range block.Transactions() {
evmTrace := blockResult.ExecutionResults[i]
from := evmTrace.Sender.Address

from := evmTrace.From.Address
// Get proof
proof, err := state.GetProof(from)
if err != nil {
log.Error("Failed to get proof", "blockNumber", block.NumberU64(), "address", from.String(), "err", err)
} else {
evmTrace.Sender.Proof = make([]string, len(proof))
evmTrace.From.Proof = make([]string, len(proof))
for i := range proof {
evmTrace.Sender.Proof[i] = hexutil.Encode(proof[i])
evmTrace.From.Proof[i] = hexutil.Encode(proof[i])
}
}

if evmTrace.To != nil {
to := evmTrace.To.Address
// Get proof
proof, err = state.GetProof(to)
if err != nil {
log.Error("Failed to get proof", "blockNumber", block.NumberU64(), "address", to.String(), "err", err)
} else {
evmTrace.To.Proof = make([]string, len(proof))
for i := range proof {
evmTrace.To.Proof[i] = hexutil.Encode(proof[i])
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion core/types/l2trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ type ExecutionResult struct {
Failed bool `json:"failed"`
ReturnValue string `json:"returnValue,omitempty"`
// Sender's account proof.
Sender *AccountProofWrapper `json:"sender,omitempty"`
From *AccountProofWrapper `json:"from,omitempty"`
// Receiver's account proof.
To *AccountProofWrapper `json:"to,omitempty"`
// It's exist only when tx is a contract call.
CodeHash *common.Hash `json:"codeHash,omitempty"`
// If it is a contract call, the contract code is returned.
Expand Down
14 changes: 13 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,17 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
Balance: (*hexutil.Big)(w.current.state.GetBalance(from)),
CodeHash: w.current.state.GetCodeHash(from),
}
// Get receiver's address.
var receiver *types.AccountProofWrapper
if tx.To() != nil {
to := *tx.To()
receiver = &types.AccountProofWrapper{
Address: to,
Nonce: w.current.state.GetNonce(to),
Balance: (*hexutil.Big)(w.current.state.GetBalance(to)),
CodeHash: w.current.state.GetCodeHash(to),
}
}

receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
if err != nil {
Expand All @@ -805,7 +816,8 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
w.current.receipts = append(w.current.receipts, receipt)
w.current.executionResults = append(w.current.executionResults, &types.ExecutionResult{
Gas: receipt.GasUsed,
Sender: sender,
From: sender,
To: receiver,
Failed: receipt.Status != types.ReceiptStatusSuccessful,
ReturnValue: fmt.Sprintf("%x", receipt.ReturnValue),
StructLogs: vm.FormatLogs(tracer.StructLogs()),
Expand Down

0 comments on commit 571dcad

Please sign in to comment.