Skip to content

Commit 2ca9da3

Browse files
Merge #7178: refactor: remove dependencies of CInstantSendManager on mempool, signer, chainstate
a98d36c fix: set cached tip for isman without validationinterface (Konstantin Akimov) 770819e fix: code review comment by pastaclaw (Konstantin Akimov) 0c6db64 refactor: review fixes for CInstantSendManager decoupling (UdjinM6) 2f47b9e refactor: removed unused includes (Konstantin Akimov) 17db40f refactor: drop dependency of CInstantSendManager on chainlocks (Konstantin Akimov) f506a00 refactor: drop dependency of CInstantSendManager on llmq::CSigningManager (Konstantin Akimov) 843716a refactor: move usages sigman directly to NetInstantSend (Konstantin Akimov) 1e88ac3 refactor: drop helper interface InstantSendSignerParent (Konstantin Akimov) 9c84ed3 refactor: re-order clean-up calls for confirmed block for instant-send handling (Konstantin Akimov) 8d0a772 refactor: remove dependency of CInstantSendManager on signer (Konstantin Akimov) 9c0e03f refactor: remove dependency of CInstantSendManager on chainstate (Konstantin Akimov) 2a06aec refactor: use only cached height of tip, don't retrieve it directly ever (Konstantin Akimov) 32916a4 refactor: move ResolveBlockConflicts to NetInstantSend (Konstantin Akimov) 5937d78 refactor: move all notification handlers from CInstantSendManager to NetInstantSend (Konstantin Akimov) 7785d7c refactor: drop dependency of mempool from instantsend/instantsend (Konstantin Akimov) 654ba8a refactor: move usages of mempool from CInstantSendManager to NetInstantSend (Konstantin Akimov) a469587 refactor: simplify ProcessInstantSendLock by using PeerManager on place instead of returning std::variant (Konstantin Akimov) 2c23869 refactor: move ProcessInstantSendLock to NetInstantSend (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented Basically, CInstantSendManager's responsibility is remembering all known instant-send locks (by using `CInstantSendDb`) and it is used all over codebase to answer a question a basic but important question "Is transaction X locked?". In details, there are 4 public interfaces that are used to answer that question: - is transaction instant-send locked? `IsLocked` - is transaction / IS lock known? `IsKnown`, `AlreadyHave` - is instant-send enabled? (spork's related features, relevant for testnet & regtest only) - get me IS lock! (`GetInstantSendLockByTxid`, `GetInstantSendLockByHash`). In the reality, current implementation of CInstantSendManager has knowledges about multiple systems and components that are irrelevant, but not really needed to provide this base functionality. ## What was done? Removed dependency of CInstantSendManager on `instantsend::InstantSendSigner`, `llmq::CSigningManager`, `CChainState`, `chainlock::Chainlocks`, `CTxMemPool`. Removing dependency on CMasternodeSync is excluded from this PR because it requires bitcoin/bitcoin#25073 to be done first. ## How Has This Been Tested? Run unit & functional tests, linters. ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone ACKs for top commit: UdjinM6: utACK a98d36c Tree-SHA512: a03b843f20fa08d9771a66eb4a5273d0340f0072f6568914d703ef8a31643e14e157bdb03171499a38b84603a8ae6906e99610a9d0d18de93347c6eec5c03f46
2 parents 84a65af + a98d36c commit 2ca9da3

16 files changed

Lines changed: 564 additions & 588 deletions

src/active/context.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ ActiveContext::ActiveContext(CBLSWorker& bls_worker, ChainstateManager& chainman
3232
const CMasternodeSync& mn_sync, const CBLSSecretKey& operator_sk,
3333
const llmq::QvvecSyncModeMap& sync_map, const util::DbWrapperParams& db_params,
3434
bool quorums_recovery, bool quorums_watch) :
35-
m_isman{isman},
3635
m_qman{qman},
3736
nodeman{std::make_unique<CActiveMasternodeManager>(connman, dmnman, operator_sk)},
3837
dkgdbgman{std::make_unique<llmq::CDKGDebugManager>(dmnman, qsnapman, chainman)},
@@ -53,14 +52,12 @@ ActiveContext::ActiveContext(CBLSWorker& bls_worker, ChainstateManager& chainman
5352
qblockman, qsnapman, *nodeman, chainman, sporkman,
5453
llmq_params, quorums_watch, quorum_idx);
5554
});
56-
m_isman.ConnectSigner(is_signer.get());
5755
m_qman.ConnectManagers(qman_handler.get(), qdkgsman.get());
5856
}
5957

