-
Notifications
You must be signed in to change notification settings - Fork 2.5k
mempool+server: add flag flip to enable usage of new v2 mempool #2448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Roasbeef
wants to merge
7
commits into
btcsuite:truc-mempool-v2-new-2
Choose a base branch
from
Roasbeef:truc-mempool-v2-flag-flip
base: truc-mempool-v2-new-2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
mempool+server: add flag flip to enable usage of new v2 mempool #2448
Roasbeef
wants to merge
7
commits into
btcsuite:truc-mempool-v2-new-2
from
Roasbeef:truc-mempool-v2-flag-flip
Conversation
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
This commit upgrades the btclog dependency from v0 to support both v1 and v2 loggers simultaneously. The dual logger pattern, inspired by LND's implementation, allows us to incrementally adopt btclog/v2's structured logging capabilities in the mempool subsystem while maintaining backward compatibility with the rest of the codebase. The key changes enable structured logging (DebugS, InfoS, WarnS, etc.) with key-value pair attributes for rich operational context, particularly valuable for security monitoring and debugging in the mempool implementation. We create separate backends: backendLog using btclogv1 for existing subsystems, and backendLogV2 using btclog v2 for the mempool. The setLogLevel function now handles both logger types via type switching, ensuring log level changes work across both versions.
This commit extends the TxMempool interface to support both the legacy TxPool and new TxMempoolV2 implementations transparently. The interface now includes all methods required by the server, netsync, and mining subsystems, enabling a feature flag to toggle between implementations at runtime. The extended interface adds critical methods that were previously only available on the concrete TxPool type: RemoveOrphansByTag for peer cleanup, MiningDescs for block template generation, and several internal methods (RemoveDoubleSpends, RemoveOrphan, ProcessOrphans, MaybeAcceptTransaction) used by netsync for transaction relay. By abstracting these operations, we enable the server to use either implementation without subsystem-specific code changes. The netsync package now accepts the TxMempool interface rather than requiring the concrete TxPool type, allowing transparent switching. The MockTxMempool test implementation is updated to provide all new interface methods, ensuring tests continue to work with the expanded interface contract.
…ions This commit introduces the --usetxmempoolv2 configuration flag that allows runtime selection between the legacy TxPool and new TxMempoolV2 implementations. The flag defaults to false, maintaining backward compatibility while enabling safe evaluation of the new implementation in production environments. The server initialization logic conditionally constructs either TxPool or TxMempoolV2 based on the flag. When using TxMempoolV2, a new helper function initTxMempoolV2() constructs the required dependency graph: PolicyEnforcer for validation rules, TxValidator for script validation, and OrphanManager for orphan handling. These components are explicitly injected, making dependencies clear and testable. The server's txMemPool field now uses the TxMempool interface, allowing transparent operation with either implementation. All subsystems (mining, netsync, RPC) interact through this interface without implementation- specific code. Startup logging clearly indicates which implementation is active, enabling operators to verify configuration and troubleshoot issues. This flag-based approach enables A/B testing, gradual rollout, and safe fallback to the legacy implementation if issues arise.
This commit adds production-grade observability to the TxMempoolV2 operation now emits structured logs with rich contextual key-value pairs, All structured logs include consistent attributes: tx_hash for transaction identity, pool_size for mempool state, fee_rate_sat_vbyte for economic analysis, and operation-specific metrics like conflicts_count or missing_parents. This standardization enables automated log parsing and alerting for operational dashboards.
This commit instruments the StandardPolicyEnforcer with structured logging for comprehensive visibility into policy decisions and potential security threats. The logging focuses on RBF validation rules, ancestor/descendant chain limits, and relay fee validation.
This commit completes the structured logging coverage for TxMempoolV2 by instrumenting the orphan management, validation pipeline, and transaction validator components.
This commit updates .gitignore to exclude the .tasks directory used for local task tracking. This directory contains markdown files with task metadata and is not intended to be committed to the repository.
Pull Request Test Coverage Report for Build 18858689345Details
💛 - Coveralls |
kmk142789
approved these changes
Nov 5, 2025
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.
In this PR, we add a flag flip to enable usage of the new v2 mempool. This allows users to experiment with the new v2 mempool, and also for use to write equivalence integration tests and run differential fuzzing against the two mempool implementations using either the p2p or rpc interface.
Finally we add structured logging uniformly for all the new v2 component.s