Skip to content

Add support for bitcoin core 29.0 #131

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

Merged
merged 1 commit into from
May 22, 2025

Conversation

GideonBature
Copy link
Contributor

@GideonBature GideonBature commented Apr 19, 2025

This PR adds support for the newly released bitcoin core version - v29.0

Updated RPCs

  • Implement getmininginfo which now returns nBits and the current target in the target field. It also returns a next object which specifies the height, nBits, difficulty, and target for the next block. (test added)
  • Implement getblock and getblockheader which now return the current target in the target field (test added)
  • Implement getblockchaininfo and getchainstates which now return nBits and the current target in the target field. (test added)
  • Implement getblocktemplate whose RPC curtime (BIP22) and mintime (BIP23) fields now account for the timewarp fix proposed in BIP94 on all networks. (test added)

New RPCs

  • Implement getdescriptoractivity rpc method which can be used to find all spend/receive activity relevant to a given set of descriptors within a set of specified blocks. (test added)

Closes #129

@GideonBature GideonBature force-pushed the support-29.0 branch 4 times, most recently from 5438355 to 1dbf4df Compare April 19, 2025 18:15
@tcharding
Copy link
Member

CI fail can be fixed by creating the RPC help file, I haven't downloaded Core v29 yet but I'd expect that on this branch we could do:

contrib/run-bitcoind.sh start v29
bt29 help > verify/rpc-api-v29.txt

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Man this is looking pretty good! This crate is hard to work on so don't feel bad if you miss things. I'm having a hard time reviewing because the changeset is so big but I've left a few comments that will make it a fair bit smaller. Keep at it! Appreciate your effort.

@GideonBature
Copy link
Contributor Author

CI fail can be fixed by creating the RPC help file, I haven't downloaded Core v29 yet but I'd expect that on this branch we could do:

contrib/run-bitcoind.sh start v29
bt29 help > verify/rpc-api-v29.txt

I tried running the command after starting the bitcoind v29, but it keeps say the bt29 command not found, checked the repository to see if I can get anything that relates to that, but didn't find any...

@GideonBature GideonBature force-pushed the support-29.0 branch 2 times, most recently from dc856f3 to 3c6c22f Compare April 22, 2025 20:08
@tcharding
Copy link
Member

Oh I have a shell alias for each version, for v28 I have

bt28: aliased to bitcoin-cli -rpcconnect=localhost:28049 -rpcuser=*** -rpcpassword=***

And fill in the stars for your setup. Remember the leading 280 comes from the config file of .run-bitcoind.conf

@GideonBature
Copy link
Contributor Author

Oh I have a shell alias for each version, for v28 I have

bt28: aliased to bitcoin-cli -rpcconnect=localhost:28049 -rpcuser=*** -rpcpassword=***

And fill in the stars for your setup. Remember the leading 280 comes from the config file of .run-bitcoind.conf

Thank you... It's done!

@GideonBature GideonBature force-pushed the support-29.0 branch 2 times, most recently from 798a62e to 2308f10 Compare April 23, 2025 05:19
@GideonBature GideonBature force-pushed the support-29.0 branch 2 times, most recently from 20080f5 to 87a78dd Compare April 28, 2025 15:15
@tcharding
Copy link
Member

Can you get rid of all the formatting changes please.

@GideonBature GideonBature force-pushed the support-29.0 branch 2 times, most recently from fb921bd to 5709498 Compare April 29, 2025 16:46
@GideonBature
Copy link
Contributor Author

Can you get rid of all the formatting changes please.

Done!

@GideonBature GideonBature force-pushed the support-29.0 branch 3 times, most recently from fa9350a to 1db66bf Compare April 29, 2025 17:13
@tcharding
Copy link
Member

It is surprising to see changes to types modules for any version other than v29. There are changes to v17. Please either remove them or justify why the changes are made.

@GideonBature
Copy link
Contributor Author

It is surprising to see changes to types modules for any version other than v29. There are changes to v17. Please either remove them or justify why the changes are made.