6058
ActiveContext::~ActiveContext()
6159
{
6260
m_qman.DisconnectManagers();
63-
m_isman.DisconnectSigner();
6461
}
6562

6663
void ActiveContext::Start(CConnman& connman, PeerManager& peerman, int16_t worker_count)

src/active/context.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ struct DbWrapperParams;
5454

5555
struct ActiveContext final : public CValidationInterface {
5656
private:
57-
llmq::CInstantSendManager& m_isman;
5857
llmq::CQuorumManager& m_qman;
5958

6059
public:
@@ -98,6 +97,8 @@ struct ActiveContext final : public CValidationInterface {
9897
const std::unique_ptr<llmq::CEHFSignalsHandler> ehf_sighandler;
9998
const std::unique_ptr<llmq::QuorumParticipant> qman_handler;
10099
const std::unique_ptr<chainlock::ChainLockSigner> cl_signer;
100+
101+
public:
101102
const std::unique_ptr<instantsend::InstantSendSigner> is_signer;
102103

103104
/** Owned by PeerManager, use GetCJServer() */

src/dsnotificationinterface.cpp

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,25 @@
55

66
#include <dsnotificationinterface.h>
77

8-
#include <util/check.h>
9-
#include <validation.h>
10-
118
#include <coinjoin/coinjoin.h>
129
#include <evo/deterministicmns.h>
1310
#include <evo/mnauth.h>
1411
#include <governance/governance.h>
1512
#include <instantsend/instantsend.h>
16-
#include <llmq/context.h>
17-
#include <llmq/dkgsessionmgr.h>
18-
#include <llmq/ehf_signals.h>
19-
#include <llmq/quorumsman.h>
2013
#include <masternode/sync.h>
14+
#include <util/check.h>
15+
#include <validation.h>
2116

22-
CDSNotificationInterface::CDSNotificationInterface(CConnman& connman,
23-
CDSTXManager& dstxman,
24-
CMasternodeSync& mn_sync,
25-
CGovernanceManager& govman,
26-
const ChainstateManager& chainman,
27-
const std::unique_ptr<CDeterministicMNManager>& dmnman,
28-
const std::unique_ptr<LLMQContext>& llmq_ctx) :
17+
18+
CDSNotificationInterface::CDSNotificationInterface(CConnman& connman, CDSTXManager& dstxman, CMasternodeSync& mn_sync,
19+
CGovernanceManager& govman, const ChainstateManager& chainman,
20+
const std::unique_ptr<CDeterministicMNManager>& dmnman) :
2921
m_connman{connman},
3022
m_dstxman{dstxman},
3123
m_mn_sync{mn_sync},
3224
m_govman{govman},
3325
m_chainman{chainman},
34-
m_dmnman{dmnman},
35-
m_llmq_ctx{llmq_ctx}
26+
m_dmnman{dmnman}
3627
{
3728
}
3829

@@ -76,7 +67,6 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con
7667
m_dstxman.UpdatedBlockTip(pindexNew);
7768
}
7869

79-
m_llmq_ctx->isman->UpdatedBlockTip(pindexNew);
8070
if (m_govman.IsValid()) {
8171
m_govman.UpdatedBlockTip(pindexNew);
8272
}
@@ -85,25 +75,16 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con
8575
void CDSNotificationInterface::TransactionAddedToMempool(const CTransactionRef& ptx, int64_t nAcceptTime,
8676
uint64_t mempool_sequence)
8777
{
88-
Assert(m_llmq_ctx)->isman->TransactionAddedToMempool(ptx);
8978
m_dstxman.TransactionAddedToMempool(ptx);
9079
}
9180

92-
void CDSNotificationInterface::TransactionRemovedFromMempool(const CTransactionRef& ptx, MemPoolRemovalReason reason,
93-
uint64_t mempool_sequence)
94-
{
95-
Assert(m_llmq_ctx)->isman->TransactionRemovedFromMempool(ptx);
96-
}
97-
9881
void CDSNotificationInterface::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
9982
{
100-
Assert(m_llmq_ctx)->isman->BlockConnected(pblock, pindex);
10183
m_dstxman.BlockConnected(pblock, pindex);
10284
}
10385

10486
void CDSNotificationInterface::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected)
10587
{
106-
Assert(m_llmq_ctx)->isman->BlockDisconnected(pblock, pindexDisconnected);
10788
m_dstxman.BlockDisconnected(pblock, pindexDisconnected);
10889
}
10990

