scripted-diff: Rename MainSignals to ValidationSignals

-BEGIN VERIFY SCRIPT-
s() { git grep -l "$1" src | xargs sed -i "s/$1/$2/g"; }

s 'CMainSignals'    'ValidationSignals'
s 'MainSignalsImpl' 'ValidationSignalsImpl'
-END VERIFY SCRIPT-
This commit is contained in:
TheCharlatan committed 2024-02-15 14:45:51 +01:00
1 parent 0d6d2b650d
commit 06069b3913
12 files changed
+47 -47

No files matched your search

+1 -1
View File
@@ -74,7 +74,7 @@ int main(int argc, char* argv[])
// Start the lightweight task scheduler thread // Start the lightweight task scheduler thread
scheduler.m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { scheduler.serviceQueue(); }); scheduler.m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { scheduler.serviceQueue(); });
CMainSignals validation_signals{scheduler}; ValidationSignals validation_signals{scheduler};
// Gather some entropy once per minute. // Gather some entropy once per minute.
scheduler.scheduleEvery(RandAddPeriodic, std::chrono::minutes{1}); scheduler.scheduleEvery(RandAddPeriodic, std::chrono::minutes{1});
+1 -1
View File
@@ -1164,7 +1164,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
}, std::chrono::minutes{5}); }, std::chrono::minutes{5});
assert(!node.validation_signals); assert(!node.validation_signals);
node.validation_signals = std::make_unique<CMainSignals>(scheduler); node.validation_signals = std::make_unique<ValidationSignals>(scheduler);
auto& validation_signals = *node.validation_signals; auto& validation_signals = *node.validation_signals;
// Create client interfaces for wallets that are supposed to be loaded // Create client interfaces for wallets that are supposed to be loaded
+2 -2
View File
@@ -18,7 +18,7 @@
#include <optional> #include <optional>
class CChainParams; class CChainParams;
class CMainSignals; class ValidationSignals;
static constexpr bool DEFAULT_CHECKPOINTS_ENABLED{true}; static constexpr bool DEFAULT_CHECKPOINTS_ENABLED{true};
static constexpr auto DEFAULT_MAX_TIP_AGE{24h}; static constexpr auto DEFAULT_MAX_TIP_AGE{24h};
@@ -45,7 +45,7 @@ struct ChainstateManagerOpts {
DBOptions coins_db{}; DBOptions coins_db{};
CoinsViewOptions coins_view{}; CoinsViewOptions coins_view{};
Notifications& notifications; Notifications& notifications;
CMainSignals* signals{nullptr}; ValidationSignals* signals{nullptr};
//! Number of script check worker threads. Zero means no parallel verification. //! Number of script check worker threads. Zero means no parallel verification.
int worker_threads_num{0}; int worker_threads_num{0};
}; };
+2 -2
View File
@@ -13,7 +13,7 @@
#include <cstdint> #include <cstdint>
#include <optional> #include <optional>
class CMainSignals; class ValidationSignals;
/** Default for -maxmempool, maximum megabytes of mempool memory usage */ /** Default for -maxmempool, maximum megabytes of mempool memory usage */
static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300}; static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300};
@@ -59,7 +59,7 @@ struct MemPoolOptions {
bool persist_v1_dat{DEFAULT_PERSIST_V1_DAT}; bool persist_v1_dat{DEFAULT_PERSIST_V1_DAT};
MemPoolLimits limits{}; MemPoolLimits limits{};
CMainSignals* signals{nullptr}; ValidationSignals* signals{nullptr};
}; };
} // namespace kernel } // namespace kernel
+2 -2
View File
@@ -20,7 +20,7 @@ class BanMan;
class BaseIndex; class BaseIndex;
class CBlockPolicyEstimator; class CBlockPolicyEstimator;
class CConnman; class CConnman;
class CMainSignals; class ValidationSignals;
class CScheduler; class CScheduler;
class CTxMemPool; class CTxMemPool;
class ChainstateManager; class ChainstateManager;
@@ -74,7 +74,7 @@ struct NodeContext {
//! Issues blocking calls about sync status, errors and warnings //! Issues blocking calls about sync status, errors and warnings
std::unique_ptr<KernelNotifications> notifications; std::unique_ptr<KernelNotifications> notifications;
//! Issues calls about blocks and transactions //! Issues calls about blocks and transactions
std::unique_ptr<CMainSignals> validation_signals; std::unique_ptr<ValidationSignals> validation_signals;
std::atomic<int> exit_status{EXIT_SUCCESS}; std::atomic<int> exit_status{EXIT_SUCCESS};
//! Declare default constructor and destructor that are not inline, so code //! Declare default constructor and destructor that are not inline, so code
+3 -3
View File
@@ -460,7 +460,7 @@ public:
class NotificationsHandlerImpl : public Handler class NotificationsHandlerImpl : public Handler
{ {
public: public:
explicit NotificationsHandlerImpl(CMainSignals& signals, std::shared_ptr<Chain::Notifications> notifications) explicit NotificationsHandlerImpl(ValidationSignals& signals, std::shared_ptr<Chain::Notifications> notifications)
: m_signals{signals}, m_proxy{std::make_shared<NotificationsProxy>(std::move(notifications))} : m_signals{signals}, m_proxy{std::make_shared<NotificationsProxy>(std::move(notifications))}
{ {
m_signals.RegisterSharedValidationInterface(m_proxy); m_signals.RegisterSharedValidationInterface(m_proxy);
@@ -473,7 +473,7 @@ public:
m_proxy.reset(); m_proxy.reset();
} }
} }
CMainSignals& m_signals; ValidationSignals& m_signals;
std::shared_ptr<NotificationsProxy> m_proxy; std::shared_ptr<NotificationsProxy> m_proxy;
}; };
@@ -823,7 +823,7 @@ public:
NodeContext* context() override { return &m_node; } NodeContext* context() override { return &m_node; }
ArgsManager& args() { return *Assert(m_node.args); } ArgsManager& args() { return *Assert(m_node.args); }
ChainstateManager& chainman() { return *Assert(m_node.chainman); } ChainstateManager& chainman() { return *Assert(m_node.chainman); }
CMainSignals& validation_signals() { return *Assert(m_node.validation_signals); } ValidationSignals& validation_signals() { return *Assert(m_node.validation_signals); }
NodeContext& m_node; NodeContext& m_node;
}; };
} // namespace } // namespace
+1 -1
View File
@@ -171,7 +171,7 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
// from blocking due to queue overrun. // from blocking due to queue overrun.
m_node.scheduler = std::make_unique<CScheduler>(); m_node.scheduler = std::make_unique<CScheduler>();
m_node.scheduler->m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { m_node.scheduler->serviceQueue(); }); m_node.scheduler->m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { m_node.scheduler->serviceQueue(); });
m_node.validation_signals = std::make_unique<CMainSignals>(*m_node.scheduler); m_node.validation_signals = std::make_unique<ValidationSignals>(*m_node.scheduler);
m_node.fee_estimator = std::make_unique<CBlockPolicyEstimator>(FeeestPath(*m_node.args), DEFAULT_ACCEPT_STALE_FEE_ESTIMATES); m_node.fee_estimator = std::make_unique<CBlockPolicyEstimator>(FeeestPath(*m_node.args), DEFAULT_ACCEPT_STALE_FEE_ESTIMATES);
m_node.mempool = std::make_unique<CTxMemPool>(MemPoolOptionsForTest(m_node)); m_node.mempool = std::make_unique<CTxMemPool>(MemPoolOptionsForTest(m_node));
+2 -2
View File
@@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(unregister_validation_interface_race)
class TestInterface : public CValidationInterface class TestInterface : public CValidationInterface
{ {
public: public:
TestInterface(CMainSignals& signals, std::function<void()> on_call = nullptr, std::function<void()> on_destroy = nullptr) TestInterface(ValidationSignals& signals, std::function<void()> on_call = nullptr, std::function<void()> on_destroy = nullptr)
: m_on_call(std::move(on_call)), m_on_destroy(std::move(on_destroy)), m_signals{signals} : m_on_call(std::move(on_call)), m_on_destroy(std::move(on_destroy)), m_signals{signals}
{ {
} }
@@ -72,7 +72,7 @@ public:
} }
std::function<void()> m_on_call; std::function<void()> m_on_call;
std::function<void()> m_on_destroy; std::function<void()> m_on_destroy;
CMainSignals& m_signals; ValidationSignals& m_signals;
}; };
// Regression test to ensure UnregisterAllValidationInterfaces calls don't // Regression test to ensure UnregisterAllValidationInterfaces calls don't
+2 -2
View File
@@ -40,7 +40,7 @@
#include <vector> #include <vector>
class CChain; class CChain;
class CMainSignals; class ValidationSignals;
/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */ /** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF; static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
@@ -448,7 +448,7 @@ public:
const Limits m_limits; const Limits m_limits;
CMainSignals* const m_signals; ValidationSignals* const m_signals;
/** Create a new CTxMemPool. /** Create a new CTxMemPool.
* Sanity checks will be off by default for performance, because otherwise * Sanity checks will be off by default for performance, because otherwise
+1 -1
View File
@@ -3213,7 +3213,7 @@ static bool NotifyHeaderTip(ChainstateManager& chainman) LOCKS_EXCLUDED(cs_main)
return fNotify; return fNotify;
} }
static void LimitValidationInterfaceQueue(CMainSignals& signals) LOCKS_EXCLUDED(cs_main) { static void LimitValidationInterfaceQueue(ValidationSignals& signals) LOCKS_EXCLUDED(cs_main) {
AssertLockNotHeld(cs_main); AssertLockNotHeld(cs_main);
if (signals.CallbacksPending() > 10) { if (signals.CallbacksPending() > 10) {
+24 -24
View File
@@ -22,14 +22,14 @@
std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept; std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
/** /**
* MainSignalsImpl manages a list of shared_ptr<CValidationInterface> callbacks. * ValidationSignalsImpl manages a list of shared_ptr<CValidationInterface> callbacks.
* *
* A std::unordered_map is used to track what callbacks are currently * A std::unordered_map is used to track what callbacks are currently
* registered, and a std::list is used to store the callbacks that are * registered, and a std::list is used to store the callbacks that are
* currently registered as well as any callbacks that are just unregistered * currently registered as well as any callbacks that are just unregistered
* and about to be deleted when they are done executing. * and about to be deleted when they are done executing.
*/ */
class MainSignalsImpl class ValidationSignalsImpl
{ {
private: private:
Mutex m_mutex; Mutex m_mutex;
@@ -47,7 +47,7 @@ public:
// our own queue here :( // our own queue here :(
SerialTaskRunner m_task_runner; SerialTaskRunner m_task_runner;
explicit MainSignalsImpl(CScheduler& scheduler LIFETIMEBOUND) : m_task_runner(scheduler) {} explicit ValidationSignalsImpl(CScheduler& scheduler LIFETIMEBOUND) : m_task_runner(scheduler) {}
void Register(std::shared_ptr<CValidationInterface> callbacks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) void Register(std::shared_ptr<CValidationInterface> callbacks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
{ {
@@ -94,56 +94,56 @@ public:
} }
}; };
CMainSignals::CMainSignals(CScheduler& scheduler) ValidationSignals::ValidationSignals(CScheduler& scheduler)
: m_internals{std::make_unique<MainSignalsImpl>(scheduler)} {} : m_internals{std::make_unique<ValidationSignalsImpl>(scheduler)} {}
CMainSignals::~CMainSignals() {} ValidationSignals::~ValidationSignals() {}
void CMainSignals::FlushBackgroundCallbacks() void ValidationSignals::FlushBackgroundCallbacks()
{ {
m_internals->m_task_runner.flush(); m_internals->m_task_runner.flush();
} }
size_t CMainSignals::CallbacksPending() size_t ValidationSignals::CallbacksPending()
{ {
return m_internals->m_task_runner.size(); return m_internals->m_task_runner.size();
} }
void CMainSignals::RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks) void ValidationSignals::RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks)
{ {
// Each connection captures the shared_ptr to ensure that each callback is // Each connection captures the shared_ptr to ensure that each callback is
// executed before the subscriber is destroyed. For more details see #18338. // executed before the subscriber is destroyed. For more details see #18338.
m_internals->Register(std::move(callbacks)); m_internals->Register(std::move(callbacks));
} }
void CMainSignals::RegisterValidationInterface(CValidationInterface* callbacks) void ValidationSignals::RegisterValidationInterface(CValidationInterface* callbacks)
{ {
// Create a shared_ptr with a no-op deleter - CValidationInterface lifecycle // Create a shared_ptr with a no-op deleter - CValidationInterface lifecycle
// is managed by the caller. // is managed by the caller.
RegisterSharedValidationInterface({callbacks, [](CValidationInterface*){}}); RegisterSharedValidationInterface({callbacks, [](CValidationInterface*){}});
} }
void CMainSignals::UnregisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks) void ValidationSignals::UnregisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks)
{ {
UnregisterValidationInterface(callbacks.get()); UnregisterValidationInterface(callbacks.get());
} }
void CMainSignals::UnregisterValidationInterface(CValidationInterface* callbacks) void ValidationSignals::UnregisterValidationInterface(CValidationInterface* callbacks)
{ {
m_internals->Unregister(callbacks); m_internals->Unregister(callbacks);
} }
void CMainSignals::UnregisterAllValidationInterfaces() void ValidationSignals::UnregisterAllValidationInterfaces()
{ {
m_internals->Clear(); m_internals->Clear();
} }
void CMainSignals::CallFunctionInValidationInterfaceQueue(std::function<void()> func) void ValidationSignals::CallFunctionInValidationInterfaceQueue(std::function<void()> func)
{ {
m_internals->m_task_runner.insert(std::move(func)); m_internals->m_task_runner.insert(std::move(func));
} }
void CMainSignals::SyncWithValidationInterfaceQueue() void ValidationSignals::SyncWithValidationInterfaceQueue()
{ {
AssertLockNotHeld(cs_main); AssertLockNotHeld(cs_main);
// Block until the validation queue drains // Block until the validation queue drains
@@ -171,7 +171,7 @@ void CMainSignals::SyncWithValidationInterfaceQueue()
#define LOG_EVENT(fmt, ...) \ #define LOG_EVENT(fmt, ...) \
LogPrint(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) LogPrint(BCLog::VALIDATION, fmt "\n", __VA_ARGS__)
void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) { void ValidationSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
// Dependencies exist that require UpdatedBlockTip events to be delivered in the order in which // Dependencies exist that require UpdatedBlockTip events to be delivered in the order in which
// the chain actually updates. One way to ensure this is for the caller to invoke this signal // the chain actually updates. One way to ensure this is for the caller to invoke this signal
// in the same critical section where the chain is updated // in the same critical section where the chain is updated
@@ -185,7 +185,7 @@ void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockInd
fInitialDownload); fInitialDownload);
} }
void CMainSignals::TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence) void ValidationSignals::TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence)
{ {
auto event = [tx, mempool_sequence, this] { auto event = [tx, mempool_sequence, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionAddedToMempool(tx, mempool_sequence); }); m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionAddedToMempool(tx, mempool_sequence); });
@@ -195,7 +195,7 @@ void CMainSignals::TransactionAddedToMempool(const NewMempoolTransactionInfo& tx
tx.info.m_tx->GetWitnessHash().ToString()); tx.info.m_tx->GetWitnessHash().ToString());
} }
void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) { void ValidationSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) {
auto event = [tx, reason, mempool_sequence, this] { auto event = [tx, reason, mempool_sequence, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionRemovedFromMempool(tx, reason, mempool_sequence); }); m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionRemovedFromMempool(tx, reason, mempool_sequence); });
}; };
@@ -205,7 +205,7 @@ void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, MemP
RemovalReasonToString(reason)); RemovalReasonToString(reason));
} }
void CMainSignals::BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex) { void ValidationSignals::BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex) {
auto event = [role, pblock, pindex, this] { auto event = [role, pblock, pindex, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockConnected(role, pblock, pindex); }); m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockConnected(role, pblock, pindex); });
}; };
@@ -214,7 +214,7 @@ void CMainSignals::BlockConnected(ChainstateRole role, const std::shared_ptr<con
pindex->nHeight); pindex->nHeight);
} }
void CMainSignals::MempoolTransactionsRemovedForBlock(const std::vector<RemovedMempoolTransactionInfo>& txs_removed_for_block, unsigned int nBlockHeight) void ValidationSignals::MempoolTransactionsRemovedForBlock(const std::vector<RemovedMempoolTransactionInfo>& txs_removed_for_block, unsigned int nBlockHeight)
{ {
auto event = [txs_removed_for_block, nBlockHeight, this] { auto event = [txs_removed_for_block, nBlockHeight, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.MempoolTransactionsRemovedForBlock(txs_removed_for_block, nBlockHeight); }); m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.MempoolTransactionsRemovedForBlock(txs_removed_for_block, nBlockHeight); });
@@ -224,7 +224,7 @@ void CMainSignals::MempoolTransactionsRemovedForBlock(const std::vector<RemovedM
txs_removed_for_block.size()); txs_removed_for_block.size());
} }
void CMainSignals::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex) void ValidationSignals::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
{ {
auto event = [pblock, pindex, this] { auto event = [pblock, pindex, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockDisconnected(pblock, pindex); }); m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockDisconnected(pblock, pindex); });
@@ -234,7 +234,7 @@ void CMainSignals::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock
pindex->nHeight); pindex->nHeight);
} }
void CMainSignals::ChainStateFlushed(ChainstateRole role, const CBlockLocator &locator) { void ValidationSignals::ChainStateFlushed(ChainstateRole role, const CBlockLocator &locator) {
auto event = [role, locator, this] { auto event = [role, locator, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.ChainStateFlushed(role, locator); }); m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.ChainStateFlushed(role, locator); });
}; };
@@ -242,13 +242,13 @@ void CMainSignals::ChainStateFlushed(ChainstateRole role, const CBlockLocator &l
locator.IsNull() ? "null" : locator.vHave.front().ToString()); locator.IsNull() ? "null" : locator.vHave.front().ToString());
} }
void CMainSignals::BlockChecked(const CBlock& block, const BlockValidationState& state) { void ValidationSignals::BlockChecked(const CBlock& block, const BlockValidationState& state) {
LOG_EVENT("%s: block hash=%s state=%s", __func__, LOG_EVENT("%s: block hash=%s state=%s", __func__,
block.GetHash().ToString(), state.ToString()); block.GetHash().ToString(), state.ToString());
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockChecked(block, state); }); m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockChecked(block, state); });
} }
void CMainSignals::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock> &block) { void ValidationSignals::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock> &block) {
LOG_EVENT("%s: block hash=%s", __func__, block->GetHash().ToString()); LOG_EVENT("%s: block hash=%s", __func__, block->GetHash().ToString());
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.NewPoWValidBlock(pindex, block); }); m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.NewPoWValidBlock(pindex, block); });
} }
+6 -6
View File
@@ -150,19 +150,19 @@ protected:
* has been received and connected to the headers tree, though not validated yet. * has been received and connected to the headers tree, though not validated yet.
*/ */
virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& block) {}; virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& block) {};
friend class CMainSignals; friend class ValidationSignals;
friend class ValidationInterfaceTest; friend class ValidationInterfaceTest;
}; };
class MainSignalsImpl; class ValidationSignalsImpl;
class CMainSignals { class ValidationSignals {
private: private:
std::unique_ptr<MainSignalsImpl> m_internals; std::unique_ptr<ValidationSignalsImpl> m_internals;
public: public:
CMainSignals(CScheduler& scheduler LIFETIMEBOUND); ValidationSignals(CScheduler& scheduler LIFETIMEBOUND);
~CMainSignals(); ~ValidationSignals();
/** Call any remaining callbacks on the calling thread */ /** Call any remaining callbacks on the calling thread */
void FlushBackgroundCallbacks(); void FlushBackgroundCallbacks();