diff options
| author | Matt Corallo <[email protected]> | 2016-11-01 11:03:18 -0400 |
|---|---|---|
| committer | Matt Corallo <[email protected]> | 2016-11-09 11:28:00 -0800 |
| commit | eecffe50efc3944d713c701fa375dacbf17fb7cf (patch) | |
| tree | df2cbe0fad1e266ac0c5f5e0e6b8c7e87a3b70e1 /src/main.cpp | |
| parent | Add deserialize + CheckBlock benchmarks, and a full block hex (diff) | |
| download | discoin-eecffe50efc3944d713c701fa375dacbf17fb7cf.tar.xz discoin-eecffe50efc3944d713c701fa375dacbf17fb7cf.zip | |
Remove redundant duplicate-input check from CheckTransaction
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/main.cpp b/src/main.cpp index 7e5b9528b..c8af01983 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1104,7 +1104,7 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i -bool CheckTransaction(const CTransaction& tx, CValidationState &state) +bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fCheckDuplicateInputs) { // Basic checks that don't depend on any context if (tx.vin.empty()) @@ -1128,13 +1128,15 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state) return state.DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge"); } - // Check for duplicate inputs - set<COutPoint> vInOutPoints; - for (const auto& txin : tx.vin) - { - if (vInOutPoints.count(txin.prevout)) - return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate"); - vInOutPoints.insert(txin.prevout); + // Check for duplicate inputs - note that this check is slow so we skip it in CheckBlock + if (fCheckDuplicateInputs) { + set<COutPoint> vInOutPoints; + for (const auto& txin : tx.vin) + { + if (vInOutPoints.count(txin.prevout)) + return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate"); + vInOutPoints.insert(txin.prevout); + } } if (tx.IsCoinBase()) @@ -3461,7 +3463,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P // Check transactions for (const auto& tx : block.vtx) - if (!CheckTransaction(tx, state)) + if (!CheckTransaction(tx, state, false)) return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(), strprintf("Transaction check failed (tx hash %s) %s", tx.GetHash().ToString(), state.GetDebugMessage())); |