Commit a9370fc8 authored by presstab's avatar presstab

Don't reject mn payment if the chain has stalled

parent 6ade2373
......@@ -135,6 +135,7 @@ public:
nStakePointerValidityPeriod = 1440; //Stake pointers are valid to stake with for the next 1 day worth of blocks
nMaxReorgDepth = 100;
nKernelModifierOffset = 100; //Number blocks before the stake pointer is the kernel modifier from
nChainStallDuration = 60*60; //Spacing between blocks that will consider the chain as "stalled"
/**
* Build the genesis block. Note that the output of the genesis coinbase cannot
......
......@@ -90,6 +90,7 @@ public:
int ValidStakePointerDuration() const { return nStakePointerValidityPeriod; }
int MaxReorganizationDepth() const { return nMaxReorgDepth; }
int KernelModifierOffset() const { return nKernelModifierOffset; }
int ChainStallDuration() const { return nChainStallDuration; }
/* Return start height of auxpow and the retarget interval change. */
virtual int AuxpowStartHeight() const = 0;
/* Return whether or not to enforce strict chain ID checks. */
......@@ -138,6 +139,7 @@ protected:
int nStakePointerValidityPeriod;
int nMaxReorgDepth;
int nKernelModifierOffset;
int nChainStallDuration;
};
/**
......
......@@ -3252,12 +3252,12 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
return state.DoS(100,
error("CheckBlock() : Masternode/systemnode payments made when payment enforcement is disabled"));
}
if(!IsBlockPayeeValid(block.vtx[0], nHeight))
if(!IsBlockPayeeValid(block.vtx[0], nHeight, block.nTime, pindexPrev->nTime))
{
mapRejectedBlocks.insert(make_pair(block.GetHash(), GetTime()));
return state.DoS(100, error("CheckBlock() : Couldn't find masternode/budget payment"));
}
if(!SNIsBlockPayeeValid(block.vtx[0], nHeight))
if(!SNIsBlockPayeeValid(block.vtx[0], nHeight, block.nTime, pindexPrev->nTime))
{
mapRejectedBlocks.insert(make_pair(block.GetHash(), GetTime()));
return state.DoS(100, error("CheckBlock() : Couldn't find systemnode/budget payment"));
......
......@@ -12,6 +12,7 @@
#include "sync.h"
#include "spork.h"
#include "addrman.h"
#include "utilmoneystr.h"
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
......@@ -71,7 +72,7 @@ bool IsBlockValueValid(const CBlock& block, int64_t nExpectedValue){
return true;
}
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight)
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, const uint32_t& nTime, const uint32_t& nTimePrevBlock)
{
if(!masternodeSync.IsSynced()) { //there is no budget data to use to check anything -- find the longest chain
LogPrint("mnpayments", "Client not synced, skipping block payee checks\n");
......@@ -79,7 +80,7 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight)
}
//check if it's a budget block
if(IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS)){
if (IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS)){
if(budget.IsBudgetPaymentBlock(nBlockHeight)){
if(budget.IsTransactionValid(txNew, nBlockHeight)){
return true;
......@@ -99,9 +100,13 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight)
if(masternodePayments.IsTransactionValid(txNew, nBlockHeight))
{
return true;
} else if (nTime - nTimePrevBlock > Params().ChainStallDuration()) {
// The chain has stalled, allow the first block to have no payment to winners
LogPrintf("%s: Chain stall, time between blocks=%d\n", __func__, nTime - nTimePrevBlock);
return true;
} else {
LogPrintf("Invalid mn payment detected %s\n", txNew.ToString().c_str());
if(IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)){
if (IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)){
return false;
} else {
LogPrintf("Masternode payment enforcement is disabled, accepting block\n");
......@@ -174,8 +179,8 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe
if(hasPayment){
txNew.vout.resize(2);
txNew.vout[1].scriptPubKey = payee;
txNew.vout[1].nValue = masternodePayment;
txNew.vout[MN_PMT_SLOT].scriptPubKey = payee;
txNew.vout[MN_PMT_SLOT].nValue = masternodePayment;
txNew.vout[0].nValue -= masternodePayment;
......@@ -419,7 +424,8 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew)
}
LogPrintf("CMasternodePayments::IsTransactionValid - Missing required payment - %s\n", strPayeesPossible.c_str());
LogPrintf("CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s\n",
FormatMoney(masternodePayment), strPayeesPossible.c_str());
return false;
}
......
......@@ -29,7 +29,7 @@ extern CMasternodePayments masternodePayments;
void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
bool IsReferenceNode(CTxIn& vin);
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight);
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, const uint32_t& nTime, const uint32_t& nTimePrevBlock);
std::string GetRequiredPaymentsString(int nBlockHeight);
bool IsBlockValueValid(const CBlock& block, int64_t nExpectedValue);
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees);
......
......@@ -22,7 +22,7 @@ CCriticalSection cs_vecSNPayments;
CCriticalSection cs_mapSystemnodeBlocks;
CCriticalSection cs_mapSystemnodePayeeVotes;
bool SNIsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight)
bool SNIsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, const uint32_t& nTime, const uint32_t& nTimePrevBlock)
{
if(!systemnodeSync.IsSynced()) { //there is no budget data to use to check anything -- find the longest chain
LogPrint("snpayments", "Client not synced, skipping block payee checks\n");
......@@ -47,8 +47,11 @@ bool SNIsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight)
}
//check for systemnode payee
if(systemnodePayments.IsTransactionValid(txNew, nBlockHeight))
{
if(systemnodePayments.IsTransactionValid(txNew, nBlockHeight)) {
return true;
} else if (nTime - nTimePrevBlock > Params().ChainStallDuration()) {
// The chain has stalled, allow the first block to have no payment to winners
LogPrintf("%s: Chain stall, time between blocks=%d\n", __func__, nTime - nTimePrevBlock);
return true;
} else {
LogPrintf("Invalid mn payment detected %s\n", txNew.ToString().c_str());
......
......@@ -27,7 +27,7 @@ extern CSystemnodePayments systemnodePayments;
#define SN_PMT_SLOT 2
void SNFillBlockPayee(CMutableTransaction& txNew, int64_t nFees);
bool SNIsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight);
bool SNIsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, const uint32_t& nTime, const uint32_t& nTimePrevBlock);
std::string SNGetRequiredPaymentsString(int nBlockHeight);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment