From 3128174c710bed15439edfc02c3008cdfe607f90 Mon Sep 17 00:00:00 2001 From: avalonche Date: Fri, 15 Sep 2023 03:17:55 +1000 Subject: [PATCH] nil pointer panic fix --- miner/ordering.go | 10 +++++++++- miner/payload_building.go | 5 +++++ miner/worker.go | 18 ++++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/miner/ordering.go b/miner/ordering.go index 967c02670..94f1ae8d0 100644 --- a/miner/ordering.go +++ b/miner/ordering.go @@ -159,7 +159,15 @@ func (s txByPriceAndTime) Less(i, j int) bool { // deterministic sorting cmp := s[i].fees.Cmp(s[j].fees) if cmp == 0 { - return s[i].Tx().Time.Before(s[j].Tx().Time) + if s[i].Tx() != nil && s[j].Tx() != nil { + return s[i].Tx().Time.Before(s[j].Tx().Time) + } else if s[i].Bundle() != nil && s[j].Bundle() != nil { + return s[i].Bundle().TotalGasUsed <= s[j].Bundle().TotalGasUsed + } else if s[i].Bundle() != nil { + return false + } + + return true } return cmp > 0 } diff --git a/miner/payload_building.go b/miner/payload_building.go index 2e29b3408..1896831e3 100644 --- a/miner/payload_building.go +++ b/miner/payload_building.go @@ -231,6 +231,11 @@ func (payload *Payload) ResolveFull() *engine.ExecutionPayloadEnvelope { default: close(payload.stop) } + + if payload.full == nil { + return nil + } + return engine.BlockToExecutableData(payload.full, payload.fullFees, payload.sidecars) } diff --git a/miner/worker.go b/miner/worker.go index ec96427ca..37e9206c4 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1836,7 +1836,14 @@ func (w *worker) simulateBundles(env *environment, bundles []types.MevBundle, sb wg.Wait() simCache.UpdateSimulatedBundles(simResult, bundles) - simulatedBundles := make([]simulatedBundle, 0, len(bundles)) + simBundleCount := 0 + for _, bundle := range simResult { + if bundle != nil { + simBundleCount += 1 + } + } + + simulatedBundles := make([]simulatedBundle, 0, simBundleCount) for _, bundle := range simResult { if bundle != nil { simulatedBundles = append(simulatedBundles, *bundle) @@ -1844,7 +1851,14 @@ func (w *worker) simulateBundles(env *environment, bundles []types.MevBundle, sb } simCache.UpdateSimSBundle(sbSimResult, sbundles) - simulatedSbundle := make([]*types.SimSBundle, 0, len(sbundles)) + simSBundleCount := 0 + for _, sbundle := range sbSimResult { + if sbundle != nil { + simSBundleCount += 1 + } + } + + simulatedSbundle := make([]*types.SimSBundle, 0, simSBundleCount) for _, sbundle := range sbSimResult { if sbundle != nil { simulatedSbundle = append(simulatedSbundle, sbundle)