nHeight calculation for BlockValue checking
This commit is contained in:
parent
6834476573
commit
6fc05e7fa8
@ -25,7 +25,7 @@ void CChain::SetTip(CBlockIndex *pindex) {
|
||||
}
|
||||
|
||||
//recalculate the coinbase payee cache if needed
|
||||
if(nChainSwitch > 0) {
|
||||
if(nChainSwitch > 1) {
|
||||
coinbasePayee.BuildIndex(true);
|
||||
}
|
||||
}
|
||||
|
@ -2097,7 +2097,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
||||
int64_t nTime1 = GetTimeMicros(); nTimeConnect += nTime1 - nTimeStart;
|
||||
LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001);
|
||||
|
||||
if(!IsBlockValueValid(block.vtx[0].GetValueOut(), GetBlockValue(pindex->pprev->nBits, pindex->pprev->nHeight, nFees))){
|
||||
if(!IsBlockValueValid(block, GetBlockValue(pindex->pprev->nBits, pindex->pprev->nHeight, nFees))){
|
||||
return state.DoS(100,
|
||||
error("ConnectBlock() : coinbase pays too much (actual=%d vs limit=%d)",
|
||||
block.vtx[0].GetValueOut(), GetBlockValue(pindex->pprev->nBits, pindex->pprev->nHeight, nFees)),
|
||||
|
@ -19,23 +19,39 @@ CMasternodePayments masternodePayments;
|
||||
map<uint256, CMasternodePaymentWinner> mapMasternodePayeeVotes;
|
||||
map<uint256, CMasternodeBlockPayees> mapMasternodeBlocks;
|
||||
|
||||
bool IsBlockValueValid(int64_t nBlockValue, int64_t nExpectedValue){
|
||||
bool IsBlockValueValid(const CBlock& block, int64_t nExpectedValue){
|
||||
CBlockIndex* pindexPrev = chainActive.Tip();
|
||||
if(pindexPrev == NULL) return true;
|
||||
|
||||
if(budget.sizeFinalized() == 0 && budget.sizeProposals() == 0) { //there is no budget data to use to check anything
|
||||
int nHeight = 0;
|
||||
if(pindexPrev->GetBlockHash() == block.hashPrevBlock)
|
||||
{
|
||||
nHeight = pindexPrev->nHeight+1;
|
||||
} else { //out of order
|
||||
BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex){
|
||||
if(item.first == block.hashPrevBlock) {
|
||||
nHeight = item.second->nHeight+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(nHeight == 0){
|
||||
LogPrintf("IsBlockValueValid() : WARNING: Couldn't find previous block");
|
||||
}
|
||||
|
||||
if((budget.sizeFinalized() == 0 && budget.sizeProposals() == 0) || nHeight == 0) { //there is no budget data to use to check anything
|
||||
//super blocks will always be on these blocks, max 100 per budgeting
|
||||
if((pindexPrev->nHeight+1) % GetBudgetPaymentCycleBlocks() < 100){
|
||||
if(nHeight % GetBudgetPaymentCycleBlocks() < 100){
|
||||
return true;
|
||||
} else {
|
||||
if(nBlockValue > nExpectedValue) return false;
|
||||
if(block.vtx[0].GetValueOut() > nExpectedValue) return false;
|
||||
}
|
||||
} else { // we're synced and have data so check the budget schedule
|
||||
if(budget.IsBudgetPaymentBlock(pindexPrev->nHeight+1)){
|
||||
if(budget.IsBudgetPaymentBlock(nHeight)){
|
||||
//the value of the block is evaluated in CheckBlock
|
||||
return true;
|
||||
} else {
|
||||
if(nBlockValue > nExpectedValue) return false;
|
||||
if(block.vtx[0].GetValueOut() > nExpectedValue) return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDa
|
||||
bool IsReferenceNode(CTxIn& vin);
|
||||
bool IsBlockPayeeValid(const CTransaction& txNew, int64_t nBlockHeight);
|
||||
std::string GetRequiredPaymentsString(int64_t nBlockHeight);
|
||||
bool IsBlockValueValid(int64_t nBlockValue, int64_t nExpectedValue);
|
||||
bool IsBlockValueValid(const CBlock& block, int64_t nExpectedValue);
|
||||
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees);
|
||||
|
||||
class CMasternodePayee
|
||||
|
Loading…
Reference in New Issue
Block a user