diff --git a/miner/worker.go b/miner/worker.go index 9a633a12f8..98981da1c7 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -2372,6 +2372,12 @@ func (w *worker) clearPending(number uint64) { // vmConfig returns the VM config. func (w *worker) vmConfig() vm.Config { cfg := *w.chain.GetVMConfig() + // The miner copies its vm.Config from the chain instance, which may include + // a vm.Config.Tracer intended only for live tracing, not for mining. Clear + // the tracer here to prevent the miner from tracing block production and + // conflicting with live tracing. + cfg.Tracer = nil + return cfg } diff --git a/miner/worker_test.go b/miner/worker_test.go index 8da774b8e4..d8fa342dae 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -43,6 +43,7 @@ import ( "github.com/ethereum/go-ethereum/core/blockstm" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/txpool" "github.com/ethereum/go-ethereum/core/txpool/legacypool" "github.com/ethereum/go-ethereum/core/types" @@ -2967,3 +2968,21 @@ func TestDelayFlagOffByOne(t *testing.T) { require.True(t, buggyDelayFlag(), "bug: last tx skipped, DAG hint incorrectly embedded") require.False(t, fixedDelayFlag(), "fix: last tx detected, DAG hint suppressed") } + +// TestVMConfigTracerStripped verifies that vmConfig() always returns a vm.Config +// with Tracer == nil, even when the chain's VMConfig has a non-nil tracer set +// (e.g. during live tracing). The chain's own VMConfig must remain unchanged. +func TestVMConfigTracerStripped(t *testing.T) { + engine := clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()) + defer engine.Close() + + w, b, cleanup := newTestWorker(t, DefaultTestConfig(), cliqueChainConfig, engine, rawdb.NewMemoryDatabase(), false, 0) + defer cleanup() + + sentinel := &tracing.Hooks{} + b.chain.GetVMConfig().Tracer = sentinel + + got := w.vmConfig() + require.Nil(t, got.Tracer, "vmConfig() must strip the tracer so the miner does not conflict with live tracing") + require.Same(t, sentinel, b.chain.GetVMConfig().Tracer, "chain VMConfig tracer must remain unchanged after vmConfig() call") +}