Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/decenomy/DSW into KYAN-d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
pedro-at-decenomy committed Jan 25, 2025
2 parents 76f7edb + 883f785 commit 403b7ba
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 41 deletions.
24 changes: 13 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,12 +1449,10 @@ bool IsInitialBlockDownload()
if (latchToFalse.load(std::memory_order_relaxed))
return false;

LOCK(cs_main);
if (latchToFalse.load(std::memory_order_relaxed))
return false;
const int chainHeight = chainActive.Height();
if (fImporting || fReindex || fVerifyingBlocks || chainHeight < Checkpoints::GetTotalBlocksEstimate())
return true;
LOCK(cs_main);
bool state = (chainHeight < pindexBestHeader->nHeight - 24 * 6 ||
pindexBestHeader->GetBlockTime() < GetTime() - nMaxTipAge);
if (!state)
Expand Down Expand Up @@ -1961,11 +1959,13 @@ DisconnectResult DisconnectBlock(CBlock& block, CBlockIndex* pindex, CCoinsViewC
// move best block pointer to prevout block
view.SetBestBlock(pindex->pprev->GetBlockHash());

// Dynamic rewards management
if(!CRewards::DisconnectBlock(pindex)) return DISCONNECT_UNCLEAN;
if(!IsInitialBlockDownload()) {
// Dynamic rewards management
if(!CRewards::DisconnectBlock(pindex)) return DISCONNECT_UNCLEAN;

// Masternode management
if(!mnodeman.DisconnectBlock(pindex, block)) return DISCONNECT_UNCLEAN;
// Masternode management
if(!mnodeman.DisconnectBlock(pindex, block)) return DISCONNECT_UNCLEAN;
}

return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN;
}
Expand Down Expand Up @@ -2249,11 +2249,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
nTimeCallbacks += nTime4 - nTime3;
LogPrint(BCLog::BENCH, " - Callbacks: %.2fms [%.2fs]\n", 0.001 * (nTime4 - nTime3), nTimeCallbacks * 0.000001);

// Dynamic rewards management
if(!CRewards::ConnectBlock(pindex, nMint)) return false;
if(!IsInitialBlockDownload()) {
// Dynamic rewards management
if(!CRewards::ConnectBlock(pindex, nMint)) return false;

// Masternode management
if(!mnodeman.ConnectBlock(pindex, block)) return false;
// Masternode management
if(!mnodeman.ConnectBlock(pindex, block)) return false;
}

