Skip to content

Conversation

@acidbunny21
Copy link
Contributor

@acidbunny21 acidbunny21 commented Jan 22, 2025

Description

Add new submit_package method to both BlockingClient and AsyncClient, as it's now supported by Esplora API, see: Blockstream/electrs#119, Blockstream/electrs#159. Also, adds new SubmitPackageResult, TxResult, and MempoolFeesSubmitPackage API structures.

It updates the internal post_request_hex method to post_request_bytes, now handling query_params and having Response as return type. Additionally, updates the internals of broadcast to utilize the new post_request and post_request_bytes without breaking its API.

Notes to the reviewers

As mentioned in the PR comments, I updated the original commit by @acidbunny21 by:

Changelog notice

### Added

- feat(client): add new `submit_package` API to `BlockingClient` and `AsyncClient`
- feat(api): add new `SubmitPackageResult`, `TxResult`, and `MempoolFeesSubmitPackage` API structures

### Changed

- feat(client): update the `post_request_hex` method to `post_request_bytes`, now handling `query_params` and having `Response` as return type.
- feat(client): update the internals of the  `broadcast` method to use new `post_request` and `post_request_bytes`, with no breaking change.

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature

The PR does not add new tests for the submit_package API, as it's not yet supported by electrsd, it's tracked by: #152

  • I've added docs for the new feature

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 20722592690

Details

  • 32 of 102 (31.37%) changed or added relevant lines in 3 files are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-4.0%) to 86.65%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/api.rs 0 12 0.0%
src/async.rs 14 43 32.56%
src/blocking.rs 18 47 38.3%
Files with Coverage Reduction New Missed Lines %
src/async.rs 1 76.44%
src/blocking.rs 7 76.11%
Totals Coverage Status
Change from base Build 20722132454: -4.0%
Covered Lines: 1402
Relevant Lines: 1618

💛 - Coveralls

@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
Contributor 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.

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
Contributor 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

@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
Contributor 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 2 times, most recently from c50be44 to 7886297 Compare March 1, 2025 07:45
@stevenroose
Copy link

stevenroose commented Mar 18, 2025

I think we uncovered a bug in here:

Reqwest(reqwest::Error { kind: Decode, source: Error("invalid type: floating point `0.0`, expected u64", line: 1, column: 230) })

I suspect it's in this field: pub base: Amount,. You should never use Amount's default deserialization. It has several options, but bitcoind does amounts as floating points:

#[serde(with = "amount::serde::as_btc")]
pub base: Amount,

the above should work

@acidbunny21 acidbunny21 force-pushed the submit-tx-pkg-clients branch 2 times, most recently from cb707fb to c0ed77e Compare March 18, 2025 17:25
@acidbunny21 acidbunny21 force-pushed the submit-tx-pkg-clients branch from c0ed77e to 1f1fa23 Compare April 23, 2025 11:35
@oleonardolima oleonardolima moved this to Needs Review in BDK Chain Aug 20, 2025
@oleonardolima
Copy link
Collaborator

@acidbunny21 Could you rebase and sign the commits on this one?

@acidbunny21 acidbunny21 force-pushed the submit-tx-pkg-clients branch from 1f1fa23 to 4719808 Compare August 23, 2025 06:50
Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

This needs a cargo fmt it seems

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.

tACK 7992b34

I've updated the example_wallet_esplora_blocking to build a zero-fee txA (v3), assert that it failed to relay due to expected: min relay fee not met, and did a CPFP with txB (v3) for the output and successfully submitted it as a package through the new API.

I've tested it for:

  • mempool.space API: I used testnet4 for syncing and submitting the package, see txA, and txB.

  • blockstream.info API: I used testnet3 (as testnet4 is not supported), though I had to use the mempool.space for syncing (due to blockstream rate limit issues), and only used blockstream.info API to try to broadcast the zero-fee and the submit package API, see txA and txB.

