fix(traces): several tracing fixes (#830)

* fix(trace): add `extraData`

* fix(trace): fix `StructLogger`'s `CaptureState`
This commit is contained in:
HAOYUatHZ 2024-07-08 17:13:44 +08:00 committed by GitHub
parent 72577219c0
commit 5e255cf5b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -219,7 +219,8 @@ func (l *StructLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, s
stackLen := len(stackData) stackLen := len(stackData)
// Copy a snapshot of the current storage to a new container // Copy a snapshot of the current storage to a new container
var storage Storage var storage Storage
if !l.cfg.DisableStorage && (op == vm.SLOAD || op == vm.SSTORE) { var recordStorageDetail bool
if op == vm.SLOAD || op == vm.SSTORE {
// initialise new changed values storage container for this contract // initialise new changed values storage container for this contract
// if not present. // if not present.
if l.storage[contract.Address()] == nil { if l.storage[contract.Address()] == nil {
@ -232,7 +233,10 @@ func (l *StructLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, s
value = l.env.StateDB.GetState(contract.Address(), address) value = l.env.StateDB.GetState(contract.Address(), address)
) )
l.storage[contract.Address()][address] = value l.storage[contract.Address()][address] = value
recordStorageDetail = true
if !l.cfg.DisableStorage {
storage = l.storage[contract.Address()].Copy() storage = l.storage[contract.Address()].Copy()
}
} else if op == vm.SSTORE && stackLen >= 2 { } else if op == vm.SSTORE && stackLen >= 2 {
// capture SSTORE opcodes and record the written entry in the local storage. // capture SSTORE opcodes and record the written entry in the local storage.
var ( var (
@ -240,9 +244,12 @@ func (l *StructLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, s
address = common.Hash(stackData[stackLen-1].Bytes32()) address = common.Hash(stackData[stackLen-1].Bytes32())
) )
l.storage[contract.Address()][address] = value l.storage[contract.Address()][address] = value
recordStorageDetail = true
if !l.cfg.DisableStorage {
storage = l.storage[contract.Address()].Copy() storage = l.storage[contract.Address()].Copy()
} }
} }
}
var rdata []byte var rdata []byte
if l.cfg.EnableReturnData { if l.cfg.EnableReturnData {
rdata = make([]byte, len(rData)) rdata = make([]byte, len(rData))
@ -251,7 +258,7 @@ func (l *StructLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, s
// create a new snapshot of the EVM. // create a new snapshot of the EVM.
structLog := StructLog{pc, op, gas, cost, mem, memory.Len(), stck, rdata, storage, depth, l.env.StateDB.GetRefund(), err, nil} structLog := StructLog{pc, op, gas, cost, mem, memory.Len(), stck, rdata, storage, depth, l.env.StateDB.GetRefund(), err, nil}
if !l.cfg.DisableStorage && (op == vm.SLOAD || op == vm.SSTORE) { if recordStorageDetail {
if err := traceStorage(l, scope, structLog.getOrInitExtraData()); err != nil { if err := traceStorage(l, scope, structLog.getOrInitExtraData()); err != nil {
log.Error("Failed to trace data", "opcode", op.String(), "err", err) log.Error("Failed to trace data", "opcode", op.String(), "err", err)
} }
@ -600,6 +607,7 @@ func FormatLogs(logs []StructLog) []types.StructLogRes {
Depth: trace.Depth, Depth: trace.Depth,
Error: trace.ErrorString(), Error: trace.ErrorString(),
RefundCounter: trace.RefundCounter, RefundCounter: trace.RefundCounter,
ExtraData: trace.ExtraData,
} }
if trace.Stack != nil { if trace.Stack != nil {
stack := make([]string, len(trace.Stack)) stack := make([]string, len(trace.Stack))