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

Bitcoin 0.16 locking PRs #5017

Merged
merged 17 commits into from Apr 17, 2021
Merged

Bitcoin 0.16 locking PRs #5017

merged 17 commits into from Apr 17, 2021

Conversation

@LarryRuane LarryRuane added C-upstream-port Category: Changes that are ported from the Bitcoin Core codebase. I-race Problems and improvements related to race conditions. labels Mar 3, 2021
@LarryRuane LarryRuane self-assigned this Mar 3, 2021
@mdr0id mdr0id added the safe-to-build Used to send PR to prod CI environment label Mar 31, 2021
@zkbot
Copy link
Contributor

zkbot commented Apr 2, 2021

☔ The latest upstream changes (presumably #5009) made this pull request unmergeable. Please resolve the merge conflicts.

ryanofsky and others added 14 commits April 12, 2021 17:15
CWallet::MarkConflicted may acquire the cs_main lock after
CWalletDB::LoadWallet acquires the cs_wallet lock during wallet initialization.
(CWalletDB::LoadWallet calls ReadKeyValue which calls CWallet::LoadToWallet
which calls CWallet::MarkConflicted). This is the opposite order that cs_main
and cs_wallet locks are acquired in the rest of the code, and so leads to
POTENTIAL DEADLOCK DETECTED errors if bitcoin is built with -DDEBUG_LOCKORDER.

This commit changes CWallet::LoadWallet (which calls CWalletDB::LoadWallet) to
acquire both locks in the standard order. It also fixes some tests that were
acquiring wallet and main locks out of order and failed with the new locking in
CWallet::LoadWallet.

Error was reported by Luke Dashjr <luke-jr@utopios.org> in
https://botbot.me/freenode/bitcoin-core-dev/msg/90244330/

zcash: cherry picked from commit de9a1db
zcash: bitcoin/bitcoin#11126
Issue: #10905

By returning the result, a few useless lines can be removed.

Return-value-optimization means there should be no copy.

zcash: cherry picked from commit 5cb3da0
zcash: bitcoin/bitcoin#10916
zcash: cherry picked from commit c626dcb
zcash: bitcoin/bitcoin#11107
A rare race condition may trigger while awaiting the body of a message, see
upsteam commit 5ff8eb26371c4dc56f384b2de35bea2d87814779 for details.

This may fix some reported rpc hangs/crashes.

zcash: currently, we build with libevent-2.1.12, so this fix is needed
zcash: cherry picked from commit 6b58360
zcash: bitcoin/bitcoin#11593
The bug was introduced in 2.1.6-beta, versions before that don't need the
workaround.

zcash: currently, we build with libevent-2.1.12, so this fix is needed
zcash: cherry picked from commit 97932cd
zcash: bitcoin/bitcoin#11593
The variable vRandom is guarded by the mutex cs.

zcash: cherry picked from commit 3ab545d
zcash: bitcoin/bitcoin#11585
This prevents a potential race condition if control flow ends up in
`ShutdownHTTPServer` before the thread gets to `queue->Run()`,
deleting the work queue while workers are still going to use it.

Meant to fix #12362.

Signed-off-by: Wladimir J. van der Laan <laanwj@gmail.com>

zcash: cherry picked from commit b1c2370
zcash: bitcoin/bitcoin#12366
This function, which waits for all threads to exit, is no longer needed
now that threads are joined instead.

Signed-off-by: Wladimir J. van der Laan <laanwj@gmail.com>

zcash: cherry picked from commit f946654
zcash: bitcoin/bitcoin#12366
The HTTP worker thread counter, as well as the RAII object that was used
to maintain it, is unused now, so can be removed.

Signed-off-by: Wladimir J. van der Laan <laanwj@gmail.com>

zcash: cherry picked from commit 11e0151
zcash: bitcoin/bitcoin#12366
TheBlueMatt and others added 3 commits April 12, 2021 17:15
This resolves an issue where getrawmempool() can race mempool
notification signals. Intuitively we use mempool.cs as a "read
lock" on the mempool with cs_main being the write lock, so holding
the read lock intermittently while doing write operations is
somewhat strange.
This also avoids the introduction of cs_main in getrawmempool()
which reviewers objected to in the previous fix in #12273

zcash: cherry picked from commit 85aa839
zcash: bitcoin/bitcoin#12368
zcash: Not an actual locking fix; just eliminates unnecessary recursive
zcash: locking (which is a long-term goal).
zcash: cherry picked from commit 1beea7a
zcash: bitcoin/bitcoin#12333
Copy link
Contributor

@therealyingtong therealyingtong left a comment

Choose a reason for hiding this comment

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

utACK, checked against upstream commits.

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

utACK. Checked against the upstream commits.

@str4d
Copy link
Contributor

str4d commented Apr 17, 2021

@zkbot r+

@zkbot
Copy link
Contributor

zkbot commented Apr 17, 2021

📌 Commit 5b2f7a6 has been approved by str4d

@zkbot
Copy link
Contributor

zkbot commented Apr 17, 2021

⌛ Testing commit 5b2f7a6 with merge 0e36226...

@zkbot
Copy link
Contributor

zkbot commented Apr 17, 2021

☀️ Test successful - pr-merge
Approved by: str4d
Pushing 0e36226 to master...

@zkbot zkbot merged commit 0e36226 into zcash:master Apr 17, 2021
@zkbot zkbot mentioned this pull request Apr 17, 2021
str4d added a commit to str4d/zcash that referenced this pull request Apr 4, 2022
The comment on `view.SetBackend(dummy)` was removed when we backported
upstream locking PRs in zcash#5017. The upstream commit in
question removed a locking scope but did not remove the reference to
that scope in the comment. Our backport removed the outdated comment,
but should have modified it instead, because otherwise the existence of
`view.SetBackend(dummy)` is very confusing (as it disconnects the cache
from `pcoinsTip`, on the assumption that everything we need from it has
been cached via calls to `CCoinsViewCache::HaveCoins` and
`CCoinsViewCache::HaveShieldedRequirements`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-upstream-port Category: Changes that are ported from the Bitcoin Core codebase. I-race Problems and improvements related to race conditions. safe-to-build Used to send PR to prod CI environment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet