Skip to content

Commit 63448ff

Browse files
committed
refactor: abstract away parent implementation from signer
1 parent 757ded3 commit 63448ff

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

src/governance/governance.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
#include <cachemap.h>
99
#include <cachemultimap.h>
10+
#include <governance/signing.h>
11+
1012
#include <protocol.h>
1113
#include <sync.h>
1214

15+
#include <chrono>
1316
#include <limits>
1417
#include <map>
1518
#include <memory>
19+
#include <optional>
1620
#include <set>
1721
#include <string>
1822
#include <string_view>
@@ -236,7 +240,7 @@ class GovernanceStore
236240
//
237241
// Governance Manager : Contains all proposals for the budget
238242
//
239-
class CGovernanceManager : public GovernanceStore
243+
class CGovernanceManager : public GovernanceStore, public GovernanceSignerParent
240244
{
241245
friend class CGovernanceObject;
242246

@@ -275,7 +279,7 @@ class CGovernanceManager : public GovernanceStore
275279

276280
bool LoadCache(bool load_cache);
277281

278-
bool IsValid() const { return is_valid; }
282+
bool IsValid() const override { return is_valid; }
279283

280284
/**
281285
* This is called by AlreadyHave in net_processing.cpp as part of the inventory
@@ -292,15 +296,15 @@ class CGovernanceManager : public GovernanceStore
292296
void DoMaintenance(CConnman& connman);
293297

294298
const CGovernanceObject* FindConstGovernanceObject(const uint256& nHash) const EXCLUSIVE_LOCKS_REQUIRED(cs);
295-
CGovernanceObject* FindGovernanceObject(const uint256& nHash) EXCLUSIVE_LOCKS_REQUIRED(!cs);
296-
CGovernanceObject* FindGovernanceObjectByDataHash(const uint256& nDataHash) EXCLUSIVE_LOCKS_REQUIRED(!cs);
299+
CGovernanceObject* FindGovernanceObject(const uint256& nHash) override EXCLUSIVE_LOCKS_REQUIRED(!cs);
300+
CGovernanceObject* FindGovernanceObjectByDataHash(const uint256& nDataHash) override EXCLUSIVE_LOCKS_REQUIRED(!cs);
297301
void DeleteGovernanceObject(const uint256& nHash);
298302

299303
// These commands are only used in RPC
300304
std::vector<CGovernanceVote> GetCurrentVotes(const uint256& nParentHash, const COutPoint& mnCollateralOutpointFilter) const;
301305
void GetAllNewerThan(std::vector<CGovernanceObject>& objs, int64_t nMoreThanTime) const;
302306

303-
void AddGovernanceObject(CGovernanceObject& govobj, PeerManager& peerman, const CNode* pfrom = nullptr);
307+
void AddGovernanceObject(CGovernanceObject& govobj, PeerManager& peerman, const CNode* pfrom = nullptr) override;
304308

305309
void CheckAndRemove();
306310

@@ -310,7 +314,7 @@ class CGovernanceManager : public GovernanceStore
310314
int64_t GetLastDiffTime() const { return nTimeLastDiff; }
311315
void UpdateLastDiffTime(int64_t nTimeIn) { nTimeLastDiff = nTimeIn; }
312316

313-
int GetCachedBlockHeight() const { return nCachedBlockHeight; }
317+
int GetCachedBlockHeight() const override { return nCachedBlockHeight; }
314318

315319
// Accessors for thread-safe access to maps
316320
bool HaveObjectForHash(const uint256& nHash) const;
@@ -327,11 +331,11 @@ class CGovernanceManager : public GovernanceStore
327331

328332
void MasternodeRateUpdate(const CGovernanceObject& govobj);
329333

330-
bool MasternodeRateCheck(const CGovernanceObject& govobj, bool fUpdateFailStatus = false);
334+
bool MasternodeRateCheck(const CGovernanceObject& govobj, bool fUpdateFailStatus = false) override;
331335

332336
bool MasternodeRateCheck(const CGovernanceObject& govobj, bool fUpdateFailStatus, bool fForce, bool& fRateCheckBypassed);
333337

334-
bool ProcessVoteAndRelay(const CGovernanceVote& vote, CGovernanceException& exception, CConnman& connman, PeerManager& peerman);
338+
bool ProcessVoteAndRelay(const CGovernanceVote& vote, CGovernanceException& exception, CConnman& connman, PeerManager& peerman) override;
335339

336340
void CheckPostponedObjects(PeerManager& peerman);
337341

@@ -352,7 +356,7 @@ class CGovernanceManager : public GovernanceStore
352356
* - Track governance objects which are triggers
353357
* - After triggers are activated and executed, they can be removed
354358
*/
355-
std::vector<std::shared_ptr<CSuperblock>> GetActiveTriggers() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
359+
std::vector<std::shared_ptr<CSuperblock>> GetActiveTriggers() const override EXCLUSIVE_LOCKS_REQUIRED(!cs);
356360
bool AddNewTrigger(uint256 nHash) EXCLUSIVE_LOCKS_REQUIRED(cs);
357361
void CleanAndRemoveTriggers() EXCLUSIVE_LOCKS_REQUIRED(cs);
358362

@@ -376,10 +380,10 @@ class CGovernanceManager : public GovernanceStore
376380
bool IsValidSuperblock(const CChain& active_chain, const CDeterministicMNList& tip_mn_list,
377381
const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
378382

379-
bool GetBestSuperblock(const CDeterministicMNList& tip_mn_list, CSuperblock_sptr& pSuperblockRet, int nBlockHeight)
383+
bool GetBestSuperblock(const CDeterministicMNList& tip_mn_list, CSuperblock_sptr& pSuperblockRet, int nBlockHeight) override
380384
EXCLUSIVE_LOCKS_REQUIRED(!cs);
381385

382-
std::vector<std::shared_ptr<const CGovernanceObject>> GetApprovedProposals(const CDeterministicMNList& tip_mn_list)
386+
std::vector<std::shared_ptr<const CGovernanceObject>> GetApprovedProposals(const CDeterministicMNList& tip_mn_list) override
383387
EXCLUSIVE_LOCKS_REQUIRED(!cs);
384388

385389
private:

src/governance/signing.cpp

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

77
#include <evo/deterministicmns.h>
88
#include <governance/classes.h>
9-
#include <governance/governance.h>
109
#include <masternode/node.h>
1110
#include <masternode/sync.h>
1211

@@ -18,7 +17,7 @@
1817

1918
#include <algorithm>
2019

21-
GovernanceSigner::GovernanceSigner(CConnman& connman, CDeterministicMNManager& dmnman, CGovernanceManager& govman,
20+
GovernanceSigner::GovernanceSigner(CConnman& connman, CDeterministicMNManager& dmnman, GovernanceSignerParent& govman,
2221
PeerManager& peerman, const CActiveMasternodeManager& mn_activeman,
2322
const ChainstateManager& chainman, const CMasternodeSync& mn_sync) :
2423
m_connman{connman},

src/governance/signing.h

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,46 @@
1010

1111
#include <uint256.h>
1212

13+
#include <memory>
1314
#include <optional>
15+
#include <vector>
1416

1517
class CActiveMasternodeManager;
1618
class CBlockIndex;
1719
class CConnman;
20+
class CDeterministicMNList;
1821
class CDeterministicMNManager;
19-
class CGovernanceManager;
22+
class CGovernanceException;
23+
class CGovernanceVote;
2024
class ChainstateManager;
2125
class CMasternodeSync;
26+
class CNode;
2227
class PeerManager;
2328
enum vote_outcome_enum_t : int;
2429

30+
class GovernanceSignerParent
31+
{
32+
public:
33+
virtual ~GovernanceSignerParent() = default;
34+
35+
virtual bool IsValid() const = 0;
36+
virtual bool GetBestSuperblock(const CDeterministicMNList& tip_mn_list, std::shared_ptr<CSuperblock>& pSuperblockRet, int nBlockHeight) = 0;
37+
virtual bool MasternodeRateCheck(const CGovernanceObject& govobj, bool fUpdateFailStatus = false) = 0;
38+
virtual bool ProcessVoteAndRelay(const CGovernanceVote& vote, CGovernanceException& exception, CConnman& connman, PeerManager& peerman) = 0;
39+
virtual int GetCachedBlockHeight() const = 0;
40+
virtual CGovernanceObject* FindGovernanceObject(const uint256& nHash) = 0;
41+
virtual CGovernanceObject* FindGovernanceObjectByDataHash(const uint256& nDataHash) = 0;
42+
virtual std::vector<std::shared_ptr<CSuperblock>> GetActiveTriggers() const = 0;
43+
virtual std::vector<std::shared_ptr<const CGovernanceObject>> GetApprovedProposals(const CDeterministicMNList& tip_mn_list) = 0;
44+
virtual void AddGovernanceObject(CGovernanceObject& govobj, PeerManager& peerman, const CNode* pfrom = nullptr) = 0;
45+
};
46+
2547
class GovernanceSigner
2648
{
2749
private:
2850
CConnman& m_connman;
2951
CDeterministicMNManager& m_dmnman;
30-
CGovernanceManager& m_govman;
52+
GovernanceSignerParent& m_govman;
3153
PeerManager& m_peerman;
3254
const CActiveMasternodeManager& m_mn_activeman;
3355
const ChainstateManager& m_chainman;
@@ -37,7 +59,7 @@ class GovernanceSigner
3759
std::optional<uint256> votedFundingYesTriggerHash{std::nullopt};
3860

3961
public:
40-
explicit GovernanceSigner(CConnman& connman, CDeterministicMNManager& dmnman, CGovernanceManager& govman,
62+
explicit GovernanceSigner(CConnman& connman, CDeterministicMNManager& dmnman, GovernanceSignerParent& govman,
4163
PeerManager& peerman, const CActiveMasternodeManager& mn_activeman,
4264
const ChainstateManager& chainman, const CMasternodeSync& mn_sync);
4365
~GovernanceSigner();

src/masternode/active/context.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <chainlock/chainlock.h>
88
#include <chainlock/signing.h>
99
#include <coinjoin/server.h>
10+
#include <governance/governance.h>
1011
#include <governance/signing.h>
1112
#include <instantsend/instantsend.h>
1213
#include <instantsend/signing.h>

0 commit comments

Comments
 (0)