Skip to content

Commit 3e6e8f5

Browse files
Merge #6838: refactor: split off governance masternode-only logic to GovernanceSigner, drop Relay()s and use periodic relay instead, minor cleanup
b51cd1d lint: apply most `clang-format` suggestions, update circular allowlist (Kittywhiskers Van Gogh) 700e069 refactor: cleanup headers and forward decls (Kittywhiskers Van Gogh) c516fd3 refactor: apply review suggestions (Kittywhiskers Van Gogh) d19e1f3 fix: add `nullptr` check before using `FindGovernanceObject()` retval (Kittywhiskers Van Gogh) 1777919 refactor: use `std::chrono` for governance time constants (Kittywhiskers Van Gogh) 4d96f5f refactor: move `DoMaintenance()` inside `Schedule()` (Kittywhiskers Van Gogh) e224991 governance: add lock annotations for `cs_relay` (Kittywhiskers Van Gogh) df589c7 governance: introduce task for relaying governance objects (Kittywhiskers Van Gogh) 3811924 governance: drop `Relay()` from `CGovernance{Object,Vote}` (Kittywhiskers Van Gogh) 63448ff refactor: abstract away parent implementation from signer (Kittywhiskers Van Gogh) 757ded3 refactor: remove need for access to private members (Kittywhiskers Van Gogh) bd6af83 refactor: separate masternode mode logic into dedicated signer class (Kittywhiskers Van Gogh) 2b74e15 refactor: move masternode mode logic to `governance/signing.cpp` (Kittywhiskers Van Gogh) fefbe27 refactor: replace `Sign` functions with direct activeman call (Kittywhiskers Van Gogh) Pull request description: ## Additional Information * Depends on #6828 * Depends on #6842 * Depends on #6877 * Dependency for #6849 * To reduce the proliferation of `PeerManager` in governance logic, relaying has been centralized to `CGovernanceManager` and now done through a scheduled task that processes a queue of requests. This reduces the amount of code that needs to fetch a reference to `PeerManager` in order to queue a message for relay and brings us closer to dropping it as a member in other objects. * On test chains, the queue of requests is processed every second but on mainnet, it is processed every 5 seconds. This is because functional tests assume instantaneous relay and fail if it takes too long to relay messages (as cascading delays cause test timeout). * Likewise, to reduce the references to `CActiveMasternodeManager`, signing logic is consolidated to `SignBasic()` with the objects using simple getter/setters (or direct assignment) where applicable. ## Breaking Changes None expected. ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK b51cd1d knst: utACK b51cd1d Tree-SHA512: cd4bba1e7314695a215a8a83e2d5319be8d2eb2e88eb42f641f6c88ca6d74ee68ced9e95475c6b1d93f5b061993efa6a195d23f61a8775f920867d9836a0dcf8
2 parents ee41b18 + b51cd1d commit 3e6e8f5

28 files changed

+691
-543
lines changed

src/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,12 @@ BITCOIN_CORE_H = \
222222
evo/specialtxman.h \
223223
evo/types.h \
224224
dsnotificationinterface.h \
225-
governance/governance.h \
226225
governance/classes.h \
227226
governance/common.h \
227+
governance/governance.h \
228228
governance/exceptions.h \
229229
governance/object.h \
230+
governance/signing.h \
230231
governance/validators.h \
231232
governance/vote.h \
232233
governance/votedb.h \
@@ -510,6 +511,7 @@ libbitcoin_node_a_SOURCES = \
510511
governance/exceptions.cpp \
511512
governance/governance.cpp \
512513
governance/object.cpp \
514+
governance/signing.cpp \
513515
governance/validators.cpp \
514516
governance/vote.cpp \
515517
governance/votedb.cpp \

src/coinjoin/coinjoin.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <bls/bls.h>
1717
#include <chainlock/chainlock.h>
1818
#include <instantsend/instantsend.h>
19-
#include <masternode/node.h>
2019
#include <masternode/sync.h>
2120

2221
#include <string>
@@ -45,18 +44,6 @@ uint256 CCoinJoinQueue::GetSignatureHash() const
4544
}
4645
uint256 CCoinJoinQueue::GetHash() const { return SerializeHash(*this, SER_NETWORK, PROTOCOL_VERSION); }
4746

