Skip to content

Comments

miner: optimize clear up logic for envs#3034

Merged
buddh0 merged 1 commit intobnb-chain:developfrom
buddh0:clear-up-bid-simulator-optimize
Apr 18, 2025
Merged

miner: optimize clear up logic for envs#3034
buddh0 merged 1 commit intobnb-chain:developfrom
buddh0:clear-up-bid-simulator-optimize

Conversation

@buddh0
Copy link
Contributor

@buddh0 buddh0 commented Apr 18, 2025

Description

miner: optimize clear up logic for envs

Rationale

1. Fix for bid.discard Conflict with worker.commit() Causing Panic

image
In bid_simulator.go, the bid.discard function conflicts with worker.commit(), resulting in a panic.
Specifically:

  • At line 304, s.db.prefetcher is not nil.
  • But at line 305, it suddenly becomes nil, causing a panic.

This happens due to concurrent modification of s.db.prefetcher.

Based on code analysis, this issue only occurs when a miner selects a bid as the final work to commit. There are two scenarios where this can happen after the worker calls GetBestBid:

  • (a) bidSimulator.SetBestBid is invoked, or
  • (b) a new chainHead event is received, triggering clearFn in bidSimulator.clearLoop.

This PR resolves the issue by delaying the discard action to avoid the race condition.


2. Centralized Discard Logic in bidSimulator

Previously, environment discards (envs) were scattered across multiple locations within bidSimulator.

In this PR, we consolidate the logic so that environment discards happen in only one place, improving maintainability and reducing complexity.


3. Optimizing clearLoop Iteration

In clearLoop, both bestBidToRun and simulatingBid retain up to b.chain.TriesInMemory() items.
Iterating over all of them is inefficient.

This PR introduces the use of GetFinalizedNumber to limit the retained items to just 2, significantly improving performance.


Example

add an example CLI or API response...

Changes

Notable changes:

  • add each change in a bullet point here
  • ...

@buddh0 buddh0 marked this pull request as ready for review April 18, 2025 02:59
@buddh0 buddh0 merged commit 275b981 into bnb-chain:develop Apr 18, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants