diff --git a/include/bitcoin/database/impl/query/confirm.ipp b/include/bitcoin/database/impl/query/confirm.ipp index 25c543e6..d5ba23d5 100644 --- a/include/bitcoin/database/impl/query/confirm.ipp +++ b/include/bitcoin/database/impl/query/confirm.ipp @@ -283,25 +283,21 @@ inline error::error_t CLASS::unspent_duplicates(const tx_link& link, if (!ctx.is_enabled(system::chain::flags::bip30_rule)) return error::success; - // Self should be strong but was not identified. const auto coinbases = to_strongs(get_tx_key(link)); if (coinbases.empty()) return error::integrity; - // Only self was found (optimization). if (is_one(coinbases.size())) return error::success; - // All but one (self) must be confirmed spent or coinbase is unspent. - size_t strong_unspent{}; - for (const auto& coinbase: coinbases) - for (spend::pt::integer out{}; out < output_count(coinbase.tx); ++out) - if (!spent_prevout(spend::compose(coinbase.tx, out)) && - is_one(strong_unspent++)) + // bip30: all (but self) must be confirmed spent or dup invalid (cb only). + size_t unspent{}; + for (const auto& cb: coinbases) + for (index out{}; out < output_count(cb.tx); ++out) + if (!spent_prevout(spend::compose(cb.tx, out)) && is_one(unspent++)) return error::unspent_coinbase_collision; - // Only self should/must be unspent. - return is_zero(strong_unspent) ? error::integrity : error::success; + return is_zero(unspent) ? error::integrity : error::success; } TEMPLATE diff --git a/include/bitcoin/database/impl/query/translate.ipp b/include/bitcoin/database/impl/query/translate.ipp index 790a80d0..509c15b2 100644 --- a/include/bitcoin/database/impl/query/translate.ipp +++ b/include/bitcoin/database/impl/query/translate.ipp @@ -254,10 +254,8 @@ inline header_links CLASS::to_blocks(const tx_link& link) const NOEXCEPT block_txs strongs{}; do { - if (!store_.strong_tx.get(it.self(), strong)) - return {}; - - if (!contains(strongs, strong)) + if (store_.strong_tx.get(it.self(), strong) && + !contains(strongs, strong)) strongs.push_back(strong); } while(it.advance()); diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index ac2b1229..81ac6160 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -73,6 +73,7 @@ class query using chain_state = system::chain::chain_state; using chain_state_ptr = system::chain::chain_state::ptr; using chain_context = system::chain::context; + using index = table::transaction::ix::integer; using sizes = std::pair; using heights = std_vector; using filter = system::data_chunk;