@@ -118,7 +99,6 @@ void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDet
11899
void CDSNotificationInterface::NotifyChainLock(const CBlockIndex* pindex,
119100
const std::shared_ptr<const chainlock::ChainLockSig>& clsig)
120101
{
121-
Assert(m_llmq_ctx)->isman->NotifyChainLock(pindex);
122102
if (m_mn_sync.IsBlockchainSynced()) {
123103
m_dstxman.NotifyChainLock(pindex);
124104
}

src/dsnotificationinterface.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,16 @@ class CDeterministicMNManager;
1313
class CGovernanceManager;
1414
class ChainstateManager;
1515
class CMasternodeSync;
16-
struct LLMQContext;
1716

1817
class CDSNotificationInterface : public CValidationInterface
1918
{
2019
public:
2120
CDSNotificationInterface() = delete;
2221
CDSNotificationInterface(const CDSNotificationInterface&) = delete;
2322
CDSNotificationInterface& operator=(const CDSNotificationInterface&) = delete;
24-
explicit CDSNotificationInterface(CConnman& connman,
25-
CDSTXManager& dstxman,
26-
CMasternodeSync& mn_sync,
27-
CGovernanceManager& govman,
28-
const ChainstateManager& chainman,
29-
const std::unique_ptr<CDeterministicMNManager>& dmnman,
30-
const std::unique_ptr<LLMQContext>& llmq_ctx);
23+
explicit CDSNotificationInterface(CConnman& connman, CDSTXManager& dstxman, CMasternodeSync& mn_sync,
24+
CGovernanceManager& govman, const ChainstateManager& chainman,
25+
const std::unique_ptr<CDeterministicMNManager>& dmnman);
3126
virtual ~CDSNotificationInterface();
3227

3328
// a small helper to initialize current block height in sub-modules on startup
@@ -40,8 +35,6 @@ class CDSNotificationInterface : public CValidationInterface
4035
void SynchronousUpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
4136
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
4237
void TransactionAddedToMempool(const CTransactionRef& tx, int64_t nAcceptTime, uint64_t mempool_sequence) override;
43-
void TransactionRemovedFromMempool(const CTransactionRef& ptx, MemPoolRemovalReason reason,
44-
uint64_t mempool_sequence) override;
4538
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex) override;
4639
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) override;
4740
void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff) override;
@@ -54,7 +47,6 @@ class CDSNotificationInterface : public CValidationInterface
5447
CGovernanceManager& m_govman;
5548
const ChainstateManager& m_chainman;
5649
const std::unique_ptr<CDeterministicMNManager>& m_dmnman;
57-
const std::unique_ptr<LLMQContext>& m_llmq_ctx;
5850
};
5951

6052
extern std::unique_ptr<CDSNotificationInterface> g_ds_notification_interface;

src/init.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
#include <instantsend/net_instantsend.h>
9898
#include <llmq/context.h>
9999
#include <llmq/dkgsessionmgr.h>
100+
#include <llmq/signing.h>
100101
#include <llmq/net_signing.h>
101102
#include <llmq/options.h>
102103
#include <llmq/observer/context.h>
@@ -2180,7 +2181,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
21802181
RegisterValidationInterface(node.peerman.get());
21812182

21822183
g_ds_notification_interface = std::make_unique<CDSNotificationInterface>(
2183-
*node.connman, *node.dstxman, *node.mn_sync, *node.govman, chainman, node.dmnman, node.llmq_ctx
2184+
*node.connman, *node.dstxman, *node.mn_sync, *node.govman, chainman, node.dmnman // todo: replace unique_ptr for dmnman to reference
21842185
);
21852186
RegisterValidationInterface(g_ds_notification_interface.get());
21862187

@@ -2212,7 +2213,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
22122213

22132214
// ********************************************************* Step 7d: Setup other Dash services
22142215

2215-
node.peerman->AddExtraHandler(std::make_unique<NetInstantSend>(node.peerman.get(), *node.llmq_ctx->isman, *node.llmq_ctx->qman, chainman.ActiveChainstate()));
2216+
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));
22162217
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));
22172218

22182219
if (node.active_ctx) {
@@ -2431,6 +2432,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
24312432
// so that GetProTxHash() is available for quorum connection setup.
24322433
}
24332434

2435+
// Seed InstantSend tip-height cache; NetInstantSend receives future
2436+
// updates via CValidationInterface but misses InitializeCurrentBlockTip.
2437+
// TODO: move cache updates from NetInstantSend to g_ds_notification due to specific of Tip's processing
2438+
node.llmq_ctx->isman->CacheTipHeight(chainman.ActiveChain().Tip());
2439+
24342440
{
24352441
// Get all UTXOs for each MN collateral in one go so that we can fill coin cache early
24362442
// and reduce further locking overhead for cs_main in other parts of code including GUI

0 commit comments

Comments
 (0)