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

[FreshEyes] locks: introduce mutex for tx download, flush rejection filters on UpdatedBlockTip #17

Open
wants to merge 7 commits into
base: bitcoin-fresheyes-staging-master-30111
Choose a base branch
from

Conversation

adamjonas
Copy link
Owner

The author glozow wrote the following PR called locks: introduce mutex for tx download, flush rejection filters on UpdatedBlockTip, issue number 30111 in bitcoin/bitcoin cloned by FreshEyes below:

See #27463 for full project tracking.

This contains the first 4 commits of #30110, which require some thinking about thread safety in review.

  • Introduce a new m_tx_download_mutex which guards the transaction download data structures including m_txrequest, the rolling bloom filters, and m_orphanage. Later this should become the mutex guarding TxDownloadManager.
    • m_txrequest doesn't need to be guarded using cs_main anymore
    • m_recent_confirmed_transactions doesn't need its own lock anymore
    • m_orphanage doesn't need its own lock anymore
  • Adds a new ValidationInterface event, UpdatedBlockTipSync, which is a synchronous version of m_txrequest0.
  • Flush m_txrequest1 and m_txrequest2 on m_txrequest3 just once instead of every time m_txrequest4 is called. This should speed up calls to that function and removes the need to lock m_txrequest5 every time it is called.

We need to synchronize between various tx download structures.
TxRequest does not inherently need cs_main for synchronization, and it's
not appropriate to lock all of the tx download logic under cs_main.
This is a synchronous version of UpdatedBlockTip.

It allows clients to respond to a new block immediately after it is
connected. The synchronicity is important for things like
m_recent_rejects, in which a transaction's validity can change (rejected
vs accepted) when this event is processed (e.g. it has a timelock
condition that has just been met). This is distinct from something like
m_recent_confirmed_transactions in which the validation outcome is the
same (valid vs already-have).
Resetting m_recent_rejects once per block is more efficient than
comparing hashRecentRejectsChainTip with the chain tip every time we
call AlreadyHaveTx. We keep hashRecentRejectsChainTip for now to assert
that updates happen correctly; it is removed in the next commit.
This also means AlreadyHaveTx no longer needs cs_main held.
The lock doesn't exist anymore.

-BEGIN VERIFY SCRIPT-
sed -i 's/EraseTxNoLock/EraseTxInternal/g' src/txorphanage.*
-END VERIFY SCRIPT-))'
Copy link

There were 14 comments left by 3 reviewers, 1 bot and the author for this pull request

LOCK(m_recent_confirmed_transactions_mutex);
if (m_recent_confirmed_transactions.contains(hash)) return true;
}
if (m_recent_confirmed_transactions.contains(hash)) return true;

Choose a reason for hiding this comment

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

2 authors commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/30111#discussion_r1601841903 at 2024/05/15, 15:19:53 UTC
  • comment link https://github.com/bitcoin/bitcoin/pull/30111#discussion_r1601878592 at 2024/05/15, 15:43:26 UTC.

@@ -1075,7 +1074,7 @@ class PeerManagerImpl final : public PeerManager
int m_peers_downloading_from GUARDED_BY(cs_main) = 0;

/** Storage for orphan information */
TxOrphanage m_orphanage;
TxOrphanage m_orphanage GUARDED_BY(m_tx_download_mutex);

Choose a reason for hiding this comment

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

4 authors commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/30111#discussion_r1601902513 at 2024/05/15, 15:59:50 UTC
  • comment link https://github.com/bitcoin/bitcoin/pull/30111#discussion_r1602816185 at 2024/05/16, 08:07:47 UTC
  • comment link https://github.com/bitcoin/bitcoin/pull/30111#discussion_r1602847832 at 2024/05/16, 08:23:19 UTC
  • comment link https://github.com/bitcoin/bitcoin/pull/30111#discussion_r1603602970 at 2024/05/16, 15:29:17 UTC.

}
} // release MempoolMutex
if (notify_updated_tip) {
m_chainman.m_options.signals->UpdatedBlockTipSync(pindexNewTip);

Choose a reason for hiding this comment

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

4 authors commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/30111#discussion_r1601903709 at 2024/05/15, 16:00:46 UTC
  • comment link https://github.com/bitcoin/bitcoin/pull/30111#discussion_r1601920676 at 2024/05/15, 16:13:15 UTC
  • comment link https://github.com/bitcoin/bitcoin/pull/30111#discussion_r1601923988 at 2024/05/15, 16:15:58 UTC
  • comment link https://github.com/bitcoin/bitcoin/pull/30111#discussion_r1601946313 at 2024/05/15, 16:33:58 UTC.

@@ -183,6 +183,12 @@ void ValidationSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlo
fInitialDownload);
}

void ValidationSignals::UpdatedBlockTipSync(const CBlockIndex *pindexNew)

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin/bitcoin/pull/30111#discussion_r1601944049 at 2024/05/15, 16:32:08 UTC.

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.

2 participants