-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add testmempoolaccept endpoint #81
Conversation
Q: Where do you plan to use this endpoint and how? |
Access to |
Yeah, if we're going to offer this publicly, we should definitely offer an optional maxfeerate parameter. Might be worth it to check the request body to make sure it's only hex and commas... and maybe we should limit it somehow. (Might be a DoS vector) |
Added support for the optional maxfeerate parameter (via query string), and added some basic pre-checks to the POSTed raw transactions for valid hexadecimal-ness and string length. |
maxfeerate: Option<f32>, | ||
) -> Result<Vec<MempoolAcceptResult>> { | ||
let params = match maxfeerate { | ||
Some(rate) => json!([txhex, format!("{:.8}", rate)]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f32::EPSILON (the smallest difference representable above 1.0) works out to about 11 sats when we consider 1.0 to be 1 BTC. So it can only really reliably show 7 decimal places.
Which I guess is fine if we consider 0.00001 BTC /kvB (5 decimal places) to be the minimum. (1 sat per vB) In which case showing 8 decimal places is pointless.
I wonder what the type is in Core. Might be worth it to use that, and round it to 8 if we use f64 and 7 if we use f32.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://doc.rust-lang.org/std/primitive.f32.html#associatedconstant.EPSILON
0.00000011920929
is the smallest increment of f32.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://doc.rust-lang.org/std/primitive.f64.html#associatedconstant.EPSILON
0.00000000000000022204460492503131
is smallest for f64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we could always just accept the sane sat/vB instead of BTC/kvB, and just slide the decimal place 5 to the left. lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testmempoolaccept in Core throws an error if you give it too many decimal places (e.g. from floating point rounding errors), so it needs to be truncated to something.
I picked 8.d.p out of habit, but yeah I'll check what Core's bounds actually are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it turns out 8.d.p is actually exactly Core's limit (it's parsed as a fixed point number with scale 8):
https://github.com/bitcoin/bitcoin/blob/c1223188e0a5fb11c3a1b9224511a49dc2f848ed/src/rpc/util.cpp#L82-L87
https://github.com/bitcoin/bitcoin/blob/c1223188e0a5fb11c3a1b9224511a49dc2f848ed/src/rpc/util.h#L105
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case you should use f64 so that 8 decimal points can be properly represented without truncating.
|
Switched maxfeerate param from f32 to f64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested ACK @ [ac32e4b]
% curl -X POST -H "Content-Type: application/json" -d '["02000000000101a89d6d6e5475d9f17f153bd71c983170e6eb7d782966021ffea8e8bf03b791d50000000000fdffffff010d2a00000000000016001449b41a4c9fdd27da6d2c182078cbcd948b8e275a0247304402200d38e7b028f0f92778f3a7eca7208eee8a8fa397e7a1970eda63c5b6c0103e900220141239cc25d7b6e7ae6df833037d8d40b869d1d9ea57c0f71e516349eb9e0099012103de74b84d2a5715f317c23b84520a76a2b7ea5f7ba6302bd64ddf439eba546e11dd762700"]' http://localhost:3000/txs/test
[{"txid":"c27cdcc1b07096e8bc0b29c9868a4052231548c0b23f20d5437226baa42e004e","wtxid":"16586c10f96e52410c9a62ae80e5f8891b62ca887ff9722fa45653e355bdfc60","allowed":true,"vsize":110,"fees":{"base":0.00001562,"effective-feerate":0.000142,"effective-includes":["16586c10f96e52410c9a62ae80e5f8891b62ca887ff9722fa45653e355bdfc60"]},"reject-reason":null}]%
Add testmempoolaccept endpoint
This PR adds a new REST API endpoint
POST /txs/test
, which accepts a comma-separated list of transactions as raw hex strings, passes them totestmempoolaccept
, and returns the results as JSON.