Skip to content

Commit

Permalink
Add testmempoolaccept pre-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mononaut committed Mar 24, 2024
1 parent 946ea71 commit 569af75
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u8>::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()))?;
Expand Down

0 comments on commit 569af75

Please sign in to comment.