Commit d187a5cf authored by Alastair Clark's avatar Alastair Clark
Browse files

Budget fail safe payment to devfund address

parent 5ab927c0
Showing with 63 additions and 11 deletions
+63 -11
......@@ -186,7 +186,7 @@ public:
nPoolMaxTransactions = 3;
strSporkKey = "0440409BDACDCE03BFB6D5F16E2D414953038996B49BEE6697CFA400A0001D0837C885C5B57DAD10E5CAAAE36EE975005CC6CBD7001A2A8DE76FF12185904A9BB1";
strLegacySignerDummyAddress = "18WTcWvwrNnfqeQAn6th9QQ2EpnXMq5Th8";
strDevfundAddress = "16tg5tuZrPKoBwfbmj2tmiEPhVPzyn3gtP";
nStartMasternodePayments = 1403728576; //Wed, 25 Jun 2014 20:36:16 GMT
}
......@@ -301,7 +301,7 @@ public:
nPoolMaxTransactions = 2;
strSporkKey = "0440409BDACDCE03BFB6D5F16E2D414953038996B49BEE6697CFA400A0001D0837C885C5B57DAD10E5CAAAE36EE975005CC6CBD7001A2A8DE76FF12185904A9BB1";
strLegacySignerDummyAddress = "y1EZuxhhNMAUofTBEeLqGE1bJrpC2TWRNp";
strDevfundAddress = "y1EZuxhhNMAUofTBEeLqGE1bJrpC2TWRNp";
nStartMasternodePayments = 1420837558; //Fri, 09 Jan 2015 21:05:58 GMT
}
const Checkpoints::CCheckpointData& Checkpoints() const
......
......@@ -79,7 +79,7 @@ public:
virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0;
int PoolMaxTransactions() const { return nPoolMaxTransactions; }
std::string SporkKey() const { return strSporkKey; }
std::string LegacySignerDummyAddress() const { return strLegacySignerDummyAddress; }
std::string DevfundAddress() const { return strDevfundAddress; }
int64_t StartMasternodePayments() const { return nStartMasternodePayments; }
CBaseChainParams::Network NetworkID() const { return networkID; }
/* Return the auxpow chain ID. */
......
......@@ -481,13 +481,13 @@ void CBudgetManager::FillBlockPayee(CMutableTransaction& txNew, CAmount nFees)
CAmount blockValue = GetBlockValue(pindexPrev->nBits, pindexPrev->nHeight, nFees);
//miners get the full amount on these blocks
// Miners get the full amount on these blocks
txNew.vout[0].nValue = blockValue;
if(nHighestCount > 0){
txNew.vout.resize(2);
//these are super blocks, so their value can be much larger than normal
// These are super blocks, so their value can be much larger than normal
txNew.vout[1].scriptPubKey = payee;
txNew.vout[1].nValue = nAmount;
......@@ -496,6 +496,16 @@ void CBudgetManager::FillBlockPayee(CMutableTransaction& txNew, CAmount nFees)
CBitcoinAddress address2(address1);
LogPrintf("CBudgetManager::FillBlockPayee - Budget payment to %s for %lld\n", address2.ToString(), nAmount);
} else {
// Pay dev fund
txNew.vout.resize(2);
// These are super blocks, so their value can be much larger than normal
CTxDestination dest = CBitcoinAddress(Params().DevfundAddress()).Get();
txNew.vout[1].scriptPubKey = GetScriptForDestination(dest);
txNew.vout[1].nValue = 4320000000000;
LogPrintf("CBudgetManager::FillBlockPayee - Budget payment to Dev fund for %lld\n", nAmount);
}
}
......@@ -557,9 +567,10 @@ bool CBudgetManager::IsBudgetPaymentBlock(int nBlockHeight)
}
/*
If budget doesn't have 5% of the network votes, then we should pay a masternode instead
If budget doesn't have 5% of the network votes, then we should pay the dev fund instead
*/
if(nHighestCount > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/20) return true;
if (nBlockHeight % GetBudgetPaymentCycleBlocks() == 0) return true;
return false;
}
......@@ -604,12 +615,15 @@ bool CBudgetManager::IsTransactionValid(const CTransaction& txNew, int nBlockHei
}
/*
If budget doesn't have 5% of the network votes, then we should pay a masternode instead
If budget doesn't have 5% of the network votes, then we should the dev fund instead
*/
if(nHighestCount < mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/20) return false;
// check the highest finalized budgets (+/- 10% to assist in consensus)
if(nHighestCount < mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/20) {
return false;
} else if (IsDevTransactionValid(txNew, nBlockHeight)) {
return true;
}
// Check the highest finalized budgets (+/- 10% to assist in consensus)
it = mapFinalizedBudgets.begin();
while(it != mapFinalizedBudgets.end())
{
......@@ -626,10 +640,47 @@ bool CBudgetManager::IsTransactionValid(const CTransaction& txNew, int nBlockHei
++it;
}
//we looked through all of the known budgets
// If budget has more than 5% of the votes but less than 10% pay the dev fund.
// If anything goes wrong above it will default to use IsDevTransactionValid.
if(nHighestCount < mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10)
{
// Check dev fund payment
if (IsDevTransactionValid(txNew, nBlockHeight)) {
return true;
}
}
// We looked through all of the known budgets
return false;
}
bool CBudgetManager::IsDevTransactionValid(const CTransaction& txNew, int nBlockHeight)
{
int nCurrentBudgetPayment = nBlockHeight % GetBudgetPaymentCycleBlocks();
if(nCurrentBudgetPayment > 0) {
LogPrintf("CFinalizedBudget::IsTransactionValid - Invalid block - height: %d start: %d\n", nBlockHeight, GetBlockStart());
return false;
}
bool found = false;
CTxDestination dest = CBitcoinAddress(Params().DevfundAddress()).Get();
CScript devscript = GetScriptForDestination(dest);
BOOST_FOREACH(CTxOut out, txNew.vout)
{
if(devscript == out.scriptPubKey && 4320000000000 == out.nValue)
found = true;
}
if(!found) {
CTxDestination address1;
ExtractDestination(devscript, address1);
CBitcoinAddress address2(address1);
LogPrintf("CFinalizedBudget::IsTransactionValid - Missing required payment - %s: %d\n", address2.ToString(), vecBudgetPayments[nCurrentBudgetPayment].nAmount);
}
return found;
}
std::vector<CBudgetProposal*> CBudgetManager::GetAllProposals()
{
LOCK(cs);
......
......@@ -138,6 +138,7 @@ public:
bool UpdateFinalizedBudget(CFinalizedBudgetVote& vote, CNode* pfrom, std::string& strError);
bool PropExists(uint256 nHash);
bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight);
bool IsDevTransactionValid(const CTransaction& txNew, int nBlockHeight);
std::string GetRequiredPaymentsString(int nBlockHeight);
void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees);
......
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