mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
eth/tracers: set use callContext to set BlockContext
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
767b00b0b5
commit
997e721991
5 changed files with 42 additions and 49 deletions
|
|
@ -27,7 +27,6 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
|
@ -39,14 +38,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/tests"
|
"github.com/ethereum/go-ethereum/tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
type callContext struct {
|
|
||||||
Number math.HexOrDecimal64 `json:"number"`
|
|
||||||
Difficulty *math.HexOrDecimal256 `json:"difficulty"`
|
|
||||||
Time math.HexOrDecimal64 `json:"timestamp"`
|
|
||||||
GasLimit math.HexOrDecimal64 `json:"gasLimit"`
|
|
||||||
Miner common.Address `json:"miner"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// callLog is the result of LOG opCode
|
// callLog is the result of LOG opCode
|
||||||
type callLog struct {
|
type callLog struct {
|
||||||
Address common.Address `json:"address"`
|
Address common.Address `json:"address"`
|
||||||
|
|
@ -125,16 +116,7 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
|
||||||
// Configure a blockchain with the given prestate
|
// Configure a blockchain with the given prestate
|
||||||
var (
|
var (
|
||||||
signer = types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time))
|
signer = types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time))
|
||||||
context = vm.BlockContext{
|
context = test.Context.toBlockContext(test.Genesis)
|
||||||
CanTransfer: core.CanTransfer,
|
|
||||||
Transfer: core.Transfer,
|
|
||||||
Coinbase: test.Context.Miner,
|
|
||||||
BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)),
|
|
||||||
Time: uint64(test.Context.Time),
|
|
||||||
Difficulty: (*big.Int)(test.Context.Difficulty),
|
|
||||||
GasLimit: uint64(test.Context.GasLimit),
|
|
||||||
BaseFee: test.Genesis.BaseFee,
|
|
||||||
}
|
|
||||||
state = tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme)
|
state = tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme)
|
||||||
)
|
)
|
||||||
state.Close()
|
state.Close()
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ type flatCallTraceResult struct {
|
||||||
|
|
||||||
// flatCallTracerTest defines a single test to check the call tracer against.
|
// flatCallTracerTest defines a single test to check the call tracer against.
|
||||||
type flatCallTracerTest struct {
|
type flatCallTracerTest struct {
|
||||||
Genesis core.Genesis `json:"genesis"`
|
Genesis *core.Genesis `json:"genesis"`
|
||||||
Context callContext `json:"context"`
|
Context *callContext `json:"context"`
|
||||||
Input string `json:"input"`
|
Input string `json:"input"`
|
||||||
TracerConfig json.RawMessage `json:"tracerConfig"`
|
TracerConfig json.RawMessage `json:"tracerConfig"`
|
||||||
Result []flatCallTrace `json:"result"`
|
Result []flatCallTrace `json:"result"`
|
||||||
|
|
@ -84,15 +84,7 @@ func flatCallTracerTestRunner(tracerName string, filename string, dirPath string
|
||||||
return fmt.Errorf("failed to parse testcase input: %v", err)
|
return fmt.Errorf("failed to parse testcase input: %v", err)
|
||||||
}
|
}
|
||||||
signer := types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time))
|
signer := types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time))
|
||||||
context := vm.BlockContext{
|
context := test.Context.toBlockContext(test.Genesis)
|
||||||
CanTransfer: core.CanTransfer,
|
|
||||||
Transfer: core.Transfer,
|
|
||||||
Coinbase: test.Context.Miner,
|
|
||||||
BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)),
|
|
||||||
Time: uint64(test.Context.Time),
|
|
||||||
Difficulty: (*big.Int)(test.Context.Difficulty),
|
|
||||||
GasLimit: uint64(test.Context.GasLimit),
|
|
||||||
}
|
|
||||||
state := tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme)
|
state := tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme)
|
||||||
defer state.Close()
|
defer state.Close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
|
@ -94,25 +93,11 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
|
||||||
// Configure a blockchain with the given prestate
|
// Configure a blockchain with the given prestate
|
||||||
var (
|
var (
|
||||||
signer = types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time))
|
signer = types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time))
|
||||||
context = vm.BlockContext{
|
context = test.Context.toBlockContext(test.Genesis)
|
||||||
CanTransfer: core.CanTransfer,
|
|
||||||
Transfer: core.Transfer,
|
|
||||||
Coinbase: test.Context.Miner,
|
|
||||||
BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)),
|
|
||||||
Time: uint64(test.Context.Time),
|
|
||||||
Difficulty: (*big.Int)(test.Context.Difficulty),
|
|
||||||
GasLimit: uint64(test.Context.GasLimit),
|
|
||||||
BaseFee: test.Genesis.BaseFee,
|
|
||||||
}
|
|
||||||
state = tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme)
|
state = tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme)
|
||||||
)
|
)
|
||||||
defer state.Close()
|
defer state.Close()
|
||||||
|
|
||||||
if test.Genesis.ExcessBlobGas != nil && test.Genesis.BlobGasUsed != nil {
|
|
||||||
excessBlobGas := eip4844.CalcExcessBlobGas(*test.Genesis.ExcessBlobGas, *test.Genesis.BlobGasUsed)
|
|
||||||
context.BlobBaseFee = eip4844.CalcBlobFee(excessBlobGas)
|
|
||||||
}
|
|
||||||
|
|
||||||
tracer, err := tracers.DefaultDirectory.New(tracerName, new(tracers.Context), test.TracerConfig)
|
tracer, err := tracers.DefaultDirectory.New(tracerName, new(tracers.Context), test.TracerConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create call tracer: %v", err)
|
t.Fatalf("failed to create call tracer: %v", err)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,16 @@
|
||||||
package tracetest
|
package tracetest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
|
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
|
||||||
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
|
|
||||||
// Force-load native and js packages, to trigger registration
|
// Force-load native and js packages, to trigger registration
|
||||||
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
|
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
|
||||||
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
|
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
|
||||||
|
|
@ -17,3 +24,30 @@ func camel(str string) string {
|
||||||
}
|
}
|
||||||
return strings.Join(pieces, "")
|
return strings.Join(pieces, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type callContext struct {
|
||||||
|
Number math.HexOrDecimal64 `json:"number"`
|
||||||
|
Difficulty *math.HexOrDecimal256 `json:"difficulty"`
|
||||||
|
Time math.HexOrDecimal64 `json:"timestamp"`
|
||||||
|
GasLimit math.HexOrDecimal64 `json:"gasLimit"`
|
||||||
|
Miner common.Address `json:"miner"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
|
||||||
|
context := vm.BlockContext{
|
||||||
|
CanTransfer: core.CanTransfer,
|
||||||
|
Transfer: core.Transfer,
|
||||||
|
Coinbase: c.Miner,
|
||||||
|
BlockNumber: new(big.Int).SetUint64(uint64(c.Number)),
|
||||||
|
Time: uint64(c.Time),
|
||||||
|
Difficulty: (*big.Int)(c.Difficulty),
|
||||||
|
GasLimit: uint64(c.GasLimit),
|
||||||
|
BaseFee: genesis.BaseFee,
|
||||||
|
}
|
||||||
|
if genesis.ExcessBlobGas != nil && genesis.BlobGasUsed != nil {
|
||||||
|
excessBlobGas := eip4844.CalcExcessBlobGas(*genesis.ExcessBlobGas, *genesis.BlobGasUsed)
|
||||||
|
context.BlobBaseFee = eip4844.CalcBlobFee(excessBlobGas)
|
||||||
|
}
|
||||||
|
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue