Skip to content

Commit 571dcad

Browse files
feat: add to AccountProof to trace (#98)
* init to * update * fix `to` address * fix * fix * refactor
1 parent 6e872d0 commit 571dcad

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

core/blockchain.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -1375,16 +1375,30 @@ func (bc *BlockChain) writeBlockResult(state *state.StateDB, block *types.Block,
13751375
blockResult.BlockTrace = types.NewTraceBlock(bc.chainConfig, block, &coinbase)
13761376
for i, tx := range block.Transactions() {
13771377
evmTrace := blockResult.ExecutionResults[i]
1378-
from := evmTrace.Sender.Address
13791378

1379+
from := evmTrace.From.Address
13801380
// Get proof
13811381
proof, err := state.GetProof(from)
13821382
if err != nil {
13831383
log.Error("Failed to get proof", "blockNumber", block.NumberU64(), "address", from.String(), "err", err)
13841384
} else {
1385-
evmTrace.Sender.Proof = make([]string, len(proof))
1385+
evmTrace.From.Proof = make([]string, len(proof))
13861386
for i := range proof {
1387-
evmTrace.Sender.Proof[i] = hexutil.Encode(proof[i])
1387+
evmTrace.From.Proof[i] = hexutil.Encode(proof[i])
1388+
}
1389+
}
1390+
1391+
if evmTrace.To != nil {
1392+
to := evmTrace.To.Address
1393+
// Get proof
1394+
proof, err = state.GetProof(to)
1395+
if err != nil {
1396+
log.Error("Failed to get proof", "blockNumber", block.NumberU64(), "address", to.String(), "err", err)
1397+
} else {
1398+
evmTrace.To.Proof = make([]string, len(proof))
1399+
for i := range proof {
1400+
evmTrace.To.Proof[i] = hexutil.Encode(proof[i])
1401+
}
13881402
}
13891403
}
13901404

core/types/l2trace.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ type ExecutionResult struct {
1919
Failed bool `json:"failed"`
2020
ReturnValue string `json:"returnValue,omitempty"`
2121
// Sender's account proof.
22-
Sender *AccountProofWrapper `json:"sender,omitempty"`
22+
From *AccountProofWrapper `json:"from,omitempty"`
23+
// Receiver's account proof.
24+
To *AccountProofWrapper `json:"to,omitempty"`
2325
// It's exist only when tx is a contract call.
2426
CodeHash *common.Hash `json:"codeHash,omitempty"`
2527
// If it is a contract call, the contract code is returned.

miner/worker.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,17 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
794794
Balance: (*hexutil.Big)(w.current.state.GetBalance(from)),
795795
CodeHash: w.current.state.GetCodeHash(from),
796796
}
797+
// Get receiver's address.
798+
var receiver *types.AccountProofWrapper
799+
if tx.To() != nil {
800+
to := *tx.To()
801+
receiver = &types.AccountProofWrapper{
802+
Address: to,
803+
Nonce: w.current.state.GetNonce(to),
804+
Balance: (*hexutil.Big)(w.current.state.GetBalance(to)),
805+
CodeHash: w.current.state.GetCodeHash(to),
806+
}
807+
}
797808

798809
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())
799810
if err != nil {
@@ -805,7 +816,8 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
805816
w.current.receipts = append(w.current.receipts, receipt)
806817
w.current.executionResults = append(w.current.executionResults, &types.ExecutionResult{
807818
Gas: receipt.GasUsed,
808-
Sender: sender,
819+
From: sender,
820+
To: receiver,
809821
Failed: receipt.Status != types.ReceiptStatusSuccessful,
810822
ReturnValue: fmt.Sprintf("%x", receipt.ReturnValue),
811823
StructLogs: vm.FormatLogs(tracer.StructLogs()),

0 commit comments

Comments
 (0)