Skip to content

Conversation

@jamesob
Copy link
Contributor

@jamesob jamesob commented Dec 3, 2021

While reviewing #23630, I noticed that DisconnectBlock is uncovered by lock annotations. CoinsTip() access requires cs_main and therefore so should this function.

CoinsTip() access requires cs_main and therefore so should this function.
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Concept ACK on preventatively ensuring the mutex continues to be held over future changes when calling this function.

* When FAILED is returned, view is left in an indeterminate state. */
DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view)
{
AssertLockHeld(::cs_main);
Copy link
Member

Choose a reason for hiding this comment

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

This assertion in the definition seems unneeded? IIUC the lock annotation in the function declaration enforces it.

Copy link
Member

Choose a reason for hiding this comment

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

Never mind, just saw the developer notes recommend this ("Combine annotations in function declarations with
run-time asserts in function definitions").

// Block (dis)connection on a given view:
DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view);
DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
Copy link
Member

Choose a reason for hiding this comment

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

Why use the ::cs_main global reference here rather than cs_main?

Copy link
Member

Choose a reason for hiding this comment

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

I think for new code we prefer ::global, unless the name of the global is prefixed with g_..., in which case ::g_... and g_... are allowed.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks.

@jonatack
Copy link
Member

jonatack commented Dec 6, 2021

ACK 7da4a8f

@maflcko maflcko merged commit dca9ab4 into bitcoin:master Dec 6, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 7, 2021
RandyMcMillan pushed a commit to RandyMcMillan/mempool-tab that referenced this pull request Dec 23, 2021
d3c01ad cover DisconnectBlock with lock annotation (James O'Beirne)

Pull request description:

  While reviewing #23630, I noticed that `DisconnectBlock` is uncovered by lock annotations. CoinsTip() access requires cs_main and therefore so should this function.

ACKs for top commit:
  jonatack:
    ACK d3c01ad

Tree-SHA512: 3e2b0247c138b31deeadcd48eb3f7bc8d32c0b6bb6d6e94ccf8ea0cbbc50b1b35d83f662eee432f2bd2d87a3fe9c94604da806ec711df93298bfb0ab34a5a05b
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 10, 2022
Summary:
CoinsTip() access requires cs_main and therefore so should this function.

This is a backport of [[bitcoin/bitcoin#23661 | core#23661]]

Test Plan:
With clang + DEBUG
`ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D12456
@bitcoin bitcoin locked and limited conversation to collaborators Dec 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants