Closed kwvg closed 1 week ago
I'm still confused by all the added cs_mains. You say
Add lock annotations for accessing pblocktree (while already protected by ::cs_main, said protection is currently not enforced but will be once moved into BlockManager in the backport)
and I don't see where cs_main locks are being acquired in develop for these cases. Can you help me figure that out?
This pull request has conflicts, please rebase.
I don't see where cs_main locks are being acquired in develop for these cases. Can you help me figure that out?
@PastaPastaPasta
pblocktree
is commented in Dash Core as being protected by ::cs_main
in develop
(source) but this isn't enforced (lack of EXCLUSIVE_LOCKS_REQUIRED
).
In Bitcoin Core, the usage of pblocktree
is mostly limited to functions like LoadBlockIndex{DB}
, which are protected by ::cs_main
(source, source) and FlushStateToDisk
, which locks ::cs_main
(source), Dash Core differs in that it utilizes pblocktree
to manage its indexes (which for the most part are covered by the locks mentioned above) but also uses it in RPC code (via Get*Index
, which aren't).
The lack of explicit annotations meant that the safety assumed from the annotations given to functions utilizing pblocktree
doesn't extend to RPC calls as no annotations are present there at all.
The annotation is made explicit in https://github.com/bitcoin/bitcoin/pull/22371 (source, renamed as m_block_tree_db
), which is part of a series of backports currently undergoing testing. In preparation of those series of backports, this pull request was opened to add explicit annotations (with added cleanups).
Additional Information
This pull request is motivated by bitcoin#22371, which gets rid of the
pblocktree
global.The sole usage of
pblocktree
introduced by Dash is for managing our {address, spent, timestamp} indexes with most of invocations withinBlockManager
orCChainState
, granting them internal access topblocktree
(nowm_block_tree_db
). The sole exception beingGet*Index
, that relies on accessing the global and has no direct internal access.This pull request aims to refactor code associated with
Get*Index
with the eventual aim of moving gaining access to the global out of the function.Get*Index
is called exclusively called through RPC, which makes giving it access toChainstateManager
quite easy, which makes switching from the global to accessing it throughChainstateManager
when backporting bitcoin#22371 a drop-in replacement.Alongside that, the surrounding code has been given some TLC:
validation.cpp
and intorpc/index_util.cpp
. The code is exclusively used in RPC logic and doesn't aid in validation.pblocktree
(while already protected by::cs_main
, said protection is currently not enforced but will be once moved intoBlockManager
in the backport)const
-ing input arguments and using pass-by-value for input arguments that can be written inline (i.e. types likeCSpentIndexKey
are still pass-by-ref).const
ingCTxMemPool
functions were possible (courtesy of the presence ofconst_iterator
s), the same is currently not possible withCBlockTreeDB
functions as the iterator is non-const
.GetSpentIndex
to bring it line with otherGet*Index
es.*Entry
typedef and replacing all explicit type constructions with it.CTxMemPool::getAddressIndex
indifferent to howCMempoolAddressDeltaKey
is constructed.std::pair<uint160, AddressType>
and construct theCMempoolAddressDeltaKey
internally, this was presumably done to account for the return type ofgetAddressesFromParams
in the sole call for theCTxMemPool::getAddressIndex
.Get*Index
functions.Breaking Changes
None expected.
Checklist: