eth/tracers/plugin_hooks, tracers/plugin_hooks, and wrappers utils refactor modifications

This commit is contained in:
philip-morlier
2021-09-08 14:38:17 -07:00
parent c36c999383
commit b36e63f184
3 changed files with 176 additions and 65 deletions
+126 -18
View File
@@ -5,10 +5,12 @@ import (
"encoding/json"
"math/big"
"sync"
"time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
gcore "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/downloader"
@@ -22,55 +24,161 @@ import (
"github.com/openrelayxyz/plugeth-utils/restricted"
)
type WrapedScopeContext struct {
type WrappedScopeContext struct {
s *vm.ScopeContext
}
func (w *WrapedScopeContext) Memory() core.Memory {
func NewWrappedScopeContext(s *vm.ScopeContext) *WrappedScopeContext {
return &WrappedScopeContext{s}
}
func (w *WrappedScopeContext) Memory() core.Memory {
return w.s.Memory
}
func (w *WrapedScopeContext) Stack() core.Stack {
func (w *WrappedScopeContext) Stack() core.Stack {
return w.s.Stack
}
// type Contract interface { <= this is the core.Contract
// AsDelegate() Contract
// GetOp(n uint64) OpCode
// GetByte(n uint64) byte
// Caller() Address
// Address() Address
// Value() *big.Int
// }
func (w *WrappedScopeContext) Contract() core.Contract {
return &WrappedContract{w.s.Contract}
}
type WrappedContract struct {
c *vm.Contract
}
func (w WrappedContract) AsDelegate() core.Contract {
return WrappedContract{w.c.AsDelegate()}
func (w *WrappedContract) AsDelegate() core.Contract {
return &WrappedContract{w.c.AsDelegate()}
}
func (w WrappedContract) GetOp(n uint64) core.OpCode {
func (w *WrappedContract) GetOp(n uint64) core.OpCode {
return core.OpCode(w.c.GetOp(n))
}
func (w WrappedContract) GetByte(n uint64) byte {
func (w *WrappedContract) GetByte(n uint64) byte {
return w.c.GetByte(n)
}
func (w WrappedContract) Caller() core.Address {
func (w *WrappedContract) Caller() core.Address {
return core.Address(w.c.Caller())
}
func (w WrappedContract) Address() core.Address {
func (w *WrappedContract) Address() core.Address {
return core.Address(w.c.Address())
}
func (w WrappedContract) Value() *big.Int {
func (w *WrappedContract) Value() *big.Int {
return w.c.Value()
}
// added UseGas bc compiler compained without it. Should investigate if the false return with effect performance.
// take this out of core.interface
func (w *WrappedContract) UseGas(gas uint64) (ok bool) {
return false
}
type WrappedTracer struct {
r core.TracerResult
}
func NewWrappedTracer(r core.TracerResult) *WrappedTracer {
return &WrappedTracer{r}
}
func (w WrappedTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
w.r.CaptureStart(core.Address(from), core.Address(to), create, input, gas, value)
}
func (w WrappedTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) {
w.r.CaptureState(pc, core.OpCode(op), gas, cost, &WrappedScopeContext{scope}, rData, depth, err)
}
func (w WrappedTracer) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error) {
w.r.CaptureFault(pc, core.OpCode(op), gas, cost, &WrappedScopeContext{scope}, depth, err)
}
func (w WrappedTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) {
w.r.CaptureEnd(output, gasUsed, t, err)
}
func (w WrappedTracer) GetResult() (interface{}, error) {
return w.r.Result()
}
type WrappedStateDB struct {
s *state.StateDB
}
func NewWrappedStateDB(d *state.StateDB) *WrappedStateDB {
return &WrappedStateDB{d}
}
// GetBalance(Address) *big.Int
func (w *WrappedStateDB) GetBalance(addr core.Address) *big.Int {
return w.s.GetBalance(common.Address(addr))
}
// GetNonce(Address) uint64
func (w *WrappedStateDB) GetNonce(addr core.Address) uint64 {
return w.s.GetNonce(common.Address(addr))
}
// GetCodeHash(Address) Hash
func (w *WrappedStateDB) GetCodeHash(addr core.Address) core.Hash {
return core.Hash(w.s.GetCodeHash(common.Address(addr)))
} // sort this out
// GetCode(Address) []byte
func (w *WrappedStateDB) GetCode(addr core.Address) []byte {
return w.s.GetCode(common.Address(addr))
}
// GetCodeSize(Address) int
func (w *WrappedStateDB) GetCodeSize(addr core.Address) int {
return w.s.GetCodeSize(common.Address(addr))
}
//GetRefund() uint64
func (w *WrappedStateDB) GetRefund() uint64 { //are we sure we want to include this? getting a refund seems like changing state
return w.s.GetRefund()
}
// GetCommittedState(Address, Hash) Hash
func (w *WrappedStateDB) GetCommittedState(addr core.Address, hsh core.Hash) core.Hash {
return core.Hash(w.s.GetCommittedState(common.Address(addr), common.Hash(hsh)))
}
// GetState(Address, Hash) Hash
func (w *WrappedStateDB) GetState(addr core.Address, hsh core.Hash) core.Hash {
return core.Hash(w.s.GetState(common.Address(addr), common.Hash(hsh)))
}
// HasSuicided(Address) bool
func (w *WrappedStateDB) HasSuicided(addr core.Address) bool { // I figured we'd skip some of the future labor and update the name now
return w.s.HasSuicided(common.Address(addr))
}
// // Exist reports whether the given account exists in state.
// // Notably this should also return true for suicided accounts.
// Exist(Address) bool
func (w *WrappedStateDB) Exist(addr core.Address) bool {
return w.s.Exist(common.Address(addr))
}
// // Empty returns whether the given account is empty. Empty
// // is defined according to EIP161 (balance = nonce = code = 0).
// Empty(Address) bool
func (w *WrappedStateDB) Empty(addr core.Address) bool {
return w.s.Empty(common.Address(addr))
}
// AddressInAccessList(addr Address) bool
func (w *WrappedStateDB) AddressInAccessList(addr core.Address) bool {
return w.s.AddressInAccessList(common.Address(addr))
}
// SlotInAccessList(addr Address, slot Hash) (addressOk bool, slotOk bool)
func (w *WrappedStateDB) SlotInAccessList(addr core.Address, slot core.Hash) (addressOK, slotOk bool) {
return w.s.SlotInAccessList(common.Address(addr), common.Hash(slot))
}
type Node struct {
n *node.Node
}