From 569af75849cc9e359325b0ba25606e4c6310de95 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sun, 24 Mar 2024 06:34:15 +0000 Subject: [PATCH] Add testmempoolaccept pre-checks --- src/rest.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/rest.rs b/src/rest.rs index cb620d4a..5ab38b7a 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -1215,6 +1215,19 @@ fn handle_request( }) .transpose()?; + // pre-checks + txhexes.iter().try_for_each(|txhex| { + // each transaction must be of reasonable size (more than 60 bytes, within 400kWU standardness limit) + if !(120..800_000).contains(&txhex.len()) { + Result::Err(HttpError::from("Invalid transaction size".to_string())) + } else { + // must be a valid hex string + Vec::::from_hex(txhex) + .map_err(|_| HttpError::from("Invalid transaction hex".to_string())) + .map(|_| ()) + } + })?; + let result = query .test_mempool_accept(txhexes, maxfeerate) .map_err(|err| HttpError::from(err.description().to_string()))?;