@@ -10,19 +10,27 @@ use crate::context::Context;
1010use crate :: error:: RpcError ;
1111use crate :: handlers:: { optional_bool, required_str, serde_to_sonic} ;
1212
13+ // Bitcoin Core defaults for relay-fee policy until per-node configuration is
14+ // wired. Units: sat/kvB (the canonical workspace internal). 1000 sat/kvB =
15+ // 1 sat/vB = 0.00001 BTC/kvB.
16+ const DEFAULT_MIN_RELAY_FEE_SAT_PER_KVB : u64 = 1_000 ;
17+ const DEFAULT_INCREMENTAL_RELAY_FEE_SAT_PER_KVB : u64 = 1_000 ;
18+
1319pub ( crate ) fn getmempoolinfo ( ctx : & Arc < Context > , params : & Value ) -> Result < Value , RpcError > {
1420 crate :: handlers:: ensure_no_params ( params) ?;
1521 let stats = ctx. mempool . read ( ) . stats ( ) ;
22+ let min_relay_fee = sat_per_kvb_to_btc ( DEFAULT_MIN_RELAY_FEE_SAT_PER_KVB ) ;
23+ let incremental_relay_fee = sat_per_kvb_to_btc ( DEFAULT_INCREMENTAL_RELAY_FEE_SAT_PER_KVB ) ;
1624 Ok ( json ! ( {
1725 "loaded" : true ,
1826 "size" : stats. txs,
1927 "bytes" : stats. bytes,
2028 "usage" : stats. bytes,
2129 "total_fee" : sats_to_btc( stats. total_fee) ,
2230 "maxmempool" : 300_000_000_u64 ,
23- "mempoolminfee" : 0.0 ,
24- "minrelaytxfee" : 0.0 ,
25- "incrementalrelayfee" : 0.0 ,
31+ "mempoolminfee" : min_relay_fee ,
32+ "minrelaytxfee" : min_relay_fee ,
33+ "incrementalrelayfee" : incremental_relay_fee ,
2634 "unbroadcastcount" : 0 ,
2735 "fullrbf" : true
2836 } ) )
@@ -171,17 +179,44 @@ fn sats_to_btc(sats: u64) -> f64 {
171179 bitcoin:: Amount :: from_sat ( sats) . to_btc ( )
172180}
173181
182+ // TODO(refactor): share fee-unit helpers via handlers::common.
183+ fn sat_per_kvb_to_btc ( sat : u64 ) -> f64 {
184+ if let Ok ( small) = u32:: try_from ( sat) {
185+ f64:: from ( small) / 100_000_000.0_f64
186+ } else {
187+ f64:: from ( u32:: MAX ) / 100_000_000.0_f64
188+ }
189+ }
190+
174191#[ cfg( test) ]
175192mod tests {
176193 use alloc:: sync:: Arc ;
177194 use alloc:: vec:: Vec ;
178195
179196 use bitcoin:: { Amount , OutPoint , ScriptBuf , Sequence , Transaction , TxIn , TxOut , Witness } ;
180197 use bitcoin_rs_mempool:: MempoolEntry ;
181- use sonic_rs:: { JsonContainerTrait , JsonValueTrait as _ , json} ;
198+ use sonic_rs:: { JsonContainerTrait , JsonValueTrait , json} ;
182199
183200 use super :: * ;
184201
202+ #[ test]
203+ fn getmempoolinfo_emits_one_sat_per_vbyte_default_for_relay_fees ( ) {
204+ let ctx = Arc :: new ( Context :: new ( ) ) ;
205+ let handler = crate :: Handler :: new ( Arc :: clone ( & ctx) ) ;
206+ let result = handler
207+ . dispatch ( "getmempoolinfo" , & json ! ( [ ] ) )
208+ . unwrap_or_else ( |err| panic ! ( "getmempoolinfo failed: {err}" ) ) ;
209+ let Some ( min_relay) = result. get ( "minrelaytxfee" ) . and_then ( JsonValueTrait :: as_f64) else {
210+ panic ! ( "minrelaytxfee missing: {result:?}" ) ;
211+ } ;
212+
213+ // 1000 sat/kvB / 100_000_000 = 0.00001
214+ assert ! (
215+ ( min_relay - 0.00001 ) . abs( ) < 1e-9 ,
216+ "expected ~0.00001, got {min_relay}"
217+ ) ;
218+ }
219+
185220 #[ test]
186221 fn getmempooldescendants_walks_real_descendant_graph ( ) -> Result < ( ) , Box < dyn std:: error:: Error > >
187222 {
0 commit comments