Skip to content

Commit 3e78504

Browse files
committed
refactor: drop dependency of CInstantSendManager on chainlocks
1 parent 0e07937 commit 3e78504

File tree

8 files changed

+21
-29
lines changed

8 files changed

+21
-29
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2208,7 +2208,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
22082208

22092209
// ********************************************************* Step 7d: Setup other Dash services
22102210

2211-
node.peerman->AddExtraHandler(std::make_unique<NetInstantSend>(node.peerman.get(), *node.llmq_ctx->isman, node.active_ctx ? node.active_ctx->is_signer.get() : nullptr, *node.llmq_ctx->sigman, *node.llmq_ctx->qman, chainman.ActiveChainstate(), *node.mempool, *node.mn_sync));
2211+
node.peerman->AddExtraHandler(std::make_unique<NetInstantSend>(node.peerman.get(), *node.llmq_ctx->isman, node.active_ctx ? node.active_ctx->is_signer.get() : nullptr, *node.llmq_ctx->sigman, *node.llmq_ctx->qman, *node.chainlocks, chainman.ActiveChainstate(), *node.mempool, *node.mn_sync));
22122212
node.peerman->AddExtraHandler(std::make_unique<llmq::NetSigning>(node.peerman.get(), *node.llmq_ctx->sigman, node.active_ctx ? node.active_ctx->shareman.get() : nullptr, *node.sporkman));
22132213

22142214
if (node.active_ctx) {

src/instantsend/instantsend.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <instantsend/instantsend.h>
66

7-
#include <chainlock/chainlock.h>
87
#include <chainparams.h>
98
#include <consensus/validation.h>
109
#include <masternode/sync.h>
@@ -16,10 +15,8 @@ using node::fImporting;
1615
using node::fReindex;
1716

1817
namespace llmq {
19-
CInstantSendManager::CInstantSendManager(const chainlock::Chainlocks& chainlocks, CSporkManager& sporkman,
20-
const util::DbWrapperParams& db_params) :
18+
CInstantSendManager::CInstantSendManager(CSporkManager& sporkman, const util::DbWrapperParams& db_params) :
2119
db{db_params},
22-
m_chainlocks{chainlocks},
2320
spork_manager{sporkman}
2421
{
2522
}

src/instantsend/instantsend.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ namespace util {
3030
struct DbWrapperParams;
3131
} // namespace util
3232

33-
namespace chainlock {
34-
class Chainlocks;
35-
}
36-
3733
namespace instantsend {
3834

3935
struct PendingISLockFromPeer {
@@ -57,8 +53,6 @@ class CInstantSendManager
5753
{
5854
private:
5955
instantsend::CInstantSendDb db;
60-
61-
const chainlock::Chainlocks& m_chainlocks;
6256
CSporkManager& spork_manager;
6357

6458
mutable Mutex cs_pendingLocks;
@@ -95,8 +89,7 @@ class CInstantSendManager
9589
CInstantSendManager() = delete;
9690
CInstantSendManager(const CInstantSendManager&) = delete;
9791
CInstantSendManager& operator=(const CInstantSendManager&) = delete;
98-
explicit CInstantSendManager(const chainlock::Chainlocks& chainlocks, CSporkManager& sporkman,
99-
const util::DbWrapperParams& db_params);
92+
explicit CInstantSendManager(CSporkManager& sporkman, const util::DbWrapperParams& db_params);
10093
~CInstantSendManager();
10194

10295
void AddNonLockedTx(const CTransactionRef& tx, const CBlockIndex* pindexMined)
@@ -122,7 +115,6 @@ class CInstantSendManager
122115
EXCLUSIVE_LOCKS_REQUIRED(!cs_pendingLocks);
123116
[[nodiscard]] std::vector<CTransactionRef> PrepareTxToRetry()
124117
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
125-
const chainlock::Chainlocks& Chainlocks() { return m_chainlocks; }
126118

127119
void RemoveBlockISLocks(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex);
128120
void WriteBlockISLocks(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex);

src/instantsend/net_instantsend.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void NetInstantSend::ProcessInstantSendLock(NodeId from, const uint256& hash, co
376376
}
377377
// Let's see if the TX that was locked by this islock is already mined in a ChainLocked block. If yes,
378378
// we can simply ignore the islock, as the ChainLock implies locking of all TXs in that chain
379-
if (minedHeight.has_value() && m_is_manager.Chainlocks().HasChainLock(*minedHeight, hashBlock)) {
379+
if (minedHeight.has_value() && m_chainlocks.HasChainLock(*minedHeight, hashBlock)) {
380380
LogPrint(BCLog::INSTANTSEND, /* Continued */
381381
"NetSigning::%s -- txlock=%s, islock=%s: dropping islock as it already got a "
382382
"ChainLock in block %s, peer=%d\n",
@@ -501,7 +501,7 @@ void NetInstantSend::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockI
501501
{
502502
bool fDIP0008Active = pindexNew->pprev && pindexNew->pprev->nHeight >= Params().GetConsensus().DIP0008Height;
503503

504-
if (m_is_manager.Chainlocks().IsEnabled() && fDIP0008Active) {
504+
if (m_chainlocks.IsEnabled() && fDIP0008Active) {
505505
// Nothing to do here. We should keep all islocks and let chainlocks handle them.
506506
return;
507507
}
@@ -529,7 +529,7 @@ void NetInstantSend::BlockConnected(const std::shared_ptr<const CBlock>& pblock,
529529
m_is_manager.CacheTipHeight(pindex);
530530

531531
if (m_mn_sync.IsBlockchainSynced()) {
532-
const bool has_chainlock = m_is_manager.Chainlocks().HasChainLock(pindex->nHeight, pindex->GetBlockHash());
532+
const bool has_chainlock = m_chainlocks.HasChainLock(pindex->nHeight, pindex->GetBlockHash());
533533
for (const auto& tx : pblock->vtx) {
534534
if (tx->IsCoinBase() || tx->vin.empty()) {
535535
// coinbase and TXs with no inputs can't be locked
@@ -571,7 +571,7 @@ void NetInstantSend::ResolveBlockConflicts(const uint256& islockHash, const inst
571571
bool hasChainLockedConflict = false;
572572
for (const auto& p : conflicts) {
573573
const auto* pindex = p.first;
574-
if (m_is_manager.Chainlocks().HasChainLock(pindex->nHeight, pindex->GetBlockHash())) {
574+
if (m_chainlocks.HasChainLock(pindex->nHeight, pindex->GetBlockHash())) {
575575
hasChainLockedConflict = true;
576576
break;
577577
}

src/instantsend/net_instantsend.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace Consensus {
1818
struct LLMQParams;
1919
} // namespace Consensus
2020

21+
namespace chainlock {
22+
class Chainlocks;
23+
} // namespace chainlock
24+
2125
class CMasternodeSync;
2226
class CTxMemPool;
2327

@@ -38,12 +42,14 @@ class NetInstantSend final : public NetHandler, public CValidationInterface
3842
public:
3943
NetInstantSend(PeerManagerInternal* peer_manager, llmq::CInstantSendManager& is_manager,
4044
instantsend::InstantSendSigner* signer, llmq::CSigningManager& sigman, llmq::CQuorumManager& qman,
41-
CChainState& chainstate, CTxMemPool& mempool, const CMasternodeSync& mn_sync) :
45+
const chainlock::Chainlocks& chainlocks, CChainState& chainstate, CTxMemPool& mempool,
46+
const CMasternodeSync& mn_sync) :
4247
NetHandler(peer_manager),
4348
m_is_manager{is_manager},
4449
m_signer{signer},
4550
m_sigman{sigman},
4651
m_qman(qman),
52+
m_chainlocks{chainlocks},
4753
m_chainstate{chainstate},
4854
m_mempool{mempool},
4955
m_mn_sync{mn_sync}
@@ -104,6 +110,7 @@ class NetInstantSend final : public NetHandler, public CValidationInterface
104110
instantsend::InstantSendSigner* m_signer; // non-null only for masternode
105111
llmq::CSigningManager& m_sigman;
106112
llmq::CQuorumManager& m_qman;
113+
const chainlock::Chainlocks& m_chainlocks;
107114
CChainState& m_chainstate;
108115
CTxMemPool& m_mempool;
109116
const CMasternodeSync& m_mn_sync;

src/llmq/context.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
#include <validation.h>
1414

1515
LLMQContext::LLMQContext(CDeterministicMNManager& dmnman, CEvoDB& evo_db, CSporkManager& sporkman,
16-
chainlock::Chainlocks& chainlocks, ChainstateManager& chainman,
17-
const util::DbWrapperParams& db_params, int8_t bls_threads, int64_t max_recsigs_age) :
16+
ChainstateManager& chainman, const util::DbWrapperParams& db_params, int8_t bls_threads,
17+
int64_t max_recsigs_age) :
1818
bls_worker{std::make_shared<CBLSWorker>()},
1919
qsnapman{std::make_unique<llmq::CQuorumSnapshotManager>(evo_db)},
2020
quorum_block_processor{std::make_unique<llmq::CQuorumBlockProcessor>(chainman.ActiveChainstate(), dmnman, evo_db,
2121
*qsnapman, bls_threads)},
2222
qman{std::make_unique<llmq::CQuorumManager>(*bls_worker, dmnman, evo_db, *quorum_block_processor, *qsnapman,
2323
chainman, db_params)},
2424
sigman{std::make_unique<llmq::CSigningManager>(*qman, db_params, max_recsigs_age)},
25-
isman{std::make_unique<llmq::CInstantSendManager>(chainlocks, sporkman, db_params)}
25+
isman{std::make_unique<llmq::CInstantSendManager>(sporkman, db_params)}
2626
{
2727
// Have to start it early to let VerifyDB check ChainLock signatures in coinbase
2828
bls_worker->Start();

src/llmq/context.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ class CEvoDB;
1616
class CSporkManager;
1717
class PeerManager;
1818

19-
namespace chainlock {
20-
class Chainlocks;
21-
}
22-
2319
namespace llmq {
2420
class CInstantSendManager;
2521
class CQuorumBlockProcessor;
@@ -37,8 +33,8 @@ struct LLMQContext {
3733
LLMQContext(const LLMQContext&) = delete;
3834
LLMQContext& operator=(const LLMQContext&) = delete;
3935
explicit LLMQContext(CDeterministicMNManager& dmnman, CEvoDB& evo_db, CSporkManager& sporkman,
40-
chainlock::Chainlocks& chainlocks, ChainstateManager& chainman,
41-
const util::DbWrapperParams& db_params, int8_t bls_threads, int64_t max_recsigs_age);
36+
ChainstateManager& chainman, const util::DbWrapperParams& db_params, int8_t bls_threads,
37+
int64_t max_recsigs_age);
4238
~LLMQContext();
4339

4440
/** Guaranteed if LLMQContext is initialized then all members are valid too

src/node/chainstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void DashChainstateSetup(ChainstateManager& chainman,
227227
dmnman = std::make_unique<CDeterministicMNManager>(evodb, mn_metaman);
228228

229229
llmq_ctx.reset();
230-
llmq_ctx = std::make_unique<LLMQContext>(*dmnman, evodb, sporkman, chainlocks, chainman,
230+
llmq_ctx = std::make_unique<LLMQContext>(*dmnman, evodb, sporkman, chainman,
231231
util::DbWrapperParams{.path = data_dir, .memory = llmq_dbs_in_memory, .wipe = llmq_dbs_wipe},
232232
bls_threads, max_recsigs_age);
233233
mempool->ConnectManagers(dmnman.get(), llmq_ctx->isman.get());

0 commit comments

Comments
 (0)