Skip to content

Commit

Permalink
refactor: split llmq/utils to Quorum Calculation and llmq/options (#5790
Browse files Browse the repository at this point in the history
)

## Issue being fixed or feature implemented
`llmq/utils` has simple util code that used all over code base and also
have too heavy code for calculation quorums such as:
`GetAllQuorumMembers`, `EnsureQuorumConnections` and other.

These helpers for calculation quorums are used only by
evo/deterministicmns, evo/simplifiedmns and llmq/* modules, but
llmq/utils is included in many other modules for various trivial
helpers.



## What was done?
Prior work:
 - #5753
 - #5486
 See also #4798

This PR remove all non-quorum calculation code from llmq/utils.
Eventually it happens that easier to take everything out rather than
move Quorum Calculation to new place atm:
- new module llmq/options have a code related to various params, command
line options, spork-related etc
- llmq/utils is not included in various files which do not use any
llmq/utils code
 - helper `BuildCommitmentHash` goes to llmq/commitment
 - helper `BuildSignHash` goes to llmq/signing
- helper `GetLLMQParam` inlined since it's trivial (it has not been
trivial when introduced ages ago)
- removed dependency of `IsQuorumEnabled` on CQuorumManager which means
`quorumManager` deglobalization is done for 90%


## How Has This Been Tested?
 - Run unit functional tests
- updated circular dependencies
`test/lint/lint-circular-dependencies.sh`
- check that llmq/utils is not included without needs to calculate
Quorums Members
```
$ grep -r include src/ 2> /dev/null | grep -v .Po: | grep -vE 'llmq/utils.(h|cpp)': | grep llmq/utils  
src/evo/mnauth.cpp:#include <llmq/utils.h>
src/evo/deterministicmns.cpp:#include <llmq/utils.h>
src/llmq/quorums.cpp:#include <llmq/utils.h>
src/llmq/blockprocessor.cpp:#include <llmq/utils.h>
src/llmq/commitment.cpp:#include <llmq/utils.h>
src/llmq/debug.cpp:#include <llmq/utils.h>
src/llmq/dkgsessionhandler.cpp:#include <llmq/utils.h>
src/llmq/dkgsession.cpp:#include <llmq/utils.h>
src/llmq/dkgsessionmgr.cpp:#include <llmq/utils.h>
src/rpc/quorums.cpp:#include <llmq/utils.h>
```


## 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
  • Loading branch information
knst authored Jan 18, 2024
1 parent dd7fac4 commit 852adb5
Show file tree
Hide file tree
Showing 41 changed files with 506 additions and 472 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ BITCOIN_CORE_H = \
llmq/ehf_signals.cpp \
llmq/ehf_signals.h \
llmq/instantsend.h \
llmq/options.h \
llmq/params.h \
llmq/quorums.h \
llmq/signing.h \
Expand Down Expand Up @@ -456,6 +457,7 @@ libbitcoin_server_a_SOURCES = \
llmq/dkgsession.cpp \
llmq/context.cpp \
llmq/instantsend.cpp \
llmq/options.cpp \
llmq/snapshot.cpp \
llmq/signing.cpp \
llmq/signing_shares.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class CChainParams
int FulfilledRequestExpireTime() const { return nFulfilledRequestExpireTime; }
const std::vector<std::string>& SporkAddresses() const { return vSporkAddresses; }
int MinSporkKeys() const { return nMinSporkKeys; }
std::optional<Consensus::LLMQParams> GetLLMQ(Consensus::LLMQType llmqType) const;
[[nodiscard]] std::optional<Consensus::LLMQParams> GetLLMQ(Consensus::LLMQType llmqType) const;

protected:
CChainParams() {}
Expand Down
1 change: 0 additions & 1 deletion src/coinjoin/coinjoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <governance/common.h>
#include <llmq/chainlocks.h>
#include <llmq/instantsend.h>
#include <llmq/utils.h>
#include <masternode/node.h>
#include <masternode/sync.h>
#include <messagesigner.h>
Expand Down
3 changes: 1 addition & 2 deletions src/evo/assetlocktx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <llmq/commitment.h>
#include <llmq/signing.h>
#include <llmq/utils.h>
#include <llmq/quorums.h>

#include <chainparams.h>
Expand Down Expand Up @@ -134,7 +133,7 @@ bool CAssetUnlockPayload::VerifySig(const uint256& msgHash, gsl::not_null<const

const uint256 requestId = ::SerializeHash(std::make_pair(ASSETUNLOCK_REQUESTID_PREFIX, index));

if (const uint256 signHash = llmq::utils::BuildSignHash(llmqType, quorum->qc->quorumHash, requestId, msgHash);
if (const uint256 signHash = llmq::BuildSignHash(llmqType, quorum->qc->quorumHash, requestId, msgHash);
quorumSig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash)) {
return true;
}
Expand Down
14 changes: 7 additions & 7 deletions src/evo/cbtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <llmq/blockprocessor.h>
#include <llmq/chainlocks.h>
#include <llmq/commitment.h>
#include <llmq/utils.h>
#include <llmq/options.h>
#include <node/blockstorage.h>
#include <evo/simplifiedmns.h>
#include <evo/specialtx.h>
Expand Down Expand Up @@ -199,9 +199,9 @@ auto CachedGetQcHashesQcIndexedHashes(const CBlockIndex* pindexPrev, const llmq:
qcIndexedHashes_cached.clear();

for (const auto& [llmqType, vecBlockIndexes] : quorums) {
const auto& llmq_params_opt = llmq::GetLLMQParams(llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(llmqType);
assert(llmq_params_opt.has_value());
bool rotation_enabled = llmq::utils::IsQuorumRotationEnabled(llmq_params_opt.value(), pindexPrev);
bool rotation_enabled = llmq::IsQuorumRotationEnabled(llmq_params_opt.value(), pindexPrev);
auto& vec_hashes = qcHashes_cached[llmqType];
vec_hashes.reserve(vecBlockIndexes.size());
auto& map_indexed_hashes = qcIndexedHashes_cached[llmqType];
Expand Down Expand Up @@ -265,13 +265,13 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
// having null commitments is ok but we don't use them here, move to the next tx
continue;
}
const auto& llmq_params_opt = llmq::GetLLMQParams(opt_qc->commitment.llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(opt_qc->commitment.llmqType);
if (!llmq_params_opt.has_value()) {
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-qc-commitment-type-calc-cbtx-quorummerkleroot");
}
const auto& llmq_params = llmq_params_opt.value();
auto qcHash = ::SerializeHash(opt_qc->commitment);
if (llmq::utils::IsQuorumRotationEnabled(llmq_params, pindexPrev)) {
const auto qcHash = ::SerializeHash(opt_qc->commitment);
if (llmq::IsQuorumRotationEnabled(llmq_params, pindexPrev)) {
auto& map_indexed_hashes = qcIndexedHashes[opt_qc->commitment.llmqType];
map_indexed_hashes[opt_qc->commitment.quorumIndex] = qcHash;
} else {
Expand All @@ -298,7 +298,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
vec_hashes_final.reserve(CalcHashCountFromQCHashes(qcHashes));

for (const auto& [llmqType, vec_hashes] : qcHashes) {
const auto& llmq_params_opt = llmq::GetLLMQParams(llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(llmqType);
assert(llmq_params_opt.has_value());
if (vec_hashes.size() > size_t(llmq_params_opt->signingActiveQuorumCount)) {
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "excess-quorums-calc-cbtx-quorummerkleroot");
Expand Down
2 changes: 1 addition & 1 deletion src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-qc-payload");
}
if (!opt_qc->commitment.IsNull()) {
const auto& llmq_params_opt = llmq::GetLLMQParams(opt_qc->commitment.llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(opt_qc->commitment.llmqType);
if (!llmq_params_opt.has_value()) {
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-qc-commitment-type");
}
Expand Down
3 changes: 1 addition & 2 deletions src/evo/mnhftx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <evo/specialtx.h>
#include <llmq/commitment.h>
#include <llmq/signing.h>
#include <llmq/utils.h>
#include <llmq/quorums.h>
#include <node/blockstorage.h>

Expand Down Expand Up @@ -93,7 +92,7 @@ bool MNHFTx::Verify(const uint256& quorumHash, const uint256& requestId, const u
const Consensus::LLMQType& llmqType = Params().GetConsensus().llmqTypeMnhf;
const auto quorum = llmq::quorumManager->GetQuorum(llmqType, quorumHash);

const uint256 signHash = llmq::utils::BuildSignHash(llmqType, quorum->qc->quorumHash, requestId, msgHash);
const uint256 signHash = llmq::BuildSignHash(llmqType, quorum->qc->quorumHash, requestId, msgHash);
if (!sig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash)) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-invalid");
}
Expand Down
1 change: 0 additions & 1 deletion src/governance/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <evo/deterministicmns.h>
#include <governance/governance.h>
#include <governance/validators.h>
#include <llmq/utils.h>
#include <masternode/meta.h>
#include <masternode/sync.h>
#include <messagesigner.h>
Expand Down
1 change: 0 additions & 1 deletion src/governance/vote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <bls/bls.h>
#include <chainparams.h>
#include <key.h>
#include <llmq/utils.h>
#include <masternode/sync.h>
#include <messagesigner.h>
#include <net.h>
Expand Down
6 changes: 3 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@
#include <llmq/instantsend.h>
#include <llmq/quorums.h>
#include <llmq/dkgsessionmgr.h>
#include <llmq/options.h>
#include <llmq/signing.h>
#include <llmq/snapshot.h>
#include <llmq/utils.h>
#include <llmq/signing_shares.h>

#include <statsd_client.h>
Expand Down Expand Up @@ -1428,8 +1428,8 @@ bool AppInitParameterInteraction(const ArgsManager& args)
}

try {
const bool fRecoveryEnabled{llmq::utils::QuorumDataRecoveryEnabled()};
const bool fQuorumVvecRequestsEnabled{llmq::utils::GetEnabledQuorumVvecSyncEntries().size() > 0};
const bool fRecoveryEnabled{llmq::QuorumDataRecoveryEnabled()};
const bool fQuorumVvecRequestsEnabled{llmq::GetEnabledQuorumVvecSyncEntries().size() > 0};
if (!fRecoveryEnabled && fQuorumVvecRequestsEnabled) {
InitWarning(Untranslated("-llmq-qvvec-sync set but recovery is disabled due to -llmq-data-recovery=0"));
}
Expand Down
31 changes: 16 additions & 15 deletions src/llmq/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <llmq/blockprocessor.h>
#include <llmq/commitment.h>
#include <llmq/options.h>
#include <llmq/utils.h>

#include <evo/evodb.h>
Expand All @@ -27,8 +28,8 @@

static void PreComputeQuorumMembers(const CBlockIndex* pindex, bool reset_cache = false)
{
for (const Consensus::LLMQParams& params : llmq::utils::GetEnabledQuorumParams(pindex->pprev)) {
if (llmq::utils::IsQuorumRotationEnabled(params, pindex) && (pindex->nHeight % params.dkgInterval == 0)) {
for (const Consensus::LLMQParams& params : llmq::GetEnabledQuorumParams(pindex->pprev)) {
if (llmq::IsQuorumRotationEnabled(params, pindex) && (pindex->nHeight % params.dkgInterval == 0)) {
llmq::utils::GetAllQuorumMembers(params.type, pindex, reset_cache);
}
}
Expand Down Expand Up @@ -67,7 +68,7 @@ PeerMsgRet CQuorumBlockProcessor::ProcessMessage(const CNode& peer, std::string_
return tl::unexpected{100};
}

const auto& llmq_params_opt = GetLLMQParams(qc.llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(qc.llmqType);
if (!llmq_params_opt.has_value()) {
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- invalid commitment type %d from peer=%d\n", __func__,
ToUnderlying(qc.llmqType), peer.GetId());
Expand Down Expand Up @@ -165,7 +166,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, gsl::not_null<cons
// until the first non-null commitment has been mined. After the non-null commitment, no other commitments are
// allowed, including null commitments.
// Note: must only check quorums that were enabled at the _previous_ block height to match mining logic
for (const Consensus::LLMQParams& params : utils::GetEnabledQuorumParams(pindex->pprev)) {
for (const Consensus::LLMQParams& params : GetEnabledQuorumParams(pindex->pprev)) {
// skip these checks when replaying blocks after the crash
if (m_chainstate.m_chain.Tip() == nullptr) {
break;
Expand All @@ -181,7 +182,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, gsl::not_null<cons
if (numCommitmentsRequired > numCommitmentsInNewBlock) {
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-qc-missing");
}
if (llmq::utils::IsQuorumRotationEnabled(params, pindex)) {
if (IsQuorumRotationEnabled(params, pindex)) {
LogPrintf("[ProcessBlock] h[%d] numCommitmentsRequired[%d] numCommitmentsInNewBlock[%d]\n", pindex->nHeight, numCommitmentsRequired, numCommitmentsInNewBlock);
}
}
Expand Down Expand Up @@ -217,7 +218,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH
{
AssertLockHeld(cs_main);

const auto& llmq_params_opt = GetLLMQParams(qc.llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(qc.llmqType);
if (!llmq_params_opt.has_value()) {
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- invalid commitment type %d\n", __func__, ToUnderlying(qc.llmqType));
return false;
Expand Down Expand Up @@ -276,7 +277,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH
return true;
}

bool rotation_enabled = utils::IsQuorumRotationEnabled(llmq_params, pQuorumBaseBlockIndex);
bool rotation_enabled = IsQuorumRotationEnabled(llmq_params, pQuorumBaseBlockIndex);

if (rotation_enabled) {
LogPrint(BCLog::LLMQ, "[ProcessCommitment] height[%d] pQuorumBaseBlockIndex[%d] quorumIndex[%d] qversion[%d] Built\n",
Expand Down Expand Up @@ -326,10 +327,10 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, gsl::not_null<const C

m_evoDb.Erase(std::make_pair(DB_MINED_COMMITMENT, std::make_pair(qc.llmqType, qc.quorumHash)));

const auto& llmq_params_opt = GetLLMQParams(qc.llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(qc.llmqType);
assert(llmq_params_opt.has_value());

if (llmq::utils::IsQuorumRotationEnabled(llmq_params_opt.value(), pindex)) {
if (IsQuorumRotationEnabled(llmq_params_opt.value(), pindex)) {
m_evoDb.Erase(BuildInversedHeightKeyIndexed(qc.llmqType, pindex->nHeight, int(qc.quorumIndex)));
} else {
m_evoDb.Erase(BuildInversedHeightKey(qc.llmqType, pindex->nHeight));
Expand Down Expand Up @@ -367,14 +368,14 @@ bool CQuorumBlockProcessor::GetCommitmentsFromBlock(const CBlock& block, gsl::no
}
auto& qc = *opt_qc;

const auto& llmq_params_opt = GetLLMQParams(qc.commitment.llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(qc.commitment.llmqType);
if (!llmq_params_opt.has_value()) {
// should not happen as it was verified before processing the block
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-qc-commitment-type");
}

// only allow one commitment per type and per block (This was changed with rotation)
if (!utils::IsQuorumRotationEnabled(llmq_params_opt.value(), pindex)) {
if (!IsQuorumRotationEnabled(llmq_params_opt.value(), pindex)) {
if (ret.count(qc.commitment.llmqType) != 0) {
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-qc-dup");
}
Expand Down Expand Up @@ -421,7 +422,7 @@ size_t CQuorumBlockProcessor::GetNumCommitmentsRequired(const Consensus::LLMQPar
assert(nHeight <= m_chainstate.m_chain.Height() + 1);
const auto *const pindex = m_chainstate.m_chain.Height() < nHeight ? m_chainstate.m_chain.Tip() : m_chainstate.m_chain.Tip()->GetAncestor(nHeight);

bool rotation_enabled = utils::IsQuorumRotationEnabled(llmqParams, pindex);
bool rotation_enabled = IsQuorumRotationEnabled(llmqParams, pindex);
size_t quorums_num = rotation_enabled ? llmqParams.signingActiveQuorumCount : 1;
size_t ret{0};

Expand Down Expand Up @@ -574,7 +575,7 @@ std::optional<const CBlockIndex*> CQuorumBlockProcessor::GetLastMinedCommitments

std::vector<std::pair<int, const CBlockIndex*>> CQuorumBlockProcessor::GetLastMinedCommitmentsPerQuorumIndexUntilBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex, size_t cycle) const
{
const auto& llmq_params_opt = GetLLMQParams(llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(llmqType);
assert(llmq_params_opt.has_value());
std::vector<std::pair<int, const CBlockIndex*>> ret;

Expand Down Expand Up @@ -626,7 +627,7 @@ std::map<Consensus::LLMQType, std::vector<const CBlockIndex*>> CQuorumBlockProce
for (const auto& params : Params().GetConsensus().llmqs) {
auto& v = ret[params.type];
v.reserve(params.signingActiveQuorumCount);
if (utils::IsQuorumRotationEnabled(params, pindex)) {
if (IsQuorumRotationEnabled(params, pindex)) {
std::vector<std::pair<int, const CBlockIndex*>> commitments = GetLastMinedCommitmentsPerQuorumIndexUntilBlock(params.type, pindex, 0);
std::transform(commitments.begin(), commitments.end(), std::back_inserter(v),
[](const std::pair<int, const CBlockIndex*>& p) { return p.second; });
Expand Down Expand Up @@ -705,7 +706,7 @@ std::optional<std::vector<CFinalCommitment>> CQuorumBlockProcessor::GetMineableC
assert(nHeight <= m_chainstate.m_chain.Height() + 1);
const auto *const pindex = m_chainstate.m_chain.Height() < nHeight ? m_chainstate.m_chain.Tip() : m_chainstate.m_chain.Tip()->GetAncestor(nHeight);

bool rotation_enabled = utils::IsQuorumRotationEnabled(llmqParams, pindex);
bool rotation_enabled = IsQuorumRotationEnabled(llmqParams, pindex);
bool basic_bls_enabled{DeploymentActiveAfter(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
size_t quorums_num = rotation_enabled ? llmqParams.signingActiveQuorumCount : 1;

Expand Down
1 change: 0 additions & 1 deletion src/llmq/chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <llmq/chainlocks.h>
#include <llmq/quorums.h>
#include <llmq/instantsend.h>
#include <llmq/utils.h>
#include <llmq/signing_shares.h>

#include <chain.h>
Expand Down
26 changes: 20 additions & 6 deletions src/llmq/commitment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <chainparams.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <llmq/options.h>
#include <llmq/utils.h>
#include <logging.h>
#include <validation.h>
Expand All @@ -35,14 +36,14 @@ void LogPrintfFinalCommitment(Types... out) {

bool CFinalCommitment::Verify(gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, bool checkSigs) const
{
const auto& llmq_params_opt = GetLLMQParams(llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(llmqType);
if (!llmq_params_opt.has_value()) {
LogPrintfFinalCommitment("q[%s] invalid llmqType=%d\n", quorumHash.ToString(), ToUnderlying(llmqType));
return false;
}
const auto& llmq_params = llmq_params_opt.value();

const uint16_t expected_nversion{CFinalCommitment::GetVersion(utils::IsQuorumRotationEnabled(llmq_params, pQuorumBaseBlockIndex),
const uint16_t expected_nversion{CFinalCommitment::GetVersion(IsQuorumRotationEnabled(llmq_params, pQuorumBaseBlockIndex),
DeploymentActiveAfter(pQuorumBaseBlockIndex, Params().GetConsensus(), Consensus::DEPLOYMENT_V19))};
if (nVersion == 0 || nVersion != expected_nversion) {
LogPrintfFinalCommitment("q[%s] invalid nVersion=%d expectednVersion\n", quorumHash.ToString(), nVersion, expected_nversion);
Expand Down Expand Up @@ -111,7 +112,7 @@ bool CFinalCommitment::Verify(gsl::not_null<const CBlockIndex*> pQuorumBaseBlock

// sigs are only checked when the block is processed
if (checkSigs) {
uint256 commitmentHash = utils::BuildCommitmentHash(llmq_params.type, quorumHash, validMembers, quorumPublicKey, quorumVvecHash);
uint256 commitmentHash = BuildCommitmentHash(llmq_params.type, quorumHash, validMembers, quorumPublicKey, quorumVvecHash);
if (LogAcceptCategory(BCLog::LLMQ)) {
std::stringstream ss3;
for (const auto &mn: members) {
Expand Down Expand Up @@ -146,7 +147,7 @@ bool CFinalCommitment::Verify(gsl::not_null<const CBlockIndex*> pQuorumBaseBlock

bool CFinalCommitment::VerifyNull() const
{
const auto& llmq_params_opt = GetLLMQParams(llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(llmqType);
if (!llmq_params_opt.has_value()) {
LogPrintfFinalCommitment("q[%s]invalid llmqType=%d\n", quorumHash.ToString(), ToUnderlying(llmqType));
return false;
Expand Down Expand Up @@ -181,9 +182,9 @@ bool CheckLLMQCommitment(const CTransaction& tx, gsl::not_null<const CBlockIndex
}
auto& qcTx = *opt_qcTx;

const auto& llmq_params_opt = GetLLMQParams(qcTx.commitment.llmqType);
const auto& llmq_params_opt = Params().GetLLMQ(qcTx.commitment.llmqType);
if (!llmq_params_opt.has_value()) {
LogPrintfFinalCommitment("h[%d] GetLLMQParams failed for llmqType[%d]\n", pindexPrev->nHeight, ToUnderlying(qcTx.commitment.llmqType));
LogPrintfFinalCommitment("h[%d] GetLLMQ failed for llmqType[%d]\n", pindexPrev->nHeight, ToUnderlying(qcTx.commitment.llmqType));
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-qc-commitment-type");
}

Expand Down Expand Up @@ -235,4 +236,17 @@ bool CheckLLMQCommitment(const CTransaction& tx, gsl::not_null<const CBlockIndex
return true;
}

uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash,
const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey,
const uint256& vvecHash)
{
CHashWriter hw(SER_GETHASH, 0);
hw << llmqType;
hw << blockHash;
hw << DYNBITSET(validMembers);
hw << pubKey;
hw << vvecHash;
return hw.GetHash();
}

} // namespace llmq
2 changes: 2 additions & 0 deletions src/llmq/commitment.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class CFinalCommitmentTxPayload

bool CheckLLMQCommitment(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state);

uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash, const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash);

} // namespace llmq

#endif // BITCOIN_LLMQ_COMMITMENT_H
1 change: 0 additions & 1 deletion src/llmq/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <llmq/quorums.h>
#include <llmq/signing.h>
#include <llmq/signing_shares.h>
#include <llmq/utils.h>
#include <masternode/sync.h>

LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CEvoDB& evo_db, CSporkManager& sporkman, CTxMemPool& mempool,
Expand Down
Loading

0 comments on commit 852adb5

Please sign in to comment.