mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
remove CBlockIndex copy construction
Copy construction of CBlockIndex objects is a footgun because of the wide use of equality-by-pointer comparison in the code base. There are also potential lifetime confusions of using copied instances, since there are recursive pointer references (e.g. pprev). We can't just delete the copy constructors because they are used for derived classes (CDiskBlockIndex), so we mark them protected. Delete move constructors and declare the destructor to satisfy the "rule of 5."
This commit is contained in:
@@ -78,11 +78,11 @@ constexpr static struct {
|
||||
{0, 792342903}, {6, 678455063}, {6, 773251385}, {5, 186617471}, {6, 883189502}, {7, 396077336},
|
||||
{8, 254702874}, {0, 455592851}};
|
||||
|
||||
static CBlockIndex CreateBlockIndex(int nHeight, CBlockIndex* active_chain_tip) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
static std::unique_ptr<CBlockIndex> CreateBlockIndex(int nHeight, CBlockIndex* active_chain_tip) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
{
|
||||
CBlockIndex index;
|
||||
index.nHeight = nHeight;
|
||||
index.pprev = active_chain_tip;
|
||||
auto index{std::make_unique<CBlockIndex>()};
|
||||
index->nHeight = nHeight;
|
||||
index->pprev = active_chain_tip;
|
||||
return index;
|
||||
}
|
||||
|
||||
@@ -394,7 +394,7 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C
|
||||
|
||||
{
|
||||
CBlockIndex* active_chain_tip = m_node.chainman->ActiveChain().Tip();
|
||||
BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, CreateBlockIndex(active_chain_tip->nHeight + 2, active_chain_tip))); // Sequence locks pass on 2nd block
|
||||
BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, *CreateBlockIndex(active_chain_tip->nHeight + 2, active_chain_tip))); // Sequence locks pass on 2nd block
|
||||
}
|
||||
|
||||
// relative time locked
|
||||
@@ -411,7 +411,7 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C
|
||||
m_node.chainman->ActiveChain().Tip()->GetAncestor(m_node.chainman->ActiveChain().Tip()->nHeight - i)->nTime += SEQUENCE_LOCK_TIME; // Trick the MedianTimePast
|
||||
{
|
||||
CBlockIndex* active_chain_tip = m_node.chainman->ActiveChain().Tip();
|
||||
BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, CreateBlockIndex(active_chain_tip->nHeight + 1, active_chain_tip)));
|
||||
BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, *CreateBlockIndex(active_chain_tip->nHeight + 1, active_chain_tip)));
|
||||
}
|
||||
|
||||
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user