move utils and noopT out of directory pkg

This commit is contained in:
Sina Mahmoodi 2024-03-22 15:20:13 +01:00 committed by Matthieu Vachon
parent bbc363f34c
commit 6ec3033ea5
6 changed files with 32 additions and 30 deletions

View file

@ -14,9 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package directory provides functionality to lookup tracers by name.
// It also includes utility functions that are imported by the other
// tracing packages.
// Package directory provides functionality to register and lookup tracers by name.
package directory
import (

View file

@ -13,7 +13,7 @@
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package directory
package internal
import (
"errors"
@ -62,6 +62,7 @@ func memoryCopy(m []byte, offset, size int64) (cpy []byte) {
return
}
// MemoryPtr returns a pointer to a slice of memory.
func MemoryPtr(m []byte, offset, size int64) []byte {
if size == 0 {
return nil

View file

@ -13,7 +13,7 @@
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package directory
package internal
import (
"testing"

View file

@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/tracers/directory"
"github.com/ethereum/go-ethereum/eth/tracers/internal"
"github.com/holiman/uint256"
"github.com/ethereum/go-ethereum/common"
@ -643,7 +644,7 @@ func (mo *memoryObj) slice(begin, end int64) ([]byte, error) {
if end < begin || begin < 0 {
return nil, fmt.Errorf("tracer accessed out of bound memory: offset %d, end %d", begin, end)
}
slice, err := directory.GetMemoryCopyPadded(mo.memory, begin, end-begin)
slice, err := internal.GetMemoryCopyPadded(mo.memory, begin, end-begin)
if err != nil {
return nil, err
}
@ -669,7 +670,7 @@ func (mo *memoryObj) getUint(addr int64) (*big.Int, error) {
if len(mo.memory) < int(addr)+32 || addr < 0 {
return nil, fmt.Errorf("tracer accessed out of bound memory: available %d, offset %d, size %d", len(mo.memory), addr, 32)
}
return new(big.Int).SetBytes(directory.MemoryPtr(mo.memory, addr, 32)), nil
return new(big.Int).SetBytes(internal.MemoryPtr(mo.memory, addr, 32)), nil
}
func (mo *memoryObj) Length() int {
@ -709,7 +710,7 @@ func (s *stackObj) peek(idx int) (*big.Int, error) {
if len(s.stack) <= idx || idx < 0 {
return nil, fmt.Errorf("tracer accessed out of bound stack: size %d, index %d", len(s.stack), idx)
}
return directory.StackBack(s.stack, idx).ToBig(), nil
return internal.StackBack(s.stack, idx).ToBig(), nil
}
func (s *stackObj) Length() int {

View file

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package directory
package native
import (
"encoding/json"
@ -23,20 +23,21 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/tracers/directory"
)
func init() {
DefaultDirectory.Register("noopTracer", newNoopTracer, false)
directory.DefaultDirectory.Register("noopTracer", newNoopTracer, false)
}
// NoopTracer is a go implementation of the Tracer interface which
// noopTracer is a go implementation of the Tracer interface which
// performs no action. It's mostly useful for testing purposes.
type NoopTracer struct{}
type noopTracer struct{}
// newNoopTracer returns a new noop tracer.
func newNoopTracer(ctx *Context, _ json.RawMessage) (*Tracer, error) {
t := &NoopTracer{}
return &Tracer{
func newNoopTracer(ctx *directory.Context, _ json.RawMessage) (*directory.Tracer, error) {
t := &noopTracer{}
return &directory.Tracer{
Hooks: &tracing.Hooks{
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
@ -56,42 +57,42 @@ func newNoopTracer(ctx *Context, _ json.RawMessage) (*Tracer, error) {
}, nil
}
func (t *NoopTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
func (t *noopTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
}
func (t *NoopTracer) OnFault(pc uint64, op byte, gas, cost uint64, _ tracing.OpContext, depth int, err error) {
func (t *noopTracer) OnFault(pc uint64, op byte, gas, cost uint64, _ tracing.OpContext, depth int, err error) {
}
func (t *NoopTracer) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {}
func (t *noopTracer) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {}
func (t *NoopTracer) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
func (t *noopTracer) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
}
func (t *NoopTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
func (t *noopTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
}
func (*NoopTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
func (*noopTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
}
func (*NoopTracer) OnTxEnd(receipt *types.Receipt, err error) {}
func (*noopTracer) OnTxEnd(receipt *types.Receipt, err error) {}
func (*NoopTracer) OnBalanceChange(a common.Address, prev, new *big.Int, reason tracing.BalanceChangeReason) {
func (*noopTracer) OnBalanceChange(a common.Address, prev, new *big.Int, reason tracing.BalanceChangeReason) {
}
func (*NoopTracer) OnNonceChange(a common.Address, prev, new uint64) {}
func (*noopTracer) OnNonceChange(a common.Address, prev, new uint64) {}
func (*NoopTracer) OnCodeChange(a common.Address, prevCodeHash common.Hash, prev []byte, codeHash common.Hash, code []byte) {
func (*noopTracer) OnCodeChange(a common.Address, prevCodeHash common.Hash, prev []byte, codeHash common.Hash, code []byte) {
}
func (*NoopTracer) OnStorageChange(a common.Address, k, prev, new common.Hash) {}
func (*noopTracer) OnStorageChange(a common.Address, k, prev, new common.Hash) {}
func (*NoopTracer) OnLog(log *types.Log) {}
func (*noopTracer) OnLog(log *types.Log) {}
// GetResult returns an empty json object.
func (t *NoopTracer) GetResult() (json.RawMessage, error) {
func (t *noopTracer) GetResult() (json.RawMessage, error) {
return json.RawMessage(`{}`), nil
}
// Stop terminates execution of the tracer at the first opportune moment.
func (t *NoopTracer) Stop(err error) {
func (t *noopTracer) Stop(err error) {
}

View file

@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/tracers/directory"
"github.com/ethereum/go-ethereum/eth/tracers/internal"
"github.com/ethereum/go-ethereum/log"
)
@ -132,7 +133,7 @@ func (t *prestateTracer) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scop
case stackLen >= 4 && op == vm.CREATE2:
offset := stackData[stackLen-2]
size := stackData[stackLen-3]
init, err := directory.GetMemoryCopyPadded(scope.MemoryData(), int64(offset.Uint64()), int64(size.Uint64()))
init, err := internal.GetMemoryCopyPadded(scope.MemoryData(), int64(offset.Uint64()), int64(size.Uint64()))
if err != nil {
log.Warn("failed to copy CREATE2 input", "err", err, "tracer", "prestateTracer", "offset", offset, "size", size)
return