Skip to content

Commit 6a8ed10

Browse files
authored
Merge pull request #716 from evoskuil/master
Fix get_block_fees() return, add get_tx_fees, ren get_block_fees.
2 parents 3bc7a3a + 8eaad90 commit 6a8ed10

3 files changed

Lines changed: 26 additions & 26 deletions

File tree

include/bitcoin/database/impl/query/estimate.ipp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,18 @@
3030
namespace libbitcoin {
3131
namespace database {
3232

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

36-
// protected
40+
out.bytes = tx->virtual_size();
41+
out.fee = tx->fee();
42+
return true;
43+
}
44+
3745
TEMPLATE
3846
bool CLASS::get_block_fees(fee_rates& out,
3947
const header_link& link) const NOEXCEPT
@@ -58,9 +66,8 @@ bool CLASS::get_block_fees(fee_rates& out,
5866
return true;
5967
}
6068

61-
// public
6269
TEMPLATE
63-
bool CLASS::get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out,
70+
bool CLASS::get_branch_fees(std::atomic_bool& cancel, fee_rate_sets& out,
6471
size_t top, size_t count) const NOEXCEPT
6572
{
6673
out.clear();
@@ -78,31 +85,22 @@ bool CLASS::get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out,
7885
std::vector<size_t> offsets(count);
7986
std::iota(offsets.begin(), offsets.end(), zero);
8087

81-
std::atomic_bool failure{};
88+
std::atomic_bool fail{};
8289
constexpr auto relaxed = std::memory_order_relaxed;
8390
std::for_each(poolstl::execution::par, offsets.begin(), offsets.end(),
8491
[&](const size_t& offset) NOEXCEPT
8592
{
86-
if (failure.load(relaxed))
87-
return;
88-
89-
if (cancel.load(relaxed))
90-
{
91-
failure.store(true, relaxed);
93+
if (fail.load(relaxed))
9294
return;
93-
}
9495

95-
const auto link = to_confirmed(start + offset);
96-
if (!get_block_fees(out.at(offset), link))
97-
{
98-
failure.store(false, relaxed);
99-
return;
100-
}
96+
if (cancel.load(relaxed) || !get_block_fees(out.at(offset),
97+
to_confirmed(start + offset)))
98+
fail.store(true, relaxed);
10199
});
102100

103-
const auto failed = failure.load(relaxed);
101+
const auto failed = fail.load(relaxed);
104102
if (failed) out.clear();
105-
return failed;
103+
return !failed;
106104
}
107105

108106
} // namespace database

include/bitcoin/database/impl/query/validate.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ code CLASS::get_block_state(const header_link& link) const NOEXCEPT
141141
}
142142

143143
TEMPLATE
144-
uint64_t CLASS::get_block_fees(const header_link& link) const NOEXCEPT
144+
uint64_t CLASS::get_block_fee(const header_link& link) const NOEXCEPT
145145
{
146146
// TODO: optimize.
147147
const auto block = get_block(link, false);

include/bitcoin/database/query.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,13 @@ class query
401401
/// Services.
402402
/// -----------------------------------------------------------------------
403403

404-
/// Gether fee rate tuples by block or set of blocks.
404+
uint64_t get_tx_fee(const tx_link& link) const NOEXCEPT;
405+
uint64_t get_block_fee(const header_link& link) const NOEXCEPT;
406+
407+
/// Gether fee rate tuples by tx, block or branch.
408+
bool get_tx_fees(fee_rate& out, const tx_link& link) const NOEXCEPT;
405409
bool get_block_fees(fee_rates& out, const header_link& link) const NOEXCEPT;
406-
bool get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out,
410+
bool get_branch_fees(std::atomic_bool& cancel, fee_rate_sets& out,
407411
size_t top, size_t count) const NOEXCEPT;
408412

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

477481
/// States.
478482
bool is_validateable(size_t height) const NOEXCEPT;
479-
uint64_t get_tx_fee(const tx_link& link) const NOEXCEPT;
480-
uint64_t get_block_fees(const header_link& link) const NOEXCEPT;
481483
code get_block_state(const header_link& link) const NOEXCEPT;
482484
code get_header_state(const header_link& link) const NOEXCEPT;
483485
code get_tx_state(const tx_link& link, const context& ctx) const NOEXCEPT;

0 commit comments

Comments
 (0)