return true;
}
Expand Down
46 changes: 24 additions & 22 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ bool CMasternodePayments::IsTransactionValid(const CBlock& block, const CBlockIn

assert(block.hashPrevBlock == pindexPrev->GetBlockHash());

const auto nBlockHeight = pindexPrev->nHeight + 1;
const auto& params = Params();
const auto& consensus = params.GetConsensus();
const auto nPrevBlockHeight = pindexPrev->nHeight;
const auto nPrevBlockTime = pindexPrev->nTime;
const auto nBlockHeight = nPrevBlockHeight + 1;

const auto& txNew = block.vtx[block.IsProofOfStake() ? 1 : 0];

auto requiredMasternodePayment = CMasternode::GetMasternodePayment(nBlockHeight);
Expand Down Expand Up @@ -181,18 +182,14 @@ bool CMasternodePayments::IsTransactionValid(const CBlock& block, const CBlockIn
return false; // should not happen
}

if (nPrevBlockHeight - collateral.nHeight < MASTERNODE_MIN_CONFIRMATIONS) {
return false; // needs more confirmations
}

// get when this masternode was last paid
int n = 0;
const auto pLastPaidBlock = mnodeman.GetLastPaidBlockSlow(paidPayee, pindexPrev);
const auto lastPaid = std::max(
static_cast<uint32_t>(pLastPaidBlock ? pLastPaidBlock->nHeight : 0),
collateral.nHeight
);

auto lastPaidDepth = mnodeman.BlocksSincePayment(paidPayee, pindexPrev);
if(lastPaidDepth < 0) {
lastPaidDepth = pindexPrev->nHeight - collateral.nHeight;
}
const auto nLastPaid = pLastPaidBlock ? pLastPaidBlock->nTime : WITH_LOCK(cs_main, return chainActive[collateral.nHeight]->nTime);

// get the masternodes choosen on this block from our point of view
const auto eligible = mnodeman.GetNextMasternodeInQueueEligible(pindexPrev);
Expand All @@ -202,21 +199,26 @@ bool CMasternodePayments::IsTransactionValid(const CBlock& block, const CBlockIn
return true;
}

const auto eligibleDepth = eligible.first->BlocksSincePayment(pindexPrev);
const auto nEligibleLastPaid = eligible.first->GetLastPaid(pindexPrev);

auto minDepth = INT32_MAX;
auto maxDepth = 0;
auto nMinLastPaid = INT64_MAX;
auto nMaxLastPaid = INT64_MIN;

for(const auto& txin : eligible.second) {
CMasternode* pmn = mnodeman.Find(txin);
if (!pmn) continue;

const auto nDepth = pmn->BlocksSincePayment(pindexPrev);
minDepth = std::min(minDepth, nDepth);
maxDepth = std::max(maxDepth, nDepth);
auto lp = pmn->GetLastPaid(pindexPrev);
nMinLastPaid = std::min(nMinLastPaid, lp);
nMaxLastPaid = std::max(nMaxLastPaid, lp);
}

if(LogAcceptCategory(BCLog::MASTERNODE)) {
if(LogAcceptCategory(BCLog::MASTERNODE))
{
const auto& params = Params();
const auto& consensus = params.GetConsensus();
const auto& nTargetSpacing = consensus.nTargetSpacing;

if(pLastPaidBlock) {

CTxDestination destination;
Expand All @@ -231,12 +233,12 @@ bool CMasternodePayments::IsTransactionValid(const CBlock& block, const CBlockIn
);
} // nBlockHeight
LogPrint(BCLog::MASTERNODE, "%s - Block tested/tip %d/%d\n", __func__, nBlockHeight, chainActive.Height());
LogPrint(BCLog::MASTERNODE, "%s - Eligible min/max depth %d/%d\n", __func__, minDepth, maxDepth);
LogPrint(BCLog::MASTERNODE, "%s - Eligible and paid depth %d/%d\n", __func__, maxDepth, lastPaidDepth);
LogPrint(BCLog::MASTERNODE, "%s - Eligible min/max depth %d/%d\n", __func__, (nPrevBlockTime - nMaxLastPaid) / nTargetSpacing, (nPrevBlockTime - nMinLastPaid) / nTargetSpacing);
LogPrint(BCLog::MASTERNODE, "%s - Eligible and paid depth %d/%d\n", __func__, (nPrevBlockTime - nMinLastPaid) / nTargetSpacing, (nPrevBlockTime - nLastPaid) / nTargetSpacing);
}

// reject it, if it is being paid faster than the shortest depth elegible MN
if (lastPaidDepth < minDepth) {
if (nLastPaid > nMaxLastPaid) {

if(LogAcceptCategory(BCLog::MASTERNODE)) {
auto p = pindexPrev;
Expand Down
2 changes: 1 addition & 1 deletion src/masternode-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ bool CMasternodeSync::SyncWithNode(CNode* pnode, bool isRegTestNet)

if (lastMasternodeList > 0 && countMasternodeList > 0 &&
RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD &&
mnodeman.CountEnabled() >= (sumMasternodeList * 90) / (countMasternodeList * 100) // only move on after getting a properly sized MN list
mnodeman.CountEnabled() >= (sumMasternodeList * 60) / (countMasternodeList * 100) // only move on after getting a properly sized MN list
) { // we have a good enough mn list, so we'll move to the next step
GetNextAsset();
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,13 +746,13 @@ std::string CMasternodePing::GetStrMessage() const

bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fCheckSigTimeOnly)
{
if (sigTime > GetAdjustedTime() + 60 * 60) {
if (sigTime > GetAdjustedTime() + HOUR_IN_SECONDS) {
LogPrint(BCLog::MNPING, "%s: Signature rejected, too far into the future %s\n", __func__, vin.prevout.ToStringShort());
// nDos = 1; //disable, this is happening frequently and causing banned peers
return false;
}

if (sigTime <= GetAdjustedTime() - 60 * 60) {
if (sigTime <= GetAdjustedTime() - MASTERNODE_EXPIRATION_SECONDS) {
LogPrint(BCLog::MNPING, "%s: Signature rejected, too far into the past %s - %d %d \n", __func__, vin.prevout.ToStringShort(), sigTime, GetAdjustedTime());
// nDos = 1; //disable, this is happening frequently and causing banned peers
return false;
Expand Down
10 changes: 9 additions & 1 deletion src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,15 @@ bool CMasternodeMan::ConnectBlock(const CBlockIndex* pindex, const CBlock& block
mapRemovedCollaterals[nHeight][outPoint] = coin;

mapCOutPointCollaterals.erase(outPoint);
mapScriptCollaterals.erase(coin.out.scriptPubKey);

const auto& script = coin.out.scriptPubKey;
mapScriptCollaterals.erase(script);

// mark the masternode as vin spent
const auto pmn = Find(script);
if(pmn) {
pmn->activeState = CMasternode::MASTERNODE_VIN_SPENT;
}
}
mapCAmountCollaterals.erase(nCollateral);
}
Expand Down
5 changes: 5 additions & 0 deletions src/primitives/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ CScript CBlock::GetPaidPayee(CAmount nAmount) const
{
if (it->nValue == nAmount) return it->scriptPubKey;
}

for (auto it = tx.vout.rbegin(); it != tx.vout.rend(); ++it)
{
return it->scriptPubKey;
}

return CScript();
}
Expand Down
6 changes: 3 additions & 3 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,10 +1162,10 @@ void RPCConsole::setmymasternodes()
ui->myactivemn->setText(QString::number(nMNCount));
}

void RPCConsole::setbstamp()
void RPCConsole::setbstamp(CBlockchainStatus& cbs)
{
QDateTime timestamp = QDateTime::currentDateTime();
QString timestring = timestamp.toString();
QString timestring = timestamp.toString() + " : " + QString::number(cbs.nBlocksPerDay) + " blks/day";
ui->bststamp->setText(timestring);
}

Expand Down Expand Up @@ -1195,5 +1195,5 @@ void RPCConsole::updateBlockchainStats()
setchainmasternodes(cbs);
setmymasternodes();
applyColor2Text(ui->bststamp, Qt::black);
setbstamp();
setbstamp(cbs);
}
2 changes: 1 addition & 1 deletion src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public Q_SLOTS:
/** show my masternode status */
void setmymasternodes();
/** show the timestamp when the status snapshot was taken */
void setbstamp();
void setbstamp(CBlockchainStatus& cbs);

enum ColumnWidths {
ADDRESS_COLUMN_WIDTH = 170,
Expand Down

0 comments on commit 403b7ba

Please sign in to comment.