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
6 changes: 4 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ test_libbitcoin_database_test_SOURCES = \
test/query/confirm.cpp \
test/query/consensus.cpp \
test/query/context.cpp \
test/query/estimate.cpp \
test/query/extent.cpp \
test/query/height.cpp \
test/query/initialize.cpp \
test/query/merkle.cpp \
test/query/network.cpp \
test/query/objects.cpp \
test/query/optional.cpp \
test/query/services.cpp \
test/query/translate.cpp \
test/query/validate.cpp \
test/tables/archives/header.cpp \
Expand Down Expand Up @@ -181,14 +182,15 @@ include_bitcoin_database_impl_query_HEADERS = \
include/bitcoin/database/impl/query/confirm.ipp \
include/bitcoin/database/impl/query/consensus.ipp \
include/bitcoin/database/impl/query/context.ipp \
include/bitcoin/database/impl/query/estimate.ipp \
include/bitcoin/database/impl/query/extent.ipp \
include/bitcoin/database/impl/query/height.ipp \
include/bitcoin/database/impl/query/initialize.ipp \
include/bitcoin/database/impl/query/merkle.ipp \
include/bitcoin/database/impl/query/network.ipp \
include/bitcoin/database/impl/query/objects.ipp \
include/bitcoin/database/impl/query/optional.ipp \
include/bitcoin/database/impl/query/query.ipp \
include/bitcoin/database/impl/query/services.ipp \
include/bitcoin/database/impl/query/translate.ipp \
include/bitcoin/database/impl/query/validate.ipp

Expand Down
3 changes: 2 additions & 1 deletion builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,14 @@ if (with-tests)
"../../test/query/confirm.cpp"
"../../test/query/consensus.cpp"
"../../test/query/context.cpp"
"../../test/query/estimate.cpp"
"../../test/query/extent.cpp"
"../../test/query/height.cpp"
"../../test/query/initialize.cpp"
"../../test/query/merkle.cpp"
"../../test/query/network.cpp"
"../../test/query/objects.cpp"
"../../test/query/optional.cpp"
"../../test/query/services.cpp"
"../../test/query/translate.cpp"
"../../test/query/validate.cpp"
"../../test/tables/archives/header.cpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,16 @@
<ClCompile Include="..\..\..\..\test\query\confirm.cpp" />
<ClCompile Include="..\..\..\..\test\query\consensus.cpp" />
<ClCompile Include="..\..\..\..\test\query\context.cpp" />
<ClCompile Include="..\..\..\..\test\query\estimate.cpp" />
<ClCompile Include="..\..\..\..\test\query\extent.cpp" />
<ClCompile Include="..\..\..\..\test\query\height.cpp">
<ObjectFileName>$(IntDir)test_query_height.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\..\..\test\query\initialize.cpp" />
<ClCompile Include="..\..\..\..\test\query\merkle.cpp" />
<ClCompile Include="..\..\..\..\test\query\network.cpp" />
<ClCompile Include="..\..\..\..\test\query\objects.cpp" />
<ClCompile Include="..\..\..\..\test\query\optional.cpp" />
<ClCompile Include="..\..\..\..\test\query\services.cpp" />
<ClCompile Include="..\..\..\..\test\query\translate.cpp" />
<ClCompile Include="..\..\..\..\test\query\validate.cpp" />
<ClCompile Include="..\..\..\..\test\settings.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<ClCompile Include="..\..\..\..\test\query\context.cpp">
<Filter>src\query</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\query\estimate.cpp">
<Filter>src\query</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\query\extent.cpp">
<Filter>src\query</Filter>
</ClCompile>
Expand All @@ -132,6 +135,9 @@
<ClCompile Include="..\..\..\..\test\query\initialize.cpp">
<Filter>src\query</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\query\merkle.cpp">
<Filter>src\query</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\query\network.cpp">
<Filter>src\query</Filter>
</ClCompile>
Expand All @@ -141,9 +147,6 @@
<ClCompile Include="..\..\..\..\test\query\optional.cpp">
<Filter>src\query</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\query\services.cpp">
<Filter>src\query</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\query\translate.cpp">
<Filter>src\query</Filter>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,15 @@
<None Include="..\..\..\..\include\bitcoin\database\impl\query\confirm.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\consensus.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\context.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\estimate.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\extent.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\height.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\initialize.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\merkle.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\network.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\objects.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\optional.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\query.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\services.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\translate.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\validate.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\store.ipp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@
<None Include="..\..\..\..\include\bitcoin\database\impl\query\context.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\database\impl\query\estimate.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\database\impl\query\extent.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
Expand All @@ -355,6 +358,9 @@
<None Include="..\..\..\..\include\bitcoin\database\impl\query\initialize.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\database\impl\query\merkle.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\database\impl\query\network.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
Expand All @@ -367,9 +373,6 @@
<None Include="..\..\..\..\include\bitcoin\database\impl\query\query.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\database\impl\query\services.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\database\impl\query\translate.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
Expand Down
11 changes: 7 additions & 4 deletions include/bitcoin/database/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,15 @@ enum error_t : uint8_t
txs_confirm,
txs_txs_put,

/// optional
/// services
not_found,
empty_block,
query_canceled,
invalid_argument,
missing_prevouts,
merkle_proof,
merkle_interval,
merkle_hashes,
merkle_arguments,
merkle_not_found
merkle_hashes
};

// No current need for error_code equivalence mapping.
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/file/rotator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <memory>
#include <filesystem>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>
#include <bitcoin/database/file/utilities.hpp>

Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/file/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define LIBBITCOIN_DATABASE_FILE_UTILITIES_HPP

#include <filesystem>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>

namespace libbitcoin {
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/memory/accessor.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define LIBBITCOIN_DATABASE_MEMORY_ACCESSOR_IPP

////#include <iterator>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>

// Zero/negative size is allowed (automatically handled by bc streams).
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/primitives/arrayhead.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define LIBBITCOIN_DATABASE_PRIMITIVES_ARRAYHEAD_IPP

#include <algorithm>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>

// TODO: xcode clang++16 does not support C++20 std::atomic_ref.
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/primitives/hashhead.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define LIBBITCOIN_DATABASE_PRIMITIVES_HASHHEAD_IPP

#include <algorithm>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>

// Heads are not subject to resize/remap and therefore do not require memory
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/primitives/hashmap.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <atomic>
#include <algorithm>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>

namespace libbitcoin {
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/primitives/iterator.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <iterator>
#include <cstring>
#include <utility>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>

namespace libbitcoin {
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/primitives/linkage.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_LINKAGE_IPP
#define LIBBITCOIN_DATABASE_PRIMITIVES_LINKAGE_IPP

#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>

namespace libbitcoin {
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/primitives/manager.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_IPP
#define LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_IPP

#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>

namespace libbitcoin {
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/primitives/nomap.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_NOMAP_IPP
#define LIBBITCOIN_DATABASE_PRIMITIVES_NOMAP_IPP

#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>

namespace libbitcoin {
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/query/archive_read.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <algorithm>
#include <ranges>
#include <utility>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>
#include <bitcoin/database/tables/tables.hpp>

Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/query/archive_write.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <algorithm>
#include <ranges>
#include <utility>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>

namespace libbitcoin {
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/query/confirm.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define LIBBITCOIN_DATABASE_QUERY_CONFIRM_IPP

#include <algorithm>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>
#include <bitcoin/database/error.hpp>

Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/query/consensus.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <algorithm>
#include <atomic>
#include <utility>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>
#include <bitcoin/database/error.hpp>

Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/query/context.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <ranges>
#include <memory>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>

namespace libbitcoin {
Expand Down
111 changes: 111 additions & 0 deletions include/bitcoin/database/impl/query/estimate.ipp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_DATABASE_QUERY_ESTIMATE_IPP
#define LIBBITCOIN_DATABASE_QUERY_ESTIMATE_IPP

#include <atomic>
#include <algorithm>
#include <iterator>
#include <memory>
#include <numeric>
#include <utility>
#include <bitcoin/database/define.hpp>

namespace libbitcoin {
namespace database {

// fee estimate
// ----------------------------------------------------------------------------

// protected
TEMPLATE
bool CLASS::get_block_fees(fee_rates& out,
const header_link& link) const NOEXCEPT
{
out.clear();
const auto block = get_block(link, false);
if (!block)
return false;

block->populate();
if (!populate_without_metadata(*block))
return false;

const auto& txs = *block->transactions_ptr();
if (txs.empty())
return false;

out.reserve(txs.size());
for (auto tx = std::next(txs.begin()); tx != txs.end(); ++tx)
out.emplace_back((*tx)->virtual_size(), (*tx)->fee());

return true;
}

// public
TEMPLATE
bool CLASS::get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out,
size_t top, size_t count) const NOEXCEPT
{
out.clear();
if (is_zero(count))
return true;

if (top > get_top_confirmed())
return false;

const auto start = top - sub1(count);
if (system::is_subtract_overflow(top, sub1(count)))
return false;

out.resize(count);
std::vector<size_t> offsets(count);
std::iota(offsets.begin(), offsets.end(), zero);

std::atomic_bool failure{};
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);
return;
}

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

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

} // namespace database
} // namespace libbitcoin

#endif
Loading
Loading