Fix crash bug with duplicate inputs within a transaction (#2302)
* Fix crash bug with duplicate inputs within a transaction Introduced by #9049 * Remove redundant parameter fCheckDuplicateInputs from CheckTransaction
This commit is contained in:
parent
31759a44d6
commit
3cc4ac1376
@ -513,7 +513,7 @@ int GetUTXOConfirmations(const COutPoint& outpoint)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fCheckDuplicateInputs)
|
bool CheckTransaction(const CTransaction& tx, CValidationState &state)
|
||||||
{
|
{
|
||||||
// Basic checks that don't depend on any context
|
// Basic checks that don't depend on any context
|
||||||
if (tx.vin.empty())
|
if (tx.vin.empty())
|
||||||
@ -539,15 +539,13 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
|
|||||||
return state.DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge");
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for duplicate inputs - note that this check is slow so we skip it in CheckBlock
|
// Check for duplicate inputs
|
||||||
if (fCheckDuplicateInputs) {
|
|
||||||
std::set<COutPoint> vInOutPoints;
|
std::set<COutPoint> vInOutPoints;
|
||||||
for (const auto& txin : tx.vin)
|
for (const auto& txin : tx.vin)
|
||||||
{
|
{
|
||||||
if (!vInOutPoints.insert(txin.prevout).second)
|
if (!vInOutPoints.insert(txin.prevout).second)
|
||||||
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate");
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (tx.IsCoinBase())
|
if (tx.IsCoinBase())
|
||||||
{
|
{
|
||||||
@ -3437,7 +3435,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
|
|||||||
|
|
||||||
// Check transactions
|
// Check transactions
|
||||||
for (const auto& tx : block.vtx)
|
for (const auto& tx : block.vtx)
|
||||||
if (!CheckTransaction(*tx, state, false))
|
if (!CheckTransaction(*tx, state))
|
||||||
return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(),
|
return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(),
|
||||||
strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), state.GetDebugMessage()));
|
strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), state.GetDebugMessage()));
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
|
|||||||
/** Transaction validation functions */
|
/** Transaction validation functions */
|
||||||
|
|
||||||
/** Context-independent validity checks */
|
/** Context-independent validity checks */
|
||||||
bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs=true);
|
bool CheckTransaction(const CTransaction& tx, CValidationState& state);
|
||||||
|
|
||||||
namespace Consensus {
|
namespace Consensus {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user