Skip to content

Commit

Permalink
Expose getblockstats for v19+ clients
Browse files Browse the repository at this point in the history
.. as it was previously only available in `v17` and `v18`.
  • Loading branch information
tnull committed Mar 6, 2025
1 parent f0f67ac commit 43b3bc7
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions client/src/client_sync/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getblockcount!();
crate::impl_client_v17__getblockhash!();
crate::impl_client_v17__getblockheader!();
crate::impl_client_v17__getblockstats!();
crate::impl_client_v17__gettxout!();

// == Control ==
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getblockcount!();
crate::impl_client_v17__getblockhash!();
crate::impl_client_v17__getblockheader!();
crate::impl_client_v17__getblockstats!();
crate::impl_client_v17__gettxout!();

// == Control ==
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getblockcount!();
crate::impl_client_v17__getblockhash!();
crate::impl_client_v17__getblockheader!();
crate::impl_client_v17__getblockstats!();
crate::impl_client_v17__gettxout!();

// == Control ==
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getblockcount!();
crate::impl_client_v17__getblockhash!();
crate::impl_client_v17__getblockheader!();
crate::impl_client_v17__getblockstats!();
crate::impl_client_v22__gettxout!();

// == Control ==
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v23.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getblockcount!();
crate::impl_client_v17__getblockhash!();
crate::impl_client_v17__getblockheader!();
crate::impl_client_v17__getblockstats!();
crate::impl_client_v22__gettxout!();

// == Control ==
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v24.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getblockcount!();
crate::impl_client_v17__getblockhash!();
crate::impl_client_v17__getblockheader!();
crate::impl_client_v17__getblockstats!();
crate::impl_client_v22__gettxout!();

// == Control ==
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v25.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getblockcount!();
crate::impl_client_v17__getblockhash!();
crate::impl_client_v17__getblockheader!();
crate::impl_client_v17__getblockstats!();
crate::impl_client_v22__gettxout!();

// == Control ==
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v26.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getblockcount!();
crate::impl_client_v17__getblockhash!();
crate::impl_client_v17__getblockheader!();
crate::impl_client_v17__getblockstats!();
crate::impl_client_v22__gettxout!();

// == Control ==
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v27.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getblockcount!();
crate::impl_client_v17__getblockhash!();
crate::impl_client_v17__getblockheader!();
crate::impl_client_v17__getblockstats!();
crate::impl_client_v22__gettxout!();

// == Control ==
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v28/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getblockcount!();
crate::impl_client_v17__getblockhash!();
crate::impl_client_v17__getblockheader!();
crate::impl_client_v17__getblockstats!();
crate::impl_client_v22__gettxout!();

// == Control ==
Expand Down
27 changes: 20 additions & 7 deletions integration_test/tests/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,39 +70,52 @@ fn get_block_header_verbose() { // verbose = true
assert!(json.into_model().is_ok());
}

// FIXME: I don't know why this passes for v17 and not v18. I tried making stats
// optional as suggested in the docs but to no avail.
#[cfg(all(not(feature = "0_18_1"), not(feature = "0_19_1"), not(feature = "0_19_1"), not(feature = "0_20_2"), not(feature = "0_21_2"), not(feature = "22_1"), not(feature = "23_2"), not(feature = "24_2")))]
// `getblockstats` used to not work on the genesis block as it doesn't have undo data saved to disk
// (see https://github.com/bitcoin/bitcoin/pull/19888). We therefore only run tests for versions
// allowing to.
#[test]
#[cfg(feature = "0_17_1")]
fn get_block_stats() {
get_block_stats_by_height();
get_block_stats_by_hash();
}

#[cfg(feature = "0_17_1")]
#[cfg(all(not(feature = "0_18_1"), not(feature = "0_19_1"), not(feature = "0_19_1"), not(feature = "0_20_2"), not(feature = "0_21_2"), not(feature = "22_1"), not(feature = "23_2"), not(feature = "24_2")))]
// `getblockstats` used to not work on the genesis block as it doesn't have undo data saved to disk
// (see https://github.com/bitcoin/bitcoin/pull/19888). We therefore only run tests for versions
// allowing to.
fn get_block_stats_by_height() {
let node = Node::new_no_wallet();
let json = node.client.get_block_stats_by_height(0).expect("getblockstats");
assert!(json.into_model().is_ok());
}

#[cfg(feature = "0_17_1")]
#[cfg(all(not(feature = "0_18_1"), not(feature = "0_19_1"), not(feature = "0_19_1"), not(feature = "0_20_2"), not(feature = "0_21_2"), not(feature = "22_1"), not(feature = "23_2"), not(feature = "24_2")))]
// `getblockstats` used to not work on the genesis block as it doesn't have undo data saved to disk
// (see https://github.com/bitcoin/bitcoin/pull/19888). We therefore only run tests for versions
// allowing to.
fn get_block_stats_by_hash() { // verbose = true
let node = Node::new_no_wallet();
let block_hash = best_block_hash();
let json = node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
assert!(json.into_model().is_ok());
}

#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
#[cfg(all(not(feature = "0_18_1"), not(feature = "0_19_1"), not(feature = "0_19_1"), not(feature = "0_20_2"), not(feature = "0_21_2"), not(feature = "22_1"), not(feature = "23_2"), not(feature = "24_2")))]
// `getblockstats` used to not work on the genesis block as it doesn't have undo data saved to disk
// (see https://github.com/bitcoin/bitcoin/pull/19888). We therefore only run tests for versions
// allowing to.
#[test]
fn get_block_stats_by_height_txindex() {
let node = Node::new_no_wallet_txindex();
let json = node.client.get_block_stats_by_height(0).expect("getblockstats");
assert!(json.into_model().is_ok());
}

#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
#[cfg(all(not(feature = "0_18_1"), not(feature = "0_19_1"), not(feature = "0_19_1"), not(feature = "0_20_2"), not(feature = "0_21_2"), not(feature = "22_1"), not(feature = "23_2"), not(feature = "24_2")))]
// `getblockstats` used to not work on the genesis block as it doesn't have undo data saved to disk
// (see https://github.com/bitcoin/bitcoin/pull/19888). We therefore only run tests for versions
// allowing to.
#[test]
fn get_block_stats_by_hash_txindex() { // verbose = true
let node = Node::new_no_wallet_txindex();
Expand Down

0 comments on commit 43b3bc7

Please sign in to comment.