bitcoin_rs_mempool/policy.rs
1use thiserror::Error;
2
3/// Mempool ancestor, descendant, and replacement limits.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub struct MempoolLimits {
6 /// Maximum number of transactions in an ancestor package, including the transaction itself.
7 pub max_ancestors: u32,
8 /// Maximum ancestor package virtual size in vbytes.
9 pub max_ancestor_size: u64,
10 /// Maximum number of transactions in a descendant package, including the transaction itself.
11 pub max_descendants: u32,
12 /// Maximum number of transactions a single BIP125 replacement may evict.
13 pub max_replacement_evictions: u32,
14 /// Maximum total mempool size in vbytes. Default 300 MB (Bitcoin Core default).
15 /// Set to 0 to disable size-bound eviction.
16 pub max_total_bytes: u64,
17 /// Minimum relay fee rate in sat/kvB. Transactions with lower `fee_rate` are
18 /// not relayed. Default 1000 sat/kvB = 1 sat/vB (Bitcoin Core default).
19 pub min_relay_fee_sat_per_kvb: u64,
20}
21
22impl Default for MempoolLimits {
23 fn default() -> Self {
24 Self {
25 max_ancestors: 25,
26 max_ancestor_size: 101_000,
27 max_descendants: 25,
28 max_replacement_evictions: 100,
29 max_total_bytes: 300_000_000,
30 min_relay_fee_sat_per_kvb: 1_000,
31 }
32 }
33}
34
35/// Policy rejection reason for non-consensus mempool limits.
36#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
37pub enum PolicyError {
38 /// The transaction would exceed the configured ancestor count limit.
39 #[error("too many unconfirmed ancestors")]
40 TooManyAncestors,
41 /// Transaction's `fee_rate` is below the configured min-relay-fee floor.
42 #[error("fee rate {tx_rate} sat/kvB below min-relay-fee {min_rate} sat/kvB")]
43 BelowMinRelayFee {
44 /// The transaction's effective `fee_rate` in sat/kvB.
45 tx_rate: u64,
46 /// The configured min-relay-fee floor.
47 min_rate: u64,
48 },
49 /// The transaction would exceed the configured ancestor package size limit.
50 #[error("ancestor package is too large")]
51 AncestorSizeLimit,
52 /// The transaction would exceed a configured descendant count limit.
53 #[error("too many unconfirmed descendants")]
54 TooManyDescendants,
55}