Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

acidbunny21
Copy link

@acidbunny21 acidbunny21 commented Jan 22, 2025

Counterpart PR for Blockstream/electrs#119 to enable submitpackage API

Copy link

@stevenroose stevenroose left a 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)

@acidbunny21 acidbunny21 force-pushed the submit-tx-pkg-clients branch 2 times, most recently from 6a22216 to 01fb9c9 Compare January 23, 2025 13:41
@oleonardolima oleonardolima added the enhancement New feature or request label Jan 27, 2025
@coveralls
Copy link

coveralls commented Jan 27, 2025

Pull Request Test Coverage Report for Build 13591205851

Details

  • 34 of 89 (38.2%) changed or added relevant lines in 2 files are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-3.6%) to 84.553%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/async.rs 14 41 34.15%
src/blocking.rs 20 48 41.67%
Files with Coverage Reduction New Missed Lines %
src/async.rs 1 72.66%
src/blocking.rs 7 72.47%
Totals Coverage Status
Change from base Build 13552496536: -3.6%
Covered Lines: 1155
Relevant Lines: 1366

💛 - Coveralls

Cargo.toml Outdated
@@ -18,6 +18,7 @@ path = "src/lib.rs"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Copy link
Contributor

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?

Copy link
Author

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,
Copy link
Contributor

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).

Copy link
Author

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(
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@acidbunny21 acidbunny21 force-pushed the submit-tx-pkg-clients branch from 01fb9c9 to a5322c6 Compare January 29, 2025 08:34
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,
Copy link
Contributor

@tnull tnull Jan 29, 2025

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?

Copy link
Collaborator

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.

Copy link
Author

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

Copy link
Collaborator

@oleonardolima oleonardolima left a 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.

Comment on lines +132 to +137
/// 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>>,
Copy link
Collaborator

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?

Copy link
Contributor

@tnull tnull Feb 3, 2025

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,
Copy link
Collaborator

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.

@acidbunny21
Copy link
Author

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.

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
Comment on lines 388 to 391
serde_json::to_string(&serialized_txs)
.unwrap()
.as_bytes()
.to_vec(),
Copy link
Collaborator

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.

Copy link
Author

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
Comment on lines 394 to 413
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)
Copy link
Collaborator

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.

Copy link
Author

@acidbunny21 acidbunny21 Feb 7, 2025

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

Copy link
Collaborator

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.

@oleonardolima
Copy link
Collaborator

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.

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

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.

@acidbunny21
Copy link
Author

@oleonardolima it looks like the pipeline failures are caused by something unrelated with the PR, could you help please? :)

@oleonardolima
Copy link
Collaborator

@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 native-tls release which bumped their MSRV to 1.80.0, it should be fine after #116 lands and a rebase should fix it.

@acidbunny21 acidbunny21 force-pushed the submit-tx-pkg-clients branch from 6147e74 to c50be44 Compare February 28, 2025 15:25
@acidbunny21 acidbunny21 force-pushed the submit-tx-pkg-clients branch from c50be44 to 7886297 Compare March 1, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants