Skip to content
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
40 changes: 19 additions & 21 deletions include/bitcoin/database/impl/query/estimate.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@
namespace libbitcoin {
namespace database {

// fee estimate
// ----------------------------------------------------------------------------
TEMPLATE
bool CLASS::get_tx_fees(fee_rate& out, const tx_link& link) const NOEXCEPT
{
const auto tx = get_transaction(link, false);
if (!tx || !populate_without_metadata(*tx))
return false;

// protected
out.bytes = tx->virtual_size();
out.fee = tx->fee();
return true;
}

TEMPLATE
bool CLASS::get_block_fees(fee_rates& out,
const header_link& link) const NOEXCEPT
Expand All @@ -58,9 +66,8 @@ bool CLASS::get_block_fees(fee_rates& out,
return true;
}

// public
TEMPLATE
bool CLASS::get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out,
bool CLASS::get_branch_fees(std::atomic_bool& cancel, fee_rate_sets& out,
size_t top, size_t count) const NOEXCEPT
{
out.clear();
Expand All @@ -78,31 +85,22 @@ bool CLASS::get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out,
std::vector<size_t> offsets(count);
std::iota(offsets.begin(), offsets.end(), zero);

std::atomic_bool failure{};
std::atomic_bool fail{};
constexpr auto relaxed = std::memory_order_relaxed;
std::for_each(poolstl::execution::par, offsets.begin(), offsets.end(),
[&](const size_t& offset) NOEXCEPT
{
if (failure.load(relaxed))
return;

if (cancel.load(relaxed))
{
failure.store(true, relaxed);
if (fail.load(relaxed))
return;
}

const auto link = to_confirmed(start + offset);
if (!get_block_fees(out.at(offset), link))
{
failure.store(false, relaxed);
return;
}
if (cancel.load(relaxed) || !get_block_fees(out.at(offset),
to_confirmed(start + offset)))
fail.store(true, relaxed);
});

const auto failed = failure.load(relaxed);
const auto failed = fail.load(relaxed);
if (failed) out.clear();
return failed;
return !failed;
}

} // namespace database
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/impl/query/validate.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ code CLASS::get_block_state(const header_link& link) const NOEXCEPT
}

TEMPLATE
uint64_t CLASS::get_block_fees(const header_link& link) const NOEXCEPT
uint64_t CLASS::get_block_fee(const header_link& link) const NOEXCEPT
{
// TODO: optimize.
const auto block = get_block(link, false);
Expand Down
10 changes: 6 additions & 4 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,13 @@ class query
/// Services.
/// -----------------------------------------------------------------------

/// Gether fee rate tuples by block or set of blocks.
uint64_t get_tx_fee(const tx_link& link) const NOEXCEPT;
uint64_t get_block_fee(const header_link& link) const NOEXCEPT;

/// Gether fee rate tuples by tx, block or branch.
bool get_tx_fees(fee_rate& out, const tx_link& link) const NOEXCEPT;
bool get_block_fees(fee_rates& out, const header_link& link) const NOEXCEPT;
bool get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out,
bool get_branch_fees(std::atomic_bool& cancel, fee_rate_sets& out,
size_t top, size_t count) const NOEXCEPT;

/// Merkle computations over the index of confirmed headers.
Expand Down Expand Up @@ -476,8 +480,6 @@ class query

/// States.
bool is_validateable(size_t height) const NOEXCEPT;
uint64_t get_tx_fee(const tx_link& link) const NOEXCEPT;
uint64_t get_block_fees(const header_link& link) const NOEXCEPT;
code get_block_state(const header_link& link) const NOEXCEPT;
code get_header_state(const header_link& link) const NOEXCEPT;
code get_tx_state(const tx_link& link, const context& ctx) const NOEXCEPT;
Expand Down
Loading