-
Notifications
You must be signed in to change notification settings - Fork 60
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
Fix blockchain sync progress #1457
Fix blockchain sync progress #1457
Conversation
Thanks very much for this PR. I tested the change is working as expected. I think merging the two functions makes sense in some ways, but it could still be useful to keep them separate for testing the rounding logic by itself so I would keep them separate for now. |
I can adapt if you want but I'm not sure to understand what you mean, because the rounding logic is still tested with even more coverage. |
I meant to test the rounding logic just in terms of the floats without any regard to the number of blocks or headers. But I think your changes are good and either approach would be fine. Given that there's already a separate utils function and in order to keep the changes small, I would keep this separate function as I don't think there's a clear advantage not to. |
78d82ec
to
0337729
Compare
I took in account your remarks. |
@@ -1262,7 +1262,7 @@ impl SyncProgress { | |||
let progress = roundup_progress(self.percentage); | |||
if progress == 1.0 && self.blocks != self.headers { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not related to this PR:
if progress == 1.0 && self.blocks != self.headers { | |
if progress == 1.0 && self.blocks < self.headers { |
@jp1ac4 i don't think this is likely to happen as iiuc as of now it's only used w/ a bitcoind backend, but wdyt we should do if self.blocks
> self.headers
? we actually return 0.999 but maybe 1.0 should be more relevant? (i'm not sure from a security POV, if returning 0.999 i guess we will stuck in the syncing process while if returning 1.0 we will assumed we are synced)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I'm not sure really but I guess if they're not equal in either direction then something still needs to happen in terms of syncing.
use super::*; | ||
|
||
#[test] | ||
fn test_rounded_up_progress() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can add this test cases?:
// approximatively year 2198
assert_eq!(
SyncProgress::new(1.0, 9999999, 9999998).rounded_up_progress(),
0.9999
);
//bug or corrupted bitcond (blocks > headers)
assert_eq!(
SyncProgress::new(1.0, 999998, 999999).rounded_up_progress(),
0.9999
);
@thomask7b could you squash your commits into a single one please? |
0337729
to
dc4feac
Compare
tACK dc4feac |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates.
In addition to the suggested test, could you also please update the docstrings of the two functions.
assert_eq!(roundup_progress(0.9998), 1.0); | ||
assert_eq!(roundup_progress(0.9991), 1.0); | ||
assert_eq!(roundup_progress(0.9476), 0.9476); | ||
assert_eq!(roundup_progress(0.94761), 0.9476); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to include an additional test to show that numbers below 0.9999 are truncated rather than rounded up, e.g.
diff --git a/src/bitcoin/d/utils.rs b/src/bitcoin/d/utils.rs
index c317172b..ddd6d8af 100644
--- a/src/bitcoin/d/utils.rs
+++ b/src/bitcoin/d/utils.rs
@@ -376,6 +376,7 @@ mod tests {
assert_eq!(roundup_progress(0.998), 0.998);
assert_eq!(roundup_progress(0.9476), 0.9476);
assert_eq!(roundup_progress(0.94761), 0.9476);
+ assert_eq!(roundup_progress(0.94769), 0.9476);
assert_eq!(roundup_progress(0.9998), 0.9998);
assert_eq!(roundup_progress(0.99998), 1.0);
assert_eq!(roundup_progress(0.99991), 1.0);
You can squash your commits again before pushing. Thanks. |
dc4feac
to
76221ae
Compare
76221ae
to
439af75
Compare
ACK 439af75 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK 439af75.
Thanks very much.
I've merged
roundup_progress
inrounded_up_progress
since was in utils and was no longer used by any other method.I also added some tests to verify the precision's update but also for specific cases that we manage. By the way tests has been moved in the related file.
Solves #907