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

txscript/hashcache_test: fix flake due to resetting RNG #1689

Merged
merged 2 commits into from
Feb 4, 2021

Conversation

cfromknecht
Copy link
Contributor

Encountered this while rebasing #1684, see commit msgs for more details

TestHashCacheAddContainsHashes flakes fairly regularly when rebasing
PR btcsuite#1684 with:
    txid <txid> wasn't inserted into cache but was found.

With probabilty 1/10^2 there will be no inputs on the transaction. This
reduces the entropy in the txid, and I belive is the primary cause of
the flake.
This resolves the more fundamental flake in the unit tests noted in the
prior commit.

Because multiple unit tests call rand.Seed in parallel, it's possible
they can be executed with the same unix timestamp (in seconds). If the
second call happens between generating the hash cache and checking that
the cache doesn't contain a random txn, the random transaction is in
fact a duplicate of one generated earlier since the RNG state was reset.

To remedy, we initialize rand.Seed once in the init function.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 532036009

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 53.433%

Totals Coverage Status
Change from base Build 530986489: 0.02%
Covered Lines: 20863
Relevant Lines: 39045

💛 - Coveralls

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@Roasbeef
Copy link
Member

Roasbeef commented Feb 4, 2021

Nice catch! I'd even forgotten I'd written this initial hash cache implementation back in the day :p

@Roasbeef Roasbeef merged commit fa683a6 into btcsuite:master Feb 4, 2021
@cfromknecht cfromknecht deleted the hashcache-flake branch February 5, 2021 18:09
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.

4 participants