Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use consistent error handling, comments, style. #441

Merged
merged 4 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions include/bitcoin/database/impl/query/confirm.ipp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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