Skip to content

Commit 79e880d

Browse files
committed
feat: Add mempool_get_info method for v1.6 mempool fee information
Add the `mempool.get_info` RPC method to the ElectrumApi trait. This method was added in protocol v1.6 and provides more detailed mempool fee information than the deprecated `blockchain.relayfee` method. The response includes: - `mempoolminfee`: Dynamic minimum fee rate for tx acceptance - `minrelaytxfee`: Static operator-configured minimum relay fee - `incrementalrelayfee`: Minimum fee rate increment for RBF/mempool limiting Co-Authored-By: Claude Code AI Signed-off-by: Elias Rohrer <dev@tnull.de>
1 parent 08ec558 commit 79e880d

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

src/api.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ where
172172
(**self).server_features()
173173
}
174174

175+
fn mempool_get_info(&self) -> Result<MempoolInfoRes, Error> {
176+
(**self).mempool_get_info()
177+
}
178+
175179
fn ping(&self) -> Result<(), Error> {
176180
(**self).ping()
177181
}
@@ -398,6 +402,12 @@ pub trait ElectrumApi {
398402
/// Returns the capabilities of the server.
399403
fn server_features(&self) -> Result<ServerFeaturesRes, Error>;
400404

405+
/// Returns information about the current state of the mempool.
406+
///
407+
/// This method was added in protocol v1.6 and replaces `relay_fee` by providing
408+
/// `minrelaytxfee` along with additional mempool fee information.
409+
fn mempool_get_info(&self) -> Result<MempoolInfoRes, Error>;
410+
401411
/// Pings the server. This method can also be used as a "dummy" call to trigger the processing
402412
/// of incoming block header or script notifications.
403413
fn ping(&self) -> Result<(), Error>;
@@ -607,6 +617,10 @@ mod test {
607617
unreachable!()
608618
}
609619

620+
fn mempool_get_info(&self) -> Result<super::MempoolInfoRes, super::Error> {
621+
unreachable!()
622+
}
623+
610624
fn ping(&self) -> Result<(), super::Error> {
611625
unreachable!()
612626
}

src/client.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ impl ElectrumApi for Client {
362362
impl_inner_call!(self, server_features)
363363
}
364364

365+
#[inline]
366+
fn mempool_get_info(&self) -> Result<MempoolInfoRes, Error> {
367+
impl_inner_call!(self, mempool_get_info)
368+
}
369+
365370
#[inline]
366371
fn ping(&self) -> Result<(), Error> {
367372
impl_inner_call!(self, ping)

src/raw_client.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,17 @@ impl<T: Read + Write> ElectrumApi for RawClient<T> {
11791179
Ok(serde_json::from_value(result)?)
11801180
}
11811181

1182+
fn mempool_get_info(&self) -> Result<MempoolInfoRes, Error> {
1183+
let req = Request::new_id(
1184+
self.last_id.fetch_add(1, Ordering::SeqCst),
1185+
"mempool.get_info",
1186+
vec![],
1187+
);
1188+
let result = self.call(req)?;
1189+
1190+
Ok(serde_json::from_value(result)?)
1191+
}
1192+
11821193
fn ping(&self) -> Result<(), Error> {
11831194
let req = Request::new_id(
11841195
self.last_id.fetch_add(1, Ordering::SeqCst),
@@ -1227,6 +1238,16 @@ mod test {
12271238
assert_eq!(resp.pruning, None);
12281239
}
12291240

1241+
#[test]
1242+
fn test_mempool_get_info() {
1243+
let client = get_test_client();
1244+
1245+
let resp = client.mempool_get_info().unwrap();
1246+
assert!(resp.mempoolminfee >= 0.0);
1247+
assert!(resp.minrelaytxfee >= 0.0);
1248+
assert!(resp.incrementalrelayfee >= 0.0);
1249+
}
1250+
12301251
#[test]
12311252
#[ignore = "depends on a live server"]
12321253
fn test_batch_response_ordering() {

src/types.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,21 @@ pub struct ServerFeaturesRes {
202202
pub pruning: Option<i64>,
203203
}
204204

205+
/// Response to a [`mempool_get_info`](../client/struct.Client.html#method.mempool_get_info) request.
206+
///
207+
/// Contains information about the current state of the mempool.
208+
#[derive(Clone, Debug, Deserialize)]
209+
pub struct MempoolInfoRes {
210+
/// Dynamic minimum fee rate in BTC/kvB for tx to be accepted given current conditions.
211+
/// The maximum of `minrelaytxfee` and minimum mempool fee.
212+
pub mempoolminfee: f64,
213+
/// Static operator-configurable minimum relay fee for transactions, in BTC/kvB.
214+
pub minrelaytxfee: f64,
215+
/// Static operator-configurable minimum fee rate increment for mempool limiting or
216+
/// replacement, in BTC/kvB.
217+
pub incrementalrelayfee: f64,
218+
}
219+
205220
/// Response to a [`server_features`](../client/struct.Client.html#method.server_features) request.
206221
#[derive(Clone, Debug, Deserialize)]
207222
pub struct GetHeadersRes {

0 commit comments

Comments
 (0)