Alright, so for v29, the getblocktemplate returns a Target field, in that case, I saw that v17 already has the getblocktemplate error, thus, I decided to add the target field Error variant to it so I could just reuse it for v29 instead of implementing the same thing for v29... I don't know if that counts... That was the reason why I added the additional field, but if it doesn't align with how the codebase is supposed to be, I can revert it back to it's original form and re-implement the error for v29 with target field....

@tcharding
Copy link
Member

Yes please. Anything that is different in one version to another should have a separate type, errors included. I'm not totally convince that we should re-use errors at all but we already do in submitpackage IIRC and its kinda nice.

@GideonBature
Copy link
Contributor Author

Yes please. Anything that is different in one version to another should have a separate type, errors included. I'm not totally convince that we should re-use errors at all but we already do in submitpackage IIRC and its kinda nice.

Alright, noted, I am going to do that right away...

/// The bits
pub bits: Option<CompactTarget>, // Only from v29 onwards
/// The difficulty target.
pub target: Option<Target>, // Only from v29 onwards
Copy link
Member

Choose a reason for hiding this comment

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

Duplicate above.

@tcharding
Copy link
Member

Man it looks like you haven't rebased this for a while. You likely need to rebase on master then check a bunch of files using diff to see what changed. That is how I found the mistakes in types/src/v29/mod.rs.

@GideonBature
Copy link
Contributor Author

Man it looks like you haven't rebased this for a while. You likely need to rebase on master then check a bunch of files using diff to see what changed. That is how I found the mistakes in types/src/v29/mod.rs.

seems I had a mix up somewhere. Thank you for pointing these out.

@GideonBature
Copy link
Contributor Author

The Most recent changes I made was to resolve pending issues, despite I rebase master earlier, seems somethings didn't apply the way they're supposed to, took care of that also. Thank you!

@GideonBature GideonBature force-pushed the support-29.0 branch 2 times, most recently from b46666e to 94554b6 Compare May 19, 2025 18:16
@tcharding
Copy link
Member

I pushed to your branch man, hope you don't mind. I'll wait till you take a look in case you want to ack my changes then if CI is green we can merge.

@GideonBature
Copy link
Contributor Author

ACK 40810ad.

Thank you so much for pushing this forward...

Copy link
Collaborator

@jamillambert jamillambert left a comment

Choose a reason for hiding this comment

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

Firstly an apology for jumping in at this late stage, it is looking good and I didn't see anything major. There are just a few things that should be changed before merging.

Comment on lines 5 to 7
//! We ignore option arguments unless they effect the shape of the returned JSON data.
pub mod blockchain;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
//! We ignore option arguments unless they effect the shape of the returned JSON data.
pub mod blockchain;
//! We ignore option arguments unless they effect the shape of the returned JSON data.
pub mod blockchain;

Copy link
Member

Choose a reason for hiding this comment

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

Ooph, good eye!

