Merge pull request #5753 from knst/refactor-llmq_vbc

refactor: drop usages of llmq/utils to check if hard-fork is active
This commit is contained in:
PastaPastaPasta 2023-12-21 23:03:12 -06:00 committed by GitHub
commit 78a69043c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 215 additions and 253 deletions

View File

@ -52,4 +52,10 @@ inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::Deploy
return params.vDeployments[dep].nTimeout != 0;
}
/** this function is convenient helper for DIP0003 because 'active' and 'enforced' are different statuses for DIP0003 */
constexpr bool DeploymentDIP0003Enforced(const int nHeight, const Consensus::Params& params)
{
return nHeight >= params.DIP0003EnforcementHeight;
}
#endif // BITCOIN_DEPLOYMENTSTATUS_H

View File

@ -16,6 +16,7 @@
#include <chain.h>
#include <chainparams.h>
#include <consensus/merkle.h>
#include <deploymentstatus.h>
#include <validation.h>
bool CheckCbTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state)
@ -42,12 +43,12 @@ bool CheckCbTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidati
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cbtx-height");
}
bool fDIP0008Active = pindexPrev->nHeight >= Params().GetConsensus().DIP0008Height;
const bool fDIP0008Active{DeploymentActiveAt(*pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0008)};
if (fDIP0008Active && cbTx.nVersion < CCbTx::Version::MERKLE_ROOT_QUORUMS) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cbtx-version");
}
bool isV20 = llmq::utils::IsV20Active(pindexPrev);
const bool isV20{DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)};
if ((isV20 && cbTx.nVersion < CCbTx::Version::CLSIG_AND_BALANCE) || (!isV20 && cbTx.nVersion >= CCbTx::Version::CLSIG_AND_BALANCE)) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cbtx-version");
}

View File

