Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,9 @@ Threads
: Started from `main()` in `bitcoind.cpp`. Responsible for starting up and
shutting down the application.

- [ThreadImport (`d-loadblk`)](https://doxygen.bitcoincore.org/namespacenode.html#ab4305679079866f0f420f7dbf278381d)
: Loads blocks from `blk*.dat` files or `-loadblock=<file>` on startup.
- [Init load (`d-initload`)](https://doxygen.bitcoincore.org/namespacenode.html#ab4305679079866f0f420f7dbf278381d)
: Performs various loading tasks that are part of init but shouldn't block the node from being started: external block import,
reindex, reindex-chainstate, main chain activation, spawn indexes background sync threads and mempool load.

- [CCheckQueue::Loop (`d-scriptch.x`)](https://doxygen.bitcoincore.org/class_c_check_queue.html#a6e7fa51d3a25e7cb65446d4b50e6a987)
: Parallel script validation threads for transactions in blocks.
Expand Down
7 changes: 7 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ BITCOIN_CORE_H = \
kernel/mempool_options.h \
kernel/mempool_persist.h \
kernel/mempool_removal_reason.h \
kernel/messagestartchars.h \
kernel/notifications_interface.h \
kernel/validation_cache_sizes.h \
key.h \
Expand Down Expand Up @@ -351,6 +352,7 @@ BITCOIN_CORE_H = \
netfulfilledman.h \
netgroup.h \
netmessagemaker.h \
node/abort.h \
node/blockmanager_args.h \
node/blockstorage.h \
node/caches.h \
Expand Down Expand Up @@ -465,6 +467,7 @@ BITCOIN_CORE_H = \
util/readwritefile.h \
util/result.h \
util/serfloat.h \
util/signalinterrupt.h \
util/sock.h \
util/spanparsing.h \
util/std23.h \
Expand Down Expand Up @@ -639,6 +642,7 @@ libbitcoin_node_a_SOURCES = \
net_processing.cpp \
netfulfilledman.cpp \
netgroup.cpp \
node/abort.cpp \
node/blockmanager_args.cpp \
node/blockstorage.cpp \
node/caches.cpp \
Expand Down Expand Up @@ -1085,6 +1089,7 @@ libbitcoin_util_a_SOURCES = \
util/moneystr.cpp \
util/ranges_set.cpp \
util/readwritefile.cpp \
util/signalinterrupt.cpp \
util/serfloat.cpp \
util/sock.cpp \
util/spanparsing.cpp \
Expand Down Expand Up @@ -1349,6 +1354,7 @@ libdashkernel_la_SOURCES = \
messagesigner.cpp \
netaddress.cpp \
netbase.cpp \
node/abort.cpp \
node/blockstorage.cpp \
node/chainstate.cpp \
node/interface_ui.cpp \
Expand Down Expand Up @@ -1394,6 +1400,7 @@ libdashkernel_la_SOURCES = \
util/moneystr.cpp \
util/ranges_set.cpp \
util/serfloat.cpp \
util/signalinterrupt.cpp \
util/sock.cpp \
util/strencodings.cpp \
util/string.cpp \
Expand Down
4 changes: 2 additions & 2 deletions src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ void DeserializeDB(Stream& stream, Data&& data, bool fCheckSum = true)
{
HashVerifier verifier{stream};
// de-serialize file header (network specific magic number) and ..
unsigned char pchMsgTmp[4];
MessageStartChars pchMsgTmp;
verifier >> pchMsgTmp;
// ... verify the network matches ours
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) {
if (pchMsgTmp != Params().MessageStart()) {
throw std::runtime_error{"Invalid network magic number"};
}

Expand Down
1 change: 1 addition & 0 deletions src/bench/block_assemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <consensus/validation.h>
#include <script/standard.h>
#include <node/miner.h>
#include <random.h>
#include <test/util/mining.h>
#include <test/util/script.h>
#include <test/util/setup_common.h>
Expand Down
2 changes: 1 addition & 1 deletion src/bench/blockfilter_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class BlockFilterIndexBenchSetup
m_filter_index = std::make_unique<BlockFilterIndex>(
interfaces::MakeChain(m_testing_setup->m_node), BlockFilterType::BASIC_FILTER,
/*n_cache_size=*/8 << 20, /*f_memory=*/false);
if (!m_filter_index->Start()) {
if (!m_filter_index->Init() || !m_filter_index->StartBackgroundSync()) {
throw std::runtime_error("failed to start block filter benchmark index");
}
IndexWaitSynced(*m_filter_index);
Expand Down
1 change: 1 addition & 0 deletions src/bench/duplicate_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <consensus/validation.h>
#include <policy/policy.h>
#include <pow.h>
#include <random.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <validation.h>
Expand Down
1 change: 1 addition & 0 deletions src/bench/mempool_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <bench/bench.h>
#include <kernel/mempool_entry.h>
#include <policy/policy.h>
#include <random.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <util/chaintype.h>
Expand Down
20 changes: 16 additions & 4 deletions src/bitcoin-chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <node/blockstorage.h>
#include <node/caches.h>
#include <node/chainstate.h>
#include <random.h>
#include <scheduler.h>
#include <script/sigcache.h>
#include <spork.h>
Expand Down Expand Up @@ -96,9 +97,10 @@ int main(int argc, char* argv[])
class KernelNotifications : public kernel::Notifications
{
public:
void blockTip(SynchronizationState, CBlockIndex&) override
kernel::InterruptResult blockTip(SynchronizationState, CBlockIndex&) override
{
std::cout << "Block tip changed" << std::endl;
return {};
}
void headerTip(SynchronizationState, int64_t height, int64_t timestamp, bool presync) override
{
Expand All @@ -112,6 +114,15 @@ int main(int argc, char* argv[])
{
std::cout << "Warning: " << warning.original << std::endl;
}
void flushError(const std::string& debug_message) override
{
std::cerr << "Error flushing block data to disk: " << debug_message << std::endl;
}
void fatalError(const std::string& debug_message, const bilingual_str& user_message) override
{
std::cerr << "Error: " << debug_message << std::endl;
std::cerr << (user_message.empty() ? "A fatal internal error occurred." : user_message.original) << std::endl;
}
};
auto notifications = std::make_unique<KernelNotifications>();

Expand All @@ -125,8 +136,9 @@ int main(int argc, char* argv[])
node::BlockManager::Options blockman_opts{
.chainparams = chainman_opts.chainparams,
.blocks_dir = abs_datadir / "blocks",
.notifications = chainman_opts.notifications,
};
ChainstateManager chainman{chainman_opts, blockman_opts};
ChainstateManager chainman{kernel_context.interrupt, chainman_opts, blockman_opts};

CMasternodeMetaMan metaman{abs_datadir};
CEvoDB evodb{util::DbWrapperParams{.path = abs_datadir, .memory = false, .wipe = false}};
Expand All @@ -139,7 +151,7 @@ int main(int argc, char* argv[])
llmq::DEFAULT_BLSCHECK_THREADS, llmq::DEFAULT_WORKER_COUNT, llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE));
auto special_tx = std::make_unique<CSpecialTxProcessor>(evodb, dmnman,
*llmq_ctx->quorum_block_processor, *llmq_ctx->qsnapman,
chainman, chainman.m_blockman, chainman.GetConsensus(),
chainman, chainman.m_blockman, chainman.GetConsensus(), chainman.GetNotifications(),
chainlocks, *llmq_ctx->qman);

node::CacheSizes cache_sizes;
Expand Down Expand Up @@ -299,7 +311,7 @@ int main(int argc, char* argv[])
// Without this precise shutdown sequence, there will be a lot of nullptr
// dereferencing and UB.
scheduler.stop();
if (chainman.m_load_block.joinable()) chainman.m_load_block.join();
if (chainman.m_thread_load.joinable()) chainman.m_thread_load.join();
StopScriptCheckWorkerThreads();

GetMainSignals().FlushBackgroundCallbacks();
Expand Down
1 change: 1 addition & 0 deletions src/bitcoin-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <core_io.h>
#include <streams.h>
#include <util/exception.h>
#include <util/strencodings.h>
#include <util/translation.h>

#include <atomic>
Expand Down
9 changes: 7 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@

#include <arith_uint256.h>
#include <chainparamsbase.h>
#include <chainparamsseeds.h>
#include <common/args.h>
#include <common/system.h>
#include <consensus/merkle.h>
#include <consensus/params.h>
#include <deploymentinfo.h>
#include <logging.h>
#include <tinyformat.h>
#include <util/chaintype.h>
#include <util/strencodings.h>
#include <versionbits.h>

#include <cassert>
#include <cstdint>
#include <limits>
#include <ranges>
#include <stdexcept>
#include <vector>

static void ReadRegTestActivationArgs(const ArgsManager& args, CChainParams::RegTestOptions& options)
{
Expand Down
2 changes: 1 addition & 1 deletion src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef BITCOIN_CHAINPARAMS_H
#define BITCOIN_CHAINPARAMS_H

#include <kernel/chainparams.h>
#include <kernel/chainparams.h> // IWYU pragma: export

#include <consensus/params.h>
#include <llmq/params.h>
Expand Down
3 changes: 1 addition & 2 deletions src/evo/creditpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <logging.h>
#include <masternode/payments.h>
#include <node/blockstorage.h>
#include <shutdown.h>
#include <util/overflow.h>
#include <validation.h>

Expand Down Expand Up @@ -158,7 +157,7 @@ void CCreditPoolManager::MaybeWriteSnapshot(const uint256& block_hash, int heigh
// translate this into a consensus rejection.
const std::string msg = strprintf("CCreditPoolManager::%s -- EvoDB credit pool mismatch for block %s", __func__,
block_hash.ToString());
AbortNode(msg);
m_chainman.GetNotifications().fatalError(msg);
throw EvoDbInconsistencyError(msg);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#include <evo/providertx.h>
#include <evo/simplifiedmns.h>
#include <evo/specialtx.h>
#include <kernel/notifications_interface.h>
#include <masternode/meta.h>
#include <node/blockstorage.h>
#include <script/standard.h>
#include <shutdown.h>
#include <stats/client.h>
#include <uint256.h>
#include <util/helpers.h>
Expand Down Expand Up @@ -680,7 +680,7 @@ CDeterministicMNManager::~CDeterministicMNManager() = default;

bool CDeterministicMNManager::ProcessBlock(gsl::not_null<const CBlockIndex*> pindex, BlockValidationState& state,
const CDeterministicMNList& oldList, const CDeterministicMNList& newList,
MNListUpdates& updatesRet)
MNListUpdates& updatesRet, kernel::Notifications& notifications)
{
AssertLockHeld(::cs_main);

Expand All @@ -706,14 +706,14 @@ bool CDeterministicMNManager::ProcessBlock(gsl::not_null<const CBlockIndex*> pin
if (!m_evoDb.WriteDerived(std::make_pair(DB_LIST_DIFF, newList.GetBlockHash()), diff)) {
const std::string msg = strprintf("CDeterministicMNManager::%s -- EvoDB list diff mismatch for block %s",
__func__, newList.GetBlockHash().ToString());
AbortNode(msg);
notifications.fatalError(msg);
return state.Error(msg);
}
if ((nHeight % DISK_SNAPSHOT_PERIOD) == 0 || pindex->pprev == m_initial_snapshot_index) {
if (!m_evoDb.WriteDerived(std::make_pair(DB_LIST_SNAPSHOT, newList.GetBlockHash()), newList)) {
const std::string msg = strprintf("CDeterministicMNManager::%s -- EvoDB list snapshot mismatch for block %s",
__func__, newList.GetBlockHash().ToString());
AbortNode(msg);
notifications.fatalError(msg);
return state.Error(msg);
}
mnListsCache.insert_or_assign(newList.GetBlockHash(), newList);
Expand Down
6 changes: 5 additions & 1 deletion src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class CBlock;
class CBlockIndex;
class CCoinsViewCache;
class ChainstateManager;
namespace kernel {
class Notifications;
} // namespace kernel
namespace node {
class BlockManager;
} // namespace node
Expand Down Expand Up @@ -785,7 +788,8 @@ class CDeterministicMNManager
~CDeterministicMNManager();

bool ProcessBlock(gsl::not_null<const CBlockIndex*> pindex, BlockValidationState& state,
const CDeterministicMNList& oldList, const CDeterministicMNList& newList, MNListUpdates& updatesRet)
const CDeterministicMNList& oldList, const CDeterministicMNList& newList, MNListUpdates& updatesRet,
kernel::Notifications& notifications)
EXCLUSIVE_LOCKS_REQUIRED(!cs, ::cs_main);
bool UndoBlock(gsl::not_null<const CBlockIndex*> pindex, MNListUpdates& updatesRet) EXCLUSIVE_LOCKS_REQUIRED(!cs);

Expand Down
10 changes: 6 additions & 4 deletions src/evo/mnhftx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include <evo/evodb.h>
#include <evo/mnhftx.h>
#include <evo/specialtx.h>
#include <kernel/notifications_interface.h>
#include <llmq/commitment.h>
#include <llmq/quorumsman.h>
#include <llmq/signhash.h>
#include <node/blockstorage.h>
#include <shutdown.h>
#include <util/std23.h>

#include <chain.h>
Expand Down Expand Up @@ -43,10 +43,12 @@ CMutableTransaction MNHFTxPayload::PrepareTx() const
return tx;
}

CMNHFManager::CMNHFManager(CEvoDB& evoDb, const node::BlockManager& blockman, const Consensus::Params& consensus_params) :
CMNHFManager::CMNHFManager(CEvoDB& evoDb, const node::BlockManager& blockman, const Consensus::Params& consensus_params,
kernel::Notifications& notifications) :
m_evoDb(evoDb),
m_blockman{blockman},
m_consensus_params{consensus_params}
m_consensus_params{consensus_params},
m_notifications{notifications}
{
assert(globalInstance == nullptr);
globalInstance = this;
Expand Down Expand Up @@ -373,7 +375,7 @@ void CMNHFManager::AddToCache(const Signals& signals, const CBlockIndex* const p
// translate this into a consensus rejection.
const std::string msg = strprintf("CMNHFManager::%s -- EvoDB MNHF state mismatch for block %s",
__func__, blockHash.ToString());
AbortNode(msg);
m_notifications.fatalError(msg);
throw EvoDbInconsistencyError(msg);
}
{
Expand Down
7 changes: 6 additions & 1 deletion src/evo/mnhftx.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class CEvoDB;
class CTransaction;
class TxValidationState;
struct RPCResult;
namespace kernel {
class Notifications;
} // namespace kernel
namespace llmq {
class CQuorumManager;
}
Expand Down Expand Up @@ -101,6 +104,7 @@ class CMNHFManager : public AbstractEHFManager
// TODO: implement migration to a new format
const node::BlockManager& m_blockman;
const Consensus::Params& m_consensus_params;
kernel::Notifications& m_notifications;

static constexpr size_t MNHFCacheSize = 1000;
Mutex cs_cache;
Expand All @@ -111,7 +115,8 @@ class CMNHFManager : public AbstractEHFManager
CMNHFManager() = delete;
CMNHFManager(const CMNHFManager&) = delete;
CMNHFManager& operator=(const CMNHFManager&) = delete;
explicit CMNHFManager(CEvoDB& evoDb, const node::BlockManager& blockman, const Consensus::Params& consensus_params);
explicit CMNHFManager(CEvoDB& evoDb, const node::BlockManager& blockman, const Consensus::Params& consensus_params,
kernel::Notifications& notifications);
~CMNHFManager() override;

/**
Expand Down
7 changes: 4 additions & 3 deletions src/evo/specialtxman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@
CSpecialTxProcessor::CSpecialTxProcessor(CEvoDB& evodb, CDeterministicMNManager& dmnman,
llmq::CQuorumBlockProcessor& qblockman, llmq::CQuorumSnapshotManager& qsnapman,
const ChainstateManager& chainman, const node::BlockManager& blockman,
const Consensus::Params& consensus_params,
const Consensus::Params& consensus_params, kernel::Notifications& notifications,
const chainlock::Chainlocks& chainlocks, const llmq::CQuorumManager& qman) :
m_cpoolman{std::make_unique<CCreditPoolManager>(evodb, chainman)},
m_mnhfman{std::make_unique<CMNHFManager>(evodb, blockman, consensus_params)},
m_mnhfman{std::make_unique<CMNHFManager>(evodb, blockman, consensus_params, notifications)},
m_dmnman{dmnman},
m_qblockman{qblockman},
m_qsnapman{qsnapman},
m_chainman(chainman),
m_blockman{blockman},
m_consensus_params{consensus_params},
m_notifications{notifications},
m_chainlocks{chainlocks},
m_qman{qman}
{
Expand Down Expand Up @@ -1030,7 +1031,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(Chainstate& chainstate, const
}
mn_list.SetBlockHash(pindex->GetBlockHash());

if (!fJustCheck && !m_dmnman.ProcessBlock(pindex, state, updatesRet.old_list, mn_list, updatesRet)) {
if (!fJustCheck && !m_dmnman.ProcessBlock(pindex, state, updatesRet.old_list, mn_list, updatesRet, m_notifications)) {
// pass the state returned by the function above
return false;
}
Expand Down
Loading
Loading