Skip to content

Conversation

@Roasbeef
Copy link
Member

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

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.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 18858689345

Details

  • 175 of 328 (53.35%) changed or added relevant lines in 8 files are covered.
  • 8 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.2%) to 56.324%

Changes Missing Coverage Covered Lines Changed/Added Lines %
log.go 0 7 0.0%
mempool/tx_validator.go 0 7 0.0%
mempool/orphan.go 78 87 89.66%
mempool/policy_enforcer.go 33 42 78.57%
mempool/mempool_v2.go 60 72 83.33%
mempool/mocks.go 0 35 0.0%
server.go 0 74 0.0%
Files with Coverage Reduction New Missed Lines %
mempool/orphan.go 1 95.0%
btcutil/gcs/gcs.go 2 81.25%
mempool/mempool_v2.go 2 81.14%
peer/peer.go 3 71.37%
Totals Coverage Status
Change from base Build 18858640566: 0.2%
Covered Lines: 33628
Relevant Lines: 59705

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants