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

refactor: minimize locking in ChainLocks Cleanup #5990

Merged
2 commits merged into from May 3, 2024

Conversation

PastaPastaPasta
Copy link
Member

Issue being fixed or feature implemented

Simple changes, just look at the two commits: first we minimize scope of cs_main to what actually needs it. Then we change where we update the lastCleanupTime to right after we check it to minimize any chance of two threads entering at the same time.

What was done?

How Has This Been Tested?

Built, ran for a bit

Breaking Changes

None

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@PastaPastaPasta PastaPastaPasta added this to the 21 milestone Apr 22, 2024
@PastaPastaPasta PastaPastaPasta changed the title Refactor clsig cs main refactor: minimize locking in ChainLocks Cleanup Apr 22, 2024
@@ -665,8 +666,6 @@ void CChainLocksHandler::Cleanup()
++it;
}
}

lastCleanupTime = GetTimeMillis();
Copy link
Collaborator

@knst knst Apr 23, 2024

Choose a reason for hiding this comment

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

can it change behavior in case if Cleanup() will take significant time?

It can cause of new iteration of Cleanup start immediately after previous iteration is done if cs_main will be busy for awhile and cleaning process will take a long time due to that.

Copy link
Member Author

Choose a reason for hiding this comment

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

It in theory could; but in practice I don't see how it possibly could. I think Cleanup is only done every 30 seconds; and I don't see it being a problem if cleanup happens after extra 30 seconds.

Copy link
Collaborator

Choose a reason for hiding this comment

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

possible if you debug application and run it step-by-step, but I guess that is not really important

@UdjinM6
Copy link

UdjinM6 commented Apr 23, 2024

Then we change where we update the lastCleanupTime to right after we check it to minimize any chance of two threads entering at the same time.

Doubt 9184edb would make any difference because TrySignChainTip() is the only place Cleanup() is called in and we call that one via a dedicated scheduler to avoid multiple parallel runs already

// don't call TrySignChainTip directly but instead let the scheduler call it. This way we ensure that cs_main is
// never locked and TrySignChainTip is not called twice in parallel. Also avoids recursive calls due to
// EnforceBestChainLock switching chains.

@PastaPastaPasta
Copy link
Member Author

Then we change where we update the lastCleanupTime to right after we check it to minimize any chance of two threads entering at the same time.

Doubt 9184edb would make any difference because TrySignChainTip() is the only place Cleanup() is called in and we call that one via a dedicated scheduler to avoid multiple parallel runs already

// don't call TrySignChainTip directly but instead let the scheduler call it. This way we ensure that cs_main is
// never locked and TrySignChainTip is not called twice in parallel. Also avoids recursive calls due to
// EnforceBestChainLock switching chains.

Agreed; it just feels the more correct way to update it

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

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

utACK

@UdjinM6
Copy link

UdjinM6 commented Apr 23, 2024

...but needs rebase to fix tests :)

@PastaPastaPasta PastaPastaPasta closed this pull request by merging all changes into dashpay:develop in d44b0d5 May 3, 2024
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.

None yet

3 participants