aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/vm.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-06-10 16:59:44 +0800
committerobscuren <geffobscura@gmail.com>2015-06-10 16:59:44 +0800
commitff5b3ef0877978699235d20b3caa9890b35ec6f8 (patch)
tree6110d396ae29f4462fe516efa26feacd5852f55f /core/vm/vm.go
parent468501cb860508af55e1fcd586e1498df0a2d984 (diff)
downloadgo-tangerine-ff5b3ef0877978699235d20b3caa9890b35ec6f8.tar
go-tangerine-ff5b3ef0877978699235d20b3caa9890b35ec6f8.tar.gz
go-tangerine-ff5b3ef0877978699235d20b3caa9890b35ec6f8.tar.bz2
go-tangerine-ff5b3ef0877978699235d20b3caa9890b35ec6f8.tar.lz
go-tangerine-ff5b3ef0877978699235d20b3caa9890b35ec6f8.tar.xz
go-tangerine-ff5b3ef0877978699235d20b3caa9890b35ec6f8.tar.zst
go-tangerine-ff5b3ef0877978699235d20b3caa9890b35ec6f8.zip
core/vm: added structured logging
Diffstat (limited to 'core/vm/vm.go')
-rw-r--r--core/vm/vm.go26
1 files changed, 22 insertions, 4 deletions
diff --git a/core/vm/vm.go b/core/vm/vm.go
index ed4157178..e6d4c8df2 100644
--- a/core/vm/vm.go
+++ b/core/vm/vm.go
@@ -11,10 +11,18 @@ import (
"github.com/ethereum/go-ethereum/params"
)
+type log struct {
+ op OpCode
+ gas *big.Int
+ memory []byte
+ stack []*big.Int
+}
+
type Vm struct {
env Environment
- logTy byte
+ // structured logging
+ Logs []log
logStr string
err error
@@ -32,9 +40,7 @@ type Vm struct {
}
func New(env Environment) *Vm {
- lt := LogTyPretty
-
- return &Vm{debug: Debug, env: env, logTy: lt, Recoverable: true}
+ return &Vm{env: env, Recoverable: true}
}
func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
@@ -106,6 +112,8 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
// Get the memory location of pc
op = context.GetOp(pc)
+ self.Log(op, context.Gas, mem, stack)
+
self.Printf("(pc) %-3d -o- %-14s (m) %-4d (s) %-4d ", pc, op.String(), mem.Len(), stack.len())
newMemSize, gas, err := self.calculateGasAndSize(context, caller, op, statedb, mem, stack)
if err != nil {
@@ -855,6 +863,16 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo
return newMemSize, gas, nil
}
+func (vm *Vm) Log(op OpCode, gas *big.Int, memory *Memory, stack *stack) {
+ if vm.debug {
+ mem := make([]byte, len(memory.store))
+ copy(mem, memory.store)
+ stck := make([]*big.Int, len(stack.data))
+ copy(stck, stack.data)
+ vm.Logs = append(vm.Logs, log{op, new(big.Int).Set(gas), mem, stck})
+ }
+}
+
func (self *Vm) RunPrecompiled(p *PrecompiledAccount, callData []byte, context *Context) (ret []byte, err error) {
gas := p.Gas(len(callData))
if context.UseGas(gas) {