mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
core/vm, internal/ethapi: tracer no full storage, nicer json output
This commit is contained in:
parent
5aa3eac22d
commit
8e1af23fed
3 changed files with 4 additions and 43 deletions
|
|
@ -45,7 +45,6 @@ type LogConfig struct {
|
||||||
DisableMemory bool // disable memory capture
|
DisableMemory bool // disable memory capture
|
||||||
DisableStack bool // disable stack capture
|
DisableStack bool // disable stack capture
|
||||||
DisableStorage bool // disable storage capture
|
DisableStorage bool // disable storage capture
|
||||||
FullStorage bool // show full storage (slow)
|
|
||||||
Limit int // maximum length of output, but zero means unlimited
|
Limit int // maximum length of output, but zero means unlimited
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,20 +156,8 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
|
||||||
// the state object to query for all values (slow process).
|
// the state object to query for all values (slow process).
|
||||||
var storage Storage
|
var storage Storage
|
||||||
if !l.cfg.DisableStorage {
|
if !l.cfg.DisableStorage {
|
||||||
if l.cfg.FullStorage {
|
// Copy a snapshot of the current storage to a new container.
|
||||||
storage = make(Storage)
|
storage = l.changedValues[contract.Address()].Copy()
|
||||||
// Get the contract account and loop over each storage entry. This may involve looping over
|
|
||||||
// the trie and is a very expensive process.
|
|
||||||
|
|
||||||
env.StateDB.ForEachStorage(contract.Address(), func(key, value common.Hash) bool {
|
|
||||||
storage[key] = value
|
|
||||||
// Return true, indicating we'd like to continue.
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// copy a snapshot of the current storage to a new container.
|
|
||||||
storage = l.changedValues[contract.Address()].Copy()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// create a new snaptshot of the EVM.
|
// create a new snaptshot of the EVM.
|
||||||
log := StructLog{pc, op, gas, cost, mem, memory.Len(), stck, storage, depth, err}
|
log := StructLog{pc, op, gas, cost, mem, memory.Len(), stck, storage, depth, err}
|
||||||
|
|
|
||||||
|
|
@ -63,32 +63,8 @@ func TestStoreCapture(t *testing.T) {
|
||||||
if len(logger.changedValues[contract.Address()]) == 0 {
|
if len(logger.changedValues[contract.Address()]) == 0 {
|
||||||
t.Fatalf("expected exactly 1 changed value on address %x, got %d", contract.Address(), len(logger.changedValues[contract.Address()]))
|
t.Fatalf("expected exactly 1 changed value on address %x, got %d", contract.Address(), len(logger.changedValues[contract.Address()]))
|
||||||
}
|
}
|
||||||
|
|
||||||
exp := common.BigToHash(big.NewInt(1))
|
exp := common.BigToHash(big.NewInt(1))
|
||||||
if logger.changedValues[contract.Address()][index] != exp {
|
if logger.changedValues[contract.Address()][index] != exp {
|
||||||
t.Errorf("expected %x, got %x", exp, logger.changedValues[contract.Address()][index])
|
t.Errorf("expected %x, got %x", exp, logger.changedValues[contract.Address()][index])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageCapture(t *testing.T) {
|
|
||||||
t.Skip("implementing this function is difficult. it requires all sort of interfaces to be implemented which isn't trivial. The value (the actual test) isn't worth it")
|
|
||||||
var (
|
|
||||||
ref = &dummyContractRef{}
|
|
||||||
contract = NewContract(ref, ref, new(big.Int), 0)
|
|
||||||
env = NewEVM(Context{}, dummyStateDB{ref: ref}, params.TestChainConfig, Config{EnableJit: false, ForceJit: false})
|
|
||||||
logger = NewStructLogger(nil)
|
|
||||||
mem = NewMemory()
|
|
||||||
stack = newstack()
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.CaptureState(env, 0, STOP, 0, 0, mem, stack, contract, 0, nil)
|
|
||||||
if ref.calledForEach {
|
|
||||||
t.Error("didn't expect for each to be called")
|
|
||||||
}
|
|
||||||
|
|
||||||
logger = NewStructLogger(&LogConfig{FullStorage: true})
|
|
||||||
logger.CaptureState(env, 0, STOP, 0, 0, mem, stack, contract, 0, nil)
|
|
||||||
if !ref.calledForEach {
|
|
||||||
t.Error("expected for each to be called")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -715,7 +715,7 @@ type StructLogRes struct {
|
||||||
Gas uint64 `json:"gas"`
|
Gas uint64 `json:"gas"`
|
||||||
GasCost uint64 `json:"gasCost"`
|
GasCost uint64 `json:"gasCost"`
|
||||||
Depth int `json:"depth"`
|
Depth int `json:"depth"`
|
||||||
Error error `json:"error"`
|
Error error `json:"error,omitempty"`
|
||||||
Stack []string `json:"stack"`
|
Stack []string `json:"stack"`
|
||||||
Memory []string `json:"memory"`
|
Memory []string `json:"memory"`
|
||||||
Storage map[string]string `json:"storage"`
|
Storage map[string]string `json:"storage"`
|
||||||
|
|
@ -733,17 +733,15 @@ func FormatLogs(structLogs []vm.StructLog) []StructLogRes {
|
||||||
Depth: trace.Depth,
|
Depth: trace.Depth,
|
||||||
Error: trace.Err,
|
Error: trace.Err,
|
||||||
Stack: make([]string, len(trace.Stack)),
|
Stack: make([]string, len(trace.Stack)),
|
||||||
|
Memory: make([]string, 0, (len(trace.Memory)+31)/32),
|
||||||
Storage: make(map[string]string),
|
Storage: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, stackValue := range trace.Stack {
|
for i, stackValue := range trace.Stack {
|
||||||
formattedStructLogs[index].Stack[i] = fmt.Sprintf("%x", math.PaddedBigBytes(stackValue, 32))
|
formattedStructLogs[index].Stack[i] = fmt.Sprintf("%x", math.PaddedBigBytes(stackValue, 32))
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i+32 <= len(trace.Memory); i += 32 {
|
for i := 0; i+32 <= len(trace.Memory); i += 32 {
|
||||||
formattedStructLogs[index].Memory = append(formattedStructLogs[index].Memory, fmt.Sprintf("%x", trace.Memory[i:i+32]))
|
formattedStructLogs[index].Memory = append(formattedStructLogs[index].Memory, fmt.Sprintf("%x", trace.Memory[i:i+32]))
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, storageValue := range trace.Storage {
|
for i, storageValue := range trace.Storage {
|
||||||
formattedStructLogs[index].Storage[fmt.Sprintf("%x", i)] = fmt.Sprintf("%x", storageValue)
|
formattedStructLogs[index].Storage[fmt.Sprintf("%x", i)] = fmt.Sprintf("%x", storageValue)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue