From 3914f4a1c4d38231873d20c799d09166ff2088df Mon Sep 17 00:00:00 2001 From: TheLazieR Yip Date: Wed, 7 Dec 2016 00:26:44 +0700 Subject: [PATCH] Update superblock valid checking to allow block creation by p2pool (#1190) * Update superblock valid checking to allow block creation by p2pool * Comment correction for superblock payment not found. * Comment correction --- src/governance-classes.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/governance-classes.cpp b/src/governance-classes.cpp index 510676cfb..be9e817c9 100644 --- a/src/governance-classes.cpp +++ b/src/governance-classes.cpp @@ -670,8 +670,7 @@ bool CSuperblock::IsValid(const CTransaction& txNew, int nBlockHeight, CAmount b nOutputs, nPayments, GetGovernanceObject()->GetDataAsHex()); // We require an exact match (including order) between the expected - // superblock payments and the payments actually in the block, after - // skipping any initial miner payments. + // superblock payments and the payments actually in the block. if(nMinerPayments < 0) { // This means the block cannot have all the superblock payments @@ -696,6 +695,7 @@ bool CSuperblock::IsValid(const CTransaction& txNew, int nBlockHeight, CAmount b return false; } + int nVoutIndex = 0; for(int i = 0; i < nPayments; i++) { CGovernancePayment payment; if(!GetPayment(i, payment)) { @@ -704,18 +704,26 @@ bool CSuperblock::IsValid(const CTransaction& txNew, int nBlockHeight, CAmount b continue; } - int nVoutIndex = nMinerPayments + i; + bool fPaymentMatch = false; - bool fPaymentMatch = ((payment.script == txNew.vout[nVoutIndex].scriptPubKey) && - (payment.nAmount == txNew.vout[nVoutIndex].nValue)); + for (int j = nVoutIndex; j < nOutputs; j++) { + // Find superblock payment + fPaymentMatch = ((payment.script == txNew.vout[j].scriptPubKey) && + (payment.nAmount == txNew.vout[j].nValue)); + + if (fPaymentMatch) { + nVoutIndex = j; + break; + } + } if(!fPaymentMatch) { - // MISMATCHED SUPERBLOCK OUTPUT! + // Superblock payment not found! CTxDestination address1; ExtractDestination(payment.script, address1); CBitcoinAddress address2(address1); - LogPrintf("CSuperblock::IsValid -- ERROR: Block invalid: output n %d payment %d to %s\n", nVoutIndex, payment.nAmount, address2.ToString()); + LogPrintf("CSuperblock::IsValid -- ERROR: Block invalid: %d payment %d to %s not found\n", i, payment.nAmount, address2.ToString()); return false; }