Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HF] Fee output logic cleanup, allow 0-value fees #160

Merged
merged 3 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1765,8 +1765,6 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C

int64_t nSigOpsCost = GetTransactionSigOpCost(tx, view, STANDARD_SCRIPT_VERIFY_FLAGS);

if (!tx.HasValidFee())
return state.DoS(0, false, REJECT_INVALID, "bad-fees");
CAmount nFees = tx.GetFee()[policyAsset];

// nModifiedFees includes any fee deltas from PrioritiseTransaction
Expand Down Expand Up @@ -2613,9 +2611,6 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins
}
}

// Tally transaction fees
if (!tx.HasValidFee())
return state.DoS(100, false, REJECT_INVALID, "bad-txns-fee-outofrange");
if (!VerifyAmounts(inputs, tx, pvChecks, cacheStore))
return state.DoS(100, false, REJECT_INVALID, "bad-txns-in-belowout", false,
strprintf("value in (%s) < value out", FormatMoney(nValueIn)));
Expand All @@ -2634,9 +2629,6 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
if (pvChecks)
pvChecks->reserve(tx.vin.size());

// Tally validity checked in CheckTxInputs
CAmountMap fee = tx.GetFee();

// The first loop above does all the inexpensive checks.
// Only if ALL inputs pass do we perform expensive ECDSA signature checks.
// Helps prevent CPU exhaustion attacks.
Expand Down Expand Up @@ -3292,8 +3284,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
if (txout.scriptPubKey.IsWithdrawLock() && txout.nValue.IsExplicit())
mLocksCreated.insert(std::make_pair(txout.scriptPubKey.GetWithdrawLockGenesisHash(), std::make_pair(COutPoint(tx.GetHash(), j), txout.nValue.GetAmount())));
}
if (!tx.HasValidFee())
return state.DoS(100, error("ConnectBlock(): transaction fee overflowed"), REJECT_INVALID, "bad-fee-outofrange");
mapFees += tx.GetFee();
if (!MoneyRange(mapFees))
return state.DoS(100, error("ConnectBlock(): total block reward overflowed"), REJECT_INVALID, "bad-blockreward-outofrange");
Expand All @@ -3306,7 +3296,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
return state.DoS(100, error("ConnectBlock(): total block reward overflowed"), REJECT_INVALID, "bad-blockreward-outofrange");
if (!VerifyCoinbaseAmount(block.vtx[0], blockReward))
return state.DoS(100,
error("ConnectBlock(): coinbase pays too much (limit=%d)",
error("ConnectBlock(): coinbase pays too much, has fee or blinded outputs (limit=%d)",
blockReward[policyAsset]),
REJECT_INVALID, "bad-cb-amount");

Expand Down
15 changes: 0 additions & 15 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,6 @@ uint256 CTransaction::ComputeWitnessHash() const
return ComputeFastMerkleRoot(leaves);
}

bool CTransaction::HasValidFee() const
{
CAmountMap totalFee;
for (unsigned int i = 0; i < vout.size(); i++) {
CAmount fee = 0;
if (vout[i].IsFee()) {
fee = vout[i].nValue.GetAmount();
if (fee == 0 || !MoneyRange(fee))
return false;
totalFee[vout[i].nAsset.GetAsset()] += fee;
}
}
return MoneyRange(totalFee);
}

CAmountMap CTransaction::GetFee() const
{
CAmountMap fee;
Expand Down
11 changes: 11 additions & 0 deletions src/test/blind_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ BOOST_AUTO_TEST_CASE(naive_blinding_test)
tx3.vout.push_back(CTxOut(bitcoinID, 22, CScript()));
BOOST_CHECK(VerifyAmounts(cache, tx3));

// Fees must have non-negative value
tx3.vout.push_back(CTxOut(bitcoinID, 0, CScript()));
BOOST_CHECK(VerifyAmounts(cache, tx3));

tx3.vout.push_back(CTxOut(bitcoinID, -1, CScript()));
BOOST_CHECK(!VerifyAmounts(cache, tx3));

tx3.vout.pop_back();
tx3.vout.pop_back();
BOOST_CHECK(VerifyAmounts(cache, tx3));

// Try to blind with a single non-fee output, which fails as its blinding factor ends up being zero.
std::vector<uint256> input_blinds;
std::vector<uint256> input_asset_blinds;
Expand Down
6 changes: 6 additions & 0 deletions src/test/verify_amounts_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ BOOST_AUTO_TEST_CASE(verify_coinbase_test)
tx.vout.push_back(CTxOut(CAsset(), 1, CScript() << OP_RETURN));
BOOST_CHECK(!VerifyCoinbaseAmount(tx, mapFees));
tx.vout.pop_back();

// Push fee output, must fail since coinbase cannot have fee
tx.vout.push_back(CTxOut(CAsset(), 1, CScript()));
BOOST_CHECK(!VerifyCoinbaseAmount(tx, mapFees));
tx.vout.pop_back();

}

BOOST_AUTO_TEST_SUITE_END()
1 change: 0 additions & 1 deletion src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,6 @@ UniValue gettransaction(const UniValue& params, bool fHelp)

CAmountMap nCredit = wtx.GetCredit(filter);
CAmountMap nDebit = wtx.GetDebit(filter);
assert(wtx.HasValidFee());
CAmount nFee = (wtx.IsFromMe(filter) ? -wtx.GetFee()[policyAsset] : 0);
CAmountMap nNet = nCredit - nDebit;
nNet[policyAsset] -= nFee;
Expand Down