refactor: use more gsl::not_null in utils.h and deterministicmns.h (#5651)

## Issue being fixed or feature implemented
Use not_null if the function would crash if given a nullptr

## What was done?
Refactored to use gsl::not_null

## How Has This Been Tested?
Compiled

## Breaking Changes
Should be none

## Checklist:
_Go over all the following points, and put an `x` in all the boxes that
apply._
- [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)_
This commit is contained in:
PastaPastaPasta 2023-11-10 08:33:21 -06:00 committed by GitHub
parent d5b2c260a4
commit 6e639c7ac3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 167 additions and 182 deletions

View File

@ -178,7 +178,7 @@ static bool CompareByLastPaid(const CDeterministicMN* _a, const CDeterministicMN
return CompareByLastPaid(*_a, *_b); return CompareByLastPaid(*_a, *_b);
} }
CDeterministicMNCPtr CDeterministicMNList::GetMNPayee(const CBlockIndex* pIndex) const CDeterministicMNCPtr CDeterministicMNList::GetMNPayee(gsl::not_null<const CBlockIndex*> pIndex) const
{ {
if (mnMap.size() == 0) { if (mnMap.size() == 0) {
return nullptr; return nullptr;
@ -214,7 +214,7 @@ CDeterministicMNCPtr CDeterministicMNList::GetMNPayee(const CBlockIndex* pIndex)
return best; return best;
} }
std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees(const CBlockIndex* const pindex, int nCount) const std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees(gsl::not_null<const CBlockIndex* const> pindex, int nCount) const
{ {
if (nCount < 0 ) { if (nCount < 0 ) {
return {}; return {};
@ -421,7 +421,7 @@ CDeterministicMNListDiff CDeterministicMNList::BuildDiff(const CDeterministicMNL
return diffRet; return diffRet;
} }
CDeterministicMNList CDeterministicMNList::ApplyDiff(const CBlockIndex* pindex, const CDeterministicMNListDiff& diff) const CDeterministicMNList CDeterministicMNList::ApplyDiff(gsl::not_null<const CBlockIndex*> pindex, const CDeterministicMNListDiff& diff) const
{ {
CDeterministicMNList result = *this; CDeterministicMNList result = *this;
result.blockHash = pindex->GetBlockHash(); result.blockHash = pindex->GetBlockHash();
@ -594,7 +594,7 @@ void CDeterministicMNList::RemoveMN(const uint256& proTxHash)
mnInternalIdMap = mnInternalIdMap.erase(dmn->GetInternalId()); mnInternalIdMap = mnInternalIdMap.erase(dmn->GetInternalId());
} }
bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, BlockValidationState& state, const CCoinsViewCache& view, bool fJustCheck) bool CDeterministicMNManager::ProcessBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindex, BlockValidationState& state, const CCoinsViewCache& view, bool fJustCheck)
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
@ -660,7 +660,7 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde
return true; return true;
} }
bool CDeterministicMNManager::UndoBlock(const CBlockIndex* pindex) bool CDeterministicMNManager::UndoBlock(gsl::not_null<const CBlockIndex*> pindex)
{ {
int nHeight = pindex->nHeight; int nHeight = pindex->nHeight;
uint256 blockHash = pindex->GetBlockHash(); uint256 blockHash = pindex->GetBlockHash();
@ -696,14 +696,14 @@ bool CDeterministicMNManager::UndoBlock(const CBlockIndex* pindex)
return true; return true;
} }
void CDeterministicMNManager::UpdatedBlockTip(const CBlockIndex* pindex) void CDeterministicMNManager::UpdatedBlockTip(gsl::not_null<const CBlockIndex*> pindex)
{ {
LOCK(cs); LOCK(cs);
tipIndex = pindex; tipIndex = pindex;
} }
bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, BlockValidationState& state, const CCoinsViewCache& view, CDeterministicMNList& mnListRet, bool debugLogs) bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindexPrev, BlockValidationState& state, const CCoinsViewCache& view, CDeterministicMNList& mnListRet, bool debugLogs)
{ {
int nHeight = pindexPrev->nHeight + 1; int nHeight = pindexPrev->nHeight + 1;
@ -991,7 +991,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
return true; return true;
} }
void CDeterministicMNManager::HandleQuorumCommitment(const llmq::CFinalCommitment& qc, const CBlockIndex* pQuorumBaseBlockIndex, CDeterministicMNList& mnList, bool debugLogs) void CDeterministicMNManager::HandleQuorumCommitment(const llmq::CFinalCommitment& qc, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, CDeterministicMNList& mnList, bool debugLogs)
{ {
// The commitment has already been validated at this point, so it's safe to use members of it // The commitment has already been validated at this point, so it's safe to use members of it
@ -1011,7 +1011,7 @@ void CDeterministicMNManager::HandleQuorumCommitment(const llmq::CFinalCommitmen
} }
} }
CDeterministicMNList CDeterministicMNManager::GetListForBlockInternal(const CBlockIndex* pindex) CDeterministicMNList CDeterministicMNManager::GetListForBlockInternal(gsl::not_null<const CBlockIndex*> pindex)
{ {
AssertLockHeld(cs); AssertLockHeld(cs);
CDeterministicMNList snapshot; CDeterministicMNList snapshot;
@ -1512,7 +1512,7 @@ static bool CheckHashSig(const ProTx& proTx, const CBLSPublicKey& pubKey, TxVali
return true; return true;
} }
bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs) bool CheckProRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs)
{ {
if (tx.nType != TRANSACTION_PROVIDER_REGISTER) { if (tx.nType != TRANSACTION_PROVIDER_REGISTER) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type"); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type");
@ -1634,7 +1634,7 @@ bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxVali
return true; return true;
} }
bool CheckProUpServTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state, bool check_sigs) bool CheckProUpServTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, bool check_sigs)
{ {
if (tx.nType != TRANSACTION_PROVIDER_UPDATE_SERVICE) { if (tx.nType != TRANSACTION_PROVIDER_UPDATE_SERVICE) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type"); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type");
@ -1661,50 +1661,48 @@ bool CheckProUpServTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxV
} }
} }
if (pindexPrev) { auto mnList = deterministicMNManager->GetListForBlock(pindexPrev);
auto mnList = deterministicMNManager->GetListForBlock(pindexPrev); auto mn = mnList.GetMN(ptx.proTxHash);
auto mn = mnList.GetMN(ptx.proTxHash); if (!mn) {
if (!mn) { return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-hash");
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-hash"); }
}
// don't allow updating to addresses already used by other MNs // don't allow updating to addresses already used by other MNs
if (mnList.HasUniqueProperty(ptx.addr) && mnList.GetUniquePropertyMN(ptx.addr)->proTxHash != ptx.proTxHash) { if (mnList.HasUniqueProperty(ptx.addr) && mnList.GetUniquePropertyMN(ptx.addr)->proTxHash != ptx.proTxHash) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-addr"); return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-addr");
} }
// don't allow updating to platformNodeIds already used by other EvoNodes // don't allow updating to platformNodeIds already used by other EvoNodes
if (ptx.nType == MnType::Evo) { if (ptx.nType == MnType::Evo) {
if (mnList.HasUniqueProperty(ptx.platformNodeID) && mnList.GetUniquePropertyMN(ptx.platformNodeID)->proTxHash != ptx.proTxHash) { if (mnList.HasUniqueProperty(ptx.platformNodeID) && mnList.GetUniquePropertyMN(ptx.platformNodeID)->proTxHash != ptx.proTxHash) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-platformnodeid"); return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-platformnodeid");
}
} }
}
if (ptx.scriptOperatorPayout != CScript()) { if (ptx.scriptOperatorPayout != CScript()) {
if (mn->nOperatorReward == 0) { if (mn->nOperatorReward == 0) {
// don't allow setting operator reward payee in case no operatorReward was set // don't allow setting operator reward payee in case no operatorReward was set
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-operator-payee"); return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-operator-payee");
}
if (!ptx.scriptOperatorPayout.IsPayToPublicKeyHash() && !ptx.scriptOperatorPayout.IsPayToScriptHash()) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-operator-payee");
}
} }
if (!ptx.scriptOperatorPayout.IsPayToPublicKeyHash() && !ptx.scriptOperatorPayout.IsPayToScriptHash()) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-operator-payee");
}
}
// we can only check the signature if pindexPrev != nullptr and the MN is known // we can only check the signature if pindexPrev != nullptr and the MN is known
if (!CheckInputsHash(tx, ptx, state)) { if (!CheckInputsHash(tx, ptx, state)) {
// pass the state returned by the function above // pass the state returned by the function above
return false; return false;
} }
if (check_sigs && !CheckHashSig(ptx, mn->pdmnState->pubKeyOperator.Get(), state)) { if (check_sigs && !CheckHashSig(ptx, mn->pdmnState->pubKeyOperator.Get(), state)) {
// pass the state returned by the function above // pass the state returned by the function above
return false; return false;
}
} }
return true; return true;
} }
bool CheckProUpRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs) bool CheckProUpRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs)
{ {
if (tx.nType != TRANSACTION_PROVIDER_UPDATE_REGISTRAR) { if (tx.nType != TRANSACTION_PROVIDER_UPDATE_REGISTRAR) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type"); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type");
@ -1726,60 +1724,58 @@ bool CheckProUpRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxVa
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-payee-dest"); return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-payee-dest");
} }
if (pindexPrev) { auto mnList = deterministicMNManager->GetListForBlock(pindexPrev);
auto mnList = deterministicMNManager->GetListForBlock(pindexPrev); auto dmn = mnList.GetMN(ptx.proTxHash);
auto dmn = mnList.GetMN(ptx.proTxHash); if (!dmn) {
if (!dmn) { return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-hash");
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-hash"); }
}
// don't allow reuse of payee key for other keys (don't allow people to put the payee key onto an online server) // don't allow reuse of payee key for other keys (don't allow people to put the payee key onto an online server)
if (payoutDest == CTxDestination(PKHash(dmn->pdmnState->keyIDOwner)) || payoutDest == CTxDestination(PKHash(ptx.keyIDVoting))) { if (payoutDest == CTxDestination(PKHash(dmn->pdmnState->keyIDOwner)) || payoutDest == CTxDestination(PKHash(ptx.keyIDVoting))) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-payee-reuse"); return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-payee-reuse");
} }
Coin coin; Coin coin;
if (!view.GetCoin(dmn->collateralOutpoint, coin) || coin.IsSpent()) { if (!view.GetCoin(dmn->collateralOutpoint, coin) || coin.IsSpent()) {
// this should never happen (there would be no dmn otherwise) // this should never happen (there would be no dmn otherwise)
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-collateral"); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-collateral");
} }
// don't allow reuse of collateral key for other keys (don't allow people to put the collateral key onto an online server) // don't allow reuse of collateral key for other keys (don't allow people to put the collateral key onto an online server)
CTxDestination collateralTxDest; CTxDestination collateralTxDest;
if (!ExtractDestination(coin.out.scriptPubKey, collateralTxDest)) { if (!ExtractDestination(coin.out.scriptPubKey, collateralTxDest)) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-collateral-dest"); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-collateral-dest");
} }
if (collateralTxDest == CTxDestination(PKHash(dmn->pdmnState->keyIDOwner)) || collateralTxDest == CTxDestination(PKHash(ptx.keyIDVoting))) { if (collateralTxDest == CTxDestination(PKHash(dmn->pdmnState->keyIDOwner)) || collateralTxDest == CTxDestination(PKHash(ptx.keyIDVoting))) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-collateral-reuse"); return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-collateral-reuse");
} }
if (mnList.HasUniqueProperty(ptx.pubKeyOperator)) { if (mnList.HasUniqueProperty(ptx.pubKeyOperator)) {
auto otherDmn = mnList.GetUniquePropertyMN(ptx.pubKeyOperator); auto otherDmn = mnList.GetUniquePropertyMN(ptx.pubKeyOperator);
if (ptx.proTxHash != otherDmn->proTxHash) { if (ptx.proTxHash != otherDmn->proTxHash) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-key"); return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-dup-key");
}
} }
}
if (!deterministicMNManager->IsDIP3Enforced(pindexPrev->nHeight)) { if (!deterministicMNManager->IsDIP3Enforced(pindexPrev->nHeight)) {
if (dmn->pdmnState->keyIDOwner != ptx.keyIDVoting) { if (dmn->pdmnState->keyIDOwner != ptx.keyIDVoting) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-key-not-same"); return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-key-not-same");
}
} }
}
if (!CheckInputsHash(tx, ptx, state)) { if (!CheckInputsHash(tx, ptx, state)) {
// pass the state returned by the function above // pass the state returned by the function above
return false; return false;
} }
if (check_sigs && !CheckHashSig(ptx, PKHash(dmn->pdmnState->keyIDOwner), state)) { if (check_sigs && !CheckHashSig(ptx, PKHash(dmn->pdmnState->keyIDOwner), state)) {
// pass the state returned by the function above // pass the state returned by the function above
return false; return false;
}
} }
return true; return true;
} }
bool CheckProUpRevTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state, bool check_sigs) bool CheckProUpRevTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, bool check_sigs)
{ {
if (tx.nType != TRANSACTION_PROVIDER_UPDATE_REVOKE) { if (tx.nType != TRANSACTION_PROVIDER_UPDATE_REVOKE) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type"); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type");
@ -1795,20 +1791,18 @@ bool CheckProUpRevTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxVa
return false; return false;
} }
if (pindexPrev) { auto mnList = deterministicMNManager->GetListForBlock(pindexPrev);
auto mnList = deterministicMNManager->GetListForBlock(pindexPrev); auto dmn = mnList.GetMN(ptx.proTxHash);
auto dmn = mnList.GetMN(ptx.proTxHash); if (!dmn)
if (!dmn) return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-hash");
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-hash");
if (!CheckInputsHash(tx, ptx, state)) { if (!CheckInputsHash(tx, ptx, state)) {
// pass the state returned by the function above // pass the state returned by the function above
return false; return false;
} }
if (check_sigs && !CheckHashSig(ptx, dmn->pdmnState->pubKeyOperator.Get(), state)) { if (check_sigs && !CheckHashSig(ptx, dmn->pdmnState->pubKeyOperator.Get(), state)) {
// pass the state returned by the function above // pass the state returned by the function above
return false; return false;
}
} }
return true; return true;

View File

@ -16,6 +16,7 @@
#include <saltedhasher.h> #include <saltedhasher.h>
#include <scheduler.h> #include <scheduler.h>
#include <sync.h> #include <sync.h>
#include <gsl/pointers.h>
#include <immer/map.hpp> #include <immer/map.hpp>
@ -339,7 +340,7 @@ public:
[[nodiscard]] CDeterministicMNCPtr GetValidMNByCollateral(const COutPoint& collateralOutpoint) const; [[nodiscard]] CDeterministicMNCPtr GetValidMNByCollateral(const COutPoint& collateralOutpoint) const;
[[nodiscard]] CDeterministicMNCPtr GetMNByService(const CService& service) const; [[nodiscard]] CDeterministicMNCPtr GetMNByService(const CService& service) const;
[[nodiscard]] CDeterministicMNCPtr GetMNByInternalId(uint64_t internalId) const; [[nodiscard]] CDeterministicMNCPtr GetMNByInternalId(uint64_t internalId) const;
[[nodiscard]] CDeterministicMNCPtr GetMNPayee(const CBlockIndex* pIndex) const; [[nodiscard]] CDeterministicMNCPtr GetMNPayee(gsl::not_null<const CBlockIndex*> pIndex) const;
/** /**
* Calculates the projected MN payees for the next *count* blocks. The result is not guaranteed to be correct * Calculates the projected MN payees for the next *count* blocks. The result is not guaranteed to be correct
@ -347,7 +348,7 @@ public:
* @param nCount the number of payees to return. "nCount = max()"" means "all", use it to avoid calling GetValidWeightedMNsCount twice. * @param nCount the number of payees to return. "nCount = max()"" means "all", use it to avoid calling GetValidWeightedMNsCount twice.
* @return * @return
*/ */
[[nodiscard]] std::vector<CDeterministicMNCPtr> GetProjectedMNPayees(const CBlockIndex* const pindex, int nCount = std::numeric_limits<int>::max()) const; [[nodiscard]] std::vector<CDeterministicMNCPtr> GetProjectedMNPayees(gsl::not_null<const CBlockIndex* const> pindex, int nCount = std::numeric_limits<int>::max()) const;
/** /**
* Calculate a quorum based on the modifier. The resulting list is deterministically sorted by score * Calculate a quorum based on the modifier. The resulting list is deterministically sorted by score
@ -392,7 +393,7 @@ public:
void PoSeDecrease(const CDeterministicMN& dmn); void PoSeDecrease(const CDeterministicMN& dmn);
[[nodiscard]] CDeterministicMNListDiff BuildDiff(const CDeterministicMNList& to) const; [[nodiscard]] CDeterministicMNListDiff BuildDiff(const CDeterministicMNList& to) const;
[[nodiscard]] CDeterministicMNList ApplyDiff(const CBlockIndex* pindex, const CDeterministicMNListDiff& diff) const; [[nodiscard]] CDeterministicMNList ApplyDiff(gsl::not_null<const CBlockIndex*> pindex, const CDeterministicMNListDiff& diff) const;
void AddMN(const CDeterministicMNCPtr& dmn, bool fBumpTotalCount = true); void AddMN(const CDeterministicMNCPtr& dmn, bool fBumpTotalCount = true);
void UpdateMN(const CDeterministicMN& oldDmn, const std::shared_ptr<const CDeterministicMNState>& pdmnState); void UpdateMN(const CDeterministicMN& oldDmn, const std::shared_ptr<const CDeterministicMNState>& pdmnState);
@ -419,9 +420,7 @@ private:
template <typename T> template <typename T>
[[nodiscard]] uint256 GetUniquePropertyHash(const T& v) const [[nodiscard]] uint256 GetUniquePropertyHash(const T& v) const
{ {
if constexpr (std::is_same<T, CBLSPublicKey>()) { static_assert(!std::is_same<T, CBLSPublicKey>(), "GetUniquePropertyHash cannot be templated against CBLSPublicKey");
assert(false);
}
return ::SerializeHash(v); return ::SerializeHash(v);
} }
template <typename T> template <typename T>
@ -596,18 +595,18 @@ public:
m_chainstate(chainstate), connman(_connman), m_evoDb(evoDb) {} m_chainstate(chainstate), connman(_connman), m_evoDb(evoDb) {}
~CDeterministicMNManager() = default; ~CDeterministicMNManager() = default;
bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, BlockValidationState& state, bool ProcessBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindex, BlockValidationState& state,
const CCoinsViewCache& view, bool fJustCheck) EXCLUSIVE_LOCKS_REQUIRED(cs_main) LOCKS_EXCLUDED(cs); const CCoinsViewCache& view, bool fJustCheck) EXCLUSIVE_LOCKS_REQUIRED(cs_main) LOCKS_EXCLUDED(cs);
bool UndoBlock(const CBlockIndex* pindex) LOCKS_EXCLUDED(cs); bool UndoBlock(gsl::not_null<const CBlockIndex*> pindex) LOCKS_EXCLUDED(cs);
void UpdatedBlockTip(const CBlockIndex* pindex) LOCKS_EXCLUDED(cs); void UpdatedBlockTip(gsl::not_null<const CBlockIndex*> pindex) LOCKS_EXCLUDED(cs);
// the returned list will not contain the correct block hash (we can't know it yet as the coinbase TX is not updated yet) // the returned list will not contain the correct block hash (we can't know it yet as the coinbase TX is not updated yet)
bool BuildNewListFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, BlockValidationState& state, const CCoinsViewCache& view, bool BuildNewListFromBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindexPrev, BlockValidationState& state, const CCoinsViewCache& view,
CDeterministicMNList& mnListRet, bool debugLogs) LOCKS_EXCLUDED(cs); CDeterministicMNList& mnListRet, bool debugLogs) LOCKS_EXCLUDED(cs);
static void HandleQuorumCommitment(const llmq::CFinalCommitment& qc, const CBlockIndex* pQuorumBaseBlockIndex, CDeterministicMNList& mnList, bool debugLogs); static void HandleQuorumCommitment(const llmq::CFinalCommitment& qc, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, CDeterministicMNList& mnList, bool debugLogs);
CDeterministicMNList GetListForBlock(const CBlockIndex* pindex) LOCKS_EXCLUDED(cs) { CDeterministicMNList GetListForBlock(gsl::not_null<const CBlockIndex*> pindex) LOCKS_EXCLUDED(cs) {
LOCK(cs); LOCK(cs);
return GetListForBlockInternal(pindex); return GetListForBlockInternal(pindex);
}; };
@ -625,13 +624,13 @@ public:
private: private:
void CleanupCache(int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs); void CleanupCache(int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs);
CDeterministicMNList GetListForBlockInternal(const CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs); CDeterministicMNList GetListForBlockInternal(gsl::not_null<const CBlockIndex*> pindex) EXCLUSIVE_LOCKS_REQUIRED(cs);
}; };
bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs); bool CheckProRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs);
bool CheckProUpServTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state, bool check_sigs); bool CheckProUpServTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, bool check_sigs);
bool CheckProUpRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs); bool CheckProUpRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs);
bool CheckProUpRevTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state, bool check_sigs); bool CheckProUpRevTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, bool check_sigs);
extern std::unique_ptr<CDeterministicMNManager> deterministicMNManager; extern std::unique_ptr<CDeterministicMNManager> deterministicMNManager;

View File

@ -64,7 +64,7 @@ static void BuildQuorumSnapshot(const Consensus::LLMQParams& llmqParams, const C
static bool IsInstantSendLLMQTypeShared(); static bool IsInstantSendLLMQTypeShared();
uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex) uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pCycleQuorumBaseBlockIndex)
{ {
ASSERT_IF_DEBUG(pCycleQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval == 0); ASSERT_IF_DEBUG(pCycleQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval == 0);
const CBlockIndex* pWorkBlockIndex = pCycleQuorumBaseBlockIndex->GetAncestor(pCycleQuorumBaseBlockIndex->nHeight - 8); const CBlockIndex* pWorkBlockIndex = pCycleQuorumBaseBlockIndex->GetAncestor(pCycleQuorumBaseBlockIndex->nHeight - 8);
@ -88,7 +88,7 @@ uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, const CBlockInd
return ::SerializeHash(std::make_pair(llmqParams.type, pCycleQuorumBaseBlockIndex->GetBlockHash())); return ::SerializeHash(std::make_pair(llmqParams.type, pCycleQuorumBaseBlockIndex->GetBlockHash()));
} }
std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, bool reset_cache) std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, bool reset_cache)
{ {
static RecursiveMutex cs_members; static RecursiveMutex cs_members;
static std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CDeterministicMNCPtr>, StaticSaltedHasher>> mapQuorumMembers GUARDED_BY(cs_members); static std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CDeterministicMNCPtr>, StaticSaltedHasher>> mapQuorumMembers GUARDED_BY(cs_members);
@ -669,10 +669,8 @@ bool IsQuorumPoseEnabled(Consensus::LLMQType llmqType)
return EvalSpork(llmqType, sporkManager->GetSporkValue(SPORK_23_QUORUM_POSE)); return EvalSpork(llmqType, sporkManager->GetSporkValue(SPORK_23_QUORUM_POSE));
} }
bool IsQuorumRotationEnabled(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindex) bool IsQuorumRotationEnabled(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pindex)
{ {
assert(pindex);
if (!llmqParams.useRotation) { if (!llmqParams.useRotation) {
return false; return false;
} }
@ -685,7 +683,7 @@ bool IsQuorumRotationEnabled(const Consensus::LLMQParams& llmqParams, const CBlo
return IsDIP0024Active(pindex->GetAncestor(cycleQuorumBaseHeight - 1)); return IsDIP0024Active(pindex->GetAncestor(cycleQuorumBaseHeight - 1));
} }
Consensus::LLMQType GetInstantSendLLMQType(const CQuorumManager& qman, const CBlockIndex* pindex) Consensus::LLMQType GetInstantSendLLMQType(const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindex)
{ {
if (IsDIP0024Active(pindex) && !qman.ScanQuorums(Params().GetConsensus().llmqTypeDIP0024InstantSend, pindex, 1).empty()) { if (IsDIP0024Active(pindex) && !qman.ScanQuorums(Params().GetConsensus().llmqTypeDIP0024InstantSend, pindex, 1).empty()) {
return Params().GetConsensus().llmqTypeDIP0024InstantSend; return Params().GetConsensus().llmqTypeDIP0024InstantSend;
@ -698,46 +696,38 @@ Consensus::LLMQType GetInstantSendLLMQType(bool deterministic)
return deterministic ? Params().GetConsensus().llmqTypeDIP0024InstantSend : Params().GetConsensus().llmqTypeInstantSend; return deterministic ? Params().GetConsensus().llmqTypeDIP0024InstantSend : Params().GetConsensus().llmqTypeInstantSend;
} }
bool IsDIP0024Active(const CBlockIndex* pindex) bool IsDIP0024Active(gsl::not_null<const CBlockIndex*> pindex)
{ {
assert(pindex);
return pindex->nHeight + 1 >= Params().GetConsensus().DIP0024Height; return pindex->nHeight + 1 >= Params().GetConsensus().DIP0024Height;
} }
bool IsV19Active(const CBlockIndex* pindex) bool IsV19Active(gsl::not_null<const CBlockIndex*> pindex)
{ {
assert(pindex);
return pindex->nHeight + 1 >= Params().GetConsensus().V19Height; return pindex->nHeight + 1 >= Params().GetConsensus().V19Height;
} }
bool IsV20Active(const CBlockIndex* pindex) bool IsV20Active(gsl::not_null<const CBlockIndex*> pindex)
{ {
assert(pindex);
LOCK(cs_llmq_vbc); LOCK(cs_llmq_vbc);
return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20, llmq_versionbitscache) == ThresholdState::ACTIVE; return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20, llmq_versionbitscache) == ThresholdState::ACTIVE;
} }
bool IsMNRewardReallocationActive(const CBlockIndex* pindex) bool IsMNRewardReallocationActive(gsl::not_null<const CBlockIndex*> pindex)
{ {
assert(pindex);
if (!IsV20Active(pindex)) return false; if (!IsV20Active(pindex)) return false;
LOCK(cs_llmq_vbc); LOCK(cs_llmq_vbc);
return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR, llmq_versionbitscache) == ThresholdState::ACTIVE; return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR, llmq_versionbitscache) == ThresholdState::ACTIVE;
} }
ThresholdState GetV20State(const CBlockIndex* pindex) ThresholdState GetV20State(gsl::not_null<const CBlockIndex*> pindex)
{ {
assert(pindex);
LOCK(cs_llmq_vbc); LOCK(cs_llmq_vbc);
return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20, llmq_versionbitscache); return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20, llmq_versionbitscache);
} }
int GetV20Since(const CBlockIndex* pindex) int GetV20Since(gsl::not_null<const CBlockIndex*> pindex)
{ {
assert(pindex);
LOCK(cs_llmq_vbc); LOCK(cs_llmq_vbc);
return VersionBitsStateSinceHeight(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20, llmq_versionbitscache); return VersionBitsStateSinceHeight(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20, llmq_versionbitscache);
} }
@ -775,7 +765,7 @@ uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256
return proTxHash2; return proTxHash2;
} }
std::set<uint256> GetQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, std::set<uint256> GetQuorumConnections(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex,
const uint256& forMember, bool onlyOutbound) const uint256& forMember, bool onlyOutbound)
{ {
if (IsAllMembersConnectedEnabled(llmqParams.type)) { if (IsAllMembersConnectedEnabled(llmqParams.type)) {
@ -799,7 +789,7 @@ std::set<uint256> GetQuorumConnections(const Consensus::LLMQParams& llmqParams,
return GetQuorumRelayMembers(llmqParams, pQuorumBaseBlockIndex, forMember, onlyOutbound); return GetQuorumRelayMembers(llmqParams, pQuorumBaseBlockIndex, forMember, onlyOutbound);
} }
std::set<uint256> GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, std::set<uint256> GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex,
const uint256& forMember, bool onlyOutbound) const uint256& forMember, bool onlyOutbound)
{ {
auto mns = GetAllQuorumMembers(llmqParams.type, pQuorumBaseBlockIndex); auto mns = GetAllQuorumMembers(llmqParams.type, pQuorumBaseBlockIndex);
@ -854,7 +844,7 @@ std::set<uint256> GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams,
return result; return result;
} }
std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex,
size_t memberCount, size_t connectionCount) size_t memberCount, size_t connectionCount)
{ {
static uint256 qwatchConnectionSeed; static uint256 qwatchConnectionSeed;
@ -875,7 +865,7 @@ std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType,
return result; return result;
} }
bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex,
CConnman& connman, const uint256& myProTxHash) CConnman& connman, const uint256& myProTxHash)
{ {
if (!fMasternodeMode && !IsWatchQuorumsEnabled()) { if (!fMasternodeMode && !IsWatchQuorumsEnabled()) {
@ -930,7 +920,7 @@ bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlo
return true; return true;
} }
void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pQuorumBaseBlockIndex, void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex,
CConnman& connman, const uint256 &myProTxHash) CConnman& connman, const uint256 &myProTxHash)
{ {
if (!IsQuorumPoseEnabled(llmqParams.type)) { if (!IsQuorumPoseEnabled(llmqParams.type)) {
@ -982,12 +972,12 @@ bool IsQuorumActive(Consensus::LLMQType llmqType, const CQuorumManager& qman, co
return ranges::any_of(quorums, [&quorumHash](const auto& q){ return q->qc->quorumHash == quorumHash; }); return ranges::any_of(quorums, [&quorumHash](const auto& q){ return q->qc->quorumHash == quorumHash; });
} }
bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, const CBlockIndex* pindex) bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindex)
{ {
return IsQuorumTypeEnabledInternal(llmqType, qman, pindex, std::nullopt, std::nullopt); return IsQuorumTypeEnabledInternal(llmqType, qman, pindex, std::nullopt, std::nullopt);
} }
bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, const CBlockIndex* pindex, bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindex,
std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums) std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums)
{ {
const Consensus::Params& consensusParams = Params().GetConsensus(); const Consensus::Params& consensusParams = Params().GetConsensus();
@ -1019,7 +1009,7 @@ bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumMana
return VersionBitsState(pindex, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY, llmq_versionbitscache) == ThresholdState::ACTIVE; return VersionBitsState(pindex, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY, llmq_versionbitscache) == ThresholdState::ACTIVE;
} }
case Consensus::LLMQType::LLMQ_100_67: case Consensus::LLMQType::LLMQ_100_67:
return pindex != nullptr && pindex->nHeight + 1 >= consensusParams.DIP0020Height; return pindex->nHeight + 1 >= consensusParams.DIP0020Height;
case Consensus::LLMQType::LLMQ_60_75: case Consensus::LLMQType::LLMQ_60_75:
case Consensus::LLMQType::LLMQ_DEVNET_DIP0024: case Consensus::LLMQType::LLMQ_DEVNET_DIP0024:
@ -1038,7 +1028,7 @@ bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumMana
assert(false); assert(false);
} }
std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(const CBlockIndex* pindex) std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(gsl::not_null<const CBlockIndex*> pindex)
{ {
std::vector<Consensus::LLMQType> ret; std::vector<Consensus::LLMQType> ret;
ret.reserve(Params().GetConsensus().llmqs.size()); ret.reserve(Params().GetConsensus().llmqs.size());
@ -1050,7 +1040,7 @@ std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(const CBlockIndex* pindex
return ret; return ret;
} }
std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuorumParams(const CBlockIndex* pindex) std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuorumParams(gsl::not_null<const CBlockIndex*> pindex)
{ {
std::vector<std::reference_wrapper<const Consensus::LLMQParams>> ret; std::vector<std::reference_wrapper<const Consensus::LLMQParams>> ret;
ret.reserve(Params().GetConsensus().llmqs.size()); ret.reserve(Params().GetConsensus().llmqs.size());

View File

@ -12,6 +12,7 @@
#include <set> #include <set>
#include <sync.h> #include <sync.h>
#include <versionbits.h> #include <versionbits.h>
#include <gsl/pointers.h>
#include <optional> #include <optional>
#include <vector> #include <vector>
@ -46,38 +47,38 @@ namespace utils
{ {
// includes members which failed DKG // includes members which failed DKG
std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, bool reset_cache = false); std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, bool reset_cache = false);
uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex); uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pCycleQuorumBaseBlockIndex);
uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash, const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash); uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash, const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash);
uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash); uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash);
bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType); bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType);
bool IsQuorumPoseEnabled(Consensus::LLMQType llmqType); bool IsQuorumPoseEnabled(Consensus::LLMQType llmqType);
uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2); uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2);
std::set<uint256> GetQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound); std::set<uint256> GetQuorumConnections(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound);
std::set<uint256> GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound); std::set<uint256> GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound);
std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, size_t memberCount, size_t connectionCount); std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, size_t memberCount, size_t connectionCount);
bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, CConnman& connman, const uint256& myProTxHash); bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, CConnman& connman, const uint256& myProTxHash);
void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, CConnman& connman, const uint256& myProTxHash); void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, CConnman& connman, const uint256& myProTxHash);
bool IsQuorumActive(Consensus::LLMQType llmqType, const CQuorumManager& qman, const uint256& quorumHash); bool IsQuorumActive(Consensus::LLMQType llmqType, const CQuorumManager& qman, const uint256& quorumHash);
bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, const CBlockIndex* pindex); bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindex);
bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, const CBlockIndex* pindex, std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums); bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindex, std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums);
std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(const CBlockIndex* pindex); std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(gsl::not_null<const CBlockIndex*> pindex);
std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuorumParams(const CBlockIndex* pindex); std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuorumParams(gsl::not_null<const CBlockIndex*> pindex);
bool IsQuorumRotationEnabled(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindex); bool IsQuorumRotationEnabled(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pindex);
Consensus::LLMQType GetInstantSendLLMQType(const CQuorumManager& qman, const CBlockIndex* pindex); Consensus::LLMQType GetInstantSendLLMQType(const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindex);
Consensus::LLMQType GetInstantSendLLMQType(bool deterministic); Consensus::LLMQType GetInstantSendLLMQType(bool deterministic);
bool IsDIP0024Active(const CBlockIndex* pindex); bool IsDIP0024Active(gsl::not_null<const CBlockIndex*> pindex);
bool IsV19Active(const CBlockIndex* pindex); bool IsV19Active(gsl::not_null<const CBlockIndex*> pindex);
bool IsV20Active(const CBlockIndex* pindex); bool IsV20Active(gsl::not_null<const CBlockIndex*> pindex);
bool IsMNRewardReallocationActive(const CBlockIndex* pindex); bool IsMNRewardReallocationActive(gsl::not_null<const CBlockIndex*> pindex);
ThresholdState GetV20State(const CBlockIndex* pindex); ThresholdState GetV20State(gsl::not_null<const CBlockIndex*> pindex);
int GetV20Since(const CBlockIndex* pindex); int GetV20Since(gsl::not_null<const CBlockIndex*> pindex);
/// Returns the state of `-llmq-data-recovery` /// Returns the state of `-llmq-data-recovery`
bool QuorumDataRecoveryEnabled(); bool QuorumDataRecoveryEnabled();

View File

@ -18,37 +18,38 @@
/* TODO: rename this file and test to llmq_utils_test */ /* TODO: rename this file and test to llmq_utils_test */
BOOST_AUTO_TEST_SUITE(evo_utils_tests) BOOST_AUTO_TEST_SUITE(evo_utils_tests)
void Test(llmq::CQuorumManager& qman) void Test(llmq::CQuorumManager& qman, NodeContext& node)
{ {
using namespace llmq::utils; using namespace llmq::utils;
auto tip = node.chainman->ActiveTip();
const auto& consensus_params = Params().GetConsensus(); const auto& consensus_params = Params().GetConsensus();
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, qman, nullptr, false, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, qman, tip, false, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, qman, nullptr, true, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, qman, tip, true, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, qman, nullptr, true, true), false); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, qman, tip, true, true), false);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, qman, nullptr, false, false), false); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, qman, tip, false, false), false);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, qman, nullptr, true, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, qman, tip, true, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, qman, nullptr, true, true), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, qman, tip, true, true), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, nullptr, false, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, tip, false, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, nullptr, true, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, tip, true, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, nullptr, true, true), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, tip, true, true), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, nullptr, false, false), Params().IsTestChain()); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, tip, false, false), Params().IsTestChain());
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, nullptr, true, false), Params().IsTestChain()); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, tip, true, false), Params().IsTestChain());
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, nullptr, true, true), Params().IsTestChain()); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, tip, true, true), Params().IsTestChain());
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, nullptr, false, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, tip, false, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, nullptr, true, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, tip, true, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, nullptr, true, true), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, tip, true, true), true);
} }
BOOST_FIXTURE_TEST_CASE(utils_IsQuorumTypeEnabled_tests_regtest, RegTestingSetup) BOOST_FIXTURE_TEST_CASE(utils_IsQuorumTypeEnabled_tests_regtest, RegTestingSetup)
{ {
assert(m_node.llmq_ctx->qman); assert(m_node.llmq_ctx->qman);
Test(*m_node.llmq_ctx->qman); Test(*m_node.llmq_ctx->qman, m_node);
} }
BOOST_FIXTURE_TEST_CASE(utils_IsQuorumTypeEnabled_tests_mainnet, TestingSetup) BOOST_FIXTURE_TEST_CASE(utils_IsQuorumTypeEnabled_tests_mainnet, TestingSetup)
{ {
assert(m_node.llmq_ctx->qman); assert(m_node.llmq_ctx->qman);
Test(*m_node.llmq_ctx->qman); Test(*m_node.llmq_ctx->qman, m_node);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()