Commit 5184c558 authored by presstab's avatar presstab

Adjust validation code to have knowledge of full value created in block.

parent a9370fc8
......@@ -3252,12 +3252,15 @@ 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, block.nTime, pindexPrev->nTime))
CAmount nBlockCreation = block.vtx[0].GetValueOut();
if (block.IsProofOfStake())
nBlockCreation += block.vtx[1].GetValueOut();
if(!IsBlockPayeeValid(nBlockCreation, 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, block.nTime, pindexPrev->nTime))
if(!SNIsBlockPayeeValid(nBlockCreation, 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"));
......
......@@ -72,7 +72,7 @@ bool IsBlockValueValid(const CBlock& block, int64_t nExpectedValue){
return true;
}
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, const uint32_t& nTime, const uint32_t& nTimePrevBlock)
bool IsBlockPayeeValid(const CAmount& nAmountCreated, 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");
......@@ -97,7 +97,7 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, const uint32
}
//check for masternode payee
if(masternodePayments.IsTransactionValid(txNew, nBlockHeight))
if(masternodePayments.IsTransactionValid(nAmountCreated, txNew, nBlockHeight))
{
return true;
} else if (nTime - nTimePrevBlock > Params().ChainStallDuration()) {
......@@ -372,14 +372,14 @@ bool CMasternodePayments::AddWinningMasternode(CMasternodePaymentWinner& winnerI
return true;
}
bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew)
bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew, const CAmount& nValueCreated)
{
LOCK(cs_vecPayments);
int nMaxSignatures = 0;
std::string strPayeesPossible = "";
CAmount masternodePayment = GetMasternodePayment(nBlockHeight, txNew.GetValueOut());
CAmount masternodePayment = GetMasternodePayment(nBlockHeight, nValueCreated);
//require at least 6 signatures
......@@ -462,12 +462,12 @@ std::string CMasternodePayments::GetRequiredPaymentsString(int nBlockHeight)
return "Unknown";
}
bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlockHeight)
bool CMasternodePayments::IsTransactionValid(const CAmount& nValueCreated, const CTransaction& txNew, int nBlockHeight)
{
LOCK(cs_mapMasternodeBlocks);
if(mapMasternodeBlocks.count(nBlockHeight)){
return mapMasternodeBlocks[nBlockHeight].IsTransactionValid(txNew);
return mapMasternodeBlocks[nBlockHeight].IsTransactionValid(txNew, nValueCreated);
}
return true;
......
......@@ -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, const uint32_t& nTime, const uint32_t& nTimePrevBlock);
bool IsBlockPayeeValid(const CAmount& nValueCreated, 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);
......@@ -115,7 +115,7 @@ public:
return false;
}
bool IsTransactionValid(const CTransaction& txNew);
bool IsTransactionValid(const CTransaction& txNew, const CAmount& nValueCreated);
std::string GetRequiredPaymentsString();
ADD_SERIALIZE_METHODS;
......@@ -224,7 +224,7 @@ public:
int LastPayment(CMasternode& mn);
bool GetBlockPayee(int nBlockHeight, CScript& payee);
bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight);
bool IsTransactionValid(const CAmount& nValueCreated, const CTransaction& txNew, int nBlockHeight);
bool IsScheduled(CMasternode& mn, int nNotBlockHeight);
bool CanVote(COutPoint outMasternode, int nBlockHeight);
......
......@@ -22,7 +22,7 @@ CCriticalSection cs_vecSNPayments;
CCriticalSection cs_mapSystemnodeBlocks;
CCriticalSection cs_mapSystemnodePayeeVotes;
bool SNIsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, const uint32_t& nTime, const uint32_t& nTimePrevBlock)
bool SNIsBlockPayeeValid(const CAmount& nValueCreated, 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,7 +47,7 @@ bool SNIsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, const uint
}
//check for systemnode payee
if(systemnodePayments.IsTransactionValid(txNew, nBlockHeight)) {
if(systemnodePayments.IsTransactionValid(nValueCreated, txNew, nBlockHeight)) {
return true;
} else if (nTime - nTimePrevBlock > Params().ChainStallDuration()) {
// The chain has stalled, allow the first block to have no payment to winners
......@@ -66,12 +66,12 @@ bool SNIsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, const uint
return false;
}
bool CSystemnodePayments::IsTransactionValid(const CTransaction& txNew, int nBlockHeight)
bool CSystemnodePayments::IsTransactionValid(const CAmount& nValueCreated, const CTransaction& txNew, int nBlockHeight)
{
LOCK(cs_mapSystemnodeBlocks);
if(mapSystemnodeBlocks.count(nBlockHeight)){
return mapSystemnodeBlocks[nBlockHeight].IsTransactionValid(txNew);
return mapSystemnodeBlocks[nBlockHeight].IsTransactionValid(txNew, nValueCreated);
}
return true;
......@@ -277,14 +277,14 @@ std::string CSystemnodePayments::GetRequiredPaymentsString(int nBlockHeight)
return "Unknown";
}
bool CSystemnodeBlockPayees::IsTransactionValid(const CTransaction& txNew)
bool CSystemnodeBlockPayees::IsTransactionValid(const CTransaction& txNew, const CAmount& nValueCreated)
{
LOCK(cs_vecPayments);
int nMaxSignatures = 0;
std::string strPayeesPossible = "";
CAmount systemnodePayment = GetSystemnodePayment(nBlockHeight, txNew.GetValueOut());
CAmount systemnodePayment = GetSystemnodePayment(nBlockHeight, nValueCreated);
//require at least 6 signatures
......
......@@ -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, const uint32_t& nTime, const uint32_t& nTimePrevBlock);
bool SNIsBlockPayeeValid(const CAmount& nValueCreated, const CTransaction& txNew, int nBlockHeight, const uint32_t& nTime, const uint32_t& nTimePrevBlock);
std::string SNGetRequiredPaymentsString(int nBlockHeight);
......@@ -112,7 +112,7 @@ public:
return false;
}
bool IsTransactionValid(const CTransaction& txNew);
bool IsTransactionValid(const CTransaction& txNew, const CAmount& nValueCreated);
std::string GetRequiredPaymentsString();
ADD_SERIALIZE_METHODS;
......@@ -218,7 +218,7 @@ public:
void ProcessMessageSystemnodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
void Sync(CNode* node, int nCountNeeded);
void CheckAndRemove();
bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight);
bool IsTransactionValid(const CAmount& nValueCreated, const CTransaction& txNew, int nBlockHeight);
bool GetBlockPayee(int nBlockHeight, CScript& payee);
bool IsScheduled(CSystemnode& sn, int nNotBlockHeight);
bool CanVote(COutPoint outSystemnode, 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