From 19cae6bae8cc7b1202781694ada938a372848f50 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 15 Nov 2023 06:55:35 +0000 Subject: [PATCH] Configurable mempool txs page size --- src/config.rs | 8 ++++++++ src/rest.rs | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 9c8cfc26..c10f6d90 100644 --- a/src/config.rs +++ b/src/config.rs @@ -58,6 +58,7 @@ pub struct Config { pub rest_default_block_limit: usize, pub rest_default_chain_txs_per_page: usize, pub rest_default_max_mempool_txs: usize, + pub rest_max_mempool_page_size: usize, #[cfg(feature = "liquid")] pub parent_network: BNetwork, @@ -231,6 +232,12 @@ impl Config { .help("The default number of mempool transactions returned by the txs endpoints.") .default_value("50") ) + .arg( + Arg::with_name("rest_max_mempool_page_size") + .long("rest-max-mempool-page-size") + .help("The maximum number of transactions returned by the paginated /internal/mempool/txs endpoint.") + .default_value("1000") + ) .arg( Arg::with_name("electrum_txs_limit") .long("electrum-txs-limit") @@ -484,6 +491,7 @@ impl Config { "rest_default_max_mempool_txs", usize ), + rest_max_mempool_page_size: value_t_or_exit!(m, "rest_max_mempool_page_size", usize), jsonrpc_import: m.is_present("jsonrpc_import"), light_mode: m.is_present("light_mode"), address_search: m.is_present("address_search"), diff --git a/src/rest.rs b/src/rest.rs index 145ba346..375d351a 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -1305,9 +1305,13 @@ fn handle_request( None, ) => { let last_seen_txid = last_seen_txid.and_then(|txid| Txid::from_hex(txid).ok()); + let max_txs = query_params + .get("max_txs") + .and_then(|s| s.parse::().ok()) + .unwrap_or(config.rest_max_mempool_page_size); let txs = query .mempool() - .txs_page(10_000, last_seen_txid) + .txs_page(max_txs, last_seen_txid) .into_iter() .map(|tx| (tx, None)) .collect();