From 8943e3fd7c83b5f5108b0f935af252e0b8c36240 Mon Sep 17 00:00:00 2001 From: Raina Date: Wed, 20 Mar 2024 17:13:07 +0800 Subject: [PATCH] fix: index out of range (#10) --- miner/bidder.go | 2 +- miner/bundle_cache.go | 15 ++++++++++----- miner/worker_builder.go | 9 ++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/miner/bidder.go b/miner/bidder.go index 8ac9f796a5..65561aab16 100644 --- a/miner/bidder.go +++ b/miner/bidder.go @@ -227,7 +227,7 @@ func (b *Bidder) bid(work *environment) { } b.deleteBestWork(work) - log.Info("Bidder: bidding success") + log.Info("Bidder: bidding success", "number", work.header.Number, "txs", len(work.txs)) } // isBestWork returns the work is better than the current best work diff --git a/miner/bundle_cache.go b/miner/bundle_cache.go index 37cf1ab74a..54609682c5 100644 --- a/miner/bundle_cache.go +++ b/miner/bundle_cache.go @@ -68,14 +68,19 @@ func (c *BundleCacheEntry) GetSimulatedBundle(bundle common.Hash) (*types.Simula return nil, false } -func (c *BundleCacheEntry) UpdateSimulatedBundles(result []*types.SimulatedBundle, bundles []*types.Bundle) { +func (c *BundleCacheEntry) UpdateSimulatedBundles(result map[common.Hash]*types.SimulatedBundle, bundles []*types.Bundle) { c.mu.Lock() defer c.mu.Unlock() - for i, simBundle := range result { - bundleHash := bundles[i].Hash() - if simBundle != nil { - c.successfulBundles[bundleHash] = simBundle + for _, bundle := range bundles { + if bundle == nil { + continue + } + + bundleHash := bundle.Hash() + + if result[bundleHash] != nil { + c.successfulBundles[bundleHash] = result[bundleHash] } else { c.failedBundles[bundleHash] = struct{}{} } diff --git a/miner/worker_builder.go b/miner/worker_builder.go index c009d3ece6..bb4c32e7d1 100644 --- a/miner/worker_builder.go +++ b/miner/worker_builder.go @@ -29,7 +29,6 @@ var ( // into the given sealing block. The selection and ordering strategy can be extended in the future. func (w *worker) fillTransactionsAndBundles(interruptCh chan int32, env *environment, stopTimer *time.Timer) error { var ( - pending map[common.Address][]*txpool.LazyTransaction localPlainTxs map[common.Address][]*txpool.LazyTransaction remotePlainTxs map[common.Address][]*txpool.LazyTransaction localBlobTxs map[common.Address][]*txpool.LazyTransaction @@ -75,7 +74,7 @@ func (w *worker) fillTransactionsAndBundles(interruptCh chan int32, env *environ bundles = w.eth.TxPool().PendingBundles(env.header.Number.Uint64(), env.header.Time) - log.Info("fill bundles and transactions", "bundles_count", len(bundles), "tx_count", len(pending)) + log.Info("fill bundles and transactions", "bundles_count", len(bundles), "tx_count", len(localPlainTxs)+len(remotePlainTxs)) // if no bundles, not necessary to fill transactions if len(bundles) == 0 { @@ -282,12 +281,12 @@ func (w *worker) generateOrderedBundles( func (w *worker) simulateBundles(env *environment, bundles []*types.Bundle) ([]*types.SimulatedBundle, error) { headerHash := env.header.Hash() simCache := w.bundleCache.GetBundleCache(headerHash) - simResult := make([]*types.SimulatedBundle, len(bundles)) + simResult := make(map[common.Hash]*types.SimulatedBundle) var wg sync.WaitGroup for i, bundle := range bundles { if simmed, ok := simCache.GetSimulatedBundle(bundle.Hash()); ok { - simResult = append(simResult, simmed) + simResult[bundle.Hash()] = simmed continue } @@ -302,7 +301,7 @@ func (w *worker) simulateBundles(env *environment, bundles []*types.Bundle) ([]* return } - simResult[idx] = simmed + simResult[bundle.Hash()] = simmed }(i, bundle, env.state.Copy()) }