Skip to content

Commit 2ac59fa

Browse files
Merge #7299: refactor: multiple kernel-0 preparations
0bcb345 refactor: move VerifyChainLock and ChainLockSig between modules to untangle chain-state dependencies (Konstantin Akimov) 3441f04 refactor: move multiple msg_result.h usages headers to implementation (Konstantin Akimov) 69d4a06 feat: better loging of p2p governance objects, separate local and pendings (Konstantin Akimov) f4ee8b4 refactor: drop dependency of CGovernanceManager on net.cpp (Konstantin Akimov) 646c2c8 fix: circular dependency over rpc/evo_util (Konstantin Akimov) 2b2d0a4 refactor: move CDeterministicMN::ToJson to core_write to avoid g_txindex dependency for linking (Konstantin Akimov) 312ca8e refactor: drop pfrom from CGovernanceManager::ProcessVote (Konstantin Akimov) d0414cc refactor: drop dependency of governance/object on core_write (ScriptToAsmStr) (Konstantin Akimov) aa4e692 fix: add guards if CTxMempool is nullptr in chainstate (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented That's some final preparation with various refactors for kernel-0 project, splitted out from #7234 ## What was done? - drop pfrom from CGovernanceManager::ProcessVote - drop dependency of CGovernanceManager on net.cpp - drop dependency of governance/object on core_write (ScriptToAsmStr) - add guards for CTxMempool is nullptr [which could be for chainstate case] - removed multiple includes of msg_result.h over codebase - moved CDeterministicMN::ToJson to core_write to avoid g_txindex - move VerifyChainLock and ChainLockSig between modules to untangle chain-state dependencies NOTE: the circular dependency over `dkgsessionhandler <-> net_processing` is not new, it's pre-existing one but discovered by replacing removing `llmq/dkgsessionhandler.h` from `llmq/dkgsessionmgr.h` and direct adding this include to llmq/observer "llmq/dkgsessionhandler -> net_processing -> llmq/dkgsessionmgr -> llmq/dkgsessionhandler", "llmq/dkgsessionhandler -> net_processing -> llmq/observer -> llmq/dkgsessionhandler", ## How Has This Been Tested? Run unit & functional tests; proof-of-concept of final PR is #7234 Compilation time is not affected by this PR: removing msg_result.h from the header have too small positive impact; replacing chainlock/clsig.h to chainlock/chainlock.h doesn't give any visible change either. ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [ ] 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 _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK 0bcb345 Tree-SHA512: 944adb2da273ac4f72f4c63a5be19511c1cabcee601ea03594a5bfe8cd65ff82512011be2e644fb12bf16c20a4149fcfa1c641df539a32c80cd511335a25c2e3
2 parents 52976e1 + 0bcb345 commit 2ac59fa

28 files changed

Lines changed: 163 additions & 144 deletions

src/chainlock/chainlock.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@
44

55
#include <chainlock/chainlock.h>
66

7-
#include <chainlock/clsig.h>
7+
#include <chain.h>
88
#include <logging.h>
99
#include <spork.h>
1010

1111
namespace chainlock {
1212

13+
ChainLockSig::ChainLockSig() = default;
14+
ChainLockSig::~ChainLockSig() = default;
15+
16+
ChainLockSig::ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig) :
17+
nHeight{nHeight},
18+
blockHash{blockHash},
19+
sig{sig}
20+
{
21+
}
22+
23+
std::string ChainLockSig::ToString() const
24+
{
25+
return strprintf("ChainLockSig(nHeight=%d, blockHash=%s)", nHeight, blockHash.ToString());
26+
}
27+
1328
Chainlocks::Chainlocks(const CSporkManager& sporkman) :
1429
m_sporks(sporkman)
1530
{

src/chainlock/chainlock.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,45 @@
55
#ifndef BITCOIN_CHAINLOCK_CHAINLOCK_H
66
#define BITCOIN_CHAINLOCK_CHAINLOCK_H
77

8-
#include <chain.h>
9-
#include <chainlock/clsig.h>
8+
#include <bls/bls.h>
109
#include <gsl/pointers.h>
10+
#include <serialize.h>
1111
#include <sync.h>
1212
#include <uint256.h>
1313

14+
class CBlockIndex;
1415
class CSporkManager;
16+
class uint256;
1517

1618
namespace chainlock {
1719

1820
//! Depth of block including transactions before it's considered safe
1921
static constexpr int32_t TX_CONFIRM_THRESHOLD{5};
2022

23+
struct ChainLockSig {
24+
private:
25+
int32_t nHeight{-1};
26+
uint256 blockHash;
27+
CBLSSignature sig;
28+
29+
public:
30+
ChainLockSig();
31+
~ChainLockSig();
32+
33+
ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig);
34+
35+
[[nodiscard]] int32_t getHeight() const { return nHeight; }
36+
[[nodiscard]] const uint256& getBlockHash() const { return blockHash; }
37+
[[nodiscard]] const CBLSSignature& getSig() const { return sig; }
38+
[[nodiscard]] bool IsNull() const { return nHeight == -1 && blockHash == uint256(); }
39+
[[nodiscard]] std::string ToString() const;
40+
41+
SERIALIZE_METHODS(ChainLockSig, obj)
42+
{
43+
READWRITE(obj.nHeight, obj.blockHash, obj.sig);
44+
}
45+
};
46+
2147
class Chainlocks
2248
{
2349
private:

src/chainlock/clsig.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,27 @@
44

55
#include <chainlock/clsig.h>
66

7-
#include <tinyformat.h>
7+
#include <chainparams.h>
8+
#include <chainlock/chainlock.h>
9+
#include <llmq/quorumsman.h>
810

911
#include <string_view>
1012

1113
namespace chainlock {
1214
static constexpr std::string_view CLSIG_REQUESTID_PREFIX{"clsig"};
1315

14-
ChainLockSig::ChainLockSig() = default;
15-
ChainLockSig::~ChainLockSig() = default;
16-
17-
ChainLockSig::ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig) :
18-
nHeight{nHeight},
19-
blockHash{blockHash},
20-
sig{sig}
16+
uint256 GenSigRequestId(const int32_t nHeight)
2117
{
18+
return ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, nHeight));
2219
}
2320

24-
std::string ChainLockSig::ToString() const
21+
llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain,
22+
const llmq::CQuorumManager& qman, const chainlock::ChainLockSig& clsig)
2523
{
26-
return strprintf("ChainLockSig(nHeight=%d, blockHash=%s)", nHeight, blockHash.ToString());
27-
}
24+
const auto llmqType = params.llmqTypeChainLocks;
25+
const uint256 request_id = GenSigRequestId(clsig.getHeight());
2826

