Skip to content

Commit

Permalink
fix: index out of range (bnb-chain#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun authored Mar 20, 2024
1 parent 884dad6 commit 8943e3f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion miner/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions miner/bundle_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
}
Expand Down
9 changes: 4 additions & 5 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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())
}

Expand Down

0 comments on commit 8943e3f

Please sign in to comment.