48-
bool CCoinJoinQueue::Sign(const CActiveMasternodeManager& mn_activeman)
49-
{
50-
uint256 hash = GetSignatureHash();
51-
CBLSSignature sig = mn_activeman.Sign(hash, /*is_legacy=*/ false);
52-
if (!sig.IsValid()) {
53-
return false;
54-
}
55-
vchSig = sig.ToByteVector(false);
56-
57-
return true;
58-
}
59-
6047
bool CCoinJoinQueue::CheckSignature(const CBLSPublicKey& blsPubKey) const
6148
{
6249
if (!CBLSSignature(Span{vchSig}, false).VerifyInsecure(blsPubKey, GetSignatureHash(), false)) {
@@ -84,18 +71,6 @@ uint256 CCoinJoinBroadcastTx::GetSignatureHash() const
8471
return SerializeHash(*this, SER_GETHASH, PROTOCOL_VERSION);
8572
}
8673

87-
bool CCoinJoinBroadcastTx::Sign(const CActiveMasternodeManager& mn_activeman)
88-
{
89-
uint256 hash = GetSignatureHash();
90-
CBLSSignature sig = mn_activeman.Sign(hash, /*is_legacy=*/ false);
91-
if (!sig.IsValid()) {
92-
return false;
93-
}
94-
vchSig = sig.ToByteVector(false);
95-
96-
return true;
97-
}
98-
9974
bool CCoinJoinBroadcastTx::CheckSignature(const CBLSPublicKey& blsPubKey) const
10075
{
10176
if (!CBLSSignature(Span{vchSig}, false).VerifyInsecure(blsPubKey, GetSignatureHash(), false)) {

src/coinjoin/coinjoin.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
#include <optional>
2323
#include <utility>
2424

25-
class CActiveMasternodeManager;
2625
class CChainState;
2726
class CBLSPublicKey;
2827
class CBlockIndex;
2928
class ChainstateManager;
3029
class CMasternodeSync;
3130
class CTxMemPool;
32-
class TxValidationState;
3331

3432
namespace llmq {
3533
class CChainLocksHandler;
@@ -209,14 +207,7 @@ class CCoinJoinQueue
209207

210208
[[nodiscard]] uint256 GetHash() const;
211209
[[nodiscard]] uint256 GetSignatureHash() const;
212-
/** Sign this mixing transaction
213-
* return true if all conditions are met:
214-
* 1) we have an active Masternode,
215-
* 2) we have a valid Masternode private key,
216-
* 3) we signed the message successfully, and
217-
* 4) we verified the message successfully
218-
*/
219-
bool Sign(const CActiveMasternodeManager& mn_activeman);
210+
220211
/// Check if we have a valid Masternode address
221212
[[nodiscard]] bool CheckSignature(const CBLSPublicKey& blsPubKey) const;
222213

@@ -284,7 +275,6 @@ class CCoinJoinBroadcastTx
284275

285276
[[nodiscard]] uint256 GetSignatureHash() const;
286277

287-
bool Sign(const CActiveMasternodeManager& mn_activeman);
288278
[[nodiscard]] bool CheckSignature(const CBLSPublicKey& blsPubKey) const;
289279

290280
// Used only for unit tests

src/coinjoin/server.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ void CCoinJoinServer::CommitFinalTransaction()
345345
if (!m_dstxman.GetDSTX(hashTx)) {
346346
CCoinJoinBroadcastTx dstxNew(finalTransaction, m_mn_activeman.GetOutPoint(), m_mn_activeman.GetProTxHash(),
347347
GetAdjustedTime());
348-
dstxNew.Sign(m_mn_activeman);
348+
dstxNew.vchSig = m_mn_activeman.SignBasic(dstxNew.GetSignatureHash());
349349
m_dstxman.AddDSTX(dstxNew);
350350
}
351351

@@ -504,7 +504,7 @@ void CCoinJoinServer::CheckForCompleteQueue()
504504
GetAdjustedTime(), true);
505505
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CheckForCompleteQueue -- queue is ready, signing and relaying (%s) " /* Continued */
506506
"with %d participants\n", dsq.ToString(), vecSessionCollaterals.size());
507-
dsq.Sign(m_mn_activeman);
507+
dsq.vchSig = m_mn_activeman.SignBasic(dsq.GetSignatureHash());
508508
m_peerman.RelayDSQ(dsq);
509509
WITH_LOCK(cs_vecqueue, vecCoinJoinQueue.push_back(dsq));
510510
}
@@ -714,7 +714,7 @@ bool CCoinJoinServer::CreateNewSession(const CCoinJoinAccept& dsa, PoolMessage&
714714
CCoinJoinQueue dsq(nSessionDenom, m_mn_activeman.GetOutPoint(), m_mn_activeman.GetProTxHash(),
715715
GetAdjustedTime(), false);
716716
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString());
717-
dsq.Sign(m_mn_activeman);
717+
dsq.vchSig = m_mn_activeman.SignBasic(dsq.GetSignatureHash());
718718
m_peerman.RelayDSQ(dsq);
719719
LOCK(cs_vecqueue);
720720
vecCoinJoinQueue.push_back(dsq);

src/dsnotificationinterface.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@
2424
CDSNotificationInterface::CDSNotificationInterface(CConnman& connman,
2525
CMasternodeSync& mn_sync,
2626
CGovernanceManager& govman,
27-
PeerManager& peerman,
2827
const ChainstateManager& chainman,
29-
const CActiveMasternodeManager* const mn_activeman,
3028
const std::unique_ptr<CDeterministicMNManager>& dmnman,
3129
const std::unique_ptr<LLMQContext>& llmq_ctx,
3230
const std::unique_ptr<CJContext>& cj_ctx)
3331
: m_connman(connman),
3432
m_mn_sync(mn_sync),
3533
m_govman(govman),
36-
m_peerman(peerman),
3734
m_chainman(chainman),
38-
m_mn_activeman(mn_activeman),
3935
m_dmnman(dmnman),
4036
m_llmq_ctx(llmq_ctx),
4137
m_cj_ctx(cj_ctx) {}
@@ -94,7 +90,7 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con
9490
m_llmq_ctx->qdkgsman->UpdatedBlockTip(pindexNew, fInitialDownload);
9591

9692
if (m_govman.IsValid()) {
97-
m_govman.UpdatedBlockTip(pindexNew, m_connman, m_peerman, m_mn_activeman);
93+
m_govman.UpdatedBlockTip(pindexNew);
9894
}
9995
}
10096

