From 0939f044ab94494938520eb0e320e557cc5ca2cf Mon Sep 17 00:00:00 2001 From: irrun Date: Wed, 8 May 2024 17:30:01 +0800 Subject: [PATCH] fix: a nil pointer when query bundle price (#28) --- eth/api_backend.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/eth/api_backend.go b/eth/api_backend.go index a95356065d..afec1190a8 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -306,14 +306,19 @@ func (b *EthAPIBackend) SendBundle(ctx context.Context, bundle *types.Bundle) er func (b *EthAPIBackend) BundlePrice() *big.Int { bundles := b.eth.txPool.AllBundles() + gasFloor := big.NewInt(b.eth.config.Miner.MevGasPriceFloor) + + if len(bundles) == 0 { + return gasFloor + } sort.SliceStable(bundles, func(i, j int) bool { return bundles[j].Price.Cmp(bundles[i].Price) < 0 }) - gasFloor := big.NewInt(b.eth.config.Miner.MevGasPriceFloor) idx := len(bundles) / 2 - if bundles[idx].Price.Cmp(gasFloor) < 0 { + + if bundles[idx] == nil || bundles[idx].Price.Cmp(gasFloor) < 0 { return gasFloor }