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

Fetch by Index + Orphan Race Fix #213

Merged
merged 17 commits into from
Oct 29, 2020

Conversation

patrick-ogrady
Copy link
Contributor

@patrick-ogrady patrick-ogrady commented Oct 29, 2020

This PR changes utils.CurrencyBalance to fetch by index instead of by hash. This fixes an issue where the reconciler requests balances of orphaned blocks (by hash) when processing reconciliations near tip. This PR also addresses a potential race condition where a reorg occurs while comparing balance.

Changelog

  • Change utils.CurrencyBalance to only lookup historical balances by index (up to the caller to determine if canonical)
  • Get head block, check live block canonical, and get computed balance in same transaction
  • Move reconciler.AccountCurrency to types.AccountCurrency (storage should not be depending on reconciler)
  • Update ReconcilerHelper interface to be more transparent about guarantees

@coveralls
Copy link

coveralls commented Oct 29, 2020

Pull Request Test Coverage Report for Build 10287

  • 35 of 38 (92.11%) changed or added relevant lines in 4 files are covered.
  • 10 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.09%) to 78.444%

Changes Missing Coverage Covered Lines Changed/Added Lines %
utils/utils.go 2 5 40.0%
Files with Coverage Reduction New Missed Lines %
utils/utils.go 1 63.72%
reconciler/reconciler.go 9 82.7%
Totals Coverage Status
Change from base Build 10147: 0.09%
Covered Lines: 7100
Relevant Lines: 9051

💛 - Coveralls

@patrick-ogrady patrick-ogrady changed the title [utils] Fetch Balance by Index [WIP] Address Reconciler Race Conditions Oct 29, 2020
@patrick-ogrady patrick-ogrady changed the title [WIP] Address Reconciler Race Conditions [WIP] Fetch by Index + Orphan Race Oct 29, 2020
qiwu7
qiwu7 previously approved these changes Oct 29, 2020
@qiwu7
Copy link
Contributor

qiwu7 commented Oct 29, 2020

@patrick-ogrady looks like there are some failing tests 🤔

@patrick-ogrady
Copy link
Contributor Author

Yep! Sorry this is still WIP in-progress @qiwu7. Was planning a lightweight PR and then decided it was a good opportunity to clean up some other potential races.

// If this is the case, we continue reconciling.
canonical, canonicalErr := r.helper.CanonicalBlock(ctx, lookupBlock)
if canonicalErr != nil {
if err != nil {
Copy link
Contributor Author

@patrick-ogrady patrick-ogrady Oct 29, 2020

Choose a reason for hiding this comment

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

We no longer expect this to error in the case of a re-org, so we don't need custom handling. CompareBalance can handle the case where a non-canonical block is returned by this call.

@patrick-ogrady patrick-ogrady changed the title [WIP] Fetch by Index + Orphan Race Fetch by Index + Orphan Race Oct 29, 2020
@patrick-ogrady patrick-ogrady force-pushed the patrick/update-currency-balance-helper branch from 166a762 to 003d728 Compare October 29, 2020 19:22
reconciler/reconciler.go Outdated Show resolved Hide resolved
arjun-io
arjun-io previously approved these changes Oct 29, 2020
@patrick-ogrady patrick-ogrady changed the title Fetch by Index + Orphan Race Fetch by Index + Orphan Race Fix Oct 29, 2020
@patrick-ogrady patrick-ogrady merged commit ce925f0 into master Oct 29, 2020
@patrick-ogrady patrick-ogrady deleted the patrick/update-currency-balance-helper branch October 29, 2020 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants