Skip to content

Commit a813d64

Browse files
committed
refactor: accept ChainstateManager in CMNHFManager ctor
The `ConnectManager` approach is no longer needed.
1 parent bd21987 commit a813d64

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

src/evo/mnhftx.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ CMutableTransaction MNHFTxPayload::PrepareTx() const
4343
return tx;
4444
}
4545

46-
CMNHFManager::CMNHFManager(CEvoDB& evoDb) :
47-
m_evoDb{evoDb}
46+
CMNHFManager::CMNHFManager(CEvoDB& evoDb, const ChainstateManager& chainman) :
47+
m_evoDb(evoDb),
48+
m_chainman{chainman}
4849
{
4950
assert(globalInstance == nullptr);
5051
globalInstance = this;
@@ -198,12 +199,11 @@ static bool extractSignals(const ChainstateManager& chainman, const llmq::CQuoru
198199

199200
std::optional<CMNHFManager::Signals> CMNHFManager::ProcessBlock(const CBlock& block, const CBlockIndex* const pindex, bool fJustCheck, BlockValidationState& state)
200201
{
201-
auto chainman = Assert(m_chainman.load(std::memory_order_acquire));
202202
auto qman = Assert(m_qman.load(std::memory_order_acquire));
203203

204204
try {
205205
std::vector<uint8_t> new_signals;
206-
if (!extractSignals(*chainman, *qman, block, pindex, new_signals, state)) {
206+
if (!extractSignals(m_chainman, *qman, block, pindex, new_signals, state)) {
207207
// state is set inside extractSignals
208208
return std::nullopt;
209209
}
@@ -250,12 +250,11 @@ std::optional<CMNHFManager::Signals> CMNHFManager::ProcessBlock(const CBlock& bl
250250

251251
bool CMNHFManager::UndoBlock(const CBlock& block, const CBlockIndex* const pindex)
252252
{
253-
auto chainman = Assert(m_chainman.load(std::memory_order_acquire));
254253
auto qman = Assert(m_qman.load(std::memory_order_acquire));
255254

256255
std::vector<uint8_t> excluded_signals;
257256
BlockValidationState state;
258-
if (!extractSignals(*chainman, *qman, block, pindex, excluded_signals, state)) {
257+
if (!extractSignals(m_chainman, *qman, block, pindex, excluded_signals, state)) {
259258
LogPrintf("CMNHFManager::%s: failed to extract signals\n", __func__);
260259
return false;
261260
}
@@ -369,31 +368,26 @@ void CMNHFManager::AddSignal(const CBlockIndex* const pindex, int bit)
369368
AddToCache(signals, pindex);
370369
}
371370

372-
void CMNHFManager::ConnectManagers(gsl::not_null<ChainstateManager*> chainman, gsl::not_null<llmq::CQuorumManager*> qman)
371+
void CMNHFManager::ConnectManagers(gsl::not_null<llmq::CQuorumManager*> qman)
373372
{
374373
// Do not allow double-initialization
375-
assert(m_chainman.load(std::memory_order_acquire) == nullptr);
376-
m_chainman.store(chainman, std::memory_order_release);
377374
assert(m_qman.load(std::memory_order_acquire) == nullptr);
378375
m_qman.store(qman, std::memory_order_release);
379376
}
380377

381378
void CMNHFManager::DisconnectManagers()
382379
{
383-
m_chainman.store(nullptr, std::memory_order_release);
384380
m_qman.store(nullptr, std::memory_order_release);
385381
}
386382

387383
bool CMNHFManager::ForceSignalDBUpdate()
388384
{
389-
auto chainman = Assert(m_chainman.load(std::memory_order_acquire));
390-
391385
// force ehf signals db update
392386
auto dbTx = m_evoDb.BeginTransaction();
393387

394388
const bool last_legacy = bls::bls_legacy_scheme.load();
395389
bls::bls_legacy_scheme.store(false);
396-
GetSignalsStage(chainman->ActiveChainstate().m_chain.Tip());
390+
GetSignalsStage(m_chainman.ActiveTip());
397391
bls::bls_legacy_scheme.store(last_legacy);
398392

399393
dbTx->Commit();

src/evo/mnhftx.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class CMNHFManager : public AbstractEHFManager
9090
{
9191
private:
9292
CEvoDB& m_evoDb;
93-
std::atomic<ChainstateManager*> m_chainman{nullptr};
93+
const ChainstateManager& m_chainman;
9494
std::atomic<llmq::CQuorumManager*> m_qman{nullptr};
9595

9696
static constexpr size_t MNHFCacheSize = 1000;
@@ -102,7 +102,7 @@ class CMNHFManager : public AbstractEHFManager
102102
CMNHFManager() = delete;
103103
CMNHFManager(const CMNHFManager&) = delete;
104104
CMNHFManager& operator=(const CMNHFManager&) = delete;
105-
explicit CMNHFManager(CEvoDB& evoDb);
105+
explicit CMNHFManager(CEvoDB& evoDb, const ChainstateManager& chainman);
106106
~CMNHFManager();
107107

108108
/**
@@ -139,7 +139,7 @@ class CMNHFManager : public AbstractEHFManager
139139
* Separated from constructor to allow LLMQContext to use CMNHFManager in read-only capacity.
140140
* Required to mutate state.
141141
*/
142-
void ConnectManagers(gsl::not_null<ChainstateManager*> chainman, gsl::not_null<llmq::CQuorumManager*> qman);
142+
void ConnectManagers(gsl::not_null<llmq::CQuorumManager*> qman);
143143

144144
/**
145145
* Reset llmq::CQuorumManager pointer.

src/node/chainstate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
7474
evodb = std::make_unique<CEvoDB>(util::DbWrapperParams{.path = data_dir, .memory = dash_dbs_in_memory, .wipe = fReset || fReindexChainState});
7575

7676
mnhf_manager.reset();
77-
mnhf_manager = std::make_unique<CMNHFManager>(*evodb);
77+
mnhf_manager = std::make_unique<CMNHFManager>(*evodb, chainman);
7878

7979
chainman.InitializeChainstate(mempool, *evodb, chain_helper);
8080
chainman.m_total_coinstip_cache = nCoinCacheUsage;
@@ -243,7 +243,7 @@ void DashChainstateSetup(ChainstateManager& chainman,
243243
util::DbWrapperParams{.path = data_dir, .memory = llmq_dbs_in_memory, .wipe = llmq_dbs_wipe});
244244
mempool->ConnectManagers(dmnman.get(), llmq_ctx->isman.get());
245245
// Enable CMNHFManager::{Process, Undo}Block
246-
mnhf_manager->ConnectManagers(&chainman, llmq_ctx->qman.get());
246+
mnhf_manager->ConnectManagers(llmq_ctx->qman.get());
247247

248248
chain_helper.reset();
249249
chain_helper = std::make_unique<CChainstateHelper>(*cpoolman, *dmnman, *mnhf_manager, govman, *(llmq_ctx->isman), *(llmq_ctx->quorum_block_processor),

src/test/util/setup_common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
222222
m_node.netfulfilledman = std::make_unique<CNetFulfilledRequestManager>();
223223
m_node.sporkman = std::make_unique<CSporkManager>();
224224
m_node.evodb = std::make_unique<CEvoDB>(util::DbWrapperParams{.path = m_node.args->GetDataDirNet(), .memory = true, .wipe = true});
225-
m_node.mnhf_manager = std::make_unique<CMNHFManager>(*m_node.evodb);
226225

227226
static bool noui_connected = false;
228227
if (!noui_connected) {
@@ -240,7 +239,6 @@ BasicTestingSetup::~BasicTestingSetup()
240239
fs::remove_all(m_path_root);
241240
gArgs.ClearArgs();
242241

243-
m_node.mnhf_manager.reset();
244242
m_node.evodb.reset();
245243
m_node.sporkman.reset();
246244
m_node.netfulfilledman.reset();
@@ -274,6 +272,7 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
274272
m_node.chainman = std::make_unique<ChainstateManager>(chainparams);
275273
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(m_cache_sizes.block_tree_db, true);
276274

275+
m_node.mnhf_manager = std::make_unique<CMNHFManager>(*m_node.evodb, *m_node.chainman);
277276
m_node.mn_sync = std::make_unique<CMasternodeSync>(std::make_unique<NodeSyncNotifierImpl>(*m_node.connman, *m_node.netfulfilledman));
278277
m_node.govman = std::make_unique<CGovernanceManager>(*m_node.mn_metaman, *m_node.netfulfilledman, *m_node.chainman, m_node.dmnman, *m_node.mn_sync);
279278

@@ -291,6 +290,7 @@ ChainTestingSetup::~ChainTestingSetup()
291290
GetMainSignals().UnregisterBackgroundSignalScheduler();
292291
m_node.govman.reset();
293292
m_node.mn_sync.reset();
293+
m_node.mnhf_manager.reset();
294294
m_node.chainman.reset();
295295
m_node.mempool.reset();
296296
m_node.fee_estimator.reset();

0 commit comments

Comments
 (0)