From cf5545a30ce41dc179b490075bbd8b39ee367377 Mon Sep 17 00:00:00 2001 From: luozhaohui Date: Tue, 25 Sep 2018 11:40:52 +0800 Subject: [PATCH] check double spend in inputs when add tx to pool. --- src/lib/blockchain/validate_transaction.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib/blockchain/validate_transaction.cpp b/src/lib/blockchain/validate_transaction.cpp index f2b4f2040..faa800861 100644 --- a/src/lib/blockchain/validate_transaction.cpp +++ b/src/lib/blockchain/validate_transaction.cpp @@ -1339,6 +1339,18 @@ code validate_transaction::check_transaction_basic() const if (tx.serialized_size() > max_transaction_size) return error::size_limits; + // check double spend in inputs + std::set set; + for (auto& input : tx.inputs) { + auto tx_hash = libbitcoin::encode_hash(input.previous_output.hash); + auto value = tx_hash + ":" + std::to_string(input.previous_output.index); + if (set.count(value)) { + return error::double_spend; + } + + set.insert(value); + } + // Check for negative or overflow output values uint64_t total_output_value = 0;