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

Fix: Dandelion mutex LOCK usages #84

Conversation

SmartArray
Copy link

This PR fixes the stempool mutex usage in ActivateBestChain().

In some places the mutex wasn't acquired which could lead to race conditions, so it was added where needed.
And in some locations the mutex wasn't required where EXCLUSIVE_LOCKS_REQUIRED as modified accordingly.

@SmartArray SmartArray self-assigned this Jan 17, 2022
@SmartArray SmartArray changed the title Fix: Dandelion mutex LOCKs: added where required, removed where not Fix: Fix Dandelion mutex LOCK usages Jan 17, 2022
@SmartArray SmartArray changed the title Fix: Fix Dandelion mutex LOCK usages Fix: Dandelion mutex LOCK usages Jan 17, 2022
@barrystyle
Copy link

Will fire this up now with --enable-debug

@@ -2645,6 +2645,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, CBlockIndex
{
AssertLockHeld(cs_main);
if (m_mempool) AssertLockHeld(m_mempool->cs);
if (m_stempool) AssertLockHeld(m_stempool->cs);

Choose a reason for hiding this comment

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

not sure if this is needed, 'MaybeUpdateMempoolForReorg' contains an assert for stempool already

Choose a reason for hiding this comment

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

Yeah agree with @barrystyle here, seems redundant.

Copy link
Member

Choose a reason for hiding this comment

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

@SmartArray ,

Are you able to remove the redundant asserts?

Copy link
Author

@SmartArray SmartArray Feb 16, 2022

Choose a reason for hiding this comment

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

I see where you are coming from. The signature of MaybeUpdateMempoolForReorgrequires callers to assert that locks are held already. Super useful for static analysis.

This is also the reason the Bitcoin Developers added a check for the mempool mutex in the first place (L2647) although it is checked again in MaybeUpdateMempoolForReorg.

@barrystyle
Copy link

Was any of this backed with 'deadlocked thread' output from debug?
A lot of the locks i had added after the new implementation were suggested by the actions compiler in github.

Copy link

@JaredTate JaredTate left a comment

Choose a reason for hiding this comment

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

ACK. Client compiles, runs & sends tx's fine.

Side note: Still seeing the "Blockpolicy error mempool tx *** already being tracked" quite often.

Copy link
Member

@gto90 gto90 left a comment

Choose a reason for hiding this comment

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

cACK. I would like to get @barrystyle 's questions answered before we merge.

@digicontributer
Copy link

cACK for now.

@SmartArray
Copy link
Author

ACK. Client compiles, runs & sends tx's fine.

Side note: Still seeing the "Blockpolicy error mempool tx *** already being tracked" quite often.

This is seriously an issue we have to fix. @barrystyle Maybe you can take a look into this?
Many features are not working as expected, such as Mempool Resurrection after Reorg, and other things.

@SmartArray
Copy link
Author

Would love to merge this if no one is opposed to that

@digicontributer digicontributer merged commit 9b175a0 into DigiByte-Core:feature/8.22.0 Feb 16, 2022
@SmartArray SmartArray deleted the feature/fix-dandelion-locks branch February 16, 2022 12:36
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.

5 participants