src/async.rs Outdated
Comment on lines 375 to 380
pub async fn broadcast(&self, transaction: &Transaction) -> Result<Txid, Error> {
let body = serialize::<Transaction>(transaction).to_lower_hex_string();
let response = self.post_request_bytes("/tx", body, None).await?;
let txid = Txid::from_str(&response.text().await?).map_err(|_| Error::InvalidResponse)?;
Ok(txid)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just noticed that landing this PR has a breaking change, due to this change here and in the blocking client.

@tnull Do you need the submit_package API as a non-breaking release?

Copy link
Contributor

Choose a reason for hiding this comment

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

@tnull Do you need the submit_package API as a non-breaking release?

No, making this a minor release would totally be fine for us!

@oleonardolima
Copy link
Collaborator

I've squashed all changes into a single patch as they touched the same files, now d9f3868

@oleonardolima
Copy link
Collaborator

I removed the breaking change on broadcast API in 970ea94, it'll be addressed by another PR #151 and by a future release.

@ValuedMammal
Copy link
Contributor

ACK 970ea94

Copy link
Member

@luisschwab luisschwab left a comment

Choose a reason for hiding this comment

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

ACK f7fbaa4

oleonardolima added a commit that referenced this pull request Jan 5, 2026
477cf8a fix(ci): pin `proc-macro2` to MSRV supported `1.0.103` (Leonardo Lima)
f857d40 fix(ci): pin `ryu` to MSRV supported `1.0.20` (Leonardo Lima)
8422454 fix(ci): pin `serde_json` to MSRV supported `1.0.145` (Leonardo Lima)
f31ba50 fix(ci): pin `itoa` to MSRV supported `1.0.15` (Leonardo Lima)
edac624 fix(ci): bump pinned `webpki-roots` to 1.0.5 (Leonardo Lima)

Pull request description:

  I was about to merge #114, but there's been a new release (i.e [v1.0.5](https://crates.io/crates/webpki-roots/versions)) for `webpki-roots` which breaks our MSRV CI.

  This PR updates its pinned version to fix our MSRV CI jobs, so we can move forward with #114.

ACKs for top commit:
  luisschwab:
    ACK 477cf8a
  ValuedMammal:
    ACK 477cf8a

Tree-SHA512: c93f83c84072865cf8d14ecca98efdadfa99dc7143d9917fa4d00cbeb6fdeff329ca22d4814498be2ed9d15ab6f40b6f6f441a2c7a43d91d618a6acb875dfbc0
- adds new `submit_package` API to `AsyncClient` and `BlockingClient`,
  it has been added to esplora by `Blockstream/electrs#159`.
- adds new `SubmitPackageResult`, `TxResult` and
  `MempoolFeesSubmitPackage` API structures.
- changes the `post_request_hex` method to `post_request_bytes`,
  now handling `query_params` and having `Response` as return type.
- updates the internals of `broadcast` to use new `post_request` and
  `post_request_bytes`, without breaking it's API.
@oleonardolima oleonardolima force-pushed the submit-tx-pkg-clients branch from f7fbaa4 to cf64f97 Compare January 5, 2026 16:52
Copy link
Member

@luisschwab luisschwab left a comment

Choose a reason for hiding this comment

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

re-ACK cf64f97

@oleonardolima
Copy link
Collaborator

oleonardolima commented Jan 5, 2026

As @ValuedMammal reviews it, I'll merge this one. I rebased it on top of master, so it has the latest CI fixes in cf64f97.

I'll add some error handling improvements I noticed in a follow-up.

@ValuedMammal
Copy link
Contributor

ACK cf64f97; used git range-diff

@oleonardolima oleonardolima changed the title feat(client): add async and blocking clients to submit txs package feat(client): add new submit_package api to blocking/async client Jan 5, 2026
@oleonardolima oleonardolima merged commit e0f7985 into bitcoindevkit:master Jan 5, 2026
26 checks passed
@github-project-automation github-project-automation bot moved this from Needs Review to Done in BDK Chain Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request summit Rust bitcoin summit

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

8 participants