29-
uint256 GenSigRequestId(const int32_t nHeight)
30-
{
31-
return ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, nHeight));
27+
return llmq::VerifyRecoveredSig(llmqType, chain, qman, clsig.getHeight(), request_id, clsig.getBlockHash(),
28+
clsig.getSig());
3229
}
3330
} // namespace chainlock

src/chainlock/clsig.h

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,28 @@
55
#ifndef BITCOIN_CHAINLOCK_CLSIG_H
66
#define BITCOIN_CHAINLOCK_CLSIG_H
77

8-
#include <serialize.h>
9-
#include <uint256.h>
8+
#include <cstdint>
109

11-
#include <bls/bls.h>
10+
class CChain;
11+
class uint256;
1212

13-
#include <cstdint>
13+
namespace Consensus {
14+
struct Params;
15+
} // namespace Consensus
16+
17+
namespace llmq {
18+
class CQuorumManager;
19+
enum class VerifyRecSigStatus : uint8_t;
20+
} // namespace llmq
1421

1522
namespace chainlock {
16-
struct ChainLockSig {
17-
private:
18-
int32_t nHeight{-1};
19-
uint256 blockHash;
20-
CBLSSignature sig;
21-
22-
public:
23-
ChainLockSig();
24-
~ChainLockSig();
25-
26-
ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig);
27-
28-
[[nodiscard]] int32_t getHeight() const { return nHeight; }
29-
[[nodiscard]] const uint256& getBlockHash() const { return blockHash; }
30-
[[nodiscard]] const CBLSSignature& getSig() const { return sig; }
31-
[[nodiscard]] bool IsNull() const { return nHeight == -1 && blockHash == uint256(); }
32-
[[nodiscard]] std::string ToString() const;
33-
34-
SERIALIZE_METHODS(ChainLockSig, obj)
35-
{
36-
READWRITE(obj.nHeight, obj.blockHash, obj.sig);
37-
}
38-
};
23+
struct ChainLockSig;
3924

4025
//! Generate clsig request ID with block height
4126
uint256 GenSigRequestId(const int32_t nHeight);
27+
28+
llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain,
29+
const llmq::CQuorumManager& qman, const ChainLockSig& clsig);
4230
} // namespace chainlock
4331

4432
#endif // BITCOIN_CHAINLOCK_CLSIG_H

src/chainlock/handler.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44

55
#include <chainlock/handler.h>
66

7+
#include <chain.h>
78
#include <chainlock/chainlock.h>
9+
#include <chainlock/clsig.h>
10+
#include <chainparams.h>
11+
#include <consensus/validation.h>
812
#include <instantsend/instantsend.h>
913
#include <llmq/quorumsman.h>
1014
#include <masternode/sync.h>
1115
#include <msg_result.h>
12-
#include <stats/client.h>
13-
#include <util/std23.h>
14-
15-
#include <chain.h>
16-
#include <chainparams.h>
17-
#include <consensus/validation.h>
1816
#include <node/interface_ui.h>
1917
#include <scheduler.h>
18+
#include <stats/client.h>
2019
#include <txmempool.h>
20+
#include <util/std23.h>
2121
#include <util/thread.h>
2222
#include <util/time.h>
2323
#include <validation.h>
@@ -325,13 +325,4 @@ void ChainlockHandler::Cleanup()
325325
}
326326
}
327327

328-
llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain,
329-
const llmq::CQuorumManager& qman, const chainlock::ChainLockSig& clsig)
330-
{
331-
const auto llmqType = params.llmqTypeChainLocks;
332-
const uint256 request_id = chainlock::GenSigRequestId(clsig.getHeight());
333-
334-
return llmq::VerifyRecoveredSig(llmqType, chain, qman, clsig.getHeight(), request_id, clsig.getBlockHash(),
335-
clsig.getSig());
336-
}
337328
} // namespace chainlock

src/chainlock/handler.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,14 @@
2424

2525
class CBlock;
2626
class CBlockIndex;
27-
class CChain;
2827
class CMasternodeSync;
2928
class ChainstateManager;
3029
class CScheduler;
3130
class CTxMemPool;
3231
struct MessageProcessingResult;
3332

34-
namespace Consensus {
35-
struct Params;
36-
} // namespace Consensus
37-
3833
namespace llmq {
3934
class CQuorumManager;
40-
enum class VerifyRecSigStatus : uint8_t;
4135
} // namespace llmq
4236

4337
namespace chainlock {
@@ -107,9 +101,6 @@ class ChainlockHandler final : public CValidationInterface
107101
private:
108102
void Cleanup() EXCLUSIVE_LOCKS_REQUIRED(!cs);
109103
};
110-
111-
llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain,
112-
const llmq::CQuorumManager& qman, const chainlock::ChainLockSig& clsig);
113104
} // namespace chainlock
114105

115106
#endif // BITCOIN_CHAINLOCK_HANDLER_H

src/chainlock/signing.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#define BITCOIN_CHAINLOCK_SIGNING_H
77

88
#include <chainlock/chainlock.h>
9-
#include <chainlock/clsig.h>
109
#include <llmq/signing.h>
1110
#include <util/time.h>
1211
#include <validationinterface.h>

src/evo/deterministicmns.cpp

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,30 @@
44

55
#include <evo/deterministicmns.h>
66

7+
#include <chainparams.h>
8+
#include <coins.h>
9+
#include <consensus/validation.h>
10+
#include <deploymentstatus.h>
711
#include <evo/dmn_types.h>
812
#include <evo/dmnstate.h>
913
#include <evo/evodb.h>
1014
#include <evo/providertx.h>
1115
#include <evo/simplifiedmns.h>
1216
#include <evo/specialtx.h>
1317
#include <masternode/meta.h>
14-
#include <stats/client.h>
15-
#include <util/helpers.h>
16-
17-
#include <chainparams.h>
18-
#include <coins.h>
19-
#include <consensus/validation.h>
20-
#include <deploymentstatus.h>
21-
#include <index/txindex.h>
2218
#include <node/blockstorage.h>
2319
#include <script/standard.h>
20+
#include <stats/client.h>
2421
#include <uint256.h>
22+
#include <util/helpers.h>
23+
24+
#include <univalue.h>
2525

2626
#include <functional>
2727
#include <optional>
2828
#include <memory>
2929
#include <ranges>
3030

31-
#include <univalue.h>
32-
3331
static const std::string DB_LIST_SNAPSHOT = "dmn_S3";
3432
static const std::string DB_LIST_DIFF = "dmn_D4"; // Bumped for nVersion-first format
3533
static const std::string DB_LIST_DIFF_LEGACY = "dmn_D3"; // Legacy format key
@@ -55,31 +53,6 @@ std::string CDeterministicMN::ToString() const
5553
return strprintf("CDeterministicMN(proTxHash=%s, collateralOutpoint=%s, nOperatorReward=%f, state=%s", proTxHash.ToString(), collateralOutpoint.ToStringShort(), (double)nOperatorReward / 100, pdmnState->ToString());
5654
}
5755

58-
UniValue CDeterministicMN::ToJson() const
59-
{
60-
UniValue obj(UniValue::VOBJ);
61-
obj.pushKV("type", std::string(GetMnType(nType).description));
62-
obj.pushKV("proTxHash", proTxHash.ToString());
63-
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
64-
obj.pushKV("collateralIndex", collateralOutpoint.n);
65-
66-
if (g_txindex) {
67-
CTransactionRef collateralTx;
68-
uint256 nBlockHash;
69-
g_txindex->FindTx(collateralOutpoint.hash, nBlockHash, collateralTx);
70-
if (collateralTx) {
71-
CTxDestination dest;
72-
if (ExtractDestination(collateralTx->vout[collateralOutpoint.n].scriptPubKey, dest)) {
73-
obj.pushKV("collateralAddress", EncodeDestination(dest));
74-
}
75-
}
76-
}
77-
78-
obj.pushKV("operatorReward", (double)nOperatorReward / 100);
79-
obj.pushKV("state", pdmnState->ToJson(nType));
80-
return obj;
81-
}
82-
8356
bool CDeterministicMNList::IsMNValid(const uint256& proTxHash) const
8457
{
8558
auto p = mnMap.find(proTxHash);

src/evo/dmnstate.cpp

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

55
#include <evo/dmnstate.h>
66

7-
#include <script/standard.h>
8-
97
#include <evo/netinfo.h>
10-
#include <rpc/evo_util.h>
11-
8+
#include <script/standard.h>
129
#include <univalue.h>
1310

1411
std::string CDeterministicMNState::ToString() const

0 commit comments

Comments
 (0)