src/dsnotificationinterface.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77

88
#include <validationinterface.h>
99

10-
class CActiveMasternodeManager;
1110
class CConnman;
1211
class CDeterministicMNManager;
1312
class CGovernanceManager;
1413
class ChainstateManager;
1514
class CMasternodeSync;
16-
class PeerManager;
1715
struct CJContext;
1816
struct LLMQContext;
1917

@@ -23,9 +21,7 @@ class CDSNotificationInterface : public CValidationInterface
2321
explicit CDSNotificationInterface(CConnman& connman,
2422
CMasternodeSync& mn_sync,
2523
CGovernanceManager& govman,
26-
PeerManager& peerman,
2724
const ChainstateManager& chainman,
28-
const CActiveMasternodeManager* const mn_activeman,
2925
const std::unique_ptr<CDeterministicMNManager>& dmnman,
3026
const std::unique_ptr<LLMQContext>& llmq_ctx,
3127
const std::unique_ptr<CJContext>& cj_ctx);
@@ -52,9 +48,7 @@ class CDSNotificationInterface : public CValidationInterface
5248
CConnman& m_connman;
5349
CMasternodeSync& m_mn_sync;
5450
CGovernanceManager& m_govman;
55-
PeerManager& m_peerman;
5651
const ChainstateManager& m_chainman;
57-
const CActiveMasternodeManager* const m_mn_activeman;
5852
const std::unique_ptr<CDeterministicMNManager>& m_dmnman;
5953
const std::unique_ptr<LLMQContext>& m_llmq_ctx;
6054
const std::unique_ptr<CJContext>& m_cj_ctx;

0 commit comments

Comments
 (0)