-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat(client): add async and blocking clients to submit txs package #114
base: master
Are you sure you want to change the base?
feat(client): add async and blocking clients to submit txs package #114
Conversation
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.
looks good, let just some nits. can confirm that the calls match the endpoint added in my pr on esplora (Blockstream/electrs#119)
6a22216
to
01fb9c9
Compare
Pull Request Test Coverage Report for Build 13591205851Details
💛 - Coveralls |
Cargo.toml
Outdated
@@ -18,6 +18,7 @@ path = "src/lib.rs" | |||
|
|||
[dependencies] | |||
serde = { version = "1.0", features = ["derive"] } | |||
serde_json = "1.0" |
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.
Can we disable default features here and only enable the features we actually need?
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.
done
src/api.rs
Outdated
|
||
#[derive(Deserialize, Debug)] | ||
pub struct TxResult { | ||
pub txid: String, |
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.
Let's deserialize these into actual types, not String
everywhere (see https://github.com/rust-bitcoin/corepc/blob/b62e8c84e3271e57b10849d27191c0357711660b/types/src/model/raw_transactions.rs#L17-L58 for examples).
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.
updated. I also added the same comments on the fields as the ones in rust-bitcoin
src/async.rs
Outdated
/// if `maxburnamount` is provided, any transaction | ||
/// with higher provably unspendable outputs amount | ||
/// will be rejected | ||
pub async fn broadcast_package( |
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.
Lets call this submit_package
to avoid introducing a new separate terminology?
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.
updated
01fb9c9
to
a5322c6
Compare
pub struct SubmitPackageResult { | ||
/// The transaction package result message. "success" indicates all transactions were accepted | ||
/// into or are already in the mempool. | ||
pub package_msg: String, |
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.
Do we know if the variants here are finite? Do we see a chance to parse this into an enum
?
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.
Agreed, that'd be best.
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.
i agree that would be best, but as I can see here, there is no enum defined for that field. I'd be happy to update that part as soon as it is upgraded to one there
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 could use a test with mempool/electrs implementation, while it's not available in blockstream/electrs and electrsd, as I've looked on the other PR and looks like it's following the same API.
/// Transaction results keyed by [`Wtxid`]. | ||
#[serde(rename = "tx-results")] | ||
pub tx_results: HashMap<Wtxid, TxResult>, | ||
/// List of txids of replaced transactions. | ||
#[serde(rename = "replaced-transactions")] | ||
pub replaced_transactions: Option<Vec<Txid>>, |
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.
Any reason not to keep the snake_case
standard to this endpoint in electrs implementation, as the other APIs do?
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.
Bitcoin Core's RPC API is inconsistent in that it mixes snake and dash-case. I assume Esplora just re-exposes the identical field names.
pub struct SubmitPackageResult { | ||
/// The transaction package result message. "success" indicates all transactions were accepted | ||
/// into or are already in the mempool. | ||
pub package_msg: String, |
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.
Agreed, that'd be best.
I'm okay with adding a test, but then we need to bump electrsd to 0.30 which introduce some breaking changes on bitcoind. Might be good to first bump it in a separated PR |
src/async.rs
Outdated
serde_json::to_string(&serialized_txs) | ||
.unwrap() | ||
.as_bytes() | ||
.to_vec(), |
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.
Can't we just send the hex as we do for broadcast tx, it looks like the parsing in blockstream/electrs
PR is the same as broadcast tx one.
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.
mmmh i don't think so, the parsing in blockstream/electrs
PR expects a json array so we cannot simply send a single hex
src/async.rs
Outdated
if let Some(maxfeerate) = maxfeerate { | ||
request = request.query(&[("maxfeerate", maxfeerate.to_string())]) | ||
} | ||
|
||
if let Some(maxburnamount) = maxburnamount { | ||
request = request.query(&[("maxburnamount", maxburnamount.to_string())]) | ||
} | ||
|
||
let response = request.send().await?; | ||
if !response.status().is_success() { | ||
return Err(Error::HttpResponse { | ||
status: response.status().as_u16(), | ||
message: response.text().await?, | ||
}); | ||
} | ||
|
||
response | ||
.json::<SubmitPackageResult>() | ||
.await | ||
.map_err(Error::Reqwest) |
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.
I'm quite divided if we should repurpose post_request_hex
to handle this too, instead of having the logic here, or maybe have another post_request_bytes
if we stick to it.
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.
mmmh i couldn't find a good way to factorize them, mainly because submitpackage request takes some query params
EDIT: i turned post_request_hex
into post_request_bytes
that accepts queryparams in addition to body
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.
Great, thanks! I'll do another round of review.
a5322c6
to
6147e74
Compare
Yes, agree that it can be done in another PR. Another way that I thought was adding a test (under #[ignore]) that uses live mempool.space to test it, so we could run locally and in another step on CI while we don't have a new release on electrsd with the blockstream's esplora changes. However I think it's better to just wait until Blockstream/electrs#119 is release and just bump everything. |
@oleonardolima it looks like the pipeline failures are caused by something unrelated with the PR, could you help please? :) |
It's caused due to recent |
6147e74
to
c50be44
Compare
c50be44
to
7886297
Compare
Counterpart PR for Blockstream/electrs#119 to enable submitpackage API