064f37d6f6
Here we add a Go API for running tracing plugins within the main block import process. As an advanced user of geth, you can now create a Go file in eth/tracers/live/, and within that file register your custom tracer implementation. Then recompile geth and select your tracer on the command line. Hooks defined in the tracer will run whenever a block is processed. The hook system is defined in package core/tracing. It uses a struct with callbacks, instead of requiring an interface, for several reasons: - We plan to keep this API stable long-term. The core/tracing hook API does not depend on on deep geth internals. - There are a lot of hooks, and tracers will only need some of them. Using a struct allows you to implement only the hooks you want to actually use. All existing tracers in eth/tracers/native have been rewritten to use the new hook system. This change breaks compatibility with the vm.EVMLogger interface that we used to have. If you are a user of vm.EVMLogger, please migrate to core/tracing, and sorry for breaking your stuff. But we just couldn't have both the old and new tracing APIs coexist in the EVM. --------- Co-authored-by: Matthieu Vachon <matthieu.o.vachon@gmail.com> Co-authored-by: Delweng <delweng@gmail.com> Co-authored-by: Martin HS <martin@swende.se>
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
// Copyright 2023 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// 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 internal
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
)
|
|
|
|
func TestMemCopying(t *testing.T) {
|
|
for i, tc := range []struct {
|
|
memsize int64
|
|
offset int64
|
|
size int64
|
|
wantErr string
|
|
wantSize int
|
|
}{
|
|
{0, 0, 100, "", 100}, // Should pad up to 100
|
|
{0, 100, 0, "", 0}, // No need to pad (0 size)
|
|
{100, 50, 100, "", 100}, // Should pad 100-150
|
|
{100, 50, 5, "", 5}, // Wanted range fully within memory
|
|
{100, -50, 0, "offset or size must not be negative", 0}, // Error
|
|
{0, 1, 1024*1024 + 1, "reached limit for padding memory slice: 1048578", 0}, // Error
|
|
{10, 0, 1024*1024 + 100, "reached limit for padding memory slice: 1048666", 0}, // Error
|
|
|
|
} {
|
|
mem := vm.NewMemory()
|
|
mem.Resize(uint64(tc.memsize))
|
|
cpy, err := GetMemoryCopyPadded(mem.Data(), tc.offset, tc.size)
|
|
if want := tc.wantErr; want != "" {
|
|
if err == nil {
|
|
t.Fatalf("test %d: want '%v' have no error", i, want)
|
|
}
|
|
if have := err.Error(); want != have {
|
|
t.Fatalf("test %d: want '%v' have '%v'", i, want, have)
|
|
}
|
|
continue
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("test %d: unexpected error: %v", i, err)
|
|
}
|
|
if want, have := tc.wantSize, len(cpy); have != want {
|
|
t.Fatalf("test %d: want %v have %v", i, want, have)
|
|
}
|
|
}
|
|
}
|