-
Notifications
You must be signed in to change notification settings - Fork 87
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
Improve model ChainSel to fix ChainDB QSM test flakiness #3990
Conversation
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 is great to see that #3689 can fixed so non-invasively, excellent identification of the core reason!
LGTM; only minor comments below.
ouroboros-consensus-test/test-storage/Test/Ouroboros/Storage/ChainDB/Model.hs
Outdated
Show resolved
Hide resolved
sortChains $ pruneKnownInvalid (invalid m) <$> chains bs | ||
where | ||
pruneKnownInvalid invalidBlocks chain = | ||
Chain.takeWhileChain (\b -> blockHash b `Map.notMember` invalidBlocks) chain |
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.
Let's include a comment why we do this, sth along the lines of
We don't want known-invalid blocks to influence the sorting of candidate chains.
Also a small style thing: What about making invalidBlocks
a where
binding under pruneKnownInvalid
?
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.
Very nice way to solve this indeed. LGTM.
@@ -876,8 +876,12 @@ validChains cfg m bs = | |||
-- first, which results in the valid chain A->B', which is then chosen | |||
-- over the equally preferable A->B as it will be the first in the list | |||
-- after a stable sort. |
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.
I would suggest enlarging this comment to explain the new behavior. It took me some passes to actually see how things are now solved.
93a13ef
to
9db8c3f
Compare
9db8c3f
to
f6df3ae
Compare
bors r+ |
…SM test" This reverts commit f6df3ae. IntersectMBO/ouroboros-network#3990
…SM test" This reverts commit f6df3ae. IntersectMBO/ouroboros-network#3990
…repancy (#284) This PR is the third round of fighting with a ChainDB q-s-m model vs SUT discrepancy for `getIsValid`, see #123 for the history. The two previous rounds either introduced new bugs or left certain bugs unaddressed. The approach of this PR is to highlight the *cumulative* change over all of these different fixes compared to the initial implementation is. For this, we first revert IntersectMBO/ouroboros-network#3651, IntersectMBO/ouroboros-network#3743 and IntersectMBO/ouroboros-network#3990 in the first four commits. It is recommended to skip these while reviewing. The fifth commit in this PR is then fixing the bug in one go with the benefit of hindsight, see its commit description for details. Closes #123
Description
Fix ChainDB QSM test by incorporating already detected invalid blocks into the model's logic that orders the candidate chains according to the way the actual implementation would try them.
Suppose that we have the candidate chains [GABCd, GAEf] in which lower case letters indicate invalid blocks, and in which the ChainDB already knows that d is invalid, and f is the last block that has been added.
The model implementation would:
It would not detect valid blocks in GAEf, in particular E.
The actual implementation already knows that d is invalid and would start from [GABC, GAEf], and the order in which it would try chains is [GAEf, GABC]. In the process it would detect that E is valid.
The solution proposed here changes 1. to already take into account known invalid blocks (we are keeping track of those in the model anyway).
Closes #3689.
Checklist