@ -9,8 +9,9 @@
#include <evo/specialtx.h>
#include <chain.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <llmq/utils.h>
#include <deploymentstatus.h>
#include <logging.h>
#include <node/blockstorage.h>
#include <validation.h>
@ -80,11 +81,11 @@ std::string CCreditPool::ToString() const
locked, currentLimit);
}
std::optional<CCreditPool> CCreditPoolManager::GetFromCache(const CBlockIndex* const block_index)
std::optional<CCreditPool> CCreditPoolManager::GetFromCache(const CBlockIndex& block_index)
{
if (!llmq::utils::IsV20Active(block_index)) return CCreditPool{};
if (!DeploymentActiveAt(block_index, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) return CCreditPool{};
const uint256 block_hash = block_index->GetBlockHash();
const uint256 block_hash = block_index.GetBlockHash();
CCreditPool pool;
{
LOCK(cache_mutex);
@ -92,7 +93,7 @@ std::optional<CCreditPool> CCreditPoolManager::GetFromCache(const CBlockIndex* c
return pool;
}
}
if (block_index->nHeight % DISK_SNAPSHOT_PERIOD == 0) {
if (block_index.nHeight % DISK_SNAPSHOT_PERIOD == 0) {
if (evoDb.Read(std::make_pair(DB_CREDITPOOL_SNAPSHOT, block_hash), pool)) {
LOCK(cache_mutex);
creditPoolCache.insert(block_hash, pool);
@ -202,10 +203,11 @@ CCreditPool CCreditPoolManager::GetCreditPool(const CBlockIndex* block_index, co
std::stack<const CBlockIndex *> to_calculate;
std::optional<CCreditPool> poolTmp;
while (!(poolTmp = GetFromCache(block_index)).has_value()) {
while (block_index != nullptr && !(poolTmp = GetFromCache(*block_index)).has_value()) {
to_calculate.push(block_index);
block_index = block_index->pprev;
}
if (block_index == nullptr) poolTmp = CCreditPool{};
while (!to_calculate.empty()) {
poolTmp = ConstructCreditPool(to_calculate.top(), *poolTmp, consensusParams);
to_calculate.pop();
@ -218,16 +220,16 @@ CCreditPoolManager::CCreditPoolManager(CEvoDB& _evoDb)
{
}
CCreditPoolDiff::CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindex, const Consensus::Params& consensusParams, const CAmount blockSubsidy) :
CCreditPoolDiff::CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindexPrev, const Consensus::Params& consensusParams, const CAmount blockSubsidy) :
pool(std::move(starter)),
pindex(pindex),
pindexPrev(pindexPrev),
params(consensusParams)
{
assert(pindex);
assert(pindexPrev);
if (llmq::utils::IsMNRewardReallocationActive(pindex)) {
if (DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_MN_RR)) {
// We consider V20 active if mn_rr is active
platformReward = MasternodePayments::PlatformShare(GetMasternodePayment(pindex->nHeight, blockSubsidy, /*fV20Active=*/ true));
platformReward = MasternodePayments::PlatformShare(GetMasternodePayment(pindexPrev->nHeight + 1, blockSubsidy, /*fV20Active=*/ true));
}
}
@ -274,7 +276,7 @@ bool CCreditPoolDiff::ProcessLockUnlockTransaction(const CTransaction& tx, TxVal
if (tx.nVersion != 3) return true;
if (tx.nType != TRANSACTION_ASSET_LOCK && tx.nType != TRANSACTION_ASSET_UNLOCK) return true;
if (!CheckAssetLockUnlockTx(tx, pindex, pool.indexes, state)) {
if (!CheckAssetLockUnlockTx(tx, pindexPrev, pool.indexes, state)) {
// pass the state returned by the function above
return false;
}

View File

@ -70,10 +70,10 @@ private:
CAmount sessionUnlocked{0};
CAmount platformReward{0};
const CBlockIndex *pindex{nullptr};
const CBlockIndex *pindexPrev{nullptr};
const Consensus::Params& params;
public:
explicit CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindex,
explicit CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindexPrev,
const Consensus::Params& consensusParams,
const CAmount blockSubsidy);
@ -128,7 +128,7 @@ public:
CCreditPool GetCreditPool(const CBlockIndex* block, const Consensus::Params& consensusParams);
private:
std::optional<CCreditPool> GetFromCache(const CBlockIndex* const block_index);
std::optional<CCreditPool> GetFromCache(const CBlockIndex& block_index);
void AddToCache(const uint256& block_hash, int height, const CCreditPool& pool);
CCreditPool ConstructCreditPool(const CBlockIndex* block_index, CCreditPool prev, const Consensus::Params& consensusParams);

View File

@ -13,6 +13,7 @@
#include <base58.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <script/standard.h>
#include <ui_interface.h>
#include <validation.h>
@ -21,6 +22,7 @@
#include <messagesigner.h>
#include <uint256.h>
#include <optional>
#include <memory>
static const std::string DB_LIST_SNAPSHOT = "dmn_S3";
@ -178,15 +180,16 @@ static bool CompareByLastPaid(const CDeterministicMN* _a, const CDeterministicMN
return CompareByLastPaid(*_a, *_b);
}
CDeterministicMNCPtr CDeterministicMNList::GetMNPayee(gsl::not_null<const CBlockIndex*> pIndex) const
CDeterministicMNCPtr CDeterministicMNList::GetMNPayee(gsl::not_null<const CBlockIndex*> pindexPrev) const
{
if (mnMap.size() == 0) {
return nullptr;
}
bool isv19Active = llmq::utils::IsV19Active(pIndex);
bool isMNRewardReallocation = llmq::utils::IsMNRewardReallocationActive(pIndex);
// Starting from v19 and until MNRewardReallocation (Platform release), EvoNodes will be rewarded 4 blocks in a row
const bool isv19Active{DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
const bool isMNRewardReallocation{DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR)};
// EvoNodes are rewarded 4 blocks in a row until MNRewardReallocation (Platform release)
// For optimization purposes we also check if v19 active to avoid loop over all masternodes
CDeterministicMNCPtr best = nullptr;
if (isv19Active && !isMNRewardReallocation) {
ForEachMNShared(true, [&](const CDeterministicMNCPtr& dmn) {
@ -214,7 +217,7 @@ CDeterministicMNCPtr CDeterministicMNList::GetMNPayee(gsl::not_null<const CBlock
return best;
}
std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees(gsl::not_null<const CBlockIndex* const> pindex, int nCount) const
std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees(gsl::not_null<const CBlockIndex* const> pindexPrev, int nCount) const
{
if (nCount < 0 ) {
return {};
@ -227,7 +230,7 @@ std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees(gsl
int remaining_evo_payments{0};
CDeterministicMNCPtr evo_to_be_skipped{nullptr};
const bool isMNRewardReallocation = llmq::utils::IsMNRewardReallocationActive(pindex);
const bool isMNRewardReallocation{DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR)};
if (!isMNRewardReallocation) {
ForEachMNShared(true, [&](const CDeterministicMNCPtr& dmn) {
if (dmn->pdmnState->nLastPaidHeight == nHeight) {
@ -599,8 +602,7 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, gsl::not_null<co
AssertLockHeld(cs_main);
const auto& consensusParams = Params().GetConsensus();
bool fDIP0003Active = pindex->nHeight >= consensusParams.DIP0003Height;
if (!fDIP0003Active) {
if (!DeploymentActiveAt(*pindex, consensusParams, Consensus::DEPLOYMENT_DIP0003)) {
return true;
}
@ -731,7 +733,8 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
newList.DecreaseScores();
bool isMNRewardReallocation = llmq::utils::IsMNRewardReallocationActive(pindexPrev);
const bool isV19Active{DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
const bool isMNRewardReallocation{DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR)};
// we skip the coinbase
for (int i = 1; i < (int)block.vtx.size(); i++) {
@ -748,7 +751,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-protx-payload");
}
if (proTx.nType == MnType::Evo && !llmq::utils::IsV19Active(pindexPrev)) {
if (proTx.nType == MnType::Evo && !isV19Active) {
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-protx-payload");
}
@ -811,7 +814,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-protx-payload");
}
if (proTx.nType == MnType::Evo && !llmq::utils::IsV19Active(pindexPrev)) {
if (proTx.nType == MnType::Evo && !DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)) {
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-protx-payload");
}
@ -1115,21 +1118,6 @@ bool CDeterministicMNManager::IsProTxWithCollateral(const CTransactionRef& tx, u
return true;
}
bool CDeterministicMNManager::IsDIP3Enforced(int nHeight)
{
if (nHeight == -1) {
LOCK(cs);
if (tipIndex == nullptr) {
// Since EnforcementHeight can be set to block 1, we shouldn't just return false here
nHeight = 1;
} else {
nHeight = tipIndex->nHeight;
}
}
return nHeight >= Params().GetConsensus().DIP0003EnforcementHeight;
}
void CDeterministicMNManager::CleanupCache(int nHeight)
{
AssertLockHeld(cs);
@ -1203,6 +1191,7 @@ bool CDeterministicMNManager::MigrateDBIfNeeded()
static const std::string DB_OLD_LIST_DIFF = "dmn_D";
static const std::string DB_OLD_BEST_BLOCK = "b_b2";
static const std::string DB_OLD_BEST_BLOCK2 = "b_b3";
const auto& consensusParams = Params().GetConsensus();
LOCK(cs_main);
@ -1231,7 +1220,7 @@ bool CDeterministicMNManager::MigrateDBIfNeeded()
return true;
}
if (m_chainstate.m_chain.Tip()->pprev != nullptr && llmq::utils::IsV19Active(m_chainstate.m_chain.Tip()->pprev)) {
if (DeploymentActiveAt(*m_chainstate.m_chain.Tip(), consensusParams, Consensus::DEPLOYMENT_V19)) {
// too late
LogPrintf("CDeterministicMNManager::%s -- migration is not possible\n", __func__);
return false;
@ -1246,7 +1235,7 @@ bool CDeterministicMNManager::MigrateDBIfNeeded()
}
m_evoDb.GetRawDB().Erase(DB_OLD_BEST_BLOCK);
if (m_chainstate.m_chain.Height() < Params().GetConsensus().DIP0003Height) {
if (!DeploymentActiveAt(*m_chainstate.m_chain.Tip(), consensusParams, Consensus::DEPLOYMENT_DIP0003)) {
// not reached DIP3 height yet, so no upgrade needed
LogPrintf("CDeterministicMNManager::%s -- migration not needed. dip3 not reached\n", __func__);
auto dbTx = m_evoDb.BeginTransaction();
@ -1313,6 +1302,7 @@ bool CDeterministicMNManager::MigrateDBIfNeeded2()
static const std::string DB_OLD_LIST_SNAPSHOT = "dmn_S2";
static const std::string DB_OLD_LIST_DIFF = "dmn_D2";
static const std::string DB_OLD_BEST_BLOCK = "b_b3";
const auto& consensusParams = Params().GetConsensus();
LOCK(cs_main);
@ -1341,7 +1331,7 @@ bool CDeterministicMNManager::MigrateDBIfNeeded2()
return true;
}
if (m_chainstate.m_chain.Tip()->pprev != nullptr && llmq::utils::IsV19Active(m_chainstate.m_chain.Tip()->pprev)) {
if (DeploymentActiveAt(*m_chainstate.m_chain.Tip(), consensusParams, Consensus::DEPLOYMENT_V19)) {
// too late
LogPrintf("CDeterministicMNManager::%s -- migration is not possible\n", __func__);
return false;
@ -1356,7 +1346,7 @@ bool CDeterministicMNManager::MigrateDBIfNeeded2()
}
m_evoDb.GetRawDB().Erase(DB_OLD_BEST_BLOCK);
if (m_chainstate.m_chain.Height() < Params().GetConsensus().DIP0003Height) {
if (!DeploymentActiveAt(*m_chainstate.m_chain.Tip(), consensusParams, Consensus::DEPLOYMENT_DIP0003)) {
// not reached DIP3 height yet, so no upgrade needed
LogPrintf("CDeterministicMNManager::%s -- migration not needed. dip3 not reached\n", __func__);
auto dbTx = m_evoDb.BeginTransaction();
@ -1509,21 +1499,35 @@ static bool CheckHashSig(const ProTx& proTx, const CBLSPublicKey& pubKey, TxVali
return true;
}
template<typename ProTx>
static std::optional<ProTx> GetValidatedPayload(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state)
{
if (tx.nType != ProTx::SPECIALTX_TYPE) {
state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type");
return std::nullopt;
}
ProTx ptx;
if (!GetTxPayload(tx, ptx)) {
state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-payload");
return std::nullopt;
}
const bool is_basic_scheme_active{DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
if (!ptx.IsTriviallyValid(is_basic_scheme_active, state)) {
// pass the state returned by the function above
return std::nullopt;
}
return ptx;
}
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) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type");
}
CProRegTx ptx;
if (!GetTxPayload(tx, ptx)) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-payload");
}
if (!ptx.IsTriviallyValid(llmq::utils::IsV19Active(pindexPrev), state)) {
const auto opt_ptx = GetValidatedPayload<CProRegTx>(tx, pindexPrev, state);
if (!opt_ptx) {
// pass the state returned by the function above
return false;
}
const auto& ptx{*opt_ptx};
// It's allowed to set addr to 0, which will put the MN into PoSe-banned state and require a ProUpServTx to be issues later
// If any of both is set, it must be valid however
@ -1603,7 +1607,7 @@ bool CheckProRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pin
}
}
if (!deterministicMNManager->IsDIP3Enforced(pindexPrev->nHeight)) {
if (!DeploymentDIP0003Enforced(pindexPrev->nHeight, Params().GetConsensus())) {
if (ptx.keyIDOwner != ptx.keyIDVoting) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-key-not-same");
}
@ -1633,19 +1637,12 @@ bool CheckProRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pin
bool CheckProUpServTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, bool check_sigs)
{
if (tx.nType != TRANSACTION_PROVIDER_UPDATE_SERVICE) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type");
}
CProUpServTx ptx;
if (!GetTxPayload(tx, ptx)) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-payload");
}
if (!ptx.IsTriviallyValid(llmq::utils::IsV19Active(pindexPrev), state)) {
const auto opt_ptx = GetValidatedPayload<CProUpServTx>(tx, pindexPrev, state);
if (!opt_ptx) {
// pass the state returned by the function above
return false;
}
const auto& ptx{*opt_ptx};
if (!CheckService(ptx, state)) {
// pass the state returned by the function above
@ -1701,19 +1698,12 @@ bool CheckProUpServTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*>
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) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type");
}
CProUpRegTx ptx;
if (!GetTxPayload(tx, ptx)) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-payload");
}
if (!ptx.IsTriviallyValid(llmq::utils::IsV19Active(pindexPrev), state)) {
const auto opt_ptx = GetValidatedPayload<CProUpRegTx>(tx, pindexPrev, state);
if (!opt_ptx) {
// pass the state returned by the function above
return false;
}
const auto& ptx{*opt_ptx};
CTxDestination payoutDest;
if (!ExtractDestination(ptx.scriptPayout, payoutDest)) {
@ -1754,7 +1744,7 @@ bool CheckProUpRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> p
}
}
if (!deterministicMNManager->IsDIP3Enforced(pindexPrev->nHeight)) {
if (!DeploymentDIP0003Enforced(pindexPrev->nHeight, Params().GetConsensus())) {
if (dmn->pdmnState->keyIDOwner != ptx.keyIDVoting) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-key-not-same");
}
@ -1774,19 +1764,12 @@ bool CheckProUpRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> p
bool CheckProUpRevTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, bool check_sigs)
{
if (tx.nType != TRANSACTION_PROVIDER_UPDATE_REVOKE) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type");
}
CProUpRevTx ptx;
if (!GetTxPayload(tx, ptx)) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-payload");
}
if (!ptx.IsTriviallyValid(llmq::utils::IsV19Active(pindexPrev), state)) {
const auto opt_ptx = GetValidatedPayload<CProUpRevTx>(tx, pindexPrev, state);
if (!opt_ptx) {
// pass the state returned by the function above
return false;
}
const auto& ptx{*opt_ptx};
auto mnList = deterministicMNManager->GetListForBlock(pindexPrev);
auto dmn = mnList.GetMN(ptx.proTxHash);

View File

@ -340,7 +340,7 @@ public:
[[nodiscard]] CDeterministicMNCPtr GetValidMNByCollateral(const COutPoint& collateralOutpoint) const;
[[nodiscard]] CDeterministicMNCPtr GetMNByService(const CService& service) const;
[[nodiscard]] CDeterministicMNCPtr GetMNByInternalId(uint64_t internalId) const;
[[nodiscard]] CDeterministicMNCPtr GetMNPayee(gsl::not_null<const CBlockIndex*> pIndex) const;
[[nodiscard]] CDeterministicMNCPtr GetMNPayee(gsl::not_null<const CBlockIndex*> pindexPrev) const;
/**
* Calculates the projected MN payees for the next *count* blocks. The result is not guaranteed to be correct
@ -348,7 +348,7 @@ public:
* @param nCount the number of payees to return. "nCount = max()"" means "all", use it to avoid calling GetValidWeightedMNsCount twice.
* @return
*/
[[nodiscard]] std::vector<CDeterministicMNCPtr> GetProjectedMNPayees(gsl::not_null<const CBlockIndex* const> pindex, int nCount = std::numeric_limits<int>::max()) const;
[[nodiscard]] std::vector<CDeterministicMNCPtr> GetProjectedMNPayees(gsl::not_null<const CBlockIndex* const> pindexPrev, int nCount = std::numeric_limits<int>::max()) const;
/**
* Calculate a quorum based on the modifier. The resulting list is deterministically sorted by score
@ -622,8 +622,6 @@ public:
// Test if given TX is a ProRegTx which also contains the collateral at index n
static bool IsProTxWithCollateral(const CTransactionRef& tx, uint32_t n);
bool IsDIP3Enforced(int nHeight = -1) LOCKS_EXCLUDED(cs);
bool MigrateDBIfNeeded();
bool MigrateDBIfNeeded2();

View File

@ -7,6 +7,7 @@
#include <bls/bls.h>
#include <chain.h>
#include <chainparams.h>
#include <deploymentstatus.h>
#include <evo/deterministicmns.h>
#include <llmq/utils.h>
#include <masternode/meta.h>
@ -40,8 +41,8 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CBlockIndex* tip)
if (Params().NetworkIDString() != CBaseChainParams::MAIN && gArgs.IsArgSet("-pushversion")) {
nOurNodeVersion = gArgs.GetArg("-pushversion", PROTOCOL_VERSION);
}
bool isV19active = llmq::utils::IsV19Active(tip);
const CBLSPublicKeyVersionWrapper pubKey(*activeMasternodeInfo.blsPubKeyOperator, !isV19active);
const bool is_basic_scheme_active{DeploymentActiveAfter(tip, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
const CBLSPublicKeyVersionWrapper pubKey(*activeMasternodeInfo.blsPubKeyOperator, !is_basic_scheme_active);
if (peer.nVersion < MNAUTH_NODE_VER_VERSION || nOurNodeVersion < MNAUTH_NODE_VER_VERSION) {
signHash = ::SerializeHash(std::make_tuple(pubKey, receivedMNAuthChallenge, peer.fInbound));
} else {
@ -106,8 +107,8 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
nOurNodeVersion = gArgs.GetArg("-pushversion", PROTOCOL_VERSION);
}
const CBlockIndex* tip = ::ChainActive().Tip();
bool isV19active = llmq::utils::IsV19Active(tip);
ConstCBLSPublicKeyVersionWrapper pubKey(dmn->pdmnState->pubKeyOperator.Get(), !isV19active);
const bool is_basic_scheme_active{DeploymentActiveAfter(tip, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
ConstCBLSPublicKeyVersionWrapper pubKey(dmn->pdmnState->pubKeyOperator.Get(), !is_basic_scheme_active);
// See comment in PushMNAUTH (fInbound is negated here as we're on the other side of the connection)
if (peer.nVersion < MNAUTH_NODE_VER_VERSION || nOurNodeVersion < MNAUTH_NODE_VER_VERSION) {
signHash = ::SerializeHash(std::make_tuple(pubKey, peer.GetSentMNAuthChallenge(), !peer.fInbound));

View File

@ -6,11 +6,11 @@
#include <evo/cbtx.h>
#include <core_io.h>
#include <deploymentstatus.h>
#include <evo/deterministicmns.h>
#include <llmq/blockprocessor.h>
#include <llmq/commitment.h>
#include <llmq/quorums.h>
#include <llmq/utils.h>
#include <node/blockstorage.h>
#include <evo/specialtx.h>
@ -363,7 +363,7 @@ bool BuildSimplifiedMNListDiff(const uint256& baseBlockHash, const uint256& bloc
return false;
}
if (llmq::utils::IsV20Active(blockIndex)) {
if (DeploymentActiveAfter(blockIndex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) {
if (!mnListDiffRet.BuildQuorumChainlockInfo(blockIndex)) {
errorRet = strprintf("failed to build quorums chainlocks info");
return false;

View File

@ -6,6 +6,7 @@
#include <chainparams.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <evo/cbtx.h>
#include <evo/creditpool.h>
#include <evo/deterministicmns.h>
@ -15,7 +16,6 @@
#include <hash.h>
#include <llmq/blockprocessor.h>
#include <llmq/commitment.h>
#include <llmq/utils.h>
#include <primitives/block.h>
#include <validation.h>
@ -26,7 +26,8 @@ static bool CheckSpecialTxInner(const CTransaction& tx, const CBlockIndex* pinde
if (tx.nVersion != 3 || tx.nType == TRANSACTION_NORMAL)
return true;
if (pindexPrev && pindexPrev->nHeight + 1 < Params().GetConsensus().DIP0003Height) {
const auto& consensusParams = Params().GetConsensus();
if (!DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_DIP0003)) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-tx-type");
}
@ -45,21 +46,21 @@ static bool CheckSpecialTxInner(const CTransaction& tx, const CBlockIndex* pinde
case TRANSACTION_QUORUM_COMMITMENT:
return llmq::CheckLLMQCommitment(tx, pindexPrev, state);
case TRANSACTION_MNHF_SIGNAL:
if (!llmq::utils::IsV20Active(pindexPrev)) {
if (!DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_V20)) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "mnhf-before-v20");
}
return CheckMNHFTx(tx, pindexPrev, state);
case TRANSACTION_ASSET_LOCK:
if (!llmq::utils::IsV20Active(pindexPrev)) {
if (!DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_V20)) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "assetlocks-before-v20");
}
return CheckAssetLockUnlockTx(tx, pindexPrev, indexes, state);
case TRANSACTION_ASSET_UNLOCK:
if (Params().NetworkIDString() == CBaseChainParams::REGTEST && !llmq::utils::IsV20Active(pindexPrev)) {
if (Params().NetworkIDString() == CBaseChainParams::REGTEST && !DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_V20)) {
// TODO: adjust functional tests to make it activated by MN_RR on regtest too
return state.Invalid(TxValidationResult::TX_CONSENSUS, "assetunlocks-before-v20");
}
if (Params().NetworkIDString() != CBaseChainParams::REGTEST && !llmq::utils::IsMNRewardReallocationActive(pindexPrev)) {
if (Params().NetworkIDString() != CBaseChainParams::REGTEST && !DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_MN_RR)) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "assetunlocks-before-mn_rr");
}
return CheckAssetLockUnlockTx(tx, pindexPrev, indexes, state);
@ -148,7 +149,7 @@ bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, CM
int64_t nTime1 = GetTimeMicros();
const CCreditPool creditPool = creditPoolManager->GetCreditPool(pindex->pprev, consensusParams);
if (llmq::utils::IsV20Active(pindex->pprev)) {
if (DeploymentActiveAt(*pindex, consensusParams, Consensus::DEPLOYMENT_V20)) {
LogPrint(BCLog::CREDITPOOL, "%s: CCreditPool is %s\n", __func__, creditPool.ToString());
}
@ -276,7 +277,7 @@ bool CheckCreditPoolDiffForBlock(const CBlock& block, const CBlockIndex* pindex,
const CAmount blockSubsidy, BlockValidationState& state)
{
try {
if (!llmq::utils::IsV20Active(pindex)) return true;
if (!DeploymentActiveAt(*pindex, consensusParams, Consensus::DEPLOYMENT_V20)) return true;
auto creditPoolDiff = GetCreditPoolDiffForBlock(block, pindex->pprev, consensusParams, blockSubsidy, state);
if (!creditPoolDiff.has_value()) return false;

View File

@ -7,9 +7,9 @@
#include <chainparams.h>
#include <consensus/validation.h>
#include <core_io.h>
#include <deploymentstatus.h>
#include <governance/governance.h>
#include <key_io.h>
#include <llmq/utils.h>
#include <primitives/transaction.h>
#include <script/standard.h>
#include <util/moneystr.h>
@ -496,13 +496,13 @@ CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight)
const CBlockIndex* pindex = ::ChainActive().Tip();
if (pindex->nHeight > nBlockHeight) pindex = pindex->GetAncestor(nBlockHeight);
const auto v20_state = llmq::utils::GetV20State(pindex);
const auto v20_state = g_versionbitscache.State(pindex, consensusParams, Consensus::DEPLOYMENT_V20);
bool fV20Active{v20_state == ThresholdState::ACTIVE};
if (!fV20Active && nBlockHeight > pindex->nHeight) {
// If fV20Active isn't active yet and nBlockHeight refers to a future SuperBlock
// then we need to check if the fork is locked_in and see if it will be active by the time of the future SuperBlock
if (v20_state == ThresholdState::LOCKED_IN) {
int activation_height = llmq::utils::GetV20Since(pindex) + static_cast<int>(Params().GetConsensus().vDeployments[Consensus::DEPLOYMENT_V20].nWindowSize);
int activation_height = g_versionbitscache.StateSinceHeight(pindex, consensusParams, Consensus::DEPLOYMENT_V20) + static_cast<int>(Params().GetConsensus().vDeployments[Consensus::DEPLOYMENT_V20].nWindowSize);
if (nBlockHeight >= activation_height) {
fV20Active = true;
}

View File

@ -8,6 +8,7 @@
#include <chain.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <evo/deterministicmns.h>
#include <flat-database.h>
#include <governance/classes.h>
@ -1461,7 +1462,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex* pindex, CConnman& co
nCachedBlockHeight = pindex->nHeight;
LogPrint(BCLog::GOBJECT, "CGovernanceManager::UpdatedBlockTip -- nCachedBlockHeight: %d\n", nCachedBlockHeight);
if (deterministicMNManager->IsDIP3Enforced(pindex->nHeight)) {
if (DeploymentDIP0003Enforced(pindex->nHeight, Params().GetConsensus())) {
RemoveInvalidVotes();
}

View File

@ -18,6 +18,7 @@
#include <chain.h>
#include <chainparams.h>
#include <context.h>
#include <deploymentstatus.h>
#include <node/coinstats.h>
#include <fs.h>
#include <hash.h>
@ -2109,9 +2110,8 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
failed_verification = true;
break;
}
bool v19active = llmq::utils::IsV19Active(tip);
if (llmq::utils::IsV19Active(tip)) {
const bool v19active{DeploymentActiveAfter(tip, chainparams.GetConsensus(), Consensus::DEPLOYMENT_V19)};
if (v19active) {
bls::bls_legacy_scheme.store(false);
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls::bls_legacy_scheme.load());
}

View File

@ -13,6 +13,7 @@
#include <chainparams.h>
#include <consensus/params.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <net.h>
#include <net_processing.h>
#include <primitives/block.h>
@ -708,7 +709,7 @@ std::optional<std::vector<CFinalCommitment>> CQuorumBlockProcessor::GetMineableC
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 basic_bls_enabled = utils::IsV19Active(pindex);
bool basic_bls_enabled{DeploymentActiveAfter(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
size_t quorums_num = rotation_enabled ? llmqParams.signingActiveQuorumCount : 1;
std::stringstream ss;

View File

@ -9,6 +9,7 @@
#include <chainparams.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <llmq/utils.h>
#include <logging.h>
#include <validation.h>
@ -41,13 +42,8 @@ bool CFinalCommitment::Verify(gsl::not_null<const CBlockIndex*> pQuorumBaseBlock
}
const auto& llmq_params = llmq_params_opt.value();
uint16_t expected_nversion{CFinalCommitment::LEGACY_BLS_NON_INDEXED_QUORUM_VERSION};
if (utils::IsQuorumRotationEnabled(llmq_params, pQuorumBaseBlockIndex)) {
expected_nversion = utils::IsV19Active(pQuorumBaseBlockIndex) ? CFinalCommitment::BASIC_BLS_INDEXED_QUORUM_VERSION : CFinalCommitment::LEGACY_BLS_INDEXED_QUORUM_VERSION;
}
else {
expected_nversion = utils::IsV19Active(pQuorumBaseBlockIndex) ? CFinalCommitment::BASIC_BLS_NON_INDEXED_QUORUM_VERSION : CFinalCommitment::LEGACY_BLS_NON_INDEXED_QUORUM_VERSION;
}
const uint16_t expected_nversion{CFinalCommitment::GetVersion(utils::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);
return false;

View File

@ -60,7 +60,6 @@ LLMQContext::~LLMQContext() {
llmq::chainLocksHandler.reset();
llmq::quorumManager.reset();
llmq::quorumBlockProcessor.reset();
llmq::llmq_versionbitscache.Clear();
}
void LLMQContext::Interrupt() {

View File

@ -14,6 +14,7 @@
#include <batchedlogger.h>
#include <chainparams.h>
#include <cxxtimer.hpp>
#include <deploymentstatus.h>
#include <logging.h>
#include <masternode/meta.h>
#include <masternode/node.h>
@ -1223,13 +1224,9 @@ std::vector<CFinalCommitment> CDKGSession::FinalizeCommitments()
fqc.quorumPublicKey = first.quorumPublicKey;
fqc.quorumVvecHash = first.quorumVvecHash;
if (utils::IsQuorumRotationEnabled(params, m_quorum_base_block_index)) {
fqc.nVersion = utils::IsV19Active(m_quorum_base_block_index) ? CFinalCommitment::BASIC_BLS_INDEXED_QUORUM_VERSION : CFinalCommitment::LEGACY_BLS_INDEXED_QUORUM_VERSION;
fqc.quorumIndex = quorumIndex;
} else {
fqc.nVersion = utils::IsV19Active(m_quorum_base_block_index) ? CFinalCommitment::BASIC_BLS_NON_INDEXED_QUORUM_VERSION : CFinalCommitment::LEGACY_BLS_NON_INDEXED_QUORUM_VERSION;
fqc.quorumIndex = 0;
}
const bool isQuorumRotationEnabled{utils::IsQuorumRotationEnabled(params, m_quorum_base_block_index)};
fqc.nVersion = CFinalCommitment::GetVersion(isQuorumRotationEnabled, DeploymentActiveAfter(m_quorum_base_block_index, Params().GetConsensus(), Consensus::DEPLOYMENT_V19));
fqc.quorumIndex = isQuorumRotationEnabled ? quorumIndex : 0;
uint256 commitmentHash = utils::BuildCommitmentHash(fqc.llmqType, fqc.quorumHash, fqc.validMembers, fqc.quorumPublicKey, fqc.quorumVvecHash);

View File

@ -12,6 +12,7 @@
#include <evo/deterministicmns.h>
#include <deploymentstatus.h>
#include <masternode/node.h>
#include <chainparams.h>
#include <net_processing.h>
@ -168,7 +169,7 @@ bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex)
{
curSession = std::make_unique<CDKGSession>(params, blsWorker, dkgManager, dkgDebugManager, connman);
if (!deterministicMNManager->IsDIP3Enforced(pQuorumBaseBlockIndex->nHeight)) {
if (!DeploymentDIP0003Enforced(pQuorumBaseBlockIndex->nHeight, Params().GetConsensus())) {
return false;
}

View File

@ -7,10 +7,10 @@
#include <llmq/quorums.h>
#include <llmq/utils.h>
#include <evo/deterministicmns.h>
#include <chainparams.h>
#include <dbwrapper.h>
#include <deploymentstatus.h>
#include <evo/deterministicmns.h>
#include <net_processing.h>
#include <spork.h>
#include <util/irange.h>
@ -162,7 +162,7 @@ void CDKGSessionManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fIni
if (fInitialDownload)
return;
if (!deterministicMNManager->IsDIP3Enforced(pindexNew->nHeight))
if (!DeploymentDIP0003Enforced(pindexNew->nHeight, Params().GetConsensus()))
return;
if (!IsQuorumDKGEnabled(spork_manager))
return;

View File

@ -3,15 +3,16 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <llmq/ehf_signals.h>
#include <llmq/utils.h>
#include <llmq/quorums.h>
#include <llmq/signing_shares.h>
#include <llmq/commitment.h>
#include <llmq/utils.h>
#include <evo/mnhftx.h>
#include <evo/specialtx.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <index/txindex.h> // g_txindex
#include <primitives/transaction.h>
#include <spork.h>
@ -43,7 +44,9 @@ CEHFSignalsHandler::~CEHFSignalsHandler()
void CEHFSignalsHandler::UpdatedBlockTip(const CBlockIndex* const pindexNew)
{
if (!fMasternodeMode || !llmq::utils::IsV20Active(pindexNew) || (Params().IsTestChain() && !sporkman.IsSporkActive(SPORK_24_TEST_EHF))) {
if (!DeploymentActiveAfter(pindexNew, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) return;
if (!fMasternodeMode || (Params().IsTestChain() && !sporkman.IsSporkActive(SPORK_24_TEST_EHF))) {
return;
}

View File

@ -9,6 +9,7 @@
#include <bls/bls.h>
#include <chainparams.h>
#include <deploymentstatus.h>
#include <evo/deterministicmns.h>
#include <evo/evodb.h>
#include <masternode/meta.h>
@ -32,11 +33,19 @@ static constexpr int TESTNET_LLMQ_25_67_ACTIVATION_HEIGHT = 847000;
*/
std::optional<std::pair<CBLSSignature, uint32_t>> GetNonNullCoinbaseChainlock(const CBlockIndex* pindex);
static bool IsV19Active(gsl::not_null<const CBlockIndex*> pindexPrev)
{
return DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_V19);
}
static bool IsV20Active(gsl::not_null<const CBlockIndex*> pindexPrev)
{
return DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_V20);
}
namespace llmq
{
VersionBitsCache llmq_versionbitscache;
namespace utils
{
@ -677,39 +686,7 @@ bool IsQuorumRotationEnabled(const Consensus::LLMQParams& llmqParams, gsl::not_n
return false;
}
// It should activate at least 1 block prior to the cycle start
return IsDIP0024Active(pindex->GetAncestor(cycleQuorumBaseHeight - 1));
}
bool IsDIP0024Active(gsl::not_null<const CBlockIndex*> pindex)
{
return pindex->nHeight + 1 >= Params().GetConsensus().DIP0024Height;
}
bool IsV19Active(gsl::not_null<const CBlockIndex*> pindex)
{
return pindex->nHeight + 1 >= Params().GetConsensus().V19Height;
}
bool IsV20Active(gsl::not_null<const CBlockIndex*> pindex)
{
return llmq_versionbitscache.State(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20) == ThresholdState::ACTIVE;
}
bool IsMNRewardReallocationActive(gsl::not_null<const CBlockIndex*> pindex)
{
if (!IsV20Active(pindex)) return false;
return llmq_versionbitscache.State(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR) == ThresholdState::ACTIVE;
}
ThresholdState GetV20State(gsl::not_null<const CBlockIndex*> pindex)
{
return llmq_versionbitscache.State(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20);
}
int GetV20Since(gsl::not_null<const CBlockIndex*> pindex)
{
return llmq_versionbitscache.StateSinceHeight(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20);
return DeploymentActiveAfter(pindex->GetAncestor(cycleQuorumBaseHeight - 1), Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0024);
}
uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2)
@ -941,16 +918,17 @@ bool IsQuorumActive(Consensus::LLMQType llmqType, const CQuorumManager& qman, co
return ranges::any_of(quorums, [&quorumHash](const auto& q){ return q->qc->quorumHash == quorumHash; });
}
bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindex)
bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindexPrev)
{
return IsQuorumTypeEnabledInternal(llmqType, qman, pindex, std::nullopt, std::nullopt);
return IsQuorumTypeEnabledInternal(llmqType, qman, pindexPrev, std::nullopt, std::nullopt);
}
bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindex,
bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindexPrev,
std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums)
{
const Consensus::Params& consensusParams = Params().GetConsensus();
const bool fDIP0024IsActive{optDIP0024IsActive.value_or(DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_DIP0024))};
switch (llmqType)
{
case Consensus::LLMQType::LLMQ_DEVNET:
@ -959,12 +937,10 @@ bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumMana
if (Params().NetworkIDString() == CBaseChainParams::TESTNET) return true;
// fall through
case Consensus::LLMQType::LLMQ_TEST_INSTANTSEND: {
bool fDIP0024IsActive = optDIP0024IsActive.has_value() ? *optDIP0024IsActive : IsDIP0024Active(pindex);
if (!fDIP0024IsActive) return true;
bool fHaveDIP0024Quorums = optHaveDIP0024Quorums.has_value() ? *optHaveDIP0024Quorums
: !qman.ScanQuorums(
consensusParams.llmqTypeDIP0024InstantSend, pindex, 1).empty();
const bool fHaveDIP0024Quorums{optHaveDIP0024Quorums.value_or(!qman.ScanQuorums(
consensusParams.llmqTypeDIP0024InstantSend, pindexPrev, 1).empty())};
return !fHaveDIP0024Quorums;
}
case Consensus::LLMQType::LLMQ_TEST:
@ -975,19 +951,18 @@ bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumMana
return true;
case Consensus::LLMQType::LLMQ_TEST_V17: {
return llmq_versionbitscache.State(pindex, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY) == ThresholdState::ACTIVE;
return DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
}
case Consensus::LLMQType::LLMQ_100_67:
return pindex->nHeight + 1 >= consensusParams.DIP0020Height;
return DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_DIP0020);
case Consensus::LLMQType::LLMQ_60_75:
case Consensus::LLMQType::LLMQ_DEVNET_DIP0024:
case Consensus::LLMQType::LLMQ_TEST_DIP0024: {
bool fDIP0024IsActive = optDIP0024IsActive.has_value() ? *optDIP0024IsActive : IsDIP0024Active(pindex);
return fDIP0024IsActive;
}
case Consensus::LLMQType::LLMQ_25_67:
return pindex->nHeight >= TESTNET_LLMQ_25_67_ACTIVATION_HEIGHT;
return pindexPrev->nHeight >= TESTNET_LLMQ_25_67_ACTIVATION_HEIGHT;
default:
throw std::runtime_error(strprintf("%s: Unknown LLMQ type %d", __func__, ToUnderlying(llmqType)));

View File

@ -29,11 +29,6 @@ namespace llmq
class CQuorumManager;
class CQuorumSnapshot;
// A separate cache instance instead of versionbitscache has been introduced to avoid locking cs_main
// and dealing with all kinds of deadlocks.
// TODO: drop llmq_versionbitscache completely so far as VersionBitsCache do not uses anymore cs_main
extern VersionBitsCache llmq_versionbitscache;
static const bool DEFAULT_ENABLE_QUORUM_DATA_RECOVERY = true;
enum class QvvecSyncMode {
@ -63,19 +58,13 @@ bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, gsl::not_n
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 IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<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);
bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindexPrev);
bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindexPrev, std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums);
std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(gsl::not_null<const CBlockIndex*> pindex);
std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuorumParams(gsl::not_null<const CBlockIndex*> pindex);
bool IsQuorumRotationEnabled(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pindex);
bool IsDIP0024Active(gsl::not_null<const CBlockIndex*> pindex);
bool IsV19Active(gsl::not_null<const CBlockIndex*> pindex);
bool IsV20Active(gsl::not_null<const CBlockIndex*> pindex);
bool IsMNRewardReallocationActive(gsl::not_null<const CBlockIndex*> pindex);
ThresholdState GetV20State(gsl::not_null<const CBlockIndex*> pindex);
int GetV20Since(gsl::not_null<const CBlockIndex*> pindex);
/// Returns the state of `-llmq-data-recovery`
bool QuorumDataRecoveryEnabled();

View File

@ -7,6 +7,7 @@
#include <evo/deterministicmns.h>
#include <chainparams.h>
#include <deploymentstatus.h>
#include <net.h>
#include <netbase.h>
#include <protocol.h>
@ -68,7 +69,7 @@ void CActiveMasternodeManager::Init(const CBlockIndex* pindex)
if (!fMasternodeMode) return;
if (!deterministicMNManager->IsDIP3Enforced(pindex->nHeight)) return;
if (!DeploymentDIP0003Enforced(pindex->nHeight, Params().GetConsensus())) return;
// Check that our local network configuration is correct
if (!fListen && Params().RequireRoutableExternalIP()) {
@ -141,7 +142,7 @@ void CActiveMasternodeManager::UpdatedBlockTip(const CBlockIndex* pindexNew, con
if (!fMasternodeMode) return;
if (!deterministicMNManager->IsDIP3Enforced(pindexNew->nHeight)) return;
if (!DeploymentDIP0003Enforced(pindexNew->nHeight, Params().GetConsensus())) return;
if (state == MASTERNODE_READY) {
auto oldMNList = deterministicMNManager->GetListForBlock(pindexNew->pprev);

View File

@ -7,12 +7,12 @@
#include <amount.h>
#include <chain.h>
#include <chainparams.h>
#include <deploymentstatus.h>
#include <evo/deterministicmns.h>
#include <governance/classes.h>
#include <governance/governance.h>
#include <key_io.h>
#include <logging.h>
#include <llmq/utils.h>
#include <masternode/sync.h>
#include <primitives/block.h>
#include <script/standard.h>
@ -29,11 +29,12 @@
voutMasternodePaymentsRet.clear();
const int nBlockHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;
const Consensus::Params& consensusParams = Params().GetConsensus();
bool fV20Active = llmq::utils::IsV20Active(pindexPrev);
bool fV20Active = DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_V20);
CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockSubsidy + feeReward, fV20Active);
if (llmq::utils::IsMNRewardReallocationActive(pindexPrev)) {
if (DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_MN_RR)) {
CAmount masternodeSubsidyReward = GetMasternodePayment(nBlockHeight, blockSubsidy, fV20Active);
const CAmount platformReward = MasternodePayments::PlatformShare(masternodeSubsidyReward);
masternodeReward -= platformReward;
@ -97,7 +98,7 @@
[[nodiscard]] static bool IsTransactionValid(const CTransaction& txNew, const CBlockIndex* const pindexPrev, const CAmount blockSubsidy, const CAmount feeReward)
{
const int nBlockHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;
if (!deterministicMNManager->IsDIP3Enforced(nBlockHeight)) {
if (!DeploymentDIP0003Enforced(nBlockHeight, Params().GetConsensus())) {
// can't verify historical blocks here
return true;
}

View File

@ -35,6 +35,7 @@
#include <llmq/utils.h>
#include <masternode/payments.h>
#include <spork.h>
#include <validation.h>
#include <algorithm>
#include <utility>
@ -72,8 +73,7 @@ BlockAssembler::BlockAssembler(const CSporkManager& sporkManager, CGovernanceMan
m_evoDb(evoDb)
{
blockMinFeeRate = options.blockMinFeeRate;
// Limit size to between 1K and MaxBlockSize()-1K for sanity:
nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MaxBlockSize(fDIP0001ActiveAtTip) - 1000), (unsigned int)options.nBlockMaxSize));
nBlockMaxSize = options.nBlockMaxSize;
}
static BlockAssembler::Options DefaultOptions()
@ -133,9 +133,14 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
assert(pindexPrev != nullptr);
nHeight = pindexPrev->nHeight + 1;
bool fDIP0003Active_context = DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0003);
bool fDIP0008Active_context = DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0008);
bool fV20Active_context = llmq::utils::IsV20Active(pindexPrev);
const bool fDIP0001Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0001)};
const bool fDIP0003Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0003)};
const bool fDIP0008Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0008)};
const bool fV20Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_V20)};
// Limit size to between 1K and MaxBlockSize()-1K for sanity:
nBlockMaxSize = std::max<unsigned int>(1000, std::min<unsigned int>(MaxBlockSize(fDIP0001Active_context) - 1000, nBlockMaxSize));
nBlockMaxSigOps = MaxBlockSigOps(fDIP0001Active_context);
pblock->nVersion = g_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
// Non-mainnet only: allow overriding block.nVersion with
@ -284,7 +289,7 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, unsigned int packageSigOp
{
if (nBlockSize + packageSize >= nBlockMaxSize)
return false;
if (nBlockSigOps + packageSigOps >= MaxBlockSigOps(fDIP0001ActiveAtTip))
if (nBlockSigOps + packageSigOps >= nBlockMaxSigOps)
return false;
return true;
}
@ -396,13 +401,12 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
// transaction package to work on next.
void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated, const CBlockIndex* const pindexPrev)
{
AssertLockHeld(cs_main); // for GetMNHFSignalsStage()
AssertLockHeld(m_mempool.cs);
// This credit pool is used only to check withdrawal limits and to find
// duplicates of indexes. There's used `BlockSubsidy` equaled to 0
std::optional<CCreditPoolDiff> creditPoolDiff;
if (llmq::utils::IsV20Active(pindexPrev)) {
if (DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_V20)) {
CCreditPool creditPool = creditPoolManager->GetCreditPool(pindexPrev, chainparams.GetConsensus());
creditPoolDiff.emplace(std::move(creditPool), pindexPrev, chainparams.GetConsensus(), 0);
}

View File

@ -8,7 +8,6 @@
#include <primitives/block.h>
#include <txmempool.h>
#include <validation.h>
#include <memory>
#include <optional>
@ -20,6 +19,7 @@
class CBlockIndex;
class CChainParams;
class CConnman;
class CEvoDB;
class CGovernanceManager;
class CScript;
class CSporkManager;
@ -142,6 +142,7 @@ private:
// Configuration parameters for the block size
unsigned int nBlockMaxSize;
unsigned int nBlockMaxSigOps;
CFeeRate blockMinFeeRate;
// Information on the current status of the block

View File

@ -29,7 +29,7 @@
#include <util/thread.h>
#include <util/time.h>
#include <util/translation.h>
#include <validation.h>
#include <validation.h> // for fDIP0001ActiveAtTip
#include <masternode/meta.h>
#include <masternode/sync.h>

View File

@ -7,6 +7,7 @@
#include <chainparams.h>
#include <consensus/validation.h>
#include <core_io.h>
#include <deploymentstatus.h>
#include <evo/deterministicmns.h>
#include <evo/dmn_types.h>
#include <evo/providertx.h>
@ -16,7 +17,6 @@
#include <index/txindex.h>
#include <llmq/blockprocessor.h>
#include <llmq/context.h>
#include <llmq/utils.h>
#include <masternode/meta.h>
#include <messagesigner.h>
#include <netbase.h>
@ -611,7 +611,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
EnsureWalletIsUnlocked(wallet.get());
}
bool isV19active = llmq::utils::IsV19Active(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();));
const bool isV19active{DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
if (isEvoRequested && !isV19active) {
throw JSONRPCError(RPC_INVALID_REQUEST, "EvoNodes aren't allowed yet");
}
@ -915,7 +915,7 @@ static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& reques
EnsureWalletIsUnlocked(wallet.get());
const bool isV19active = llmq::utils::IsV19Active(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();));
const bool isV19active{DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
const bool is_bls_legacy = !isV19active;
if (isEvoRequested && !isV19active) {
throw JSONRPCError(RPC_INVALID_REQUEST, "EvoNodes aren't allowed yet");
@ -1056,7 +1056,8 @@ static UniValue protx_update_registrar_wrapper(const JSONRPCRequest& request, co
ptx.keyIDVoting = dmn->pdmnState->keyIDVoting;
ptx.scriptPayout = dmn->pdmnState->scriptPayout;
const bool use_legacy = llmq::utils::IsV19Active(chainman.ActiveChain().Tip()) ? specific_legacy_bls_scheme : true;
const bool isV19Active{DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
const bool use_legacy = isV19Active ? specific_legacy_bls_scheme : true;
if (request.params[1].get_str() != "") {
// new pubkey
@ -1156,7 +1157,7 @@ static UniValue protx_revoke(const JSONRPCRequest& request, const ChainstateMana
EnsureWalletIsUnlocked(wallet.get());
const bool isV19active = llmq::utils::IsV19Active(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();));
const bool isV19active{DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
const bool is_bls_legacy = !isV19active;
CProUpRevTx ptx;
ptx.nVersion = CProUpRevTx::GetVersion(isV19active);
@ -1678,7 +1679,7 @@ static UniValue bls_generate(const JSONRPCRequest& request, const ChainstateMana
CBLSSecretKey sk;
sk.MakeNewKey();
bool bls_legacy_scheme = !llmq::utils::IsV19Active(chainman.ActiveChain().Tip());
bool bls_legacy_scheme{!DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
if (!request.params[0].isNull()) {
bls_legacy_scheme = ParseBoolV(request.params[0], "bls_legacy_scheme");
}
@ -1715,7 +1716,7 @@ static UniValue bls_fromsecret(const JSONRPCRequest& request, const ChainstateMa
{
bls_fromsecret_help(request);
bool bls_legacy_scheme = !llmq::utils::IsV19Active(chainman.ActiveChain().Tip());
bool bls_legacy_scheme{!DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
if (!request.params[1].isNull()) {
bls_legacy_scheme = ParseBoolV(request.params[1], "bls_legacy_scheme");
}

View File

@ -903,6 +903,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
aMutable.push_back("version/force");
}
const bool fDIP0001Active_context{DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_DIP0001)};
result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex());
result.pushKV("transactions", transactions);
result.pushKV("coinbaseaux", aux);
@ -912,8 +913,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1);
result.pushKV("mutable", aMutable);
result.pushKV("noncerange", "00000000ffffffff");
result.pushKV("sigoplimit", (int64_t)MaxBlockSigOps(fDIP0001ActiveAtTip));
result.pushKV("sizelimit", (int64_t)MaxBlockSize(fDIP0001ActiveAtTip));
result.pushKV("sigoplimit", (int64_t)MaxBlockSigOps(fDIP0001Active_context));
result.pushKV("sizelimit", (int64_t)MaxBlockSize(fDIP0001Active_context));
result.pushKV("curtime", pblock->GetBlockTime());
result.pushKV("bits", strprintf("%08x", pblock->nBits));
result.pushKV("previousbits", strprintf("%08x", pblocktemplate->nPrevBits));

View File

@ -7,6 +7,7 @@
#include <addressindex.h>
#include <chainparams.h>
#include <consensus/consensus.h>
#include <deploymentstatus.h>
#include <evo/mnauth.h>
#include <httpserver.h>
#include <index/blockfilterindex.h>
@ -15,7 +16,6 @@
#include <init.h>
#include <interfaces/chain.h>
#include <key_io.h>
#include <llmq/utils.h>
#include <net.h>
#include <node/context.h>
#include <rpc/blockchain.h>
@ -581,7 +581,7 @@ static UniValue mnauth(const JSONRPCRequest& request)
ChainstateManager& chainman = EnsureAnyChainman(request.context);
CBLSPublicKey publicKey;
bool bls_legacy_scheme = !llmq::utils::IsV19Active(chainman.ActiveChain().Tip());
const bool bls_legacy_scheme{!DeploymentActiveAfter(chainman.ActiveChain().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
publicKey.SetHexStr(request.params[2].get_str(), bls_legacy_scheme);
if (!publicKey.IsValid()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "publicKey invalid");

View File

@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <deploymentstatus.h>
#include <index/txindex.h>
#include <node/context.h>
#include <rpc/blockchain.h>
@ -896,7 +897,7 @@ static UniValue verifychainlock(const JSONRPCRequest& request)
CBLSSignature sig;
if (pIndex) {
bool use_legacy_signature = !llmq::utils::IsV19Active(pIndex);
const bool use_legacy_signature{!DeploymentActiveAfter(pIndex, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
if (!sig.SetHexStr(request.params[1].get_str(), use_legacy_signature)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid signature format");
}
@ -976,7 +977,7 @@ static UniValue verifyislock(const JSONRPCRequest& request)
CHECK_NONFATAL(pBlockIndex != nullptr);
CBLSSignature sig;
const bool use_bls_legacy = !llmq::utils::IsV19Active(pBlockIndex);
const bool use_bls_legacy{!DeploymentActiveAfter(pBlockIndex, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
if (!sig.SetHexStr(request.params[2].get_str(), use_bls_legacy)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid signature format");
}

View File

@ -7,6 +7,7 @@
#include <bls/bls.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <messagesigner.h>
#include <miner.h>
#include <netbase.h>
@ -26,7 +27,6 @@
#include <llmq/chainlocks.h>
#include <llmq/context.h>
#include <llmq/instantsend.h>
#include <llmq/utils.h>
#include <masternode/payments.h>
#include <util/enumerate.h>
#include <util/irange.h>
@ -150,7 +150,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
CScript coinbasePubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
BOOST_ASSERT(deterministicMNManager->IsDIP3Enforced(WITH_LOCK(cs_main, return m_node.chainman->ActiveChain().Height())));
BOOST_ASSERT(DeploymentDIP0003Enforced(WITH_LOCK(cs_main, return m_node.chainman->ActiveChain().Height()), consensus_params));
// Register one MN
CKey ownerKey;
@ -206,7 +206,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
// next block should be signaling by default
LOCK(cs_main);
const CBlockIndex* const tip{m_node.chainman->ActiveChain().Tip()};
const bool isV20Active{llmq::utils::IsV20Active(tip)};
const bool isV20Active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V20)};
deterministicMNManager->UpdatedBlockTip(tip);
BOOST_ASSERT(deterministicMNManager->GetListAtChainTip().HasMN(tx.GetHash()));
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
@ -222,7 +222,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
{
LOCK(cs_main);
const CBlockIndex* const tip{m_node.chainman->ActiveChain().Tip()};
const bool isV20Active{llmq::utils::IsV20Active(tip)};
const bool isV20Active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V20)};
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, isV20Active);
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
@ -240,20 +240,20 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
}
LOCK(cs_main);
const CBlockIndex* const tip{m_node.chainman->ActiveChain().Tip()};
const bool isV20Active{llmq::utils::IsV20Active(tip)};
const bool isV20Active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V20)};
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, isV20Active);
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
}
}
BOOST_CHECK(llmq::utils::IsV20Active(m_node.chainman->ActiveChain().Tip()));
BOOST_CHECK(DeploymentActiveAfter(m_node.chainman->ActiveChain().Tip(), consensus_params, Consensus::DEPLOYMENT_V20));
// Allocation of block subsidy is 60% MN, 20% miners and 20% treasury
{
// Reward split should reach ~75/25 after reallocation is done
LOCK(cs_main);
const CBlockIndex* const tip{m_node.chainman->ActiveChain().Tip()};
const bool isV20Active{llmq::utils::IsV20Active(tip)};
const bool isV20Active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V20)};
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
const CAmount block_subsidy_sb = GetSuperblockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
CAmount block_subsidy_potential = block_subsidy + block_subsidy_sb;
@ -267,7 +267,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, 50662764); // 0.75
}
BOOST_CHECK(!llmq::utils::IsMNRewardReallocationActive(m_node.chainman->ActiveChain().Tip()));
BOOST_CHECK(!DeploymentActiveAfter(m_node.chainman->ActiveChain().Tip(), consensus_params, Consensus::DEPLOYMENT_MN_RR));
// Activate EHF "MN_RR"
{
@ -283,8 +283,8 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
}
LOCK(cs_main);
const CBlockIndex* const tip{m_node.chainman->ActiveChain().Tip()};
const bool isV20Active{llmq::utils::IsV20Active(tip)};
const bool isMNRewardReallocated{llmq::utils::IsMNRewardReallocationActive(tip)};
const bool isV20Active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V20)};
const bool isMNRewardReallocated{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_MN_RR)};
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, isV20Active);
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
@ -298,12 +298,12 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[payment_index].nValue, masternode_payment);
}
BOOST_CHECK(llmq::utils::IsMNRewardReallocationActive(m_node.chainman->ActiveChain().Tip()));
BOOST_CHECK(DeploymentActiveAfter(m_node.chainman->ActiveChain().Tip(), consensus_params, Consensus::DEPLOYMENT_MN_RR));
{ // At this moment Masternode reward should be reallocated to platform
// Allocation of block subsidy is 60% MN, 20% miners and 20% treasury
LOCK(cs_main);
const CBlockIndex* const tip{m_node.chainman->ActiveChain().Tip()};
const bool isV20Active{llmq::utils::IsV20Active(tip)};
const bool isV20Active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V20)};
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
const CAmount block_subsidy_sb = GetSuperblockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, isV20Active);

