From 4dfe383912761669a968f8535ed43437da160ec8 Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Wed, 18 Jun 2025 09:51:34 -0400 Subject: [PATCH] refactor: Convert ChainstateRole enum to struct Change ChainstateRole parameter passed to wallets and indexes. Wallets and indexes need to know whether chainstate is historical and whether it is fully validated. They should not be aware of the assumeutxo snapshot validation process. --- src/bench/wallet_create_tx.cpp | 4 +++- src/bench/wallet_migration.cpp | 1 + src/index/base.cpp | 18 ++++++++-------- src/index/base.h | 4 ++-- src/interfaces/chain.h | 8 ++++--- src/kernel/bitcoinkernel.cpp | 3 ++- src/kernel/chain.cpp | 16 ++++++++------ src/kernel/chain.h | 20 ++--------------- src/kernel/types.h | 30 ++++++++++++++++++++++++++ src/net_processing.cpp | 11 +++++----- src/node/blockstorage.cpp | 2 ++ src/node/interfaces.cpp | 6 ++++-- src/test/chainstate_write_tests.cpp | 6 ++++-- src/test/coinstatsindex_tests.cpp | 5 ++++- src/test/util/validation.cpp | 11 ++++++---- src/test/util/validation.h | 2 +- src/test/validation_block_tests.cpp | 3 ++- src/test/validationinterface_tests.cpp | 1 - src/validation.cpp | 12 ++++++----- src/validation.h | 5 ++++- src/validationinterface.cpp | 10 ++++++--- src/validationinterface.h | 12 ++++++----- src/wallet/wallet.cpp | 7 +++--- src/wallet/wallet.h | 2 +- src/zmq/zmqnotificationinterface.cpp | 8 ++++--- src/zmq/zmqnotificationinterface.h | 2 +- 26 files changed, 130 insertions(+), 79 deletions(-) create mode 100644 src/kernel/types.h diff --git a/src/bench/wallet_create_tx.cpp b/src/bench/wallet_create_tx.cpp index 7fb535f4c72..73ad0e7e568 100644 --- a/src/bench/wallet_create_tx.cpp +++ b/src/bench/wallet_create_tx.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,7 @@ #include #include +using kernel::ChainstateRole; using wallet::CWallet; using wallet::CreateMockableWalletDatabase; using wallet::WALLET_FLAG_DESCRIPTORS; @@ -101,7 +103,7 @@ void generateFakeBlock(const CChainParams& params, // notify wallet const auto& pindex = WITH_LOCK(::cs_main, return context.chainman->ActiveChain().Tip()); - wallet.blockConnected(ChainstateRole::NORMAL, kernel::MakeBlockInfo(pindex, &block)); + wallet.blockConnected(ChainstateRole{}, kernel::MakeBlockInfo(pindex, &block)); } struct PreSelectInputs { diff --git a/src/bench/wallet_migration.cpp b/src/bench/wallet_migration.cpp index 0ce23a49b4e..9d61b984792 100644 --- a/src/bench/wallet_migration.cpp +++ b/src/bench/wallet_migration.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/src/index/base.cpp b/src/index/base.cpp index a94b4ca7225..425f9f7eb18 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,8 @@ #include #include +using kernel::ChainstateRole; + constexpr uint8_t DB_BEST_BLOCK{'B'}; constexpr auto SYNC_LOG_INTERVAL{30s}; @@ -323,15 +326,13 @@ bool BaseIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_ti return true; } -void BaseIndex::BlockConnected(ChainstateRole role, const std::shared_ptr& block, const CBlockIndex* pindex) +void BaseIndex::BlockConnected(const ChainstateRole& role, const std::shared_ptr& block, const CBlockIndex* pindex) { - // Ignore events from the assumed-valid chain; we will process its blocks - // (sequentially) after it is fully verified by the background chainstate. This - // is to avoid any out-of-order indexing. + // Ignore events from not fully validated chains to avoid out-of-order indexing. // // TODO at some point we could parameterize whether a particular index can be // built out of order, but for now just do the conservative simple thing. - if (role == ChainstateRole::ASSUMEDVALID) { + if (!role.validated) { return; } @@ -377,11 +378,10 @@ void BaseIndex::BlockConnected(ChainstateRole role, const std::shared_ptr& block, const CBlockIndex* pindex) override; + void BlockConnected(const kernel::ChainstateRole& role, const std::shared_ptr& block, const CBlockIndex* pindex) override; - void ChainStateFlushed(ChainstateRole role, const CBlockLocator& locator) override; + void ChainStateFlushed(const kernel::ChainstateRole& role, const CBlockLocator& locator) override; /// Return custom notification options for index. [[nodiscard]] virtual interfaces::Chain::NotifyOptions CustomOptions() { return {}; } diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 40291d20513..1741721828c 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -30,10 +30,12 @@ class Coin; class uint256; enum class MemPoolRemovalReason; enum class RBFTransactionState; -enum class ChainstateRole; struct bilingual_str; struct CBlockLocator; struct FeeCalculation; +namespace kernel { +struct ChainstateRole; +} // namespace kernel namespace node { struct NodeContext; } // namespace node @@ -321,10 +323,10 @@ public: virtual ~Notifications() = default; virtual void transactionAddedToMempool(const CTransactionRef& tx) {} virtual void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) {} - virtual void blockConnected(ChainstateRole role, const BlockInfo& block) {} + virtual void blockConnected(const kernel::ChainstateRole& role, const BlockInfo& block) {} virtual void blockDisconnected(const BlockInfo& block) {} virtual void updatedBlockTip() {} - virtual void chainStateFlushed(ChainstateRole role, const CBlockLocator& locator) {} + virtual void chainStateFlushed(const kernel::ChainstateRole& role, const CBlockLocator& locator) {} }; //! Options specifying which chain notifications are required. diff --git a/src/kernel/bitcoinkernel.cpp b/src/kernel/bitcoinkernel.cpp index be7c22de998..3a36e2c8e76 100644 --- a/src/kernel/bitcoinkernel.cpp +++ b/src/kernel/bitcoinkernel.cpp @@ -51,6 +51,7 @@ #include #include +using kernel::ChainstateRole; using util::ImmediateTaskRunner; // Define G_TRANSLATION_FUN symbol in libbitcoinkernel library so users of the @@ -359,7 +360,7 @@ protected: } } - void BlockConnected(ChainstateRole role, const std::shared_ptr& block, const CBlockIndex* pindex) override + void BlockConnected(const ChainstateRole& role, const std::shared_ptr& block, const CBlockIndex* pindex) override { if (m_cbs.block_connected) { m_cbs.block_connected(m_cbs.user_data, diff --git a/src/kernel/chain.cpp b/src/kernel/chain.cpp index 318c956b386..52da2e3c667 100644 --- a/src/kernel/chain.cpp +++ b/src/kernel/chain.cpp @@ -5,11 +5,14 @@ #include #include #include +#include #include #include class CBlock; +using kernel::ChainstateRole; + namespace kernel { interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* index, const CBlock* data) { @@ -25,14 +28,15 @@ interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* index, const CBlock* data info.data = data; return info; } -} // namespace kernel std::ostream& operator<<(std::ostream& os, const ChainstateRole& role) { - switch(role) { - case ChainstateRole::NORMAL: os << "normal"; break; - case ChainstateRole::ASSUMEDVALID: os << "assumedvalid"; break; - case ChainstateRole::BACKGROUND: os << "background"; break; - default: os.setstate(std::ios_base::failbit); + if (!role.validated) { + os << "assumedvalid"; + } else if (role.historical) { + os << "background"; + } else { + os << "normal"; } return os; } +} // namespace kernel diff --git a/src/kernel/chain.h b/src/kernel/chain.h index feba24a557e..7dbd0eb6f2a 100644 --- a/src/kernel/chain.h +++ b/src/kernel/chain.h @@ -14,26 +14,10 @@ struct BlockInfo; } // namespace interfaces namespace kernel { +struct ChainstateRole; //! Return data from block index. interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* block_index, const CBlock* data = nullptr); - +std::ostream& operator<<(std::ostream& os, const ChainstateRole& role); } // namespace kernel -//! This enum describes the various roles a specific Chainstate instance can take. -//! Other parts of the system sometimes need to vary in behavior depending on the -//! existence of a background validation chainstate, e.g. when building indexes. -enum class ChainstateRole { - // Single chainstate in use, "normal" IBD mode. - NORMAL, - - // Doing IBD-style validation in the background. Implies use of an assumed-valid - // chainstate. - BACKGROUND, - - // Active assumed-valid chainstate. Implies use of a background IBD chainstate. - ASSUMEDVALID, -}; - -std::ostream& operator<<(std::ostream& os, const ChainstateRole& role); - #endif // BITCOIN_KERNEL_CHAIN_H diff --git a/src/kernel/types.h b/src/kernel/types.h new file mode 100644 index 00000000000..164d4cfda81 --- /dev/null +++ b/src/kernel/types.h @@ -0,0 +1,30 @@ +// Copyright (c) The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +//! @file kernel/types.h is a home for simple enum and struct type definitions +//! that can be used internally by functions in the libbitcoin_kernel library, +//! but also used externally by node, wallet, and GUI code. +//! +//! This file is intended to define only simple types that do not have external +//! dependencies. More complicated types should be defined in dedicated header +//! files. + +#ifndef BITCOIN_KERNEL_TYPES_H +#define BITCOIN_KERNEL_TYPES_H + +namespace kernel { +//! Information about chainstate that notifications are sent from. +struct ChainstateRole { + //! Whether this is a notification from a chainstate that's been fully + //! validated starting from the genesis block. False if it is from an + //! assumeutxo snapshot chainstate that has not been validated yet. + bool validated{true}; + + //! Whether this is a historical chainstate downloading old blocks to + //! validate an assumeutxo snapshot, not syncing to the network tip. + bool historical{false}; +}; +} // namespace kernel + +#endif // BITCOIN_KERNEL_TYPES_H diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 09b2f221c1e..d7fd2879880 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -85,6 +85,7 @@ #include #include +using kernel::ChainstateRole; using namespace util::hex_literals; TRACEPOINT_SEMAPHORE(net, inbound_message); @@ -507,7 +508,7 @@ public: /** Overridden from CValidationInterface. */ void ActiveTipChange(const CBlockIndex& new_tip, bool) override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex); - void BlockConnected(ChainstateRole role, const std::shared_ptr& pblock, const CBlockIndex* pindexConnected) override + void BlockConnected(const ChainstateRole& role, const std::shared_ptr& pblock, const CBlockIndex* pindexConnected) override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex); void BlockDisconnected(const std::shared_ptr &block, const CBlockIndex* pindex) override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex); @@ -1946,7 +1947,7 @@ void PeerManagerImpl::ActiveTipChange(const CBlockIndex& new_tip, bool is_ibd) * possibly reduce dynamic block stalling timeout. */ void PeerManagerImpl::BlockConnected( - ChainstateRole role, + const ChainstateRole& role, const std::shared_ptr& pblock, const CBlockIndex* pindex) { @@ -1965,8 +1966,8 @@ void PeerManagerImpl::BlockConnected( } // The following task can be skipped since we don't maintain a mempool for - // the ibd/background chainstate. - if (role == ChainstateRole::BACKGROUND) { + // the historical chainstate. + if (role.historical) { return; } LOCK(m_tx_download_mutex); diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index a5984df6171..c5d26e5cbb0 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -12,9 +12,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index ac817e01b15..dfcf66290c8 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -81,6 +81,7 @@ using interfaces::MakeSignalHandler; using interfaces::Mining; using interfaces::Node; using interfaces::WalletLoader; +using kernel::ChainstateRole; using node::BlockAssembler; using node::BlockWaitOptions; using util::Join; @@ -461,7 +462,7 @@ public: { m_notifications->transactionRemovedFromMempool(tx, reason); } - void BlockConnected(ChainstateRole role, const std::shared_ptr& block, const CBlockIndex* index) override + void BlockConnected(const ChainstateRole& role, const std::shared_ptr& block, const CBlockIndex* index) override { m_notifications->blockConnected(role, kernel::MakeBlockInfo(index, block.get())); } @@ -473,7 +474,8 @@ public: { m_notifications->updatedBlockTip(); } - void ChainStateFlushed(ChainstateRole role, const CBlockLocator& locator) override { + void ChainStateFlushed(const ChainstateRole& role, const CBlockLocator& locator) override + { m_notifications->chainStateFlushed(role, locator); } std::shared_ptr m_notifications; diff --git a/src/test/chainstate_write_tests.cpp b/src/test/chainstate_write_tests.cpp index e1b82ebc121..5c459227763 100644 --- a/src/test/chainstate_write_tests.cpp +++ b/src/test/chainstate_write_tests.cpp @@ -8,6 +8,8 @@ #include +using kernel::ChainstateRole; + // Taken from validation.cpp static constexpr auto DATABASE_WRITE_INTERVAL_MIN{50min}; static constexpr auto DATABASE_WRITE_INTERVAL_MAX{70min}; @@ -18,7 +20,7 @@ BOOST_FIXTURE_TEST_CASE(chainstate_write_interval, TestingSetup) { struct TestSubscriber final : CValidationInterface { bool m_did_flush{false}; - void ChainStateFlushed(ChainstateRole, const CBlockLocator&) override + void ChainStateFlushed(const ChainstateRole&, const CBlockLocator&) override { m_did_flush = true; } @@ -55,7 +57,7 @@ BOOST_FIXTURE_TEST_CASE(write_during_multiblock_activation, TestChain100Setup) { const CBlockIndex* m_tip{nullptr}; const CBlockIndex* m_flushed_at_block{nullptr}; - void ChainStateFlushed(ChainstateRole, const CBlockLocator&) override + void ChainStateFlushed(const ChainstateRole&, const CBlockLocator&) override { m_flushed_at_block = m_tip; } diff --git a/src/test/coinstatsindex_tests.cpp b/src/test/coinstatsindex_tests.cpp index 7d54f0fdf15..d55fb1b05fc 100644 --- a/src/test/coinstatsindex_tests.cpp +++ b/src/test/coinstatsindex_tests.cpp @@ -6,12 +6,15 @@ #include #include #include +#include #include #include #include #include +using kernel::ChainstateRole; + BOOST_AUTO_TEST_SUITE(coinstatsindex_tests) BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup) @@ -101,7 +104,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_unclean_shutdown, TestChain100Setup) // Send block connected notification, then stop the index without // sending a chainstate flushed notification. Prior to #24138, this // would cause the index to be corrupted and fail to reload. - ValidationInterfaceTest::BlockConnected(ChainstateRole::NORMAL, index, new_block, new_block_index); + ValidationInterfaceTest::BlockConnected(ChainstateRole{}, index, new_block, new_block_index); index.Stop(); } diff --git a/src/test/util/validation.cpp b/src/test/util/validation.cpp index ce558078a6d..ae8642f9482 100644 --- a/src/test/util/validation.cpp +++ b/src/test/util/validation.cpp @@ -9,6 +9,8 @@ #include #include +using kernel::ChainstateRole; + void TestChainstateManager::DisableNextWrite() { struct TestChainstate : public Chainstate { @@ -18,6 +20,7 @@ void TestChainstateManager::DisableNextWrite() static_cast(cs)->ResetNextWrite(); } } + void TestChainstateManager::ResetIbd() { m_cached_finished_ibd = false; @@ -32,10 +35,10 @@ void TestChainstateManager::JumpOutOfIbd() } void ValidationInterfaceTest::BlockConnected( - ChainstateRole role, - CValidationInterface& obj, - const std::shared_ptr& block, - const CBlockIndex* pindex) + const ChainstateRole& role, + CValidationInterface& obj, + const std::shared_ptr& block, + const CBlockIndex* pindex) { obj.BlockConnected(role, block, pindex); } diff --git a/src/test/util/validation.h b/src/test/util/validation.h index f9c6a8ac02a..4a24c97ed24 100644 --- a/src/test/util/validation.h +++ b/src/test/util/validation.h @@ -22,7 +22,7 @@ class ValidationInterfaceTest { public: static void BlockConnected( - ChainstateRole role, + const kernel::ChainstateRole& role, CValidationInterface& obj, const std::shared_ptr& block, const CBlockIndex* pindex); diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp index a0b23f5d3b7..9f574be86ef 100644 --- a/src/test/validation_block_tests.cpp +++ b/src/test/validation_block_tests.cpp @@ -19,6 +19,7 @@ #include +using kernel::ChainstateRole; using node::BlockAssembler; namespace validation_block_tests { @@ -43,7 +44,7 @@ struct TestSubscriber final : public CValidationInterface { BOOST_CHECK_EQUAL(m_expected_tip, pindexNew->GetBlockHash()); } - void BlockConnected(ChainstateRole role, const std::shared_ptr& block, const CBlockIndex* pindex) override + void BlockConnected(const ChainstateRole& role, const std::shared_ptr& block, const CBlockIndex* pindex) override { BOOST_CHECK_EQUAL(m_expected_tip, block->hashPrevBlock); BOOST_CHECK_EQUAL(m_expected_tip, pindex->pprev->GetBlockHash()); diff --git a/src/test/validationinterface_tests.cpp b/src/test/validationinterface_tests.cpp index 8a24b282458..0b0bae80721 100644 --- a/src/test/validationinterface_tests.cpp +++ b/src/test/validationinterface_tests.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include diff --git a/src/validation.cpp b/src/validation.cpp index da60efbc3cf..c229851e40d 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -20,13 +20,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include #include @@ -77,6 +77,7 @@ #include using kernel::CCoinsStats; +using kernel::ChainstateRole; using kernel::CoinStatsHashType; using kernel::ComputeUTXOStats; using kernel::Notifications; @@ -1986,7 +1987,7 @@ void Chainstate::CheckForkWarningConditions() { AssertLockHeld(cs_main); - if (this->GetRole() == ChainstateRole::BACKGROUND) { + if (this->GetRole().historical) { return; } @@ -2532,7 +2533,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state, Ticks(m_chainman.time_forks) / m_chainman.num_blocks_total); const bool fScriptChecks{!!script_check_reason}; - if (script_check_reason != m_last_script_check_reason_logged && GetRole() == ChainstateRole::NORMAL) { + const kernel::ChainstateRole role{GetRole()}; + if (script_check_reason != m_last_script_check_reason_logged && role.validated && !role.historical) { if (fScriptChecks) { LogInfo("Enabling script verification at block #%d (%s): %s.", pindex->nHeight, block_hash.ToString(), script_check_reason); @@ -4656,7 +4658,7 @@ bool Chainstate::LoadChainTip() m_chainman.GuessVerificationProgress(tip)); // Ensure KernelNotifications m_tip_block is set even if no new block arrives. - if (this->GetRole() != ChainstateRole::BACKGROUND) { + if (!this->GetRole().historical) { // Ignoring return value for now. (void)m_chainman.GetNotifications().blockTip( /*state=*/GetSynchronizationState(/*init=*/true, m_chainman.m_blockman.m_blockfiles_indexed), @@ -6354,7 +6356,7 @@ bool ChainstateManager::DeleteSnapshotChainstate() ChainstateRole Chainstate::GetRole() const { - return m_target_blockhash ? ChainstateRole::BACKGROUND : m_assumeutxo == Assumeutxo::UNVALIDATED ? ChainstateRole::ASSUMEDVALID : ChainstateRole::NORMAL; + return ChainstateRole{.validated = m_assumeutxo == Assumeutxo::VALIDATED, .historical = bool{m_target_blockhash}}; } void ChainstateManager::RecalculateBestHeader() diff --git a/src/validation.h b/src/validation.h index 464dcbd03a7..0f7fa2cbb88 100644 --- a/src/validation.h +++ b/src/validation.h @@ -58,6 +58,9 @@ class DisconnectedBlockTransactions; struct PrecomputedTransactionData; struct LockPoints; struct AssumeutxoData; +namespace kernel { +struct ChainstateRole; +} // namespace kernel namespace node { class SnapshotMetadata; } // namespace node @@ -586,7 +589,7 @@ public: //! documentation for a description of the different types of chainstates. //! //! @sa ChainstateRole - ChainstateRole GetRole() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + kernel::ChainstateRole GetRole() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main); /** * Initialize the CoinsViews UTXO set database management data structures. The in-memory diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index 313f730ea09..c4cd10104f3 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -7,9 +7,9 @@ #include #include -#include #include #include +#include #include #include #include @@ -21,6 +21,8 @@ #include #include +using kernel::ChainstateRole; + /** * ValidationSignalsImpl manages a list of shared_ptr callbacks. * @@ -209,7 +211,8 @@ void ValidationSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, RemovalReasonToString(reason)); } -void ValidationSignals::BlockConnected(ChainstateRole role, const std::shared_ptr &pblock, const CBlockIndex *pindex) { +void ValidationSignals::BlockConnected(const ChainstateRole& role, const std::shared_ptr& pblock, const CBlockIndex* pindex) +{ auto event = [role, pblock, pindex, this] { m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockConnected(role, pblock, pindex); }); }; @@ -238,7 +241,8 @@ void ValidationSignals::BlockDisconnected(const std::shared_ptr& p pindex->nHeight); } -void ValidationSignals::ChainStateFlushed(ChainstateRole role, const CBlockLocator &locator) { +void ValidationSignals::ChainStateFlushed(const ChainstateRole& role, const CBlockLocator& locator) +{ auto event = [role, locator, this] { m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.ChainStateFlushed(role, locator); }); }; diff --git a/src/validationinterface.h b/src/validationinterface.h index e0a88ad0f21..4777e8dca8d 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -6,7 +6,6 @@ #ifndef BITCOIN_VALIDATIONINTERFACE_H #define BITCOIN_VALIDATIONINTERFACE_H -#include #include #include #include @@ -17,6 +16,9 @@ #include #include +namespace kernel { +struct ChainstateRole; +} // namespace kernel namespace util { class TaskRunnerInterface; } // namespace util @@ -118,7 +120,7 @@ protected: * * Called on a background thread. */ - virtual void BlockConnected(ChainstateRole role, const std::shared_ptr &block, const CBlockIndex *pindex) {} + virtual void BlockConnected(const kernel::ChainstateRole& role, const std::shared_ptr& block, const CBlockIndex* pindex) {} /** * Notifies listeners of a block being disconnected * Provides the block that was disconnected. @@ -143,7 +145,7 @@ protected: * * Called on a background thread. */ - virtual void ChainStateFlushed(ChainstateRole role, const CBlockLocator &locator) {} + virtual void ChainStateFlushed(const kernel::ChainstateRole& role, const CBlockLocator& locator) {} /** * Notifies listeners of a block validation result. * If the provided BlockValidationState IsValid, the provided block @@ -221,9 +223,9 @@ public: void TransactionAddedToMempool(const NewMempoolTransactionInfo&, uint64_t mempool_sequence); void TransactionRemovedFromMempool(const CTransactionRef&, MemPoolRemovalReason, uint64_t mempool_sequence); void MempoolTransactionsRemovedForBlock(const std::vector&, unsigned int nBlockHeight); - void BlockConnected(ChainstateRole, const std::shared_ptr &, const CBlockIndex *pindex); + void BlockConnected(const kernel::ChainstateRole&, const std::shared_ptr&, const CBlockIndex* pindex); void BlockDisconnected(const std::shared_ptr &, const CBlockIndex* pindex); - void ChainStateFlushed(ChainstateRole, const CBlockLocator &); + void ChainStateFlushed(const kernel::ChainstateRole&, const CBlockLocator&); void BlockChecked(const std::shared_ptr&, const BlockValidationState&); void NewPoWValidBlock(const CBlockIndex *, const std::shared_ptr&); }; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 86474a456d7..d7b749bcaed 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -22,8 +22,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -87,6 +87,7 @@ using common::AmountErrMsg; using common::AmountHighWarn; using common::PSBTError; using interfaces::FoundBlock; +using kernel::ChainstateRole; using util::ReplaceAll; using util::ToString; @@ -1477,9 +1478,9 @@ void CWallet::transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRe } } -void CWallet::blockConnected(ChainstateRole role, const interfaces::BlockInfo& block) +void CWallet::blockConnected(const ChainstateRole& role, const interfaces::BlockInfo& block) { - if (role == ChainstateRole::BACKGROUND) { + if (role.historical) { return; } assert(block.data); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 275d4ead293..1d463564758 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -629,7 +629,7 @@ public: CWalletTx* AddToWallet(CTransactionRef tx, const TxState& state, const UpdateWalletTxFn& update_wtx=nullptr, bool rescanning_old_block = false); bool LoadToWallet(const Txid& hash, const UpdateWalletTxFn& fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void transactionAddedToMempool(const CTransactionRef& tx) override; - void blockConnected(ChainstateRole role, const interfaces::BlockInfo& block) override; + void blockConnected(const kernel::ChainstateRole& role, const interfaces::BlockInfo& block) override; void blockDisconnected(const interfaces::BlockInfo& block) override; void updatedBlockTip() override; int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver& reserver, bool update); diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp index e5b5f9d8054..316c7a19b3c 100644 --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -5,8 +5,8 @@ #include #include -#include #include +#include #include #include #include @@ -24,6 +24,8 @@ #include #include +using kernel::ChainstateRole; + CZMQNotificationInterface::CZMQNotificationInterface() = default; CZMQNotificationInterface::~CZMQNotificationInterface() @@ -176,9 +178,9 @@ void CZMQNotificationInterface::TransactionRemovedFromMempool(const CTransaction }); } -void CZMQNotificationInterface::BlockConnected(ChainstateRole role, const std::shared_ptr& pblock, const CBlockIndex* pindexConnected) +void CZMQNotificationInterface::BlockConnected(const ChainstateRole& role, const std::shared_ptr& pblock, const CBlockIndex* pindexConnected) { - if (role == ChainstateRole::BACKGROUND) { + if (role.historical) { return; } for (const CTransactionRef& ptx : pblock->vtx) { diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h index 5dacf3b32e7..12d805c1094 100644 --- a/src/zmq/zmqnotificationinterface.h +++ b/src/zmq/zmqnotificationinterface.h @@ -35,7 +35,7 @@ protected: // CValidationInterface void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence) override; void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override; - void BlockConnected(ChainstateRole role, const std::shared_ptr& pblock, const CBlockIndex* pindexConnected) override; + void BlockConnected(const kernel::ChainstateRole& role, const std::shared_ptr& pblock, const CBlockIndex* pindexConnected) override; void BlockDisconnected(const std::shared_ptr& pblock, const CBlockIndex* pindexDisconnected) override; void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;