Merge #227: Decrease threshold of the bitcoind sync progress
030bfadaf7ef5e88500f6f64ea814d3656b07fba bitcoind: decrease the sync progress roundup threshold (Antoine Poinsot) 4560bc9ed2e41e81797cadfdecb5a97a6d351850 bitcoind: move roundup_progress() to utils and unit test it (Antoine Poinsot) Pull request description: Part of #217. ACKs for top commit: darosior: ACK 030bfadaf7ef5e88500f6f64ea814d3656b07fba Tree-SHA512: 253eaaa7a2dfad34858bcb54e9d001ac4f0f5037646075f80db1bf2259f8b2bcda002e8bf19f5d06aa0959d62b1a770df9fc2eba8454b3545734ee27b36234e3
This commit is contained in:
commit
3be64f4cd5
@ -7,7 +7,7 @@ use crate::{
|
||||
config,
|
||||
descriptors::MultipathDescriptor,
|
||||
};
|
||||
use utils::block_before_date;
|
||||
use utils::{block_before_date, roundup_progress};
|
||||
|
||||
use std::{
|
||||
cmp, collections::HashSet, convert::TryInto, fs, io, str::FromStr, thread, time::Duration,
|
||||
@ -959,18 +959,6 @@ impl BitcoinD {
|
||||
)
|
||||
}
|
||||
}
|
||||
// Bitcoind uses a guess for the value of verificationprogress. It will eventually get to
|
||||
// be 1, and we want to be less conservative.
|
||||
fn roundup_progress(progress: f64) -> f64 {
|
||||
let precision = 10u64.pow(5) as f64;
|
||||
let progress_rounded = (progress * precision + 1.0) as u64;
|
||||
|
||||
if progress_rounded >= precision as u64 {
|
||||
1.0
|
||||
} else {
|
||||
(progress_rounded as f64 / precision) as f64
|
||||
}
|
||||
}
|
||||
|
||||
/// An entry in the 'listdescriptors' result.
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
@ -2,6 +2,22 @@ use crate::bitcoin::{d::BlockStats, BlockChainTip};
|
||||
|
||||
use miniscript::bitcoin;
|
||||
|
||||
/// Truncate the sync progress, rounding it up if it gets above 0.999. Note this also caps the
|
||||
/// progress to 1.0, as bitcoind could temporarily return value >1.0 in getblockchaininfo's
|
||||
/// "verificationprogress" field.
|
||||
/// Bitcoind uses a guess for the value of verificationprogress. It will eventually get to
|
||||
/// be 1, and we want to be less conservative.
|
||||
pub fn roundup_progress(progress: f64) -> f64 {
|
||||
let precision = 10u64.pow(3) as f64;
|
||||
let progress_rounded = (progress * precision + 1.0) as u64;
|
||||
|
||||
if progress_rounded >= precision as u64 {
|
||||
1.0
|
||||
} else {
|
||||
(progress * precision) as u64 as f64 / precision
|
||||
}
|
||||
}
|
||||
|
||||
// As a standalone function to unit test it.
|
||||
/// Get the last block of the chain before the given date by performing a binary search.
|
||||
pub fn block_before_date<Fh, Fs>(
|
||||
@ -346,4 +362,16 @@ mod tests {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitcoind_roundup_progress() {
|
||||
assert_eq!(roundup_progress(0.6), 0.6);
|
||||
assert_eq!(roundup_progress(0.67891), 0.678);
|
||||
assert_eq!(roundup_progress(0.98), 0.98);
|
||||
assert_eq!(roundup_progress(0.998), 0.998);
|
||||
assert_eq!(roundup_progress(0.9476), 0.947);
|
||||
assert_eq!(roundup_progress(0.998), 0.998);
|
||||
assert_eq!(roundup_progress(0.9998), 1.0);
|
||||
assert_eq!(roundup_progress(0.9991), 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user