Skip to content
Closed
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
8 changes: 8 additions & 0 deletions src/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ static const CAmount COIN = 100000000;
static const CAmount MAX_MONEY = 21000000 * COIN;
inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }

/** Check if an amount is a valid fee delta.
*
* Like MoneyRange(...), but allows for negative money amounts.
*/
inline bool FeeDeltaRange(const CAmount fee_delta) {
return fee_delta >= -MAX_MONEY && fee_delta <= MAX_MONEY;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fee deltas outside MAX_MONEY are valid and have at least a conceptual use case (consider that fee rate is divided by transaction size: a larger transaction would need >MAX_MONEY feerate to go before a MAX_MONEY smaller tx).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luke-jr What is the valid fee delta range in your opinion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is actionable unless we can establish what the valid range should be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a feerate, but an absolute amount in satoshis

}

#endif // BITCOIN_AMOUNT_H
14 changes: 11 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5081,10 +5081,14 @@ bool LoadMempool(CTxMemPool& pool)

CAmount amountdelta = nFeeDelta;
if (amountdelta) {
pool.PrioritiseTransaction(tx->GetHash(), amountdelta);
if (FeeDeltaRange(amountdelta)) {
pool.PrioritiseTransaction(tx->GetHash(), amountdelta);
} else {
LogPrintf("Invalid fee delta encountered (corrupt mempool.dat file?). Skipping PrioritiseTransaction(...).\n");
}
}
TxValidationState state;
if (nTime + nExpiryTimeout > nNow) {
if (nTime > nNow - nExpiryTimeout) {
LOCK(cs_main);
AcceptToMemoryPoolWithTime(chainparams, pool, state, tx, nTime,
nullptr /* plTxnReplaced */, false /* bypass_limits */,
Expand Down Expand Up @@ -5112,7 +5116,11 @@ bool LoadMempool(CTxMemPool& pool)
file >> mapDeltas;

for (const auto& i : mapDeltas) {
pool.PrioritiseTransaction(i.first, i.second);
if (FeeDeltaRange(i.second)) {
pool.PrioritiseTransaction(i.first, i.second);
} else {
LogPrintf("Invalid fee delta encountered (corrupt mempool.dat file?). Skipping PrioritiseTransaction(...).\n");
}
}

// TODO: remove this try except in v0.22
Expand Down