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

Lock cs_main for TestBlockValidity #486

Closed
wants to merge 6 commits into from

Conversation

jmjatlanta
Copy link

Fixes issue #483

The BitcoinMiner() did not properly lock cs_main before using chainActive or calling TestBlockValidity.

I have verified that all other calls to TestBlockValidity maintain the lock on cs_main before the call.

dimxy
dimxy previously approved these changes Sep 18, 2021
Copy link
Collaborator

@dimxy dimxy left a comment

Choose a reason for hiding this comment

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

I agree with this fix.
Actually I have already added this lock in my experimental branches. I did load tests with and without it and got -25 mempool errors when the lock omitted

@ca333 ca333 requested a review from DeckerSU September 19, 2021 12:04
@DeckerSU
Copy link

DeckerSU commented Sep 19, 2021

Actually CChain::LastTip() is kind of a hack introduced in our codebase few years ago (in 2018), all Bitcoin-based coins using CChain::Tip() to get the index entry for the last tip of chain. So, my offer is to follow the Bitcoin codebase:

  • get rid of this CChain::LastTip() and change all LastTip() calls on Tip().
  • don't try to introduce new methods, like GetLastTipWithLock(), but just use LOCK(cs_main) instead where needed.

It will be more clear and make the codebase following bitcoin upstream at the same time. Actually we have a lot of things which are implemented in Bitcoin, but absent in Komodo ... if you'll look on ZCash codebase - they trying to merge Bitcoin upstream step-by-step ... my opinion - we should do the same first: try to take the best from Bitcoin upstream and minimize introducing
fixes like GetLastTipWithLock().

p.s. All of above is just my personal opinion.

@dimxy
Copy link
Collaborator

dimxy commented Sep 23, 2021

maybe let's now replace LastTip everywhere (it is really confusing)
not use GetLastTipWithLock and run more tests with DEBUGLOCKORDER on later
but add now LOCK(cs_main) for TestBlockValidity: I believe running it without a lock is dangerous for critical code

dimxy
dimxy previously approved these changes Sep 27, 2021
Copy link
Collaborator

@dimxy dimxy left a comment

Choose a reason for hiding this comment

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

maybe this function GetLastTipWithLock() is not needed as we agreed not to use it

@dimxy dimxy mentioned this pull request Jan 14, 2022
2 tasks
@ca333 ca333 requested a review from dimxy February 20, 2022 18:03
@dimxy
Copy link
Collaborator

dimxy commented Feb 21, 2022

the conflict needs to be resolved

@jmjatlanta
Copy link
Author

Conflict resolved.

@dimxy
Copy link
Collaborator

dimxy commented Jul 31, 2022

I am running my NN on this code, seems this code is okay.
I have also code in succession for this PR with more refactoring of mining code: use LOCK2 in CreateNewBlock, block connecting code moved out from validBlock(), elimination of extra call to TestLockValidity - still in testing.
But for now this PR#486 code could be used on dev NNs to fix the deadlock situation (#554)

@Alrighttt
Copy link
Member

LGTM, but I did not personally test as I no longer have access to a notary.

DeckerSU added a commit to DeckerSU/KomodoOcean that referenced this pull request Aug 20, 2022
- KomodoPlatform/komodo#486

Also we get rid of LastTip() calls in this PR, changed them to Tip().
Copy link

@DeckerSU DeckerSU left a comment

Choose a reason for hiding this comment

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

LGTM generallу.

p.s. May be we also need to include this changes zcash#5853 in this PR. Good to have protection if chain tip is nullptr somehow. I added this change to Komodo-Qt codebase.
p.p.s. Also github web ui shows that this PR changes marmara.cpp which is absent at the moment. As I remember we get rid of it earlier, or I did it only in Komodo-Qt codebase.

@dimxy
Copy link
Collaborator

dimxy commented Aug 22, 2022

p.s. May be we also need to include this changes zcash#5853 in this PR. Good to have protection if chain tip is nullptr somehow.

Currently this code

while (!fRequestShutdown && chainActive.Tip() == NULL)
in AppInit2() ensures that the genesis block is imported (and chainActive becomes not empty) before mining starts
But there is a bad thing that if fShutdown is set chainActive still may be empty. So I think first we should add a return false if fShutdown is true. And we could also add zcash#5853 for better safety

@dimxy
Copy link
Collaborator

dimxy commented Aug 22, 2022

p.p.s. Also github web ui shows that this PR changes marmara.cpp which is absent at the moment. As I remember we get rid of it earlier, or I did it only in Komodo-Qt codebase.

I remember jmjatlanta intended to remove marmara.cpp but now I have all his PRs merged in my branch and marmara.cpp is still here. Maybe he did not make a PR with this removal

@tonymorony
Copy link

these changes implemented in combined PR: #559

@tonymorony tonymorony closed this Sep 5, 2022
who-biz pushed a commit to who-biz/komodo that referenced this pull request Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants