Skip to content

Commit f88dd1c

Browse files
committed
mempool: implement StandardPolicyEnforcer for RBF and limits
In this commit, we introduce the StandardPolicyEnforcer, a new component that separates policy decisions from graph data structure operations. This clean separation enables easier testing, different policy configurations, and clearer code boundaries between what the mempool stores versus what policies it enforces. The PolicyEnforcer interface defines five core validation methods that work against a minimal PolicyGraph interface. This abstraction allows policy enforcement to operate on any graph-like structure without tight coupling to the specific txgraph.Graph implementation. The StandardPolicyEnforcer implements Bitcoin Core-compatible policies: RBF (Replace-By-Fee) Support: We implement full BIP 125 RBF validation including both explicit signaling (sequence numbers ≤ 0xfffffffd) and inherited signaling where transactions inherit replaceability from unconfirmed ancestors. The recursive ancestor traversal uses a cache to avoid redundant graph walks when checking deep transaction chains. The ValidateReplacement method enforces all five BIP 125 rules: eviction limits, no parent spending, higher fee rates, sufficient absolute fees, and no new unconfirmed inputs. This matches Bitcoin Core's logic and ensures compatibility with the existing network. Ancestor/Descendant Limits: Bitcoin Core limits transaction chains to 25 ancestors and 25 descendants, each with a maximum total size of 101 KB, to prevent unbounded chain growth in the mempool. We implement identical limits with clear error messages that specify which limit was exceeded and by how much. Fee Rate Validation: The ValidateRelayFee method implements minimum relay fee checking with an exponentially decaying rate limiter for low-fee transactions. This prevents spam while allowing some free transactions through, using the same 10-minute half-life decay as Bitcoin Core. The PolicyConfig structure provides sensible defaults matching Bitcoin Core but allows operators to customize limits for different network conditions or use cases. All policy violations return specific error types that enable callers to distinguish between different rejection reasons.
1 parent a12b308 commit f88dd1c

1 file changed

Lines changed: 473 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)