View File

@ -7,6 +7,7 @@
#include <base58.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <messagesigner.h>
#include <netbase.h>
#include <policy/policy.h>
@ -21,7 +22,6 @@
#include <evo/deterministicmns.h>
#include <evo/providertx.h>
#include <evo/specialtx.h>
#include <llmq/utils.h>
#include <boost/test/unit_test.hpp>
@ -267,7 +267,7 @@ void FuncDIP3Activation(TestChainSetup& setup)
void FuncV19Activation(TestChainSetup& setup)
{
BOOST_ASSERT(!llmq::utils::IsV19Active(::ChainActive().Tip()));
BOOST_ASSERT(!DeploymentActiveAfter(::ChainActive().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19));
// create
auto utxos = BuildSimpleUtxoMap(setup.m_coinbase_txns);
@ -283,7 +283,7 @@ void FuncV19Activation(TestChainSetup& setup)
auto block = std::make_shared<CBlock>(setup.CreateBlock({tx_reg}, setup.coinbaseKey));
BOOST_ASSERT(Assert(setup.m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
BOOST_ASSERT(!llmq::utils::IsV19Active(::ChainActive().Tip()));
BOOST_ASSERT(!DeploymentActiveAfter(::ChainActive().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19));
++nHeight;
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight);
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
@ -301,7 +301,7 @@ void FuncV19Activation(TestChainSetup& setup)
block = std::make_shared<CBlock>(setup.CreateBlock({tx_upreg}, setup.coinbaseKey));
BOOST_ASSERT(Assert(setup.m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
BOOST_ASSERT(!llmq::utils::IsV19Active(::ChainActive().Tip()));
BOOST_ASSERT(!DeploymentActiveAfter(::ChainActive().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19));
++nHeight;
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight);
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
@ -321,7 +321,7 @@ void FuncV19Activation(TestChainSetup& setup)
BOOST_ASSERT(SignSignature(signing_provider, CTransaction(tx_reg), tx_spend, 0, SIGHASH_ALL));
block = std::make_shared<CBlock>(setup.CreateBlock({tx_spend}, setup.coinbaseKey));
BOOST_ASSERT(Assert(setup.m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
BOOST_ASSERT(!llmq::utils::IsV19Active(::ChainActive().Tip()));
BOOST_ASSERT(!DeploymentActiveAfter(::ChainActive().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19));
++nHeight;
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight);
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
@ -333,7 +333,7 @@ void FuncV19Activation(TestChainSetup& setup)
// mine another block so that it's not the last one before V19
setup.CreateAndProcessBlock({}, setup.coinbaseKey);
BOOST_ASSERT(!llmq::utils::IsV19Active(::ChainActive().Tip()));
BOOST_ASSERT(!DeploymentActiveAfter(::ChainActive().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19));
++nHeight;
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight);
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
@ -345,7 +345,7 @@ void FuncV19Activation(TestChainSetup& setup)
// this block should activate V19
setup.CreateAndProcessBlock({}, setup.coinbaseKey);
BOOST_ASSERT(llmq::utils::IsV19Active(::ChainActive().Tip()));
BOOST_ASSERT(DeploymentActiveAfter(::ChainActive().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19));
++nHeight;
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight);
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
@ -365,7 +365,7 @@ void FuncV19Activation(TestChainSetup& setup)
for (int i = 0; i < 10; ++i)
{
setup.CreateAndProcessBlock({}, setup.coinbaseKey);
BOOST_ASSERT(llmq::utils::IsV19Active(::ChainActive().Tip()));
BOOST_ASSERT(DeploymentActiveAfter(::ChainActive().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19));
BOOST_CHECK_EQUAL(::ChainActive().Height(), nHeight + 1 + i);
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
deterministicMNManager->DoMaintenance();

View File

@ -10,6 +10,7 @@
#include <consensus/consensus.h>
#include <consensus/params.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <crypto/sha256.h>
#include <flat-database.h>
#include <governance/governance.h>
@ -27,7 +28,6 @@
#include <llmq/signing.h>
#include <llmq/signing_shares.h>
#include <llmq/snapshot.h>
#include <llmq/utils.h>
#include <masternode/sync.h>
#include <miner.h>
#include <net.h>
@ -464,14 +464,14 @@ CBlock getBlock13b8a()
TestChainV19Setup::TestChainV19Setup() : TestChainSetup(899)
{
bool v19_just_activated = llmq::utils::IsV19Active(::ChainActive().Tip()) &&
!llmq::utils::IsV19Active(::ChainActive().Tip()->pprev);
bool v19_just_activated{DeploymentActiveAfter(::ChainActive().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19) &&
!DeploymentActiveAt(*::ChainActive().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
assert(v19_just_activated);
}
// 5 blocks earlier
TestChainV19BeforeActivationSetup::TestChainV19BeforeActivationSetup() : TestChainSetup(894)
{
bool v19_active = llmq::utils::IsV19Active(::ChainActive().Tip());
bool v19_active{DeploymentActiveAfter(::ChainActive().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
assert(!v19_active);
}

View File

@ -61,7 +61,6 @@
#include <llmq/instantsend.h>
#include <llmq/chainlocks.h>
#include <llmq/utils.h>
#include <statsd_client.h>
@ -157,7 +156,7 @@ bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
uint64_t nPruneTarget = 0;
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
// TODO: drop this global variable
// TODO: drop this global variable. Used by net.cpp module only
std::atomic<bool> fDIP0001ActiveAtTip{false};
uint256 hashAssumeValid;
@ -1171,7 +1170,7 @@ CAmount GetBlockSubsidyInner(int nPrevBits, int nPrevHeight, const Consensus::Pa
CAmount GetBlockSubsidy(const CBlockIndex* const pindex, const Consensus::Params& consensusParams)
{
if (pindex->pprev == nullptr) return Params().GenesisBlock().vtx[0]->GetValueOut();
bool isV20Active = llmq::utils::IsV20Active(pindex->pprev);
const bool isV20Active{DeploymentActiveAt(*pindex, consensusParams, Consensus::DEPLOYMENT_V20)};
return GetBlockSubsidyInner(pindex->pprev->nBits, pindex->pprev->nHeight, consensusParams, isV20Active);
}

View File

@ -766,7 +766,7 @@ public:
size_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
/** Return list of MN EHF signals for current Tip() */
std::unordered_map<uint8_t, int> GetMNHFSignalsStage(const CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
std::unordered_map<uint8_t, int> GetMNHFSignalsStage(const CBlockIndex* pindex);
std::string ToString() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
private:

View File

@ -100,7 +100,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"governance/object -> validationinterface -> governance/object"
"governance/vote -> validation -> validationinterface -> governance/vote"
"llmq/signing -> masternode/node -> validationinterface -> llmq/signing"
"llmq/utils -> validation -> llmq/utils"
"evo/mnhftx -> validation -> evo/mnhftx"
"evo/deterministicmns -> validation -> evo/deterministicmns"
)