Skip to content

Commit

Permalink
Fix worker tracing nil pointer exception (maticnetwork#899)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
maoueh authored and cffls committed Jul 12, 2023
1 parent 29ea1aa commit 69292d4
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 69292d4

Please sign in to comment.