Skip to content

Commit a618ef0

Browse files
committed
Merge #547: Change the type of prune_target_size field in model::GetBlockchainInfo from u32 to u64
b10dc06 Document the presence of u64 for NumericError (Razvan Pricop) 2616578 Change the type of model::GetBlockchainInfo::prune_target_size from u32 to u64 (Razvan Pricop) 7dd7876 Add to_u64 function in corepc-types (Razvan Pricop) Pull request description: Solves #544 ## Manual testing **Before:** Run `git checkout 26e3998` (the commit that introduced the integration test). Then: ``` cd integration_test/ cargo test --release --features <bitcoind_version> ``` Example: `cargo test --release --features 28_1`. This test should fail in the commit it was introduced. **After:** Checkout back to the branch and run the same test again. Now, the test should succeed. ACKs for top commit: jamillambert: ACK b10dc06 tcharding: ACK b10dc06 Tree-SHA512: 8896dbcaf153abe257a58be40842036533953e80d5ca3d286584fcf9eebc0d401d90d70944ee18025ddbf40b031e936f1bb0ae832e4e0158e93d059bc03ef3e6
2 parents 890983d + b10dc06 commit a618ef0

9 files changed

Lines changed: 17 additions & 12 deletions

File tree

integration_test/tests/blockchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ fn blockchain__get_block__modelled() {
206206

207207
#[test]
208208
fn blockchain__get_blockchain_info__modelled() {
209-
let node = Node::with_wallet(Wallet::None, &[]);
209+
let node = Node::with_wallet(Wallet::None, &["-prune=10000"]);
210210

211211
let json: GetBlockchainInfo = node.client.get_blockchain_info().expect("rpc");
212212
let model: Result<mtype::GetBlockchainInfo, GetBlockchainInfoError> = json.into_model();

types/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,16 @@ pub fn to_u32(value: i64, field: &str) -> Result<u32, NumericError> {
6363
u32::try_from(value).map_err(|_| NumericError::Overflow { value, field: field.to_owned() })
6464
}
6565

66-
/// Error converting an `i64` to a `u32`.
66+
/// Converts an `i64` numeric type to a `u64`.
67+
pub fn to_u64(value: i64, field: &str) -> Result<u64, NumericError> {
68+
u64::try_from(value).map_err(|_| NumericError::Negative { value, field: field.to_owned() })
69+
}
70+
71+
/// Error converting an `i64` to a `u32` or `u64`.
6772
///
68-
/// If we expect a numeric value to sanely fit inside a `u32` we use that type in the `model`
69-
/// module, this requires converting the `i64` returned by the JSONRPC API into a `u32`, if our
70-
/// expectations are not met this error will be encountered.
73+
/// The JSONRPC API returns `i64` values. If these values match our expectations, then
74+
/// we convert them to either `u32` or `u64`, depending on the JSONRPC field. If our
75+
/// expectations are not met, this error is returned.
7176
#[derive(Debug)]
7277
pub enum NumericError {
7378
/// Expected an unsigned numeric value however the value was negative.

types/src/model/blockchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub struct GetBlockchainInfo {
241241
/// Whether automatic pruning is enabled (only present if pruning is enabled).
242242
pub automatic_pruning: Option<bool>,
243243
/// The target size used by pruning (only present if automatic pruning is enabled).
244-
pub prune_target_size: Option<u32>,
244+
pub prune_target_size: Option<u64>,
245245
/// Status of softforks in progress, maps softfork name -> [`Softfork`] (empty from v29 onwards).
246246
pub softforks: BTreeMap<String, Softfork>,
247247
/// The block challenge (aka. block script)

types/src/v17/blockchain/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl GetBlockchainInfo {
9898
let prune_height =
9999
self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?;
100100
let prune_target_size =
101-
self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?;
101+
self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?;
102102
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.
103103

104104
Ok(model::GetBlockchainInfo {

types/src/v19/blockchain/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl GetBlockchainInfo {
2929
let prune_height =
3030
self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?;
3131
let prune_target_size =
32-
self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?;
32+
self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?;
3333
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.
3434

3535
Ok(model::GetBlockchainInfo {

types/src/v21/blockchain/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl GetBlockchainInfo {
2424
let prune_height =
2525
self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?;
2626
let prune_target_size =
27-
self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?;
27+
self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?;
2828
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.
2929

3030
Ok(model::GetBlockchainInfo {

types/src/v23/blockchain/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl GetBlockchainInfo {
2525
let prune_height =
2626
self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?;
2727
let prune_target_size =
28-
self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?;
28+
self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?;
2929
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.
3030

3131
Ok(model::GetBlockchainInfo {

types/src/v28/blockchain/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl GetBlockchainInfo {
2323
let prune_height =
2424
self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?;
2525
let prune_target_size =
26-
self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?;
26+
self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?;
2727
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.
2828

2929
Ok(model::GetBlockchainInfo {

types/src/v29/blockchain/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl GetBlockchainInfo {
267267
let prune_height =
268268
self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?;
269269
let prune_target_size =
270-
self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?;
270+
self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?;
271271
let signet_challenge =
272272
self.signet_challenge.as_ref().map(|s| ScriptBuf::from_hex(s)).transpose()?;
273273

0 commit comments

Comments
 (0)