Skip to content

[Wallet] Lock cs_wallet in additional places.#949

Merged
codeofalltrades merged 1 commit intoVeil-Project:masterfrom
Zannick:clang2
May 26, 2021
Merged

[Wallet] Lock cs_wallet in additional places.#949
codeofalltrades merged 1 commit intoVeil-Project:masterfrom
Zannick:clang2

Conversation

@Zannick
Copy link
Collaborator

@Zannick Zannick commented May 18, 2021

Problem

tsan identifies a data race within WalletBatch, commonly between KeepKey and AddToWallet.

Solution

Declare CWallet::KeepKey as requiring cs_wallet, and take it before all calls as prescribed by clang. (This moved the tsan data race to the nearby fields of CReserveKey, which was mitigated by including their access within the lock.)
Add another cs_wallet use per clang warning: AddKeyPubKey requires holding mutex 'pwalletParent->cs_wallet' exclusively.

Tested

Configured with --with-sanitizers=thread, built with clang, and run on regtest. tsan warnings for this area no longer appear.

- Declare CWallet::KeepKey as requiring the lock, and take it before all calls.
This eliminates a tsan data race.
Also, fields within CReserveKey may similarly contend during mining,
declare that they are guarded by the same lock.

- Add other cs_wallet uses per lock annotations.
This eliminates some clang warnings: AddKeyPubKey requires holding mutex 'pwalletParent->cs_wallet' exclusively
@Zannick Zannick self-assigned this May 18, 2021
@CaveSpectre11 CaveSpectre11 added Component: Core App Related to the application itself. Component: Wallet Relating to keystore, tx creation, and balance tracking Tag: Waiting For Code Review Waiting for code review from a core developer labels May 18, 2021
Copy link
Collaborator

@CaveSpectre11 CaveSpectre11 left a comment

Choose a reason for hiding this comment

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

utACK c9cdb22

Copy link
Collaborator

@codeofalltrades codeofalltrades left a comment

Choose a reason for hiding this comment

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

ACK c9cdb22

@codeofalltrades codeofalltrades added Code Review: Passed and removed Tag: Waiting For Code Review Waiting for code review from a core developer labels May 26, 2021
@codeofalltrades codeofalltrades merged commit d87eb85 into Veil-Project:master May 26, 2021
@Zannick Zannick deleted the clang2 branch October 22, 2021 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code Review: Passed Component: Core App Related to the application itself. Component: Wallet Relating to keystore, tx creation, and balance tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants