miner: optimize clear up logic for envs#3034
Merged
buddh0 merged 1 commit intobnb-chain:developfrom Apr 18, 2025
buddh0:clear-up-bid-simulator-optimize
Merged
miner: optimize clear up logic for envs#3034buddh0 merged 1 commit intobnb-chain:developfrom buddh0:clear-up-bid-simulator-optimize
buddh0 merged 1 commit intobnb-chain:developfrom
buddh0:clear-up-bid-simulator-optimize
Conversation
zzzckck
approved these changes
Apr 18, 2025
galaio
approved these changes
Apr 18, 2025
This was referenced May 16, 2025
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
miner: optimize clear up logic for envs
Rationale
1. Fix for
bid.discardConflict withworker.commit()Causing PanicIn
bid_simulator.go, thebid.discardfunction conflicts withworker.commit(), resulting in a panic.Specifically:
s.db.prefetcheris notnil.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:bidSimulator.SetBestBidis invoked, orchainHeadevent is received, triggeringclearFninbidSimulator.clearLoop.This PR resolves the issue by delaying the discard action to avoid the race condition.
2. Centralized Discard Logic in
bidSimulatorPreviously, environment discards (
envs) were scattered across multiple locations withinbidSimulator.In this PR, we consolidate the logic so that environment discards happen in only one place, improving maintainability and reducing complexity.
3. Optimizing
clearLoopIterationIn
clearLoop, bothbestBidToRunandsimulatingBidretain up tob.chain.TriesInMemory()items.Iterating over all of them is inefficient.
This PR introduces the use of
GetFinalizedNumberto limit the retained items to just 2, significantly improving performance.Example
add an example CLI or API response...
Changes
Notable changes: