Skip to content

Commit

Permalink
Merge pull request #441 from evoskuil/master
Browse files Browse the repository at this point in the history
Use consistent error handling, comments, style.
  • Loading branch information
evoskuil committed Apr 20, 2024
2 parents c5a8a7f + f18fc95 commit a3f0b6a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
16 changes: 6 additions & 10 deletions include/bitcoin/database/impl/query/confirm.ipp
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions include/bitcoin/database/impl/query/translate.ipp
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/database/query.hpp
Expand Up @@ -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<size_t, size_t>;
using heights = std_vector<size_t>;
using filter = system::data_chunk;
Expand Down

0 comments on commit a3f0b6a

Please sign in to comment.