fix(storage): Fix wrong update to the best_block_tips_cache#874
Merged
fix(storage): Fix wrong update to the best_block_tips_cache#874
Conversation
msbrogli
commented
Nov 11, 2023
| storage.update_best_block_tips_cache([not_none(blk.hash) for blk in heads]) | ||
| best_block_tips = [not_none(blk.hash) for blk in heads] | ||
| best_block_tips.append(not_none(block.hash)) | ||
| storage.update_best_block_tips_cache(best_block_tips) |
Member
Author
There was a problem hiding this comment.
Should we just set to None and let the next call cache it?
Member
There was a problem hiding this comment.
Either way is fine for me. I wish we can get rid of this cache in the future. Will we even need it if we don't have best block ties, because even for sync-v1 the block height index would have a ready O(1) (or at least however fast best_blocks[-1] is) response?
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #874 +/- ##
==========================================
- Coverage 85.42% 85.20% -0.23%
==========================================
Files 281 281
Lines 22353 22355 +2
Branches 3388 3388
==========================================
- Hits 19096 19048 -48
- Misses 2582 2622 +40
- Partials 675 685 +10
☔ View full report in Codecov by Sentry. |
jansegre
approved these changes
Nov 13, 2023
2 tasks
glevco
approved these changes
Nov 13, 2023
31c98fb to
13e49bf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The
tests/simulation/test_simulator.py::SyncV2RandomSimulatorTestCase::test_many_miners_since_beginningwas flaky because of this issue.When the consensus algorithm updates the
best_block_tips_cache, it does not include the current block being evaluated. Notice that the current block is not part of theheads.Acceptance Criteria
blockto the list of best block tips used to update thebest_block_tips_cache.assertTipsEqualSyncV2(), we shouldn't assertb1 == b2because the height index keeps its previous entry when two or more blocks have the same score. So we can safely just check ifb1 in s1andb2 in s2.len(s1) == len(s2) == 1, checking ifb1 in s1andb2 in s2is exactly the same as checking ifb1 == b2.Checklist
master, confirm this code is production-ready and can be included in future releases as soon as it gets merged