Skip to content

Commit

Permalink
Merge #5883: refactor: use atomic to avoid blocking chainlocks cs on …
Browse files Browse the repository at this point in the history
…each call to cleanup

75d81fd refactor: use atomic to avoid blocking chainlocks cs on each call to cleanup (pasta)

Pull request description:

  ## Issue being fixed or feature implemented
  Avoid needing to lock CS on each call to cleanup. Cleanup only gets called once every 5 seconds it seems; but maybe that'll change in the future.

  ## What was done?
  Make `lastCleanupTime` atomic instead of CS guarded

  ## How Has This Been Tested?
  Building

  ## Breaking Changes
  None

  ## Checklist:
    _Go over all the following points, and put an `x` in all the boxes that apply._
  - [x] 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
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

Top commit has no ACKs.

Tree-SHA512: 587dbfbecce430c25b4d572b2e158fcda86aced3db976c16166c0cabcf960f46d300739bbf54644def30769347cc88ac14c58d71dd78d848f7d8af562cd12bc6
  • Loading branch information
PastaPastaPasta committed Feb 24, 2024
2 parents 3fd913a + 75d81fd commit d6b5590
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/llmq/chainlocks.cpp
Expand Up @@ -617,11 +617,8 @@ void CChainLocksHandler::Cleanup()
return;
}

{
LOCK(cs);
if (GetTimeMillis() - lastCleanupTime < CLEANUP_INTERVAL) {
return;
}
if (GetTimeMillis() - lastCleanupTime < CLEANUP_INTERVAL) {
return;
}

// need mempool.cs due to GetTransaction calls
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/chainlocks.h
Expand Up @@ -82,7 +82,7 @@ class CChainLocksHandler : public CRecoveredSigsListener

std::map<uint256, int64_t> seenChainLocks GUARDED_BY(cs);

int64_t lastCleanupTime GUARDED_BY(cs) {0};
std::atomic<int64_t> lastCleanupTime{0};

public:
explicit CChainLocksHandler(CChainState& chainstate, CConnman& _connman, CMasternodeSync& mn_sync, CQuorumManager& _qman,
Expand Down

0 comments on commit d6b5590

Please sign in to comment.