Skip to content
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

Merged

Conversation

thomask7b
Copy link
Contributor

@thomask7b thomask7b commented Nov 12, 2024

I've merged roundup_progress in rounded_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

@thomask7b thomask7b changed the title Fix precision, merge roundup methods, add tests Fix blockchain sync progess Nov 12, 2024
@jp1ac4
Copy link
Collaborator

jp1ac4 commented Nov 12, 2024

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.

@thomask7b
Copy link
Contributor Author

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.
Also think it adds complexity to have the function in another file when it can be in SyncProgress.
So we could move both metohds in SyncProgress. And then why not merge them and test the final method.
I don't understand what you dislike.
Let me know what you think and I'll adapt.

@thomask7b thomask7b changed the title Fix blockchain sync progess Fix blockchain sync progress Nov 12, 2024
@jp1ac4
Copy link
Collaborator

jp1ac4 commented Nov 12, 2024

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.

@thomask7b thomask7b force-pushed the fix-907-blockchain-sync-progress branch from 78d82ec to 0337729 Compare November 12, 2024 17:22
@thomask7b
Copy link
Contributor Author

I took in account your remarks.
I kept specific tests for SyncProgress::rounded_up_progress to verify that we "don't return a 100% progress until we are actually done syncing"

@@ -1262,7 +1262,7 @@ impl SyncProgress {
let progress = roundup_progress(self.percentage);
if progress == 1.0 && self.blocks != self.headers {
Copy link
Collaborator

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:

Suggested change
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)

Copy link
Collaborator

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() {
Copy link
Collaborator

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
        );

@pythcoiner
Copy link
Collaborator

pythcoiner commented Nov 13, 2024

lgtm:
image

@thomask7b could you squash your commits into a single one please?

@thomask7b thomask7b force-pushed the fix-907-blockchain-sync-progress branch from 0337729 to dc4feac Compare November 13, 2024 09:11
@pythcoiner
Copy link
Collaborator

tACK dc4feac

Copy link
Collaborator

@jp1ac4 jp1ac4 left a 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);
Copy link
Collaborator

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);

@jp1ac4
Copy link
Collaborator

jp1ac4 commented Nov 13, 2024

You can squash your commits again before pushing. Thanks.

@thomask7b thomask7b force-pushed the fix-907-blockchain-sync-progress branch from dc4feac to 76221ae Compare November 13, 2024 10:14
@thomask7b thomask7b force-pushed the fix-907-blockchain-sync-progress branch from 76221ae to 439af75 Compare November 13, 2024 10:16
@pythcoiner
Copy link
Collaborator

ACK 439af75

Copy link
Collaborator

@jp1ac4 jp1ac4 left a 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.

@edouardparis edouardparis merged commit b46efc6 into wizardsardine:master Nov 13, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants