From 447761c8228d58f948aae7e73ed079c028cacb97 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Wed, 10 May 2023 22:29:17 +0200 Subject: [PATCH 1/8] kernel: Add notification interface This commit is part of the libbitcoinkernel project and seeks to remove the ChainstateManager's and, more generally, the kernel library's dependency on interface_ui with options methods in this and the following few commits. By removing interface_ui from the kernel library, its dependency on boost is reduced to just boost::multi_index. Define a new kernel notification class with virtual methods for notifying about internal kernel events. Create a new file in the node library for defining a function creating the default set of notification methods such that these do not need to be re-defined all over the codebase. As a first step, add a `blockTip` method, wrapping `uiInterface.NotifyBlockTip`. --- src/Makefile.am | 3 +++ src/bitcoin-chainstate.cpp | 12 +++++++++ src/init.cpp | 6 +++++ src/kernel/chainstatemanager_opts.h | 3 +++ src/kernel/notifications_interface.h | 26 +++++++++++++++++++ src/node/context.cpp | 1 + src/node/context.h | 3 +++ src/node/kernel_notifications.cpp | 16 ++++++++++++ src/node/kernel_notifications.h | 21 +++++++++++++++ src/test/util/setup_common.cpp | 5 ++++ .../validation_chainstatemanager_tests.cpp | 4 +++ src/validation.cpp | 4 +-- src/validation.h | 1 + 13 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 src/kernel/notifications_interface.h create mode 100644 src/node/kernel_notifications.cpp create mode 100644 src/node/kernel_notifications.h diff --git a/src/Makefile.am b/src/Makefile.am index 713b9a30d14..2bbd3436577 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -186,6 +186,7 @@ BITCOIN_CORE_H = \ kernel/mempool_limits.h \ kernel/mempool_options.h \ kernel/mempool_persist.h \ + kernel/notifications_interface.h \ kernel/validation_cache_sizes.h \ key.h \ key_io.h \ @@ -214,6 +215,7 @@ BITCOIN_CORE_H = \ node/database_args.h \ node/eviction.h \ node/interface_ui.h \ + node/kernel_notifications.h \ node/mempool_args.h \ node/mempool_persist_args.h \ node/miner.h \ @@ -408,6 +410,7 @@ libbitcoin_node_a_SOURCES = \ node/eviction.cpp \ node/interface_ui.cpp \ node/interfaces.cpp \ + node/kernel_notifications.cpp \ node/mempool_args.cpp \ node/mempool_persist_args.cpp \ node/miner.cpp \ diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index 16c3bfb7081..91acc34054c 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -12,6 +12,7 @@ // It is part of the libbitcoinkernel project. #include +#include #include #include #include @@ -34,6 +35,7 @@ #include #include #include +#include int main(int argc, char* argv[]) { @@ -80,12 +82,22 @@ int main(int argc, char* argv[]) GetMainSignals().RegisterBackgroundSignalScheduler(scheduler); + class KernelNotifications : public kernel::Notifications + { + public: + void blockTip(SynchronizationState, CBlockIndex&) override + { + std::cout << "Block tip changed" << std::endl; + } + }; + auto notifications = std::make_unique(); // SETUP: Chainstate const ChainstateManager::Options chainman_opts{ .chainparams = *chainparams, .datadir = gArgs.GetDataDirNet(), .adjusted_time_callback = NodeClock::now, + .notifications = *notifications, }; const node::BlockManager::Options blockman_opts{ .chainparams = chainman_opts.chainparams, diff --git a/src/init.cpp b/src/init.cpp index a543fd9ef20..48492eab6b4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -124,6 +125,7 @@ using node::DEFAULT_PERSIST_MEMPOOL; using node::DEFAULT_PRINTPRIORITY; using node::fReindex; using node::g_indexes_ready_to_sync; +using node::KernelNotifications; using node::LoadChainstate; using node::MempoolPath; using node::NodeContext; @@ -1019,9 +1021,11 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb // Also report errors from parsing before daemonization { + KernelNotifications notifications{}; ChainstateManager::Options chainman_opts_dummy{ .chainparams = chainparams, .datadir = args.GetDataDirNet(), + .notifications = notifications, }; if (const auto error{ApplyArgsManOptions(args, chainman_opts_dummy)}) { return InitError(*error); @@ -1427,12 +1431,14 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) // ********************************************************* Step 7: load block chain + node.notifications = std::make_unique(); fReindex = args.GetBoolArg("-reindex", false); bool fReindexChainState = args.GetBoolArg("-reindex-chainstate", false); ChainstateManager::Options chainman_opts{ .chainparams = chainparams, .datadir = args.GetDataDirNet(), .adjusted_time_callback = GetAdjustedTime, + .notifications = *node.notifications, }; Assert(!ApplyArgsManOptions(args, chainman_opts)); // no error can happen, already checked in AppInitParameterInteraction diff --git a/src/kernel/chainstatemanager_opts.h b/src/kernel/chainstatemanager_opts.h index 2395f601645..917f7d226c5 100644 --- a/src/kernel/chainstatemanager_opts.h +++ b/src/kernel/chainstatemanager_opts.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_KERNEL_CHAINSTATEMANAGER_OPTS_H #define BITCOIN_KERNEL_CHAINSTATEMANAGER_OPTS_H +#include + #include #include #include @@ -42,6 +44,7 @@ struct ChainstateManagerOpts { DBOptions block_tree_db{}; DBOptions coins_db{}; CoinsViewOptions coins_view{}; + Notifications& notifications; }; } // namespace kernel diff --git a/src/kernel/notifications_interface.h b/src/kernel/notifications_interface.h new file mode 100644 index 00000000000..d90284fbea6 --- /dev/null +++ b/src/kernel/notifications_interface.h @@ -0,0 +1,26 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H +#define BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H + +class CBlockIndex; +enum class SynchronizationState; + +namespace kernel { + +/** + * A base class defining functions for notifying about certain kernel + * events. + */ +class Notifications +{ +public: + virtual ~Notifications(){}; + + virtual void blockTip(SynchronizationState state, CBlockIndex& index) {} +}; +} // namespace kernel + +#endif // BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H diff --git a/src/node/context.cpp b/src/node/context.cpp index af59ab932bb..ca56fa0b866 100644 --- a/src/node/context.cpp +++ b/src/node/context.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/src/node/context.h b/src/node/context.h index 84f4053c840..9532153cdb3 100644 --- a/src/node/context.h +++ b/src/node/context.h @@ -30,6 +30,8 @@ class WalletLoader; } // namespace interfaces namespace node { +class KernelNotifications; + //! NodeContext struct containing references to chain state and connection //! state. //! @@ -62,6 +64,7 @@ struct NodeContext { interfaces::WalletLoader* wallet_loader{nullptr}; std::unique_ptr scheduler; std::function rpc_interruption_point = [] {}; + std::unique_ptr notifications; //! Declare default constructor and destructor that are not inline, so code //! instantiating the NodeContext struct doesn't need to #include class diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp new file mode 100644 index 00000000000..b710d0c5dbd --- /dev/null +++ b/src/node/kernel_notifications.cpp @@ -0,0 +1,16 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include + +namespace node { + +void KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& index) +{ + uiInterface.NotifyBlockTip(state, &index); +} + +} // namespace node diff --git a/src/node/kernel_notifications.h b/src/node/kernel_notifications.h new file mode 100644 index 00000000000..11b270f1dbf --- /dev/null +++ b/src/node/kernel_notifications.h @@ -0,0 +1,21 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_NODE_KERNEL_NOTIFICATIONS_H +#define BITCOIN_NODE_KERNEL_NOTIFICATIONS_H + +#include + +class CBlockIndex; +enum class SynchronizationState; + +namespace node { +class KernelNotifications : public kernel::Notifications +{ +public: + void blockTip(SynchronizationState state, CBlockIndex& index) override; +}; +} // namespace node + +#endif // BITCOIN_NODE_KERNEL_NOTIFICATIONS_H diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index eedb406cbd1..8ac17838acb 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,7 @@ using node::ApplyArgsManOptions; using node::BlockAssembler; using node::BlockManager; using node::CalculateCacheSizes; +using node::KernelNotifications; using node::LoadChainstate; using node::RegenerateCommitments; using node::VerifyLoadedChainstate; @@ -182,11 +184,14 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto m_cache_sizes = CalculateCacheSizes(m_args); + m_node.notifications = std::make_unique(); + const ChainstateManager::Options chainman_opts{ .chainparams = chainparams, .datadir = m_args.GetDataDirNet(), .adjusted_time_callback = GetAdjustedTime, .check_block_index = true, + .notifications = *m_node.notifications, }; const BlockManager::Options blockman_opts{ .chainparams = chainman_opts.chainparams, diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index 05e27870753..8ca4e62e279 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -4,6 +4,7 @@ // #include #include +#include #include #include #include @@ -23,6 +24,7 @@ #include using node::BlockManager; +using node::KernelNotifications; using node::SnapshotMetadata; BOOST_FIXTURE_TEST_SUITE(validation_chainstatemanager_tests, ChainTestingSetup) @@ -377,10 +379,12 @@ struct SnapshotTestSetup : TestChain100Setup { LOCK(::cs_main); chainman.ResetChainstates(); BOOST_CHECK_EQUAL(chainman.GetAll().size(), 0); + m_node.notifications = std::make_unique(); const ChainstateManager::Options chainman_opts{ .chainparams = ::Params(), .datadir = m_args.GetDataDirNet(), .adjusted_time_callback = GetAdjustedTime, + .notifications = *m_node.notifications, }; const BlockManager::Options blockman_opts{ .chainparams = chainman_opts.chainparams, diff --git a/src/validation.cpp b/src/validation.cpp index e536dfb4ebd..7762cf68d9a 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3206,7 +3206,7 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr< GetMainSignals().UpdatedBlockTip(pindexNewTip, pindexFork, fInitialDownload); // Always notify the UI if a new block tip was connected - uiInterface.NotifyBlockTip(GetSynchronizationState(fInitialDownload), pindexNewTip); + m_chainman.GetNotifications().blockTip(GetSynchronizationState(fInitialDownload), *pindexNewTip); } } // When we reach this point, we switched to a new tip (stored in pindexNewTip). @@ -3403,7 +3403,7 @@ bool Chainstate::InvalidateBlock(BlockValidationState& state, CBlockIndex* pinde // Only notify about a new block tip if the active chain was modified. if (pindex_was_in_chain) { - uiInterface.NotifyBlockTip(GetSynchronizationState(IsInitialBlockDownload()), to_mark_failed->pprev); + m_chainman.GetNotifications().blockTip(GetSynchronizationState(IsInitialBlockDownload()), *to_mark_failed->pprev); } return true; } diff --git a/src/validation.h b/src/validation.h index fd0e2115f7d..352056f0636 100644 --- a/src/validation.h +++ b/src/validation.h @@ -955,6 +955,7 @@ public: bool ShouldCheckBlockIndex() const { return *Assert(m_options.check_block_index); } const arith_uint256& MinimumChainWork() const { return *Assert(m_options.minimum_chain_work); } const uint256& AssumedValidBlock() const { return *Assert(m_options.assumed_valid_block); } + kernel::Notifications& GetNotifications() const { return m_options.notifications; }; /** * Alias for ::cs_main. From 84d71457e7250ab25c0a11d1ad1c7657197ffd90 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Wed, 10 May 2023 22:35:49 +0200 Subject: [PATCH 2/8] kernel: Add headerTip method to notifications This commit is part of the libbitcoinkernel project and seeks to remove the ChainstateManager's and, more generally, the kernel library's dependency on interface_ui with options methods in this and the following few commits. By removing interface_ui from the kernel library, its dependency on boost is reduced to just boost::multi_index. --- src/bitcoin-chainstate.cpp | 5 +++++ src/kernel/notifications_interface.h | 3 +++ src/node/kernel_notifications.cpp | 5 +++++ src/node/kernel_notifications.h | 4 ++++ src/validation.cpp | 4 ++-- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index 91acc34054c..a184d64ff00 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -89,6 +90,10 @@ int main(int argc, char* argv[]) { std::cout << "Block tip changed" << std::endl; } + void headerTip(SynchronizationState, int64_t height, int64_t timestamp, bool presync) override + { + std::cout << "Header tip changed: " << height << ", " << timestamp << ", " << presync << std::endl; + } }; auto notifications = std::make_unique(); diff --git a/src/kernel/notifications_interface.h b/src/kernel/notifications_interface.h index d90284fbea6..7f88176d03c 100644 --- a/src/kernel/notifications_interface.h +++ b/src/kernel/notifications_interface.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H #define BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H +#include + class CBlockIndex; enum class SynchronizationState; @@ -20,6 +22,7 @@ public: virtual ~Notifications(){}; virtual void blockTip(SynchronizationState state, CBlockIndex& index) {} + virtual void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {} }; } // namespace kernel diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp index b710d0c5dbd..1e4bc20f2f9 100644 --- a/src/node/kernel_notifications.cpp +++ b/src/node/kernel_notifications.cpp @@ -13,4 +13,9 @@ void KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& inde uiInterface.NotifyBlockTip(state, &index); } +void KernelNotifications::headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) +{ + uiInterface.NotifyHeaderTip(state, height, timestamp, presync); +} + } // namespace node diff --git a/src/node/kernel_notifications.h b/src/node/kernel_notifications.h index 11b270f1dbf..1507c3214a2 100644 --- a/src/node/kernel_notifications.h +++ b/src/node/kernel_notifications.h @@ -7,6 +7,8 @@ #include +#include + class CBlockIndex; enum class SynchronizationState; @@ -15,6 +17,8 @@ class KernelNotifications : public kernel::Notifications { public: void blockTip(SynchronizationState state, CBlockIndex& index) override; + + void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override; }; } // namespace node diff --git a/src/validation.cpp b/src/validation.cpp index 7762cf68d9a..21592709439 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3097,7 +3097,7 @@ static bool NotifyHeaderTip(Chainstate& chainstate) LOCKS_EXCLUDED(cs_main) { } // Send block tip changed notifications without cs_main if (fNotify) { - uiInterface.NotifyHeaderTip(GetSynchronizationState(fInitialBlockDownload), pindexHeader->nHeight, pindexHeader->nTime, false); + chainstate.m_chainman.GetNotifications().headerTip(GetSynchronizationState(fInitialBlockDownload), pindexHeader->nHeight, pindexHeader->nTime, false); } return fNotify; } @@ -3920,7 +3920,7 @@ void ChainstateManager::ReportHeadersPresync(const arith_uint256& work, int64_t m_last_presync_update = now; } bool initial_download = chainstate.IsInitialBlockDownload(); - uiInterface.NotifyHeaderTip(GetSynchronizationState(initial_download), height, timestamp, /*presync=*/true); + GetNotifications().headerTip(GetSynchronizationState(initial_download), height, timestamp, /*presync=*/true); if (initial_download) { const int64_t blocks_left{(GetTime() - timestamp) / GetConsensus().nPowTargetSpacing}; const double progress{100.0 * height / (height + blocks_left)}; From 4452707edec91c7d7991f486dd41ef3edb4f7fbf Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Wed, 10 May 2023 22:36:04 +0200 Subject: [PATCH 3/8] kernel: Add progress method to notifications This commit is part of the libbitcoinkernel project and seeks to remove the ChainstateManager's and, more generally, the kernel library's dependency on interface_ui with options methods in this and the following few commits. By removing interface_ui from the kernel library, its dependency on boost is reduced to just boost::multi_index. --- src/bitcoin-chainstate.cpp | 5 +++++ src/kernel/notifications_interface.h | 3 +++ src/node/chainstate.cpp | 2 +- src/node/kernel_notifications.cpp | 6 ++++++ src/node/kernel_notifications.h | 4 ++++ src/rpc/blockchain.cpp | 2 +- src/validation.cpp | 19 +++++++++++-------- src/validation.h | 8 ++++++-- 8 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index a184d64ff00..b949bafcc8e 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -37,6 +37,7 @@ #include #include #include +#include int main(int argc, char* argv[]) { @@ -94,6 +95,10 @@ int main(int argc, char* argv[]) { std::cout << "Header tip changed: " << height << ", " << timestamp << ", " << presync << std::endl; } + void progress(const bilingual_str& title, int progress_percent, bool resume_possible) override + { + std::cout << "Progress: " << title.original << ", " << progress_percent << ", " << resume_possible << std::endl; + } }; auto notifications = std::make_unique(); diff --git a/src/kernel/notifications_interface.h b/src/kernel/notifications_interface.h index 7f88176d03c..1d5643ca074 100644 --- a/src/kernel/notifications_interface.h +++ b/src/kernel/notifications_interface.h @@ -6,9 +6,11 @@ #define BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H #include +#include class CBlockIndex; enum class SynchronizationState; +struct bilingual_str; namespace kernel { @@ -23,6 +25,7 @@ public: virtual void blockTip(SynchronizationState state, CBlockIndex& index) {} virtual void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {} + virtual void progress(const bilingual_str& title, int progress_percent, bool resume_possible) {} }; } // namespace kernel diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index 40b609d0691..8f997b05947 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -253,7 +253,7 @@ ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager& chainman, const C "Only rebuild the block database if you are sure that your computer's date and time are correct")}; } - VerifyDBResult result = CVerifyDB().VerifyDB( + VerifyDBResult result = CVerifyDB(chainman.GetNotifications()).VerifyDB( *chainstate, chainman.GetConsensus(), chainstate->CoinsDB(), options.check_level, options.check_blocks); diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp index 1e4bc20f2f9..9efbc6c4cac 100644 --- a/src/node/kernel_notifications.cpp +++ b/src/node/kernel_notifications.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace node { @@ -18,4 +19,9 @@ void KernelNotifications::headerTip(SynchronizationState state, int64_t height, uiInterface.NotifyHeaderTip(state, height, timestamp, presync); } +void KernelNotifications::progress(const bilingual_str& title, int progress_percent, bool resume_possible) +{ + uiInterface.ShowProgress(title.translated, progress_percent, resume_possible); +} + } // namespace node diff --git a/src/node/kernel_notifications.h b/src/node/kernel_notifications.h index 1507c3214a2..ecd21c3a581 100644 --- a/src/node/kernel_notifications.h +++ b/src/node/kernel_notifications.h @@ -8,9 +8,11 @@ #include #include +#include class CBlockIndex; enum class SynchronizationState; +struct bilingual_str; namespace node { class KernelNotifications : public kernel::Notifications @@ -19,6 +21,8 @@ public: void blockTip(SynchronizationState state, CBlockIndex& index) override; void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override; + + void progress(const bilingual_str& title, int progress_percent, bool resume_possible) override; }; } // namespace node diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 72866532d2a..88370b59259 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1123,7 +1123,7 @@ static RPCHelpMan verifychain() LOCK(cs_main); Chainstate& active_chainstate = chainman.ActiveChainstate(); - return CVerifyDB().VerifyDB( + return CVerifyDB(chainman.GetNotifications()).VerifyDB( active_chainstate, chainman.GetParams().GetConsensus(), active_chainstate.CoinsTip(), check_level, check_depth) == VerifyDBResult::SUCCESS; }, }; diff --git a/src/validation.cpp b/src/validation.cpp index 21592709439..46b5b3e8ef1 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,7 @@ using kernel::CCoinsStats; using kernel::CoinStatsHashType; using kernel::ComputeUTXOStats; using kernel::LoadMempool; +using kernel::Notifications; using fsbridge::FopenFn; using node::BlockManager; @@ -4145,14 +4147,15 @@ bool Chainstate::LoadChainTip() return true; } -CVerifyDB::CVerifyDB() +CVerifyDB::CVerifyDB(Notifications& notifications) + : m_notifications{notifications} { - uiInterface.ShowProgress(_("Verifying blocks…").translated, 0, false); + m_notifications.progress(_("Verifying blocks…"), 0, false); } CVerifyDB::~CVerifyDB() { - uiInterface.ShowProgress("", 100, false); + m_notifications.progress(bilingual_str{}, 100, false); } VerifyDBResult CVerifyDB::VerifyDB( @@ -4192,7 +4195,7 @@ VerifyDBResult CVerifyDB::VerifyDB( LogPrintf("Verification progress: %d%%\n", percentageDone); reportDone = percentageDone / 10; } - uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false); + m_notifications.progress(_("Verifying blocks…"), percentageDone, false); if (pindex->nHeight <= chainstate.m_chain.Height() - nCheckDepth) { break; } @@ -4268,7 +4271,7 @@ VerifyDBResult CVerifyDB::VerifyDB( LogPrintf("Verification progress: %d%%\n", percentageDone); reportDone = percentageDone / 10; } - uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false); + m_notifications.progress(_("Verifying blocks…"), percentageDone, false); pindex = chainstate.m_chain.Next(pindex); CBlock block; if (!chainstate.m_blockman.ReadBlockFromDisk(block, *pindex)) { @@ -4327,7 +4330,7 @@ bool Chainstate::ReplayBlocks() if (hashHeads.empty()) return true; // We're already in a consistent state. if (hashHeads.size() != 2) return error("ReplayBlocks(): unknown inconsistent state"); - uiInterface.ShowProgress(_("Replaying blocks…").translated, 0, false); + m_chainman.GetNotifications().progress(_("Replaying blocks…"), 0, false); LogPrintf("Replaying blocks\n"); const CBlockIndex* pindexOld = nullptr; // Old tip during the interrupted flush. @@ -4374,13 +4377,13 @@ bool Chainstate::ReplayBlocks() const CBlockIndex& pindex{*Assert(pindexNew->GetAncestor(nHeight))}; LogPrintf("Rolling forward %s (%i)\n", pindex.GetBlockHash().ToString(), nHeight); - uiInterface.ShowProgress(_("Replaying blocks…").translated, (int) ((nHeight - nForkHeight) * 100.0 / (pindexNew->nHeight - nForkHeight)) , false); + m_chainman.GetNotifications().progress(_("Replaying blocks…"), (int)((nHeight - nForkHeight) * 100.0 / (pindexNew->nHeight - nForkHeight)), false); if (!RollforwardBlock(&pindex, cache)) return false; } cache.SetBestBlock(pindexNew->GetBlockHash()); cache.Flush(); - uiInterface.ShowProgress("", 100, false); + m_chainman.GetNotifications().progress(bilingual_str{}, 100, false); return true; } diff --git a/src/validation.h b/src/validation.h index 352056f0636..444fe72db4e 100644 --- a/src/validation.h +++ b/src/validation.h @@ -364,9 +364,13 @@ enum class VerifyDBResult { }; /** RAII wrapper for VerifyDB: Verify consistency of the block and coin databases */ -class CVerifyDB { +class CVerifyDB +{ +private: + kernel::Notifications& m_notifications; + public: - CVerifyDB(); + explicit CVerifyDB(kernel::Notifications& notifications); ~CVerifyDB(); [[nodiscard]] VerifyDBResult VerifyDB( Chainstate& chainstate, From f871c69191dfe1331861ebcdbadb6bd47e45c8b1 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Mon, 8 May 2023 14:49:37 +0200 Subject: [PATCH 4/8] kernel: Add warning method to notifications This commit is part of the libbitcoinkernel project and seeks to remove the ChainstateManager's and, more generally, the kernel library's dependency on interface_ui with options methods in this and the following few commits. By removing interface_ui from the kernel library, its dependency on boost is reduced to just boost::multi_index. The DoWarning and AlertNotify functions are moved out of the validation.cpp file, which removes its dependency on interface_ui as well as util/system. --- src/bitcoin-chainstate.cpp | 4 +++ src/kernel/notifications_interface.h | 1 + src/node/kernel_notifications.cpp | 48 ++++++++++++++++++++++++++++ src/node/kernel_notifications.h | 2 ++ src/validation.cpp | 34 +------------------- 5 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index b949bafcc8e..6ee1ff45948 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -99,6 +99,10 @@ int main(int argc, char* argv[]) { std::cout << "Progress: " << title.original << ", " << progress_percent << ", " << resume_possible << std::endl; } + void warning(const bilingual_str& warning) override + { + std::cout << "Warning: " << warning.original << std::endl; + } }; auto notifications = std::make_unique(); diff --git a/src/kernel/notifications_interface.h b/src/kernel/notifications_interface.h index 1d5643ca074..48248e9aa0b 100644 --- a/src/kernel/notifications_interface.h +++ b/src/kernel/notifications_interface.h @@ -26,6 +26,7 @@ public: virtual void blockTip(SynchronizationState state, CBlockIndex& index) {} virtual void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {} virtual void progress(const bilingual_str& title, int progress_percent, bool resume_possible) {} + virtual void warning(const bilingual_str& warning) {} }; } // namespace kernel diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp index 9efbc6c4cac..2bc4544aee4 100644 --- a/src/node/kernel_notifications.cpp +++ b/src/node/kernel_notifications.cpp @@ -4,8 +4,51 @@ #include +#if defined(HAVE_CONFIG_H) +#include +#endif + +#include #include +#include +#include +#include #include +#include + +#include +#include +#include + +static void AlertNotify(const std::string& strMessage) +{ + uiInterface.NotifyAlertChanged(); +#if HAVE_SYSTEM + std::string strCmd = gArgs.GetArg("-alertnotify", ""); + if (strCmd.empty()) return; + + // Alert text should be plain ascii coming from a trusted source, but to + // be safe we first strip anything not in safeChars, then add single quotes around + // the whole string before passing it to the shell: + std::string singleQuote("'"); + std::string safeStatus = SanitizeString(strMessage); + safeStatus = singleQuote+safeStatus+singleQuote; + ReplaceAll(strCmd, "%s", safeStatus); + + std::thread t(runCommand, strCmd); + t.detach(); // thread runs free +#endif +} + +static void DoWarning(const bilingual_str& warning) +{ + static bool fWarned = false; + SetMiscWarning(warning); + if (!fWarned) { + AlertNotify(warning.original); + fWarned = true; + } +} namespace node { @@ -24,4 +67,9 @@ void KernelNotifications::progress(const bilingual_str& title, int progress_perc uiInterface.ShowProgress(title.translated, progress_percent, resume_possible); } +void KernelNotifications::warning(const bilingual_str& warning) +{ + DoWarning(warning); +} + } // namespace node diff --git a/src/node/kernel_notifications.h b/src/node/kernel_notifications.h index ecd21c3a581..3e665bbf14e 100644 --- a/src/node/kernel_notifications.h +++ b/src/node/kernel_notifications.h @@ -23,6 +23,8 @@ public: void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override; void progress(const bilingual_str& title, int progress_percent, bool resume_possible) override; + + void warning(const bilingual_str& warning) override; }; } // namespace node diff --git a/src/validation.cpp b/src/validation.cpp index 46b5b3e8ef1..86c5c4d1619 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -53,7 +52,6 @@ #include #include #include -#include #include #include #include @@ -1641,26 +1639,6 @@ bool Chainstate::IsInitialBlockDownload() const return false; } -static void AlertNotify(const std::string& strMessage) -{ - uiInterface.NotifyAlertChanged(); -#if HAVE_SYSTEM - std::string strCmd = gArgs.GetArg("-alertnotify", ""); - if (strCmd.empty()) return; - - // Alert text should be plain ascii coming from a trusted source, but to - // be safe we first strip anything not in safeChars, then add single quotes around - // the whole string before passing it to the shell: - std::string singleQuote("'"); - std::string safeStatus = SanitizeString(strMessage); - safeStatus = singleQuote+safeStatus+singleQuote; - ReplaceAll(strCmd, "%s", safeStatus); - - std::thread t(runCommand, strCmd); - t.detach(); // thread runs free -#endif -} - void Chainstate::CheckForkWarningConditions() { AssertLockHeld(cs_main); @@ -2601,16 +2579,6 @@ void Chainstate::PruneAndFlush() } } -static void DoWarning(const bilingual_str& warning) -{ - static bool fWarned = false; - SetMiscWarning(warning); - if (!fWarned) { - AlertNotify(warning.original); - fWarned = true; - } -} - /** Private helper function that concatenates warning messages. */ static void AppendWarning(bilingual_str& res, const bilingual_str& warn) { @@ -2677,7 +2645,7 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew) if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) { const bilingual_str warning = strprintf(_("Unknown new rules activated (versionbit %i)"), bit); if (state == ThresholdState::ACTIVE) { - DoWarning(warning); + m_chainman.GetNotifications().warning(warning); } else { AppendWarning(warning_messages, warning); } From 9ec5da36b62276ae22e348f26f88aaf646357d6d Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Sat, 6 May 2023 22:14:11 +0200 Subject: [PATCH 5/8] refactor: Move ScheduleBatchPriority to its own file With the previous move of AlertNotify out of the validation file, and thus out of the kernel library, ScheduleBatchPriority is the last remaining function used by the kernel library from util/system. Move it to its own file, such that util/system can be moved out of the util library in the following few commits. Moving util/system out of the kernel library removes further networking as well as shell related code from it. --- src/Makefile.am | 4 +++- src/node/blockstorage.cpp | 1 + src/util/batchpriority.cpp | 26 ++++++++++++++++++++++++++ src/util/batchpriority.h | 15 +++++++++++++++ src/util/system.cpp | 18 ------------------ src/util/system.h | 7 ------- 6 files changed, 45 insertions(+), 26 deletions(-) create mode 100644 src/util/batchpriority.cpp create mode 100644 src/util/batchpriority.h diff --git a/src/Makefile.am b/src/Makefile.am index 2bbd3436577..9764df7fbc6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -280,6 +280,7 @@ BITCOIN_CORE_H = \ txrequest.h \ undo.h \ util/asmap.h \ + util/batchpriority.h \ util/bip32.h \ util/bitdeque.h \ util/bytevectorhash.h \ @@ -711,6 +712,7 @@ libbitcoin_util_a_SOURCES = \ support/cleanse.cpp \ sync.cpp \ util/asmap.cpp \ + util/batchpriority.cpp \ util/bip32.cpp \ util/bytevectorhash.cpp \ util/chaintype.cpp \ @@ -963,6 +965,7 @@ libbitcoinkernel_la_SOURCES = \ txdb.cpp \ txmempool.cpp \ uint256.cpp \ + util/batchpriority.cpp \ util/chaintype.cpp \ util/check.cpp \ util/exception.cpp \ @@ -978,7 +981,6 @@ libbitcoinkernel_la_SOURCES = \ util/string.cpp \ util/syscall_sandbox.cpp \ util/syserror.cpp \ - util/system.cpp \ util/thread.cpp \ util/threadnames.cpp \ util/time.cpp \ diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index f8d4e6c1da5..a97f837e285 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/src/util/batchpriority.cpp b/src/util/batchpriority.cpp new file mode 100644 index 00000000000..c73aef1eb48 --- /dev/null +++ b/src/util/batchpriority.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include + +#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) +#include +#include +#endif + +#ifndef WIN32 +#include +#endif + +void ScheduleBatchPriority() +{ +#ifdef SCHED_BATCH + const static sched_param param{}; + const int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m); + if (rc != 0) { + LogPrintf("Failed to pthread_setschedparam: %s\n", SysErrorString(rc)); + } +#endif +} diff --git a/src/util/batchpriority.h b/src/util/batchpriority.h new file mode 100644 index 00000000000..5ffc8dd684d --- /dev/null +++ b/src/util/batchpriority.h @@ -0,0 +1,15 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_UTIL_BATCHPRIORITY_H +#define BITCOIN_UTIL_BATCHPRIORITY_H + +/** + * On platforms that support it, tell the kernel the calling thread is + * CPU-intensive and non-interactive. See SCHED_BATCH in sched(7) for details. + * + */ +void ScheduleBatchPriority(); + +#endif // BITCOIN_UTIL_BATCHPRIORITY_H diff --git a/src/util/system.cpp b/src/util/system.cpp index 598e6adb886..0b342c03a01 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -7,16 +7,9 @@ #include #include -#include #include -#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) -#include -#include -#endif - #ifndef WIN32 -#include #include #else #include @@ -112,14 +105,3 @@ int64_t GetStartupTime() { return nStartupTime; } - -void ScheduleBatchPriority() -{ -#ifdef SCHED_BATCH - const static sched_param param{}; - const int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m); - if (rc != 0) { - LogPrintf("Failed to pthread_setschedparam: %s\n", SysErrorString(rc)); - } -#endif -} diff --git a/src/util/system.h b/src/util/system.h index e2fc3450f69..a8c049ad441 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -36,13 +36,6 @@ void runCommand(const std::string& strCommand); */ int GetNumCores(); -/** - * On platforms that support it, tell the kernel the calling thread is - * CPU-intensive and non-interactive. See SCHED_BATCH in sched(7) for details. - * - */ -void ScheduleBatchPriority(); - namespace util { //! Simplification of std insertion From 44de325d95447498036479c3112ba741caf45bf6 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Wed, 17 May 2023 17:40:32 +0200 Subject: [PATCH 6/8] refactor: Split util::insert into its own file --- src/Makefile.am | 1 + src/util/insert.h | 24 ++++++++++++++++++++++++ src/util/system.h | 10 ---------- src/wallet/coinselection.h | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 src/util/insert.h diff --git a/src/Makefile.am b/src/Makefile.am index 9764df7fbc6..c952d737584 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -297,6 +297,7 @@ BITCOIN_CORE_H = \ util/golombrice.h \ util/hash_type.h \ util/hasher.h \ + util/insert.h \ util/macros.h \ util/message.h \ util/moneystr.h \ diff --git a/src/util/insert.h b/src/util/insert.h new file mode 100644 index 00000000000..5332eca60a3 --- /dev/null +++ b/src/util/insert.h @@ -0,0 +1,24 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_UTIL_INSERT_H +#define BITCOIN_UTIL_INSERT_H + +#include + +namespace util { + +//! Simplification of std insertion +template +inline void insert(Tdst& dst, const Tsrc& src) { + dst.insert(dst.begin(), src.begin(), src.end()); +} +template +inline void insert(std::set& dst, const Tsrc& src) { + dst.insert(src.begin(), src.end()); +} + +} // namespace util + +#endif // BITCOIN_UTIL_INSERT_H diff --git a/src/util/system.h b/src/util/system.h index a8c049ad441..463713d565a 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -38,16 +38,6 @@ int GetNumCores(); namespace util { -//! Simplification of std insertion -template -inline void insert(Tdst& dst, const Tsrc& src) { - dst.insert(dst.begin(), src.begin(), src.end()); -} -template -inline void insert(std::set& dst, const Tsrc& src) { - dst.insert(src.begin(), src.end()); -} - /** * Helper function to access the contained object of a std::any instance. * Returns a pointer to the object if passed instance has a value and the type diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h index 723f5bbfb3a..432d7d14314 100644 --- a/src/wallet/coinselection.h +++ b/src/wallet/coinselection.h @@ -11,8 +11,8 @@ #include #include #include -#include #include +#include #include #include From 7eee356c0a7fefd70c8de21689efa335f52a69ba Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Wed, 17 May 2023 17:47:25 +0200 Subject: [PATCH 7/8] refactor: Split util::AnyPtr into its own file --- src/Makefile.am | 1 + src/rest.cpp | 2 +- src/rpc/node.cpp | 2 +- src/rpc/server_util.cpp | 2 +- src/util/any.h | 26 ++++++++++++++++++++++++++ src/util/system.h | 17 ----------------- src/wallet/rpc/util.cpp | 2 +- 7 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 src/util/any.h diff --git a/src/Makefile.am b/src/Makefile.am index c952d737584..e2c7af8c583 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -279,6 +279,7 @@ BITCOIN_CORE_H = \ txorphanage.h \ txrequest.h \ undo.h \ + util/any.h \ util/asmap.h \ util/batchpriority.h \ util/bip32.h \ diff --git a/src/rest.cpp b/src/rest.cpp index dae064f89d5..c9e61d70bd0 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -24,8 +24,8 @@ #include #include #include +#include #include -#include #include #include diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp index ca8db0f82a8..45d46d223ba 100644 --- a/src/rpc/node.cpp +++ b/src/rpc/node.cpp @@ -19,9 +19,9 @@ #include #include #include +#include #include #include -#include #include #ifdef HAVE_MALLOC_INFO diff --git a/src/rpc/server_util.cpp b/src/rpc/server_util.cpp index 13d007b4962..1d4afb3758c 100644 --- a/src/rpc/server_util.cpp +++ b/src/rpc/server_util.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/util/any.h b/src/util/any.h new file mode 100644 index 00000000000..4562c5bd8aa --- /dev/null +++ b/src/util/any.h @@ -0,0 +1,26 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_UTIL_ANY_H +#define BITCOIN_UTIL_ANY_H + +#include + +namespace util { + +/** + * Helper function to access the contained object of a std::any instance. + * Returns a pointer to the object if passed instance has a value and the type + * matches, nullptr otherwise. + */ +template +T* AnyPtr(const std::any& any) noexcept +{ + T* const* ptr = std::any_cast(&any); + return ptr ? *ptr : nullptr; +} + +} // namespace util + +#endif // BITCOIN_UTIL_ANY_H diff --git a/src/util/system.h b/src/util/system.h index 463713d565a..719cd28f979 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -36,20 +35,4 @@ void runCommand(const std::string& strCommand); */ int GetNumCores(); -namespace util { - -/** - * Helper function to access the contained object of a std::any instance. - * Returns a pointer to the object if passed instance has a value and the type - * matches, nullptr otherwise. - */ -template -T* AnyPtr(const std::any& any) noexcept -{ - T* const* ptr = std::any_cast(&any); - return ptr ? *ptr : nullptr; -} - -} // namespace util - #endif // BITCOIN_UTIL_SYSTEM_H diff --git a/src/wallet/rpc/util.cpp b/src/wallet/rpc/util.cpp index 4ff44b84b07..06ec7db1bc2 100644 --- a/src/wallet/rpc/util.cpp +++ b/src/wallet/rpc/util.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include From 7d3b35004b039f2bd606bb46a540de7babdbc41e Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Mon, 8 May 2023 11:32:13 +0200 Subject: [PATCH 8/8] refactor: Move system from util to common library Since the kernel library no longer depends on the system file, move it to the common library instead in accordance to the diagram in doc/design/libraries.md. --- src/Makefile.am | 4 ++-- src/banman.cpp | 2 +- src/bench/checkqueue.cpp | 2 +- src/bitcoin-cli.cpp | 2 +- src/bitcoin-tx.cpp | 2 +- src/bitcoin-util.cpp | 2 +- src/bitcoin-wallet.cpp | 2 +- src/bitcoind.cpp | 2 +- src/blockencodings.cpp | 4 ++-- src/{util => common}/system.cpp | 2 +- src/{util => common}/system.h | 6 +++--- src/core_write.cpp | 2 +- src/external_signer.h | 2 +- src/i2p.cpp | 2 +- src/init.cpp | 2 +- src/ipc/interfaces.cpp | 2 +- src/mapport.cpp | 2 +- src/net_permissions.cpp | 2 +- src/node/blockstorage.cpp | 1 - src/node/kernel_notifications.cpp | 2 +- src/node/txreconciliation.cpp | 2 +- src/policy/fees.cpp | 2 +- src/protocol.cpp | 2 +- src/qt/bitcoin.cpp | 2 +- src/qt/bitcoingui.cpp | 5 +++-- src/qt/clientmodel.cpp | 2 +- src/qt/optionsdialog.cpp | 6 +++--- src/qt/rpcconsole.cpp | 2 +- src/qt/splashscreen.cpp | 2 +- src/qt/test/rpcnestedtests.cpp | 4 ++-- src/qt/transactiondesc.cpp | 2 +- src/rpc/external_signer.cpp | 2 +- src/rpc/mining.cpp | 2 +- src/rpc/request.cpp | 2 +- src/rpc/server.cpp | 2 +- src/script/sigcache.cpp | 2 +- src/signet.cpp | 2 +- src/test/allocator_tests.cpp | 2 +- src/test/bloom_tests.cpp | 2 +- src/test/fuzz/integer.cpp | 2 +- src/test/fuzz/string.cpp | 2 +- src/test/fuzz/system.cpp | 4 ++-- src/test/key_tests.cpp | 2 +- src/test/mempool_tests.cpp | 2 +- src/test/miner_tests.cpp | 2 +- src/test/miniminer_tests.cpp | 1 - src/test/rbf_tests.cpp | 2 +- src/test/script_tests.cpp | 2 +- src/test/sighash_tests.cpp | 2 +- src/test/sock_tests.cpp | 2 +- src/test/util/setup_common.cpp | 2 +- src/test/util_tests.cpp | 2 +- src/txmempool.cpp | 2 +- src/util/sock.cpp | 2 +- src/wallet/bdb.h | 2 +- src/wallet/coinselection.cpp | 2 +- src/wallet/crypter.cpp | 2 +- src/wallet/external_signer_scriptpubkeyman.cpp | 2 +- src/wallet/feebumper.cpp | 2 +- src/wallet/spend.cpp | 2 +- src/wallet/walletdb.cpp | 2 +- src/warnings.cpp | 2 +- 62 files changed, 70 insertions(+), 71 deletions(-) rename src/{util => common}/system.cpp (99%) rename src/{util => common}/system.h (89%) diff --git a/src/Makefile.am b/src/Makefile.am index e2c7af8c583..0b25ef9c6b4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -143,6 +143,7 @@ BITCOIN_CORE_H = \ compat/compat.h \ compat/cpuid.h \ compat/endian.h \ + common/system.h \ compressor.h \ consensus/consensus.h \ consensus/tx_check.h \ @@ -314,7 +315,6 @@ BITCOIN_CORE_H = \ util/string.h \ util/syscall_sandbox.h \ util/syserror.h \ - util/system.h \ util/thread.h \ util/threadinterrupt.h \ util/threadnames.h \ @@ -663,6 +663,7 @@ libbitcoin_common_a_SOURCES = \ common/init.cpp \ common/interfaces.cpp \ common/run_command.cpp \ + common/system.cpp \ compressor.cpp \ core_read.cpp \ core_write.cpp \ @@ -728,7 +729,6 @@ libbitcoin_util_a_SOURCES = \ util/hasher.cpp \ util/sock.cpp \ util/syserror.cpp \ - util/system.cpp \ util/message.cpp \ util/moneystr.cpp \ util/rbf.cpp \ diff --git a/src/banman.cpp b/src/banman.cpp index 5b2049d6548..a96b7e3c536 100644 --- a/src/banman.cpp +++ b/src/banman.cpp @@ -5,11 +5,11 @@ #include +#include #include #include #include #include -#include #include #include diff --git a/src/bench/checkqueue.cpp b/src/bench/checkqueue.cpp index 8ad6fde6bff..70e0b86ebaa 100644 --- a/src/bench/checkqueue.cpp +++ b/src/bench/checkqueue.cpp @@ -4,11 +4,11 @@ #include #include +#include #include #include #include #include -#include #include diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 48dc11b95a5..45db7a9a66c 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +24,6 @@ #include #include #include -#include #include #include diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index e291f20a11c..0c25ddf3738 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -27,7 +28,6 @@ #include #include #include -#include #include #include diff --git a/src/bitcoin-util.cpp b/src/bitcoin-util.cpp index f62a9f7bbfb..582c18c9c60 100644 --- a/src/bitcoin-util.cpp +++ b/src/bitcoin-util.cpp @@ -12,11 +12,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp index 1863173aa88..d5dfbbec271 100644 --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -18,7 +19,6 @@ #include #include #include -#include #include #include diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index e476b060174..aefb130e9c5 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/src/blockencodings.cpp b/src/blockencodings.cpp index a29e4f794e9..9aa0a6ba204 100644 --- a/src/blockencodings.cpp +++ b/src/blockencodings.cpp @@ -3,16 +3,16 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include +#include #include #include -#include #include #include #include #include #include #include -#include #include diff --git a/src/util/system.cpp b/src/common/system.cpp similarity index 99% rename from src/util/system.cpp rename to src/common/system.cpp index 0b342c03a01..1d1c5fa56ad 100644 --- a/src/util/system.cpp +++ b/src/common/system.cpp @@ -3,7 +3,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include #include diff --git a/src/util/system.h b/src/common/system.h similarity index 89% rename from src/util/system.h rename to src/common/system.h index 719cd28f979..40206aaa01d 100644 --- a/src/util/system.h +++ b/src/common/system.h @@ -3,8 +3,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_UTIL_SYSTEM_H -#define BITCOIN_UTIL_SYSTEM_H +#ifndef BITCOIN_COMMON_SYSTEM_H +#define BITCOIN_COMMON_SYSTEM_H #if defined(HAVE_CONFIG_H) #include @@ -35,4 +35,4 @@ void runCommand(const std::string& strCommand); */ int GetNumCores(); -#endif // BITCOIN_UTIL_SYSTEM_H +#endif // BITCOIN_COMMON_SYSTEM_H diff --git a/src/core_write.cpp b/src/core_write.cpp index b0e3b0b3c43..54ca306f601 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -4,6 +4,7 @@ #include +#include #include #include #include @@ -17,7 +18,6 @@ #include #include #include -#include #include #include diff --git a/src/external_signer.h b/src/external_signer.h index 90f07478e3e..81a601811a6 100644 --- a/src/external_signer.h +++ b/src/external_signer.h @@ -5,8 +5,8 @@ #ifndef BITCOIN_EXTERNAL_SIGNER_H #define BITCOIN_EXTERNAL_SIGNER_H +#include #include -#include #include #include diff --git a/src/i2p.cpp b/src/i2p.cpp index c67b6ed185d..f03e375adfa 100644 --- a/src/i2p.cpp +++ b/src/i2p.cpp @@ -336,7 +336,7 @@ void Session::GenerateAndSavePrivateKey(const Sock& sock) { DestGenerate(sock); - // umask is set to 0077 in util/system.cpp, which is ok. + // umask is set to 0077 in common/system.cpp, which is ok. if (!WriteBinaryFile(m_private_key_file, std::string(m_private_key.begin(), m_private_key.end()))) { throw std::runtime_error( diff --git a/src/init.cpp b/src/init.cpp index 48492eab6b4..bb14d3dbfd8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -80,7 +81,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ipc/interfaces.cpp b/src/ipc/interfaces.cpp index d804d9d291f..e446cc98db5 100644 --- a/src/ipc/interfaces.cpp +++ b/src/ipc/interfaces.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include #include @@ -10,7 +11,6 @@ #include #include #include -#include #include #include diff --git a/src/mapport.cpp b/src/mapport.cpp index 994fd12cf50..76f8a4d0c91 100644 --- a/src/mapport.cpp +++ b/src/mapport.cpp @@ -9,12 +9,12 @@ #include #include +#include #include #include #include #include #include -#include #include #include diff --git a/src/net_permissions.cpp b/src/net_permissions.cpp index f829e56aa28..1e4ec5b529c 100644 --- a/src/net_permissions.cpp +++ b/src/net_permissions.cpp @@ -2,10 +2,10 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include #include -#include #include const std::vector NET_PERMISSIONS_DOC{ diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index a97f837e285..b7afa8a7c39 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp index 2bc4544aee4..926b157f3b1 100644 --- a/src/node/kernel_notifications.cpp +++ b/src/node/kernel_notifications.cpp @@ -9,10 +9,10 @@ #endif #include +#include #include #include #include -#include #include #include diff --git a/src/node/txreconciliation.cpp b/src/node/txreconciliation.cpp index 99387590743..d62046daaaa 100644 --- a/src/node/txreconciliation.cpp +++ b/src/node/txreconciliation.cpp @@ -4,9 +4,9 @@ #include +#include #include #include -#include #include #include diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 6121224979b..ae226f70114 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -19,7 +20,6 @@ #include #include #include -#include #include #include diff --git a/src/protocol.cpp b/src/protocol.cpp index 5725813b7e5..5ecaabec367 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -5,7 +5,7 @@ #include -#include +#include #include diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index d602d2c1ac2..e33753f5e77 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include #include #include #include diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index d26ef52eb43..f201d8fa011 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -30,16 +30,17 @@ #include #endif -#include #include #include +#include #include #include #include -#include #include #include +#include + #include #include #include diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index b22f1bc35c8..ff7405d1395 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -12,11 +12,11 @@ #include #include +#include #include #include #include #include -#include #include #include #include diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 6dec4b2e42e..ea624efeaa1 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -15,11 +15,11 @@ #include #include +#include #include -#include // for DEFAULT_SCRIPTCHECK_THREADS and MAX_SCRIPTCHECK_THREADS #include -#include // for -dbcache defaults -#include +#include +#include #include diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index bac64e3d5f6..90aae0219ee 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -21,7 +22,6 @@ #include #include #include -#include #include #include diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index 096f8a0dedc..8872f8be321 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -9,13 +9,13 @@ #include #include +#include #include #include #include #include #include #include -#include #include #include diff --git a/src/qt/test/rpcnestedtests.cpp b/src/qt/test/rpcnestedtests.cpp index 669a05fe0f2..72e80554255 100644 --- a/src/qt/test/rpcnestedtests.cpp +++ b/src/qt/test/rpcnestedtests.cpp @@ -4,12 +4,12 @@ #include +#include #include -#include #include +#include #include #include -#include #include diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 2461a069307..fa110cfbc9b 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -13,12 +13,12 @@ #include #include +#include #include #include #include #include #include -#include #include #include diff --git a/src/rpc/external_signer.cpp b/src/rpc/external_signer.cpp index ac135ba216a..310eec5f15e 100644 --- a/src/rpc/external_signer.cpp +++ b/src/rpc/external_signer.cpp @@ -3,12 +3,12 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include #include #include -#include #include #include diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 68017e5af25..eb61d58a336 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include #include #include #include diff --git a/src/rpc/request.cpp b/src/rpc/request.cpp index cf1b6cd92b8..4c67da8b70c 100644 --- a/src/rpc/request.cpp +++ b/src/rpc/request.cpp @@ -88,7 +88,7 @@ bool GenerateAuthCookie(std::string *cookie_out) std::string cookie = COOKIEAUTH_USER + ":" + HexStr(rand_pwd); /** the umask determines what permissions are used to create this file - - * these are set to 0077 in util/system.cpp. + * these are set to 0077 in common/system.cpp. */ std::ofstream file; fs::path filepath_tmp = GetAuthCookieFile(true); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 354f9490024..474b318c66b 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -6,13 +6,13 @@ #include #include +#include #include #include #include #include #include #include -#include #include #include diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index e52e8cd3090..7c6c282cc47 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -5,11 +5,11 @@ #include