From 7e0e4c8905ade34dabab5f35fbba743fe07d3cc5 Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Thu, 6 Jul 2023 01:27:56 -0400 Subject: [PATCH] Fix worker tracing `nil` pointer exception (#899) The `baseFee` can be `nil` in certain situations, the tracing must not use `baseFee` unless it was checked otherwise if such case happen, Go is going to panic. --- miner/worker.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index c46d0b2c8d..bd7ac13294 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -32,6 +32,7 @@ import ( mapset "github.com/deckarep/golang-set" lru "github.com/hashicorp/golang-lru" + "github.com/holiman/uint256" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -670,7 +671,12 @@ func (w *worker) mainLoop(ctx context.Context) { txs[acc] = append(txs[acc], tx) } - txset := types.NewTransactionsByPriceAndNonce(w.current.signer, txs, cmath.FromBig(w.current.header.BaseFee)) + var baseFee *uint256.Int + if w.current.header.BaseFee != nil { + baseFee = cmath.FromBig(w.current.header.BaseFee) + } + + txset := types.NewTransactionsByPriceAndNonce(w.current.signer, txs, baseFee) tcount := w.current.tcount //nolint:contextcheck @@ -1509,7 +1515,12 @@ func (w *worker) fillTransactions(ctx context.Context, interrupt *int32, env *en var txs *types.TransactionsByPriceAndNonce tracing.Exec(ctx, "", "worker.LocalTransactionsByPriceAndNonce", func(ctx context.Context, span trace.Span) { - txs = types.NewTransactionsByPriceAndNonce(env.signer, localTxs, cmath.FromBig(env.header.BaseFee)) + var baseFee *uint256.Int + if env.header.BaseFee != nil { + baseFee = cmath.FromBig(env.header.BaseFee) + } + + txs = types.NewTransactionsByPriceAndNonce(env.signer, localTxs, baseFee) tracing.SetAttributes( span, @@ -1532,7 +1543,12 @@ func (w *worker) fillTransactions(ctx context.Context, interrupt *int32, env *en var txs *types.TransactionsByPriceAndNonce tracing.Exec(ctx, "", "worker.RemoteTransactionsByPriceAndNonce", func(ctx context.Context, span trace.Span) { - txs = types.NewTransactionsByPriceAndNonce(env.signer, remoteTxs, cmath.FromBig(env.header.BaseFee)) + var baseFee *uint256.Int + if env.header.BaseFee != nil { + baseFee = cmath.FromBig(env.header.BaseFee) + } + + txs = types.NewTransactionsByPriceAndNonce(env.signer, remoteTxs, baseFee) tracing.SetAttributes( span,