diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2016-11-10 16:02:45 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2016-11-10 16:02:55 +0100 |
commit | 71bc39eb74839c7916d2e04c207853d44d0f6c24 (patch) | |
tree | 7bcb32f4eee327f943dae5809909023b525203ac /src/main.cpp | |
parent | e5364991daecb73aca3bb5ac37f2619d7a89211b (diff) | |
parent | e2b3fb349ed99f05ea518c7eb260db606350a2b5 (diff) |
Merge #9049: Remove duplicatable duplicate-input check from CheckTransaction
e2b3fb3 Optimize vInOutPoints insertion a bit (Matt Corallo)
eecffe5 Remove redundant duplicate-input check from CheckTransaction (Matt Corallo)
b2e178a Add deserialize + CheckBlock benchmarks, and a full block hex (Matt Corallo)
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/main.cpp b/src/main.cpp index 14bdd824e9..c6e8a6b791 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,14 @@ 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.insert(txin.prevout).second) + return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate"); + } } if (tx.IsCoinBase()) @@ -3461,7 +3462,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())); |