Added value balance consensus enforcement for pours.

This commit is contained in:
Sean Bowe 2016-01-04 06:02:01 -07:00
parent 45d6bee945
commit f512cf7c7b
4 changed files with 34 additions and 0 deletions

View File

@ -382,6 +382,8 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const
for (unsigned int i = 0; i < tx.vin.size(); i++) for (unsigned int i = 0; i < tx.vin.size(); i++)
nResult += GetOutputFor(tx.vin[i]).nValue; nResult += GetOutputFor(tx.vin[i]).nValue;
nResult += tx.GetPourValueIn();
return nResult; return nResult;
} }

View File

@ -1533,6 +1533,11 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
} }
nValueIn += tx.GetPourValueIn();
if (!MoneyRange(nValueIn))
return state.DoS(100, error("CheckInputs(): vpub_old values out of range"),
REJECT_INVALID, "bad-txns-inputvalues-outofrange");
if (nValueIn < tx.GetValueOut()) if (nValueIn < tx.GetValueOut())
return state.DoS(100, error("CheckInputs(): %s value in (%s) < value out (%s)", return state.DoS(100, error("CheckInputs(): %s value in (%s) < value out (%s)",
tx.GetHash().ToString(), FormatMoney(nValueIn), FormatMoney(tx.GetValueOut())), tx.GetHash().ToString(), FormatMoney(nValueIn), FormatMoney(tx.GetValueOut())),

View File

@ -178,9 +178,33 @@ CAmount CTransaction::GetValueOut() const
if (!MoneyRange(it->nValue) || !MoneyRange(nValueOut)) if (!MoneyRange(it->nValue) || !MoneyRange(nValueOut))
throw std::runtime_error("CTransaction::GetValueOut(): value out of range"); throw std::runtime_error("CTransaction::GetValueOut(): value out of range");
} }
for (std::vector<CPourTx>::const_iterator it(vpour.begin()); it != vpour.end(); ++it)
{
// NB: vpub_old "takes" money from the value pool just as outputs do
nValueOut += it->vpub_old;
if (!MoneyRange(it->vpub_old) || !MoneyRange(nValueOut))
throw std::runtime_error("CTransaction::GetValueOut(): value out of range");
}
return nValueOut; return nValueOut;
} }
CAmount CTransaction::GetPourValueIn() const
{
CAmount nValue = 0;
for (std::vector<CPourTx>::const_iterator it(vpour.begin()); it != vpour.end(); ++it)
{
// NB: vpub_old "gives" money to the value pool just as inputs do
nValue += it->vpub_new;
if (!MoneyRange(it->vpub_new) || !MoneyRange(nValue))
throw std::runtime_error("CTransaction::GetPourValueIn(): value out of range");
}
return nValue;
}
double CTransaction::ComputePriority(double dPriorityInputs, unsigned int nTxSize) const double CTransaction::ComputePriority(double dPriorityInputs, unsigned int nTxSize) const
{ {
nTxSize = CalculateModifiedSize(nTxSize); nTxSize = CalculateModifiedSize(nTxSize);

View File

@ -346,6 +346,9 @@ public:
// GetValueIn() is a method on CCoinsViewCache, because // GetValueIn() is a method on CCoinsViewCache, because
// inputs must be known to compute value in. // inputs must be known to compute value in.
// Return sum of pour vpub_new
CAmount GetPourValueIn() const;
// Compute priority, given priority of inputs and (optionally) tx size // Compute priority, given priority of inputs and (optionally) tx size
double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const; double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const;