-
Notifications
You must be signed in to change notification settings - Fork 113
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
[Downloader] Simplify downloader code #330
Conversation
151a77b
to
afeab4d
Compare
Codecov Report
@@ Coverage Diff @@
## master #330 +/- ##
============================================
- Coverage 51.97% 51.79% -0.19%
+ Complexity 437 431 -6
============================================
Files 56 56
Lines 2738 2707 -31
Branches 373 366 -7
============================================
- Hits 1423 1402 -21
+ Misses 1151 1147 -4
+ Partials 164 158 -6
Continue to review full report at Codecov.
|
This change uses DataTypeHandler interface introduced in last change (PR #330) to replace 3 verifySigsAndDownload<Type>Files() fns by a common download function (Downloader.verifySigsAndDownloadDataFiles()). Advantages: More code sharing, removes multiple copies. Easier to maintain single logic rather than three copies which keep differing with time. (Note D = Downloader) Notable changes: - RecordD and eventsD didn't check for newFileName > oldFileName (since prevFileHash check was enough). The common function always checks for newFileName > oldFileName condition. It's needed for balances file and acts as extra validity check for record & event files. - Earlier, eventsD was not sorting sigFiles before iterating on them, which led to more complicated veriffication logic. EventsD was first moving all files (after verifying sig) to valid dir and then checking for validity of prevFilehash in verifyValidFiles() fn. In contrast, recordD was checking for both, sigs and prevFileHash, before moving to vaild dir. And the logic was simpler and better too. So Downloader.verifySigsAndDownloadDataFiles() follows the latter one i.e. check sigs and hash-linking before moving to valid dir. - In different download fns, checkStopFile() was sprinkled in different places. In new code, kept those ones around which are in tighter loops. The ones in new code seem okay to me to be valid exit points, I'd request reviewers to please take extra care to verify the same. Thanks. - Unlike RecordsD, EventD wasn't respecting bypass parameter (EVENT_HASH_MISMATCH_BYPASS_UNTIL_AFTER). Now it does. If that's not the expected behavior, please let me know. Signed-off-by: Apekshit Sharma <apekshit.sharma@hedera.com>
Here's the followup PR #331 |
src/main/java/com/hedera/signatureVerifier/NodeSignatureVerifier.java
Outdated
Show resolved
Hide resolved
afeab4d
to
b88001d
Compare
9c9e2d8
to
0fb8764
Compare
Motivation: By abstracting out few functions, we can easily simplify some of the downloader code i.e. share more code, simplify functions' parameters, less places with switch-case branching logic, etc. Other changes: Call Utility.extractHashAndSigFromFile once instead of 3 times. Which issue(s) this PR fixes: Fixes #167 too. Signed-off-by: Apekshit Sharma <apekshit.sharma@hedera.com>
0fb8764
to
e0b292d
Compare
This change builds on the last change (PR #330) to replace 3 verifySigsAndDownload<Type>Files() fns by a single function Downloader.verifySigsAndDownloadDataFiles(), therefore removing 3 copies of mostly similar code with one. This will make further changes to Downloader code easier. (Note D = Downloader) Notable changes: - RecordD and eventsD didn't check for newFileName > oldFileName (since prevFileHash check was enough). The common function always checks for newFileName > oldFileName condition. It's needed for balances file and acts as extra validity check for record & event files. - Earlier, eventsD was not sorting sigFiles before iterating on them, which led to more complicated verification logic. EventsD was first moving all files (after verifying sig) to valid dir and then checking for validity of prevFilehash in verifyValidFiles() fn. In contrast, recordD was checking for both, sigs and prevFileHash, before moving to vaild dir. And the logic was simpler and better too. So Downloader.verifySigsAndDownloadDataFiles() follows the latter one i.e. check sigs and hash-linking before moving to valid dir. - Unlike RecordsD, EventD wasn't respecting bypass parameter (EVENT_HASH_MISMATCH_BYPASS_UNTIL_AFTER). Now it does. If that's not the expected behavior, please let me know. Signed-off-by: Apekshit Sharma <apekshit.sharma@hedera.com>
src/main/java/com/hedera/mirror/downloader/balance/AccountBalancesDownloader.java
Outdated
Show resolved
Hide resolved
src/main/java/com/hedera/mirror/downloader/event/EventDownloaderProperties.java
Outdated
Show resolved
Hide resolved
src/main/java/com/hedera/mirror/downloader/balance/BalanceDownloaderProperties.java
Outdated
Show resolved
Hide resolved
src/main/java/com/hedera/mirror/downloader/record/RecordDownloaderProperties.java
Outdated
Show resolved
Hide resolved
src/main/java/com/hedera/mirror/downloader/DownloaderProperties.java
Outdated
Show resolved
Hide resolved
src/main/java/com/hedera/mirror/downloader/balance/AccountBalancesDownloader.java
Outdated
Show resolved
Hide resolved
src/main/java/com/hedera/mirror/downloader/NodeSignatureVerifier.java
Outdated
Show resolved
Hide resolved
b07d434
to
38f2c62
Compare
Signed-off-by: Apekshit Sharma <apekshit.sharma@hedera.com>
38f2c62
to
051bf77
Compare
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.
Looks good. Much cleaner downloader code now.
This change builds on the last change (PR #330) to replace 3 verifySigsAndDownload<Type>Files() fns by a single function Downloader.verifySigsAndDownloadDataFiles(), therefore removing 3 copies of mostly similar code with one. This will make further changes to Downloader code easier. (Note D = Downloader) Notable changes: - RecordD and eventsD didn't check for newFileName > oldFileName (since prevFileHash check was enough). The common function always checks for newFileName > oldFileName condition. It's needed for balances file and acts as extra validity check for record & event files. - Earlier, eventsD was not sorting sigFiles before iterating on them, which led to more complicated verification logic. EventsD was first moving all files (after verifying sig) to valid dir and then checking for validity of prevFilehash in verifyValidFiles() fn. In contrast, recordD was checking for both, sigs and prevFileHash, before moving to vaild dir. And the logic was simpler and better too. So Downloader.verifySigsAndDownloadDataFiles() follows the latter one i.e. check sigs and hash-linking before moving to valid dir. - Unlike RecordsD, EventD wasn't respecting bypass parameter (EVENT_HASH_MISMATCH_BYPASS_UNTIL_AFTER). Now it does. If that's not the expected behavior, please let me know. Signed-off-by: Apekshit Sharma <apekshit.sharma@hedera.com>
Thanks for the review and merging. |
This change builds on the last change (PR #330) to replace 3 verifySigsAndDownload<Type>Files() fns by a single function Downloader.verifySigsAndDownloadDataFiles(), therefore removing 3 copies of mostly similar code with one. This will make further changes to Downloader code easier. (Note D = Downloader) Notable changes: - RecordD and eventsD didn't check for newFileName > oldFileName (since prevFileHash check was enough). The common function always checks for newFileName > oldFileName condition. It's needed for balances file and acts as extra validity check for record & event files. - Earlier, eventsD was not sorting sigFiles before iterating on them, which led to more complicated verification logic. EventsD was first moving all files (after verifying sig) to valid dir and then checking for validity of prevFilehash in verifyValidFiles() fn. In contrast, recordD was checking for both, sigs and prevFileHash, before moving to vaild dir. And the logic was simpler and better too. So Downloader.verifySigsAndDownloadDataFiles() follows the latter one i.e. check sigs and hash-linking before moving to valid dir. - Unlike RecordsD, EventD wasn't respecting bypass parameter (EVENT_HASH_MISMATCH_BYPASS_UNTIL_AFTER). Now it does. If that's not the expected behavior, please let me know. Signed-off-by: Apekshit Sharma <apekshit.sharma@hedera.com>
* [Downloader] Common sig verifier and data download code This change builds on the last change (PR #330) to replace 3 verifySigsAndDownload<Type>Files() fns by a single function Downloader.verifySigsAndDownloadDataFiles(), therefore removing 3 copies of mostly similar code with one. This will make further changes to Downloader code easier. (Note D = Downloader) Notable changes: - RecordD and eventsD didn't check for newFileName > oldFileName (since prevFileHash check was enough). The common function always checks for newFileName > oldFileName condition. It's needed for balances file and acts as extra validity check for record & event files. - Earlier, eventsD was not sorting sigFiles before iterating on them, which led to more complicated verification logic. EventsD was first moving all files (after verifying sig) to valid dir and then checking for validity of prevFilehash in verifyValidFiles() fn. In contrast, recordD was checking for both, sigs and prevFileHash, before moving to vaild dir. And the logic was simpler and better too. So Downloader.verifySigsAndDownloadDataFiles() follows the latter one i.e. check sigs and hash-linking before moving to valid dir. - Unlike RecordsD, EventD wasn't respecting bypass parameter (EVENT_HASH_MISMATCH_BYPASS_UNTIL_AFTER). Now it does. If that's not the expected behavior, please let me know. Signed-off-by: Apekshit Sharma <apekshit.sharma@hedera.com> * Remove unsued imports Signed-off-by: Apekshit Sharma <apekshit.sharma@hedera.com> * Address review comments. Signed-off-by: Apekshit Sharma <apekshit.sharma@hedera.com> * use Answers.RETURNS_SMART_NULLS Signed-off-by: Apekshit Sharma <apekshit.sharma@hedera.com> * address review comments Signed-off-by: Apekshit Sharma <apekshit.sharma@hedera.com>
Motivation:
By abstracting out few functions, we can easily simplify some of the downloader code i.e. simplify functions' parameters, less places with switch-case branching logic, etc.
Other changes:
Call Utility.extractHashAndSigFromFile once instead of 3 times.
Which issue(s) this PR fixes:
Fixes #167 too.
Special notes for your reviewer:
Checklist