Skip to content

Commit

Permalink
Revert "Cleanup of tracer to working"
Browse files Browse the repository at this point in the history
This reverts commit b8a5ec8.
  • Loading branch information
gameofpointers committed Dec 9, 2023
1 parent 5ed8420 commit 7d9cdea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 38 deletions.
20 changes: 12 additions & 8 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/dominant-strategies/go-quai/core/types"
"github.com/dominant-strategies/go-quai/core/vm"
"github.com/dominant-strategies/go-quai/ethdb"
"github.com/dominant-strategies/go-quai/internal/quaiapi"
"github.com/dominant-strategies/go-quai/internal/ethapi"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/params"
"github.com/dominant-strategies/go-quai/rlp"
Expand Down Expand Up @@ -168,7 +168,7 @@ type TraceCallConfig struct {
Tracer *string
Timeout *string
Reexec *uint64
StateOverrides *quaiapi.StateOverride
StateOverrides *ethapi.StateOverride
}

// StdTraceConfig holds extra parameters to standard-json trace functions.
Expand Down Expand Up @@ -277,7 +277,7 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config
break
}
// Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect
task.statedb.Finalise(true)
task.statedb.Finalise(api.backend.ChainConfig().IsEIP158(task.block.Number()))
task.results[i] = &txTraceResult{Result: res}
}
// Stream the result back to the user or abort on teardown
Expand Down Expand Up @@ -547,7 +547,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
}
// Finalize the state so any modifications are written to the trie
// Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect
statedb.Finalise(true)
statedb.Finalise(vmenv.ChainConfig().IsEIP158(block.Number()))
}
close(jobs)
pend.Wait()
Expand Down Expand Up @@ -615,6 +615,10 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
chainConfigCopy := new(params.ChainConfig)
*chainConfigCopy = *chainConfig
chainConfig = chainConfigCopy
if berlin := config.LogConfig.Overrides.BerlinBlock; berlin != nil {
chainConfig.BerlinBlock = berlin
canon = false
}
}
for i, tx := range block.Transactions() {
// Prepare the trasaction for un-traced execution
Expand Down Expand Up @@ -663,7 +667,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
}
// Finalize the state so any modifications are written to the trie
// Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect
statedb.Finalise(true)
statedb.Finalise(vmenv.ChainConfig().IsEIP158(block.Number()))

// If we've traced the transaction we were looking for, abort
if tx.Hash() == txHash {
Expand Down Expand Up @@ -719,7 +723,7 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *
// created during the execution of EVM if the given transaction was added on
// top of the provided block and returns them as a JSON object.
// You can provide -2 as a block number to trace on top of the pending block.
func (api *API) TraceCall(ctx context.Context, args quaiapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) (interface{}, error) {
func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) (interface{}, error) {
// Try to retrieve the specified block
var (
err error
Expand Down Expand Up @@ -827,11 +831,11 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex
if len(result.Revert()) > 0 {
returnVal = fmt.Sprintf("%x", result.Revert())
}
return &quaiapi.ExecutionResult{
return &ethapi.ExecutionResult{
Gas: result.UsedGas,
Failed: result.Failed(),
ReturnValue: returnVal,
StructLogs: quaiapi.FormatLogs(tracer.StructLogs()),
StructLogs: ethapi.FormatLogs(tracer.StructLogs()),
}, nil

case *Tracer:
Expand Down
46 changes: 18 additions & 28 deletions eth/tracers/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,21 @@ func (dw *dbWrapper) pushObject(vm *duktape.Context) {

// Push the wrapper for statedb.GetBalance
vm.PushGoFunction(func(ctx *duktape.Context) int {
addr, _ := common.BytesToAddress(popSlice(ctx)).InternalAddress()
pushBigInt(dw.db.GetBalance(addr), ctx)
pushBigInt(dw.db.GetBalance(common.BytesToAddress(popSlice(ctx))), ctx)
return 1
})
vm.PutPropString(obj, "getBalance")

// Push the wrapper for statedb.GetNonce
vm.PushGoFunction(func(ctx *duktape.Context) int {
addr, _ := common.BytesToAddress(popSlice(ctx)).InternalAddress()
ctx.PushInt(int(dw.db.GetNonce(addr)))
ctx.PushInt(int(dw.db.GetNonce(common.BytesToAddress(popSlice(ctx)))))
return 1
})
vm.PutPropString(obj, "getNonce")

// Push the wrapper for statedb.GetCode
vm.PushGoFunction(func(ctx *duktape.Context) int {
addr, _ := common.BytesToAddress(popSlice(ctx)).InternalAddress()
code := dw.db.GetCode(addr)
code := dw.db.GetCode(common.BytesToAddress(popSlice(ctx)))

ptr := ctx.PushFixedBuffer(len(code))
copy(makeSlice(ptr, uint(len(code))), code)
Expand All @@ -227,8 +224,7 @@ func (dw *dbWrapper) pushObject(vm *duktape.Context) {
hash := popSlice(ctx)
addr := popSlice(ctx)

iAddr, _ := common.BytesToAddress(addr).InternalAddress()
state := dw.db.GetState(iAddr, common.BytesToHash(hash))
state := dw.db.GetState(common.BytesToAddress(addr), common.BytesToHash(hash))

ptr := ctx.PushFixedBuffer(len(state))
copy(makeSlice(ptr, uint(len(state))), state[:])
Expand All @@ -238,8 +234,7 @@ func (dw *dbWrapper) pushObject(vm *duktape.Context) {

// Push the wrapper for statedb.Exists
vm.PushGoFunction(func(ctx *duktape.Context) int {
addr, _ := common.BytesToAddress(popSlice(ctx)).InternalAddress()
ctx.PushBoolean(dw.db.Exist(addr))
ctx.PushBoolean(dw.db.Exist(common.BytesToAddress(popSlice(ctx))))
return 1
})
vm.PutPropString(obj, "exists")
Expand Down Expand Up @@ -374,34 +369,27 @@ func New(code string, ctx *Context) (*Tracer, error) {
return 1
})
tracer.vm.PushGlobalGoFunction("toAddress", func(ctx *duktape.Context) int {
var addr common.InternalAddress
var addr common.Address
if ptr, size := ctx.GetBuffer(-1); ptr != nil {
addr, _ = common.BytesToAddress(makeSlice(ptr, size)).InternalAddress()
addr = common.BytesToAddress(makeSlice(ptr, size))
} else {
addr, _ = common.HexToAddress(ctx.GetString(-1)).InternalAddress()
addr = common.HexToAddress(ctx.GetString(-1))
}
ctx.Pop()
copy(makeSlice(ctx.PushFixedBuffer(20), 20), addr[:])
return 1
})
tracer.vm.PushGlobalGoFunction("toContract", func(ctx *duktape.Context) int {
var from common.Address
if ptr, size := ctx.GetBuffer(-3); ptr != nil {
if ptr, size := ctx.GetBuffer(-2); ptr != nil {
from = common.BytesToAddress(makeSlice(ptr, size))
} else {
from = common.HexToAddress(ctx.GetString(-2))
}
nonce := uint64(ctx.GetInt(-2))
// Retrieve code slice from js stack
var code []byte
if ptr, size := ctx.GetBuffer(-1); ptr != nil {
code = common.CopyBytes(makeSlice(ptr, size))
} else {
code = common.FromHex(ctx.GetString(-1))
}
ctx.Pop3()
nonce := uint64(ctx.GetInt(-1))
ctx.Pop2()

contract, _ := crypto.CreateAddress(from, nonce, code).InternalAddress()
contract := crypto.CreateAddress(from, nonce)
copy(makeSlice(ctx.PushFixedBuffer(20), 20), contract[:])
return 1
})
Expand All @@ -423,7 +411,7 @@ func New(code string, ctx *Context) (*Tracer, error) {
}
codeHash := crypto.Keccak256(code)
ctx.Pop3()
contract, _ := crypto.CreateAddress2(from, salt, codeHash).InternalAddress()
contract := crypto.CreateAddress2(from, salt, codeHash)
copy(makeSlice(ctx.PushFixedBuffer(20), 20), contract[:])
return 1
})
Expand Down Expand Up @@ -594,7 +582,10 @@ func (jst *Tracer) CaptureStart(env *vm.EVM, from common.Address, to common.Addr
rules := env.ChainConfig().Rules(env.Context.BlockNumber)
jst.activePrecompiles = vm.ActivePrecompiles(rules)

intrinsicGas, err := core.IntrinsicGas(input, nil, jst.ctx["type"] == "CREATE")
// Compute intrinsic gas
isHomestead := env.ChainConfig().IsHomestead(env.Context.BlockNumber)
isIstanbul := env.ChainConfig().IsIstanbul(env.Context.BlockNumber)
intrinsicGas, err := core.IntrinsicGas(input, nil, jst.ctx["type"] == "CREATE", isHomestead, isIstanbul)
if err != nil {
return
}
Expand Down Expand Up @@ -677,8 +668,7 @@ func (jst *Tracer) GetResult() (json.RawMessage, error) {

case common.Address:
ptr := jst.vm.PushFixedBuffer(20)
addr, _ := val.InternalAddress()
copy(makeSlice(ptr, 20), addr[:])
copy(makeSlice(ptr, 20), val[:])

case *big.Int:
pushBigInt(val, jst.vm)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,6 @@ gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20210326210528-650f7c854440 h1:SxFAMd+8zfpL/Rk4pgdb8leeZDiL3M/gCWCbBvmLkoE=
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20210326210528-650f7c854440/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0=
Expand Down

0 comments on commit 7d9cdea

Please sign in to comment.