Skip to content

Conversation

@oleonardolima
Copy link
Contributor

@oleonardolima oleonardolima commented Feb 6, 2025

partially addresses #1949

Description

It upgrades the electrsd version from 0.28.0 to 0.36.1, migrating from old bitcoind to corepc-node and using the corepc-node_28_2 feature.

Updates the bitcoind client type for TestEnv, and its internal methods. Also, updates: bdk_bitcoind_rpc, bdk_esplora, bdk_electrum usage of bdk_testenv and TestEnv.

Notes to the reviewers

As we are upgrading to the latest electrsd, we can drop for now the pinning for home in the MSRV step.

Also for both list_unspent and get_raw_transaction_verbose corepc-client APIs didn't support some required arguments in some of the tests. That said, I implemented our own RPC calls as two new methods in TestEnv.

Changelog notice

TBD

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

@oleonardolima
Copy link
Contributor Author

It looks like I'll need to open a PR on corepc-client to add get-block-template RPC, then I'll get back to this one :(

I'll do the same in rust-electrum-client for the tests, but I'll do it to 0.30.x instead to prevent this issue from blocking the PR there.

@oleonardolima oleonardolima force-pushed the deps/bump-electrsd-version branch from af3988d to b4d655a Compare February 9, 2025 02:57
@oleonardolima oleonardolima force-pushed the deps/bump-electrsd-version branch 4 times, most recently from ef27736 to f52f04d Compare March 22, 2025 18:46
@notmandatory notmandatory added the dependencies Pull requests that update a dependency file label Apr 23, 2025
@notmandatory notmandatory moved this to In Progress in BDK Chain Apr 23, 2025
@ValuedMammal
Copy link
Collaborator

@oleonardolima I noticed that the getblocktemplate RPC is implemented in corepc-client.

@oleonardolima
Copy link
Contributor Author

@oleonardolima I noticed that the getblocktemplate RPC is implemented in corepc-client.

Yes, it was added a few releases after I started this PR, but IIRC some other methods were missing too. I'll check that again.

@ValuedMammal
Copy link
Collaborator

Yes, it was added a few releases after I started this PR, but IIRC some other methods were missing too. I'll check that again.

Seems to be lacking good support for get_raw_mempool_verbose, at least for versions of Bitcoin Core later than 0.17.

@oleonardolima
Copy link
Contributor Author

Once #1988 lands, we won't be relying on get_raw_mempool_verbose; instead, we will use get_raw_mempool. It should unblock this one.

@oleonardolima oleonardolima force-pushed the deps/bump-electrsd-version branch from f52f04d to e8fc019 Compare August 5, 2025 02:23
@oleonardolima
Copy link
Contributor Author

Once #1988 lands, we won't be relying on get_raw_mempool_verbose; instead, we will use get_raw_mempool. It should unblock this one.

It appears that other methods are missing in the corepc-client at electrsd 0.34. They're released on corepc-node 0.8, which will be included in the next release of electrsd. Will check if there are alternative methods for those.

@oleonardolima oleonardolima force-pushed the deps/bump-electrsd-version branch 4 times, most recently from 2ab640d to 366c9d9 Compare August 8, 2025 20:11
@oleonardolima
Copy link
Contributor Author

It appears that other methods are missing in the corepc-client at electrsd 0.34. They're released on corepc-node 0.8, which will be included in the next release of electrsd. Will check if there are alternative methods for those.

As of the latest v0.35 release, it appears that all the necessary methods are implemented in corepc-{node|client}. I went ahead and updated the bdk-testenv and bdk-electrum/esplora crates.

It requires a more significant refactor and changes for the bdk_bitcoind_rpc, as the Emitter relies on the bitcoincore-rpc ' RpcApi' trait. I can cover it all in a single PR, but would like to know what you guys think as well.

cc @ValuedMammal @LagginTimes

@ValuedMammal
Copy link
Collaborator

Replaying a comment from discord

I also noticed that updating electrsd means potentially changing the Emitter to use corepc Client because of how it relates to testenv, etc. We have to make sure switching clients doesn't negatively impact behavior, performance and stuff

@ValuedMammal
Copy link
Collaborator

We may be able to unblock this by having a way to create a new RPC client using the node credentials of a TestEnv instance but independent of the actual test client that is used by electrsd. oleonardolima#3

@oleonardolima
Copy link
Contributor Author

We may be able to unblock this by having a way to create a new RPC client using the node credentials of a TestEnv instance but independent of the actual test client that is used by electrsd. oleonardolima#3

Cool, I'll take a look at your PR this morning.

@oleonardolima oleonardolima force-pushed the deps/bump-electrsd-version branch from 366c9d9 to a2784f5 Compare November 24, 2025 01:37
@oleonardolima
Copy link
Contributor Author

We may be able to unblock this by having a way to create a new RPC client using the node credentials of a TestEnv instance but independent of the actual test client that is used by electrsd. oleonardolima#3

Alright, but if I got it right, the idea would to still rely on bitcoincore_rpc API for bdk_bitcoind_rpc tests (which I think makes sense), right ? And when we land bdk_bitcoind_client that wouldn't an issue anymore, right

@oleonardolima
Copy link
Contributor Author

re-posting from oleonardolima#3 (comment)

Thanks for the suggestion, I'll cherry-pick this one and update the remaining tests.

@oleonardolima
Copy link
Contributor Author

Also, it looks like the latest one is v0.36.1, I'll give it a try on that one too.

@ValuedMammal
Copy link
Collaborator

Alright, but if I got it right, the idea would to still rely on bitcoincore_rpc API for bdk_bitcoind_rpc tests (which I think makes sense), right ? And when we land bdk_bitcoind_client that wouldn't an issue anymore, right

The approach I had in mind is to bump electrsd to the latest version in bdk_testenv which might entail updating some methods in order to benefit from all new corepc types. In bdk_bitcoind_rpc we can start using the TestEnv client for tests, and this ClientExt trait or whatever we're calling it can be used to create a client just for the Emitter with no other code changes needed. When bdk_bitcoind_client is available we'll update the Emitter to use that and remove bitcoincore_rpc. Don't know if I've fully answered the question.

@oleonardolima
Copy link
Contributor Author

AFAICT the only blocker now is: rust-bitcoin/corepc#425

@oleonardolima oleonardolima force-pushed the deps/bump-electrsd-version branch from a83a8fe to 62d9c07 Compare January 7, 2026 21:21
oleonardolima and others added 4 commits January 7, 2026 20:59
- add `ClientExt` trait to it's own common module.
- update the `bdk_bitcoind_rpc` lib.rs tests to use `ClientExt`.
- update the `bdk_bitcoind_rpc` test_emitter.rs tests to use `ClientExt`.
- update the `bdk_bitcoind_rpc` test_filter_iter.rs tests to use `ClientExt`.
- add new methods `list_unspent` and `get_raw_transaction_verbose` to
  `TestEnv`, it's need as they require specific arguments in the call,
  that are not available in corepc API.
@oleonardolima oleonardolima force-pushed the deps/bump-electrsd-version branch from fd8926d to 10baef9 Compare January 8, 2026 00:00
@oleonardolima oleonardolima changed the title deps(bdk_testenv): bump electrsd to 0.31.0 deps(bdk_testenv): bump electrsd to 0.36.1 Jan 8, 2026
@oleonardolima oleonardolima moved this from In Progress to Needs Review in BDK Chain Jan 8, 2026
@oleonardolima oleonardolima marked this pull request as ready for review January 8, 2026 00:17
@oleonardolima
Copy link
Contributor Author

AFAICT the only blocker now is: rust-bitcoin/corepc#425

It's not a block anymore, by using the latest electrsd, the corepc-types are already fixed as it was suggested in the issue.

let (chain, _) = LocalChain::from_genesis(env.genesis_hash()?);
let chain_tip = chain.tip();

// TODO: (@oleonardolima) We should use the `ClientExt` trait instead.
Copy link
Member

Choose a reason for hiding this comment

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

Is this currently possible or do we need the new bdk_bitcoind_rpc client ready?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's already possible, lingering TODO.

env.mine_blocks(1, Some(sender_addr.clone()))?;
env.mine_blocks(101, None)?;

// TODO: (@oleonardolima) remove unwraps
Copy link
Member

Choose a reason for hiding this comment

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

Lingering TODO here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already solved those, forgot to remove the comment.

impl ScenarioEnv {
fn new() -> anyhow::Result<Self> {
let env = TestEnv::new()?;
let client = env.rpc_client();
Copy link
Member

Choose a reason for hiding this comment

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

Thought: why not drop TestEnv::rpc_client altogether and rely only on ClientExt::get_rpc_client(&env)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the standard-way to use testenv's rpc client, the ClientExt is just a workaround to upgrade the bdk_testenv in bdk_bitcoind_rpc while we don't have the new client that relies on the same corepc types.

Comment on lines +146 to +158
// let unconfirmed_txs = mempool_txids
// .iter()
// // .map(|txid| -> Result<_, _> { client.get_raw_transaction(*txid)?.into_model()
// })? .map(
// |txid| -> Result<
// GetRawTransaction,
// bdk_testenv::corepc_client::client_sync::Error,
// > { client.get_raw_transaction(*txid) },
// )
// .collect::<Vec<Result<_, _>>>()
// .map(|get_raw_tx| get_raw_tx.into_model())
// .map(|tx| (tx.0, 0))
// .collect::<Vec<(Transaction, u64)>>();
Copy link
Member

Choose a reason for hiding this comment

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

Needs resolving

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's solved, forgot to remove the comment.

@@ -1,3 +1,3 @@
[package]
name = "bdk_testenv"
version = "0.13.1"
Copy link
Member

Choose a reason for hiding this comment

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

Need to bump bdk_testenv's version as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's only bumped in the release PRs.

@luisschwab
Copy link
Member

Tests are failing locally for me:

cargo test -p bdk_chain --all-features
   Compiling bdk_testenv v0.13.1 (/Users/luisschwab/git/bdk/crates/testenv)
error[E0432]: unresolved import `bdk_chain::bitcoin::secp256k1::rand`
   --> crates/testenv/src/lib.rs:8:20
    |
8   | ...   secp256k1::rand::random, transaction, Address, Amount, Block, BlockHas...
    |                  ^^^^ could not find `rand` in `secp256k1`
    |
note: found an item that was configured out
   --> /Users/luisschwab/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/secp256k1-0.29.1/src/lib.rs:186:9
    |
186 | pub use rand;
    |         ^^^^
note: the item is gated behind the `rand` feature
   --> /Users/luisschwab/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/secp256k1-0.29.1/src/lib.rs:185:7
    |
185 | #[cfg(feature = "rand")]
    |       ^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0432`.
error: could not compile `bdk_testenv` (lib) due to 1 previous error
error: Recipe `_test-chain` failed on line 41 with exit code 101
error: Recipe `test` failed on line 30 with exit code 101

@oleonardolima
Copy link
Contributor Author

oleonardolima commented Jan 19, 2026

Tests are failing locally for me:

cargo test -p bdk_chain --all-features
   Compiling bdk_testenv v0.13.1 (/Users/luisschwab/git/bdk/crates/testenv)
error[E0432]: unresolved import `bdk_chain::bitcoin::secp256k1::rand`
   --> crates/testenv/src/lib.rs:8:20
    |
8   | ...   secp256k1::rand::random, transaction, Address, Amount, Block, BlockHas...
    |                  ^^^^ could not find `rand` in `secp256k1`
    |
note: found an item that was configured out
   --> /Users/luisschwab/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/secp256k1-0.29.1/src/lib.rs:186:9
    |
186 | pub use rand;
    |         ^^^^
note: the item is gated behind the `rand` feature
   --> /Users/luisschwab/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/secp256k1-0.29.1/src/lib.rs:185:7
    |
185 | #[cfg(feature = "rand")]
    |       ^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0432`.
error: could not compile `bdk_testenv` (lib) due to 1 previous error
error: Recipe `_test-chain` failed on line 41 with exit code 101
error: Recipe `test` failed on line 30 with exit code 101

Indeed, needs debugging. Still unsure why it's now failing.

@luisschwab
Copy link
Member

luisschwab commented Jan 19, 2026

I think you need to import bitcoin with the rand feature so it re-exports secp256k1 with it: https://docs.rs/crate/bitcoin/latest/features#rand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

4 participants