Comment on lines 39 to 40
#[cfg(not(feature = "v29"))]
#[test]
fn blockchain__get_blockchain_info__modelled() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#[cfg(not(feature = "v29"))]
#[test]
fn blockchain__get_blockchain_info__modelled() {
#[test]
fn blockchain__get_blockchain_info__modelled() {
#[cfg(not(feature = "v29"))]
// Call to a pre v29 test function, i.e. what this test is now
#[cfg(feature = "v29")]
// Call to a v29 test

The v29 rpc still exists so should be tested. It could be done as a follow up PR but then the table in types should say UNTESTED for getblockchaininfo in v29

Copy link
Member

Choose a reason for hiding this comment

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

Oh yes this is better.

@@ -18,12 +18,22 @@ fn mining__get_block_template__modelled() {
node1.mine_a_block();
node2.mine_a_block();
node3.mine_a_block();
std::thread::sleep(std::time::Duration::from_millis(500));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
std::thread::sleep(std::time::Duration::from_millis(500));

What is this for? The test passes fine on my end without it.
NB. There is an intermittent error that causes a random test to fail, running the test again usually passes: failed to create node: it appears that bitcoind is not reachable

Copy link
Member

@tcharding tcharding May 21, 2025

Choose a reason for hiding this comment

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

I'd guess its 'wait for nodes to start'? And I'd guess that its from an intermittent failure during dev. Ok to remove or keep but if any time was lost debugging in the past because of this I'd keep it. Should have a comment on it if we keep it. I believe I mentioned this before in review at some stage?

I just removed it.

Method::new_numeric("uptime", "uptime"),
// mining
Method::new_modelled("getblocktemplate", "GetBlockTemplate", "get_block_template"),
Method::new_no_model("getmininginfo", "GetMiningInfo", "get_mining_info"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Method::new_no_model("getmininginfo", "GetMiningInfo", "get_mining_info"),
Method::new_modelled("getmininginfo", "GetMiningInfo", "get_mining_info"),

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tcharding how is this handled when no model is required for earlier versions? Verify currently complains for all versions.
Although for this case it makes sense to add a model for all versions.

Copy link
Member

Choose a reason for hiding this comment

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

Oh this is wrong, thanks man. Changed to new_modelled for all versions and implemented into_model for the v17 type.

Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),

Recent change in master needs to be added.

Copy link
Member

@tcharding tcharding May 21, 2025

Choose a reason for hiding this comment

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

Niiiice - done.

Copy link
Member

Choose a reason for hiding this comment

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

I fixed up all the mod.rs in types too.

PreviousBlockHash(ref e) =>
write_err!(f, "conversion of the `previous_bock_hash` field failed"; e),
NextBlockHash(ref e) =>
write_err!(f, "conversion of the `next_bock_hash` field failed"; e),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
write_err!(f, "conversion of the `next_bock_hash` field failed"; e),
write_err!(f, "conversion of the `next_block_hash` field failed"; e),

Copy link
Member

Choose a reason for hiding this comment

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

Good eye, fixed in v17 also.

/// Maximum allowable input to coinbase transaction, including the generation award and transaction fees (in satoshis).
#[serde(rename = "coinbasevalue")]
pub coinbase_value: i64,
/// A list of supported features,for example `proporsal`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// A list of supported features,for example `proporsal`
/// A list of supported features, for example `proposal`

Copy link
Member

Choose a reason for hiding this comment

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

Doe.

pub coinbase_value: i64,
/// A list of supported features,for example `proporsal`
pub capabilities: Vec<String>,
/// ID to include with a request to longpool on an update to this template
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// ID to include with a request to longpool on an update to this template
/// ID to include with a request to longpoll on an update to this template

Copy link
Member

Choose a reason for hiding this comment

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

Done.

pub capabilities: Vec<String>,
/// ID to include with a request to longpool on an update to this template
#[serde(rename = "longpollid")]
pub long_pool_id: String,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pub long_pool_id: String,
pub long_poll_id: String,

Copy link
Member

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,78 @@
// SPDX-License-Identifier: CC0-1.0

//! The JSON-RPC API for Bitcoin Core `v28` - network.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
//! The JSON-RPC API for Bitcoin Core `v28` - network.
//! The JSON-RPC API for Bitcoin Core `v29` - network.

Copy link
Member

Choose a reason for hiding this comment

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

Done

@tcharding
Copy link
Member

tcharding commented May 21, 2025

Bother, we both force pushed. I went through you changes and I think I got all the ones that were correct. Can you not force push again please man. I'm going to get this through CI then merge it and we can follow up if needed.

@tcharding tcharding force-pushed the support-29.0 branch 9 times, most recently from 002dec9 to 1214d36 Compare May 21, 2025 23:55
Add support for the latest version of Core. Along the way fix various
bugs, typos, and mistakes repo wide.

Co-authored-by: Tobin C. Harding <[email protected]>
@tcharding
Copy link
Member

I've made the PR into a single commit, you are the author still @GideonBature and I added myself using a co-developed-by tag.

@tcharding tcharding merged commit 1462881 into rust-bitcoin:master May 22, 2025
28 checks passed
@tcharding
Copy link
Member

Phew - that was hard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Bitcoin Core 29.0
3 participants