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

Improve model ChainSel to fix ChainDB QSM test flakiness #3990

Merged
merged 1 commit into from
Sep 20, 2022

Conversation

bartfrenk
Copy link
Contributor

@bartfrenk bartfrenk commented Sep 7, 2022

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:

  1. order the candidates [GABCd, GAEf] (attempting to mimic the way the actual implementation tries chains),
  2. truncate the chains to their valid prefixes [GABC, GAE]
  3. select GABC as the current chain.
    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

  • Branch
    • Commit sequence broadly makes sense
    • Commits have useful messages
    • New tests are added if needed and existing tests are updated
  • Pull Request
    • Self-reviewed the diff
    • Useful pull request description at least containing the following information:
      • What does this PR change?
      • Why these changes were needed?
      • How does this affect downstream repositories and/or end-users?
      • Which ticket does this PR close (if any)? If it does, is it linked?
    • Reviewer requested

@bartfrenk bartfrenk changed the title Bartfrenk/3689/fix tests Re-enable ChainDB QSM tests Sep 7, 2022
@bartfrenk bartfrenk marked this pull request as ready for review September 7, 2022 12:08
@bartfrenk bartfrenk requested review from jasagredo and removed request for dnadales September 7, 2022 12:08
@bartfrenk bartfrenk requested a review from coot as a code owner September 8, 2022 14:23
@bartfrenk bartfrenk requested review from amesgen and removed request for coot, nfrisby and jasagredo September 8, 2022 14:43
Copy link
Member

@amesgen amesgen left a 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-network/src/Ouroboros/Network/MockChain/Chain.hs Outdated Show resolved Hide resolved
Comment on lines 880 to 883
sortChains $ pruneKnownInvalid (invalid m) <$> chains bs
where
pruneKnownInvalid invalidBlocks chain =
Chain.takeWhileChain (\b -> blockHash b `Map.notMember` invalidBlocks) chain
Copy link
Member

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?

@bartfrenk bartfrenk changed the title Re-enable ChainDB QSM tests Improve model ChainSel to fix ChainDB QSM test flakiness Sep 15, 2022
Copy link
Contributor

@jasagredo jasagredo left a 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.
Copy link
Contributor

@jasagredo jasagredo Sep 15, 2022

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.

@bartfrenk bartfrenk force-pushed the bartfrenk/3689/fix-tests branch from 93a13ef to 9db8c3f Compare September 19, 2022 08:15
@bartfrenk bartfrenk force-pushed the bartfrenk/3689/fix-tests branch from 9db8c3f to f6df3ae Compare September 19, 2022 08:26
@bartfrenk
Copy link
Contributor Author

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Sep 20, 2022

@iohk-bors iohk-bors bot merged commit cb2109a into master Sep 20, 2022
@iohk-bors iohk-bors bot deleted the bartfrenk/3689/fix-tests branch September 20, 2022 09:28
amesgen added a commit to IntersectMBO/ouroboros-consensus that referenced this pull request Aug 10, 2023
amesgen added a commit to IntersectMBO/ouroboros-consensus that referenced this pull request Aug 15, 2023
github-merge-queue bot pushed a commit to IntersectMBO/ouroboros-consensus that referenced this pull request Aug 17, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ChainDB q-s-m failure with GetIsValid
3 participants