mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
merge bitcoin#19277: Add Assert identity function
This commit is contained in:
parent
e235d834da
commit
21f5405e4a
@ -1781,9 +1781,9 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
|
||||
node.mempool = &::mempool;
|
||||
assert(!node.chainman);
|
||||
node.chainman = &g_chainman;
|
||||
ChainstateManager& chainman = EnsureChainman(node);
|
||||
ChainstateManager& chainman = *Assert(node.chainman);
|
||||
|
||||
node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), *node.scheduler, *node.chainman, *node.mempool, args.GetBoolArg("-enablebip61", DEFAULT_ENABLE_BIP61)));
|
||||
node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), *node.scheduler, chainman, *node.mempool, args.GetBoolArg("-enablebip61", DEFAULT_ENABLE_BIP61)));
|
||||
RegisterValidationInterface(node.peer_logic.get());
|
||||
|
||||
// sanitize comments per BIP-0014, format user agent and check total size
|
||||
|
@ -56,10 +56,4 @@ struct NodeContext {
|
||||
~NodeContext();
|
||||
};
|
||||
|
||||
inline ChainstateManager& EnsureChainman(const NodeContext& node)
|
||||
{
|
||||
assert(node.chainman);
|
||||
return *node.chainman;
|
||||
}
|
||||
|
||||
#endif // BITCOIN_NODE_CONTEXT_H
|
||||
|
@ -85,7 +85,10 @@ CTxMemPool& EnsureMemPool(const util::Ref& context)
|
||||
ChainstateManager& EnsureChainman(const util::Ref& context)
|
||||
{
|
||||
NodeContext& node = EnsureNodeContext(context);
|
||||
return EnsureChainman(node);
|
||||
if (!node.chainman) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found");
|
||||
}
|
||||
return *node.chainman;
|
||||
}
|
||||
|
||||
/* Calculate the difficulty for a given block index.
|
||||
|
@ -94,7 +94,7 @@ bool BuildChainTestingSetup::BuildChain(const CBlockIndex* pindex,
|
||||
CBlockHeader header = block->GetBlockHeader();
|
||||
|
||||
CValidationState state;
|
||||
if (!EnsureChainman(m_node).ProcessNewBlockHeaders({header}, state, Params(), &pindex, nullptr)) {
|
||||
if (!Assert(m_node.chainman)->ProcessNewBlockHeaders({header}, state, Params(), &pindex, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -171,7 +171,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
|
||||
uint256 chainA_last_header = last_header;
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
const auto& block = chainA[i];
|
||||
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
|
||||
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
|
||||
}
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
const auto& block = chainA[i];
|
||||
@ -189,7 +189,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
|
||||
uint256 chainB_last_header = last_header;
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
const auto& block = chainB[i];
|
||||
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
|
||||
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
|
||||
}
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
const auto& block = chainB[i];
|
||||
@ -220,7 +220,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
|
||||
// Reorg back to chain A.
|
||||
for (size_t i = 2; i < 4; i++) {
|
||||
const auto& block = chainA[i];
|
||||
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
|
||||
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
|
||||
}
|
||||
|
||||
// Check that chain A and B blocks can be retrieved.
|
||||
|
@ -245,7 +245,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_activation, TestChainDIP3BeforeActivationSetup)
|
||||
|
||||
// We start one block before DIP3 activation, so mining a block with a DIP3 transaction should fail
|
||||
auto block = std::make_shared<CBlock>(CreateBlock(txns, coinbaseKey));
|
||||
EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr);
|
||||
Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr);
|
||||
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight);
|
||||
BOOST_ASSERT(block->GetHash() != ::ChainActive().Tip()->GetBlockHash());
|
||||
BOOST_ASSERT(!deterministicMNManager->GetListAtChainTip().HasMN(tx.GetHash()));
|
||||
@ -255,7 +255,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_activation, TestChainDIP3BeforeActivationSetup)
|
||||
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 1);
|
||||
// Mining a block with a DIP3 transaction should succeed now
|
||||
block = std::make_shared<CBlock>(CreateBlock(txns, coinbaseKey));
|
||||
BOOST_ASSERT(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
|
||||
BOOST_ASSERT(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
|
||||
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
|
||||
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 2);
|
||||
BOOST_CHECK_EQUAL(block->GetHash(), ::ChainActive().Tip()->GetBlockHash());
|
||||
@ -470,7 +470,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_test_mempool_reorg, TestChainDIP3Setup)
|
||||
SignTransaction(*m_node.mempool, tx_collateral, coinbaseKey);
|
||||
|
||||
auto block = std::make_shared<CBlock>(CreateBlock({tx_collateral}, coinbaseKey));
|
||||
BOOST_ASSERT(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
|
||||
BOOST_ASSERT(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
|
||||
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
|
||||
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 1);
|
||||
BOOST_CHECK_EQUAL(block->GetHash(), ::ChainActive().Tip()->GetBlockHash());
|
||||
@ -600,7 +600,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_verify_db, TestChainDIP3Setup)
|
||||
SignTransaction(*m_node.mempool, tx_collateral, coinbaseKey);
|
||||
|
||||
auto block = std::make_shared<CBlock>(CreateBlock({tx_collateral}, coinbaseKey));
|
||||
BOOST_ASSERT(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
|
||||
BOOST_ASSERT(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
|
||||
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
|
||||
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 1);
|
||||
BOOST_CHECK_EQUAL(block->GetHash(), ::ChainActive().Tip()->GetBlockHash());
|
||||
@ -631,7 +631,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_verify_db, TestChainDIP3Setup)
|
||||
auto tx_reg_hash = tx_reg.GetHash();
|
||||
|
||||
block = std::make_shared<CBlock>(CreateBlock({tx_reg}, coinbaseKey));
|
||||
BOOST_ASSERT(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
|
||||
BOOST_ASSERT(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
|
||||
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
|
||||
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 2);
|
||||
BOOST_CHECK_EQUAL(block->GetHash(), ::ChainActive().Tip()->GetBlockHash());
|
||||
@ -643,7 +643,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_verify_db, TestChainDIP3Setup)
|
||||
auto proUpRevTx = CreateProUpRevTx(*m_node.mempool, collateral_utxos, tx_reg_hash, operatorKey, collateralKey);
|
||||
|
||||
block = std::make_shared<CBlock>(CreateBlock({proUpRevTx}, coinbaseKey));
|
||||
BOOST_ASSERT(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
|
||||
BOOST_ASSERT(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
|
||||
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
|
||||
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 3);
|
||||
BOOST_CHECK_EQUAL(block->GetHash(), ::ChainActive().Tip()->GetBlockHash());
|
||||
|
@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
}
|
||||
}
|
||||
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
|
||||
BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlock(chainparams, shared_pblock, true, nullptr));
|
||||
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr));
|
||||
pblock->hashPrevBlock = pblock->GetHash();
|
||||
};
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <pow.h>
|
||||
#include <script/standard.h>
|
||||
#include <validation.h>
|
||||
#include <util/check.h>
|
||||
#ifdef ENABLE_WALLET
|
||||
#include <wallet/wallet.h>
|
||||
#endif
|
||||
@ -62,7 +63,7 @@ CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
|
||||
assert(block->nNonce);
|
||||
}
|
||||
|
||||
bool processed{EnsureChainman(node).ProcessNewBlock(Params(), block, true, nullptr)};
|
||||
bool processed{Assert(node.chainman)->ProcessNewBlock(Params(), block, true, nullptr)};
|
||||
assert(processed);
|
||||
|
||||
return CTxIn{block->vtx[0]->GetHash(), 0};
|
||||
|
@ -248,7 +248,7 @@ CBlock TestChainSetup::CreateAndProcessBlock(const std::vector<CMutableTransacti
|
||||
auto block = CreateBlock(txns, scriptPubKey);
|
||||
|
||||
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
|
||||
EnsureChainman(m_node).ProcessNewBlock(chainparams, shared_pblock, true, nullptr);
|
||||
Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr);
|
||||
|
||||
CBlock result = block;
|
||||
return result;
|
||||
|
@ -160,10 +160,10 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
|
||||
std::transform(blocks.begin(), blocks.end(), std::back_inserter(headers), [](std::shared_ptr<const CBlock> b) { return b->GetBlockHeader(); });
|
||||
|
||||
// Process all the headers so we understand the toplogy of the chain
|
||||
BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlockHeaders(headers, state, Params()));
|
||||
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders(headers, state, Params()));
|
||||
|
||||
// Connect the genesis block and drain any outstanding events
|
||||
BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlock(Params(), std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored));
|
||||
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(Params(), std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored));
|
||||
SyncWithValidationInterfaceQueue();
|
||||
|
||||
// subscribe to events (this subscriber will validate event ordering)
|
||||
@ -185,13 +185,13 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
|
||||
FastRandomContext insecure;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
auto block = blocks[insecure.randrange(blocks.size() - 1)];
|
||||
EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, &ignored);
|
||||
Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored);
|
||||
}
|
||||
|
||||
// to make sure that eventually we process the full chain - do it here
|
||||
for (auto block : blocks) {
|
||||
if (block->vtx.size() == 1) {
|
||||
bool processed = EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, &ignored);
|
||||
bool processed = Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored);
|
||||
assert(processed);
|
||||
}
|
||||
}
|
||||
@ -232,7 +232,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
|
||||
{
|
||||
bool ignored;
|
||||
auto ProcessBlock = [&](std::shared_ptr<const CBlock> block) -> bool {
|
||||
return EnsureChainman(m_node).ProcessNewBlock(Params(), block, /* fForceProcessing */ true, /* fNewBlock */ &ignored);
|
||||
return Assert(m_node.chainman)->ProcessNewBlock(Params(), block, /* fForceProcessing */ true, /* fNewBlock */ &ignored);
|
||||
};
|
||||
|
||||
// Process all mined blocks
|
||||
|
@ -88,7 +88,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
||||
// Prune the older block file.
|
||||
{
|
||||
LOCK(cs_main);
|
||||
EnsureChainman(m_node).PruneOneBlockFile(oldTip->GetBlockPos().nFile);
|
||||
Assert(m_node.chainman)->PruneOneBlockFile(oldTip->GetBlockPos().nFile);
|
||||
}
|
||||
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
|
||||
|
||||
@ -114,7 +114,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
||||
// Prune the remaining block file.
|
||||
{
|
||||
LOCK(cs_main);
|
||||
EnsureChainman(m_node).PruneOneBlockFile(newTip->GetBlockPos().nFile);
|
||||
Assert(m_node.chainman)->PruneOneBlockFile(newTip->GetBlockPos().nFile);
|
||||
}
|
||||
UnlinkPrunedFiles({newTip->GetBlockPos().nFile});
|
||||
|
||||
@ -151,7 +151,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
|
||||
// Prune the older block file.
|
||||
{
|
||||
LOCK(cs_main);
|
||||
EnsureChainman(m_node).PruneOneBlockFile(oldTip->GetBlockPos().nFile);
|
||||
Assert(m_node.chainman)->PruneOneBlockFile(oldTip->GetBlockPos().nFile);
|
||||
}
|
||||
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user