Skip to content

Commit

Permalink
fix(trace): fix incorrect sender state info. (ethereum#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
mask-pp authored Apr 1, 2022
1 parent 40e8f08 commit 2329d32
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
11 changes: 2 additions & 9 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1370,16 +1370,9 @@ 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

// 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),
CodeHash: state.GetCodeHash(from),
}
// Get sender's account proof.
// Get proof
proof, err := state.GetProof(from)
if err != nil {
log.Error("Failed to get proof", "blockNumber", block.NumberU64(), "address", from.String(), "err", err)
Expand Down
6 changes: 3 additions & 3 deletions core/types/l2trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ type ExtraData struct {
}

type AccountProofWrapper struct {
Address common.Address `json:"address,omitempty"`
Nonce uint64 `json:"nonce,omitempty"`
Balance *big.Int `json:"balance,omitempty"`
Address common.Address `json:"address"`
Nonce uint64 `json:"nonce"`
Balance *big.Int `json:"balance"`
CodeHash common.Hash `json:"codeHash,omitempty"`
Proof []string `json:"proof,omitempty"`
Storage *StorageProofWrapper `json:"storage,omitempty"` // StorageProofWrapper can be empty if irrelated to storage operation
Expand Down
10 changes: 10 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,16 +785,26 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
// reset tracer.
tracer := w.chain.GetVMConfig().Tracer.(*vm.StructLogger)
tracer.Reset()
// Get sender's address.
from, _ := types.Sender(w.current.signer, tx)
sender := &types.AccountProofWrapper{
Address: from,
Nonce: w.current.state.GetNonce(from),
Balance: w.current.state.GetBalance(from),
CodeHash: w.current.state.GetCodeHash(from),
}

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 {
w.current.state.RevertToSnapshot(snap)
return nil, err
}

w.current.txs = append(w.current.txs, tx)
w.current.receipts = append(w.current.receipts, receipt)
w.current.executionResults = append(w.current.executionResults, &types.ExecutionResult{
Gas: receipt.GasUsed,
Sender: sender,
Failed: receipt.Status != types.ReceiptStatusSuccessful,
ReturnValue: fmt.Sprintf("%x", receipt.ReturnValue),
StructLogs: vm.FormatLogs(tracer.StructLogs()),
Expand Down

0 comments on commit 2329d32

Please sign in to comment.