diff --git a/Makefile.am b/Makefile.am index 74c63bc39..87c4a2935 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ @@ -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 diff --git a/builds/cmake/CMakeLists.txt b/builds/cmake/CMakeLists.txt index 84c6c5886..73a8c2ebb 100644 --- a/builds/cmake/CMakeLists.txt +++ b/builds/cmake/CMakeLists.txt @@ -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" diff --git a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj index 2f3d71807..144d20903 100644 --- a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj @@ -152,15 +152,16 @@ + $(IntDir)test_query_height.obj + - diff --git a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters index 444136b76..c42b1fc49 100644 --- a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters @@ -123,6 +123,9 @@ src\query + + src\query + src\query @@ -132,6 +135,9 @@ src\query + + src\query + src\query @@ -141,9 +147,6 @@ src\query - - src\query - src\query diff --git a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj index 9f0399b7c..1fcd181f2 100644 --- a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj @@ -219,14 +219,15 @@ + + - diff --git a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters index f4c97428c..8eb2eeef8 100644 --- a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters @@ -346,6 +346,9 @@ include\bitcoin\database\impl\query + + include\bitcoin\database\impl\query + include\bitcoin\database\impl\query @@ -355,6 +358,9 @@ include\bitcoin\database\impl\query + + include\bitcoin\database\impl\query + include\bitcoin\database\impl\query @@ -367,9 +373,6 @@ include\bitcoin\database\impl\query - - include\bitcoin\database\impl\query - include\bitcoin\database\impl\query diff --git a/include/bitcoin/database/error.hpp b/include/bitcoin/database/error.hpp index 2272f607e..2dd91ff40 100644 --- a/include/bitcoin/database/error.hpp +++ b/include/bitcoin/database/error.hpp @@ -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. diff --git a/include/bitcoin/database/file/rotator.hpp b/include/bitcoin/database/file/rotator.hpp index 31262b4d4..9c4484f43 100644 --- a/include/bitcoin/database/file/rotator.hpp +++ b/include/bitcoin/database/file/rotator.hpp @@ -21,7 +21,6 @@ #include #include -#include #include #include diff --git a/include/bitcoin/database/file/utilities.hpp b/include/bitcoin/database/file/utilities.hpp index 2c823753c..9dd4a2a93 100644 --- a/include/bitcoin/database/file/utilities.hpp +++ b/include/bitcoin/database/file/utilities.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_FILE_UTILITIES_HPP #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/impl/memory/accessor.ipp b/include/bitcoin/database/impl/memory/accessor.ipp index a19511236..e257c628d 100644 --- a/include/bitcoin/database/impl/memory/accessor.ipp +++ b/include/bitcoin/database/impl/memory/accessor.ipp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_MEMORY_ACCESSOR_IPP ////#include -#include #include // Zero/negative size is allowed (automatically handled by bc streams). diff --git a/include/bitcoin/database/impl/primitives/arrayhead.ipp b/include/bitcoin/database/impl/primitives/arrayhead.ipp index ddfedb97f..61157f2c5 100644 --- a/include/bitcoin/database/impl/primitives/arrayhead.ipp +++ b/include/bitcoin/database/impl/primitives/arrayhead.ipp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_PRIMITIVES_ARRAYHEAD_IPP #include -#include #include // TODO: xcode clang++16 does not support C++20 std::atomic_ref. diff --git a/include/bitcoin/database/impl/primitives/hashhead.ipp b/include/bitcoin/database/impl/primitives/hashhead.ipp index 61afb9726..7e2d874a5 100644 --- a/include/bitcoin/database/impl/primitives/hashhead.ipp +++ b/include/bitcoin/database/impl/primitives/hashhead.ipp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_PRIMITIVES_HASHHEAD_IPP #include -#include #include // Heads are not subject to resize/remap and therefore do not require memory diff --git a/include/bitcoin/database/impl/primitives/hashmap.ipp b/include/bitcoin/database/impl/primitives/hashmap.ipp index 6d3d0b78b..f9116eb2f 100644 --- a/include/bitcoin/database/impl/primitives/hashmap.ipp +++ b/include/bitcoin/database/impl/primitives/hashmap.ipp @@ -21,7 +21,6 @@ #include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/impl/primitives/iterator.ipp b/include/bitcoin/database/impl/primitives/iterator.ipp index 1c012f3e4..f1d155648 100644 --- a/include/bitcoin/database/impl/primitives/iterator.ipp +++ b/include/bitcoin/database/impl/primitives/iterator.ipp @@ -22,7 +22,6 @@ #include #include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/impl/primitives/linkage.ipp b/include/bitcoin/database/impl/primitives/linkage.ipp index 6dc26adba..00e8c9a43 100644 --- a/include/bitcoin/database/impl/primitives/linkage.ipp +++ b/include/bitcoin/database/impl/primitives/linkage.ipp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_LINKAGE_IPP #define LIBBITCOIN_DATABASE_PRIMITIVES_LINKAGE_IPP -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/impl/primitives/manager.ipp b/include/bitcoin/database/impl/primitives/manager.ipp index f9d748b17..ddc920d64 100644 --- a/include/bitcoin/database/impl/primitives/manager.ipp +++ b/include/bitcoin/database/impl/primitives/manager.ipp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_IPP #define LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_IPP -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/impl/primitives/nomap.ipp b/include/bitcoin/database/impl/primitives/nomap.ipp index a5d836b8a..346a5dd53 100644 --- a/include/bitcoin/database/impl/primitives/nomap.ipp +++ b/include/bitcoin/database/impl/primitives/nomap.ipp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_NOMAP_IPP #define LIBBITCOIN_DATABASE_PRIMITIVES_NOMAP_IPP -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/impl/query/archive_read.ipp b/include/bitcoin/database/impl/query/archive_read.ipp index 9f9cfefb3..969a51b0e 100644 --- a/include/bitcoin/database/impl/query/archive_read.ipp +++ b/include/bitcoin/database/impl/query/archive_read.ipp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include diff --git a/include/bitcoin/database/impl/query/archive_write.ipp b/include/bitcoin/database/impl/query/archive_write.ipp index 7886372c2..a35be3771 100644 --- a/include/bitcoin/database/impl/query/archive_write.ipp +++ b/include/bitcoin/database/impl/query/archive_write.ipp @@ -22,7 +22,6 @@ #include #include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/impl/query/confirm.ipp b/include/bitcoin/database/impl/query/confirm.ipp index 5cbd0fc5d..4dd7f9325 100644 --- a/include/bitcoin/database/impl/query/confirm.ipp +++ b/include/bitcoin/database/impl/query/confirm.ipp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_QUERY_CONFIRM_IPP #include -#include #include #include diff --git a/include/bitcoin/database/impl/query/consensus.ipp b/include/bitcoin/database/impl/query/consensus.ipp index b9929b180..2eb4ec3f8 100644 --- a/include/bitcoin/database/impl/query/consensus.ipp +++ b/include/bitcoin/database/impl/query/consensus.ipp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include diff --git a/include/bitcoin/database/impl/query/context.ipp b/include/bitcoin/database/impl/query/context.ipp index c921113d2..5756daa4b 100644 --- a/include/bitcoin/database/impl/query/context.ipp +++ b/include/bitcoin/database/impl/query/context.ipp @@ -21,7 +21,6 @@ #include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/impl/query/estimate.ipp b/include/bitcoin/database/impl/query/estimate.ipp new file mode 100644 index 000000000..da976ee71 --- /dev/null +++ b/include/bitcoin/database/impl/query/estimate.ipp @@ -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 . + */ +#ifndef LIBBITCOIN_DATABASE_QUERY_ESTIMATE_IPP +#define LIBBITCOIN_DATABASE_QUERY_ESTIMATE_IPP + +#include +#include +#include +#include +#include +#include +#include + +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 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 diff --git a/include/bitcoin/database/impl/query/extent.ipp b/include/bitcoin/database/impl/query/extent.ipp index 9e543b851..838db3163 100644 --- a/include/bitcoin/database/impl/query/extent.ipp +++ b/include/bitcoin/database/impl/query/extent.ipp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_QUERY_EXTENT_IPP #include -#include #include #define DEFINE_SIZES(name) \ diff --git a/include/bitcoin/database/impl/query/height.ipp b/include/bitcoin/database/impl/query/height.ipp index 7e77bf5c9..fa2544ac3 100644 --- a/include/bitcoin/database/impl/query/height.ipp +++ b/include/bitcoin/database/impl/query/height.ipp @@ -21,7 +21,6 @@ #include #include -#include #include namespace libbitcoin { @@ -382,8 +381,6 @@ bool CLASS::pop_confirmed() NOEXCEPT if (!set_strong(link, txs.number, txs.coinbase_fk, false)) return false; - // Truncate cannot fail for disk full. - // This truncate assumes no concurrent writes to the table. /////////////////////////////////////////////////////////////////////////// std::unique_lock interlock{ confirmed_reorganization_mutex_ }; return store_.confirmed.truncate(top); diff --git a/include/bitcoin/database/impl/query/initialize.ipp b/include/bitcoin/database/impl/query/initialize.ipp index 762183b9d..e6f23db14 100644 --- a/include/bitcoin/database/impl/query/initialize.ipp +++ b/include/bitcoin/database/impl/query/initialize.ipp @@ -21,7 +21,6 @@ #include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/impl/query/services.ipp b/include/bitcoin/database/impl/query/merkle.ipp similarity index 92% rename from include/bitcoin/database/impl/query/services.ipp rename to include/bitcoin/database/impl/query/merkle.ipp index 657c3ccf8..1327841fe 100644 --- a/include/bitcoin/database/impl/query/services.ipp +++ b/include/bitcoin/database/impl/query/merkle.ipp @@ -16,13 +16,12 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_DATABASE_QUERY_SERVICES_IPP -#define LIBBITCOIN_DATABASE_QUERY_SERVICES_IPP +#ifndef LIBBITCOIN_DATABASE_QUERY_MERKLE_IPP +#define LIBBITCOIN_DATABASE_QUERY_MERKLE_IPP #include #include #include -#include #include namespace libbitcoin { @@ -145,10 +144,10 @@ code CLASS::get_merkle_root_and_proof(hash_digest& root, hashes& proof, size_t target, size_t waypoint) const NOEXCEPT { if (target > waypoint) - return error::merkle_arguments; + return error::invalid_argument; if (waypoint > get_top_confirmed()) - return error::merkle_not_found; + return error::not_found; hashes tree{}; if (const auto ec = get_merkle_tree(tree, waypoint)) @@ -162,6 +161,16 @@ code CLASS::get_merkle_root_and_proof(hash_digest& root, hashes& proof, return {}; } +TEMPLATE +hash_digest CLASS::get_merkle_root(size_t height) const NOEXCEPT +{ + hashes tree{}; + if (const auto ec = get_merkle_tree(tree, height)) + return {}; + + return system::merkle_root(std::move(tree)); +} + } // namespace database } // namespace libbitcoin diff --git a/include/bitcoin/database/impl/query/network.ipp b/include/bitcoin/database/impl/query/network.ipp index e3c5cccaf..f1084e44c 100644 --- a/include/bitcoin/database/impl/query/network.ipp +++ b/include/bitcoin/database/impl/query/network.ipp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_QUERY_NETWORK_IPP #include -#include #include namespace libbitcoin { @@ -134,7 +133,6 @@ bool CLASS::get_ancestry(header_links& ancestry, const header_link& descendant, auto link = descendant; // Ancestry navigation ensures continuity without locks. - // If count is zero then not even descendant is pushed. // link terminal if previous was genesis (avoided by count <= height). for (auto& ancestor: ancestry) link = to_parent((ancestor = link)); diff --git a/include/bitcoin/database/impl/query/objects.ipp b/include/bitcoin/database/impl/query/objects.ipp index 72b7e0ded..d057dc82d 100644 --- a/include/bitcoin/database/impl/query/objects.ipp +++ b/include/bitcoin/database/impl/query/objects.ipp @@ -21,7 +21,6 @@ #include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/impl/query/optional.ipp b/include/bitcoin/database/impl/query/optional.ipp index 1092baef1..dd2b3b018 100644 --- a/include/bitcoin/database/impl/query/optional.ipp +++ b/include/bitcoin/database/impl/query/optional.ipp @@ -23,7 +23,6 @@ #include #include #include -#include #include // TODO: address table could use point keys to compress the multimap. diff --git a/include/bitcoin/database/impl/query/query.ipp b/include/bitcoin/database/impl/query/query.ipp index 87dae87dd..3d35b6ad1 100644 --- a/include/bitcoin/database/impl/query/query.ipp +++ b/include/bitcoin/database/impl/query/query.ipp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_QUERY_QUERY_IPP #define LIBBITCOIN_DATABASE_QUERY_QUERY_IPP -#include #include // Error handling: diff --git a/include/bitcoin/database/impl/query/translate.ipp b/include/bitcoin/database/impl/query/translate.ipp index d59fbec1b..bcffdb391 100644 --- a/include/bitcoin/database/impl/query/translate.ipp +++ b/include/bitcoin/database/impl/query/translate.ipp @@ -24,7 +24,6 @@ #include #include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/impl/query/validate.ipp b/include/bitcoin/database/impl/query/validate.ipp index 4b78ff86e..dcd4aa9eb 100644 --- a/include/bitcoin/database/impl/query/validate.ipp +++ b/include/bitcoin/database/impl/query/validate.ipp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_QUERY_VALIDATE_IPP #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/locks/file_lock.hpp b/include/bitcoin/database/locks/file_lock.hpp index 0dde12740..8ee2f1e58 100644 --- a/include/bitcoin/database/locks/file_lock.hpp +++ b/include/bitcoin/database/locks/file_lock.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_LOCKS_FILE_LOCK_HPP #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/locks/flush_lock.hpp b/include/bitcoin/database/locks/flush_lock.hpp index b38f675a7..ba2e05b29 100644 --- a/include/bitcoin/database/locks/flush_lock.hpp +++ b/include/bitcoin/database/locks/flush_lock.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_LOCKS_FLUSH_LOCK_HPP #include -#include #include #include diff --git a/include/bitcoin/database/locks/interprocess_lock.hpp b/include/bitcoin/database/locks/interprocess_lock.hpp index 7b0ac8807..6fdbcda36 100644 --- a/include/bitcoin/database/locks/interprocess_lock.hpp +++ b/include/bitcoin/database/locks/interprocess_lock.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_LOCKS_INTERPROCESS_LOCK_HPP #include -#include #include #include #include diff --git a/include/bitcoin/database/memory/accessor.hpp b/include/bitcoin/database/memory/accessor.hpp index f7984c4da..2b0e74619 100644 --- a/include/bitcoin/database/memory/accessor.hpp +++ b/include/bitcoin/database/memory/accessor.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_MEMORY_ACCESSOR_HPP #include -#include #include #include diff --git a/include/bitcoin/database/memory/finalizer.hpp b/include/bitcoin/database/memory/finalizer.hpp index 613c97e8a..42e261065 100644 --- a/include/bitcoin/database/memory/finalizer.hpp +++ b/include/bitcoin/database/memory/finalizer.hpp @@ -21,7 +21,6 @@ #include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/memory/interfaces/memory.hpp b/include/bitcoin/database/memory/interfaces/memory.hpp index 26ad67e7b..db371cee9 100644 --- a/include/bitcoin/database/memory/interfaces/memory.hpp +++ b/include/bitcoin/database/memory/interfaces/memory.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_MEMORY_INTERFACES_MEMORY_HPP #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/memory/interfaces/storage.hpp b/include/bitcoin/database/memory/interfaces/storage.hpp index 09edee748..6b1d9367b 100644 --- a/include/bitcoin/database/memory/interfaces/storage.hpp +++ b/include/bitcoin/database/memory/interfaces/storage.hpp @@ -20,8 +20,6 @@ #define LIBBITCOIN_DATABASE_MEMORY_INTERFACES_STORAGE_HPP #include -#include -#include #include #include diff --git a/include/bitcoin/database/memory/map.hpp b/include/bitcoin/database/memory/map.hpp index 41d63d751..ab3e410e9 100644 --- a/include/bitcoin/database/memory/map.hpp +++ b/include/bitcoin/database/memory/map.hpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/include/bitcoin/database/memory/reader.hpp b/include/bitcoin/database/memory/reader.hpp index 6a62d1832..2424528c4 100644 --- a/include/bitcoin/database/memory/reader.hpp +++ b/include/bitcoin/database/memory/reader.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_MEMORY_READER_HPP #define LIBBITCOIN_DATABASE_MEMORY_READER_HPP -#include #include #include diff --git a/include/bitcoin/database/memory/streamers.hpp b/include/bitcoin/database/memory/streamers.hpp index 068a557a6..b485daa2b 100644 --- a/include/bitcoin/database/memory/streamers.hpp +++ b/include/bitcoin/database/memory/streamers.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_MEMORY_STREAMERS_HPP #define LIBBITCOIN_DATABASE_MEMORY_STREAMERS_HPP -#include #include #include diff --git a/include/bitcoin/database/primitives/arrayhead.hpp b/include/bitcoin/database/primitives/arrayhead.hpp index f14e075cb..df5846bb9 100644 --- a/include/bitcoin/database/primitives/arrayhead.hpp +++ b/include/bitcoin/database/primitives/arrayhead.hpp @@ -21,7 +21,6 @@ #include #include -#include #include #include diff --git a/include/bitcoin/database/primitives/arraymap.hpp b/include/bitcoin/database/primitives/arraymap.hpp index 32d977043..ebb08c079 100644 --- a/include/bitcoin/database/primitives/arraymap.hpp +++ b/include/bitcoin/database/primitives/arraymap.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_ARRAYMAP_HPP #define LIBBITCOIN_DATABASE_PRIMITIVES_ARRAYMAP_HPP -#include #include #include #include diff --git a/include/bitcoin/database/primitives/hashhead.hpp b/include/bitcoin/database/primitives/hashhead.hpp index b0ae7dd52..35fb0a0fd 100644 --- a/include/bitcoin/database/primitives/hashhead.hpp +++ b/include/bitcoin/database/primitives/hashhead.hpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/include/bitcoin/database/primitives/hashmap.hpp b/include/bitcoin/database/primitives/hashmap.hpp index 5a38c1141..7ac90a0aa 100644 --- a/include/bitcoin/database/primitives/hashmap.hpp +++ b/include/bitcoin/database/primitives/hashmap.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_PRIMITIVES_HASHMAP_HPP #include -#include #include #include #include diff --git a/include/bitcoin/database/primitives/iterator.hpp b/include/bitcoin/database/primitives/iterator.hpp index ad97310c5..4ec5f2fe5 100644 --- a/include/bitcoin/database/primitives/iterator.hpp +++ b/include/bitcoin/database/primitives/iterator.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_ITERATOR_HPP #define LIBBITCOIN_DATABASE_PRIMITIVES_ITERATOR_HPP -#include #include #include #include diff --git a/include/bitcoin/database/primitives/linkage.hpp b/include/bitcoin/database/primitives/linkage.hpp index 3d8ca3523..7c67dd1f7 100644 --- a/include/bitcoin/database/primitives/linkage.hpp +++ b/include/bitcoin/database/primitives/linkage.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_LINKAGE_HPP #define LIBBITCOIN_DATABASE_PRIMITIVES_LINKAGE_HPP -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/primitives/manager.hpp b/include/bitcoin/database/primitives/manager.hpp index a5ff380bc..1c00bb675 100644 --- a/include/bitcoin/database/primitives/manager.hpp +++ b/include/bitcoin/database/primitives/manager.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_HPP #define LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_HPP -#include #include #include #include diff --git a/include/bitcoin/database/primitives/nomap.hpp b/include/bitcoin/database/primitives/nomap.hpp index 749282c3c..a02a2169e 100644 --- a/include/bitcoin/database/primitives/nomap.hpp +++ b/include/bitcoin/database/primitives/nomap.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_NOMAP_HPP #define LIBBITCOIN_DATABASE_PRIMITIVES_NOMAP_HPP -#include #include #include #include diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index 59d1a4bfe..217b4772b 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -402,6 +401,13 @@ class query /// Services. /// ----------------------------------------------------------------------- + /// Gether fee rate tuples by block or set of blocks. + 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, + size_t top, size_t count) const NOEXCEPT; + + /// Merkle computations over the index of confirmed headers. + hash_digest get_merkle_root(size_t height) const NOEXCEPT; code get_merkle_root_and_proof(hash_digest& root, hashes& proof, size_t target, size_t checkpoint) const NOEXCEPT; @@ -723,7 +729,7 @@ class query outpoints& out, const hash_digest& key, uint64_t minimum) const NOEXCEPT; - /// services:merkle + /// merkle /// ----------------------------------------------------------------------- static void merge_merkle(hashes& branch, hashes&& hashes, @@ -783,7 +789,8 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) #include #include #include -#include +#include +#include #include #include diff --git a/include/bitcoin/database/settings.hpp b/include/bitcoin/database/settings.hpp index c4c5d523c..6bb3f142e 100644 --- a/include/bitcoin/database/settings.hpp +++ b/include/bitcoin/database/settings.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_SETTINGS_HPP #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/tables/archives/header.hpp b/include/bitcoin/database/tables/archives/header.hpp index e43fa428d..cc9a03e5a 100644 --- a/include/bitcoin/database/tables/archives/header.hpp +++ b/include/bitcoin/database/tables/archives/header.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_ARCHIVES_HEADER_HPP #define LIBBITCOIN_DATABASE_TABLES_ARCHIVES_HEADER_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/archives/input.hpp b/include/bitcoin/database/tables/archives/input.hpp index 8432a7d1e..8784c2b28 100644 --- a/include/bitcoin/database/tables/archives/input.hpp +++ b/include/bitcoin/database/tables/archives/input.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_TABLES_ARCHIVES_INPUT_HPP #include -#include #include #include #include diff --git a/include/bitcoin/database/tables/archives/ins.hpp b/include/bitcoin/database/tables/archives/ins.hpp index 55673a107..cb72bc6fd 100644 --- a/include/bitcoin/database/tables/archives/ins.hpp +++ b/include/bitcoin/database/tables/archives/ins.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_ARCHIVES_INS_HPP #define LIBBITCOIN_DATABASE_TABLES_ARCHIVES_INS_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/archives/output.hpp b/include/bitcoin/database/tables/archives/output.hpp index 43cba2efe..f87caf6c5 100644 --- a/include/bitcoin/database/tables/archives/output.hpp +++ b/include/bitcoin/database/tables/archives/output.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_TABLES_ARCHIVES_OUTPUT_HPP #include -#include #include #include #include diff --git a/include/bitcoin/database/tables/archives/outs.hpp b/include/bitcoin/database/tables/archives/outs.hpp index 0d5060de9..0c295c234 100644 --- a/include/bitcoin/database/tables/archives/outs.hpp +++ b/include/bitcoin/database/tables/archives/outs.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_TABLES_ARCHIVES_OUTS_HPP #include -#include #include #include #include diff --git a/include/bitcoin/database/tables/archives/point.hpp b/include/bitcoin/database/tables/archives/point.hpp index 18d154a46..edfd21ffc 100644 --- a/include/bitcoin/database/tables/archives/point.hpp +++ b/include/bitcoin/database/tables/archives/point.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_TABLES_ARCHIVES_POINT_HPP #include -#include #include #include #include diff --git a/include/bitcoin/database/tables/archives/transaction.hpp b/include/bitcoin/database/tables/archives/transaction.hpp index 0663dd274..e7b6759d1 100644 --- a/include/bitcoin/database/tables/archives/transaction.hpp +++ b/include/bitcoin/database/tables/archives/transaction.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_ARCHIVES_TRANSACTION_HPP #define LIBBITCOIN_DATABASE_TABLES_ARCHIVES_TRANSACTION_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/archives/txs.hpp b/include/bitcoin/database/tables/archives/txs.hpp index b93943df7..88217b6b6 100644 --- a/include/bitcoin/database/tables/archives/txs.hpp +++ b/include/bitcoin/database/tables/archives/txs.hpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/include/bitcoin/database/tables/association.hpp b/include/bitcoin/database/tables/association.hpp index 3383df429..397820eb7 100644 --- a/include/bitcoin/database/tables/association.hpp +++ b/include/bitcoin/database/tables/association.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_ASSOCIATION_HPP #define LIBBITCOIN_DATABASE_TABLES_ASSOCIATION_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/associations.hpp b/include/bitcoin/database/tables/associations.hpp index c2b6cdce5..fdf3efa37 100644 --- a/include/bitcoin/database/tables/associations.hpp +++ b/include/bitcoin/database/tables/associations.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_ASSOCIATIONS_HPP #define LIBBITCOIN_DATABASE_TABLES_ASSOCIATIONS_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/caches/duplicate.hpp b/include/bitcoin/database/tables/caches/duplicate.hpp index 8c4ccec26..dc98bbbbe 100644 --- a/include/bitcoin/database/tables/caches/duplicate.hpp +++ b/include/bitcoin/database/tables/caches/duplicate.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_CACHES_DOUBLES_HPP #define LIBBITCOIN_DATABASE_TABLES_CACHES_DOUBLES_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/caches/prevout.hpp b/include/bitcoin/database/tables/caches/prevout.hpp index f593e426a..b03072203 100644 --- a/include/bitcoin/database/tables/caches/prevout.hpp +++ b/include/bitcoin/database/tables/caches/prevout.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_TABLES_CACHES_PREVOUT_HPP #include -#include #include #include #include diff --git a/include/bitcoin/database/tables/caches/validated_bk.hpp b/include/bitcoin/database/tables/caches/validated_bk.hpp index 284446f3d..a5f7d7d7f 100644 --- a/include/bitcoin/database/tables/caches/validated_bk.hpp +++ b/include/bitcoin/database/tables/caches/validated_bk.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_CACHES_VALIDATED_BK_HPP #define LIBBITCOIN_DATABASE_TABLES_CACHES_VALIDATED_BK_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/caches/validated_tx.hpp b/include/bitcoin/database/tables/caches/validated_tx.hpp index 89c06ca1e..172d31743 100644 --- a/include/bitcoin/database/tables/caches/validated_tx.hpp +++ b/include/bitcoin/database/tables/caches/validated_tx.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_CACHES_VALIDATED_TX_HPP #define LIBBITCOIN_DATABASE_TABLES_CACHES_VALIDATED_TX_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/context.hpp b/include/bitcoin/database/tables/context.hpp index d12dd21d8..c21036bfd 100644 --- a/include/bitcoin/database/tables/context.hpp +++ b/include/bitcoin/database/tables/context.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_CONTEXT_HPP #define LIBBITCOIN_DATABASE_CONTEXT_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/indexes/height.hpp b/include/bitcoin/database/tables/indexes/height.hpp index 6f65b9c02..343ced0d5 100644 --- a/include/bitcoin/database/tables/indexes/height.hpp +++ b/include/bitcoin/database/tables/indexes/height.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_INDEXES_HEIGHT_HPP #define LIBBITCOIN_DATABASE_TABLES_INDEXES_HEIGHT_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/indexes/strong_tx.hpp b/include/bitcoin/database/tables/indexes/strong_tx.hpp index c143f4054..ac67f3caf 100644 --- a/include/bitcoin/database/tables/indexes/strong_tx.hpp +++ b/include/bitcoin/database/tables/indexes/strong_tx.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_INDEXES_STRONG_TX_HPP #define LIBBITCOIN_DATABASE_TABLES_INDEXES_STRONG_TX_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/names.hpp b/include/bitcoin/database/tables/names.hpp index a12ed75d2..6cff748d0 100644 --- a/include/bitcoin/database/tables/names.hpp +++ b/include/bitcoin/database/tables/names.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_NAMES_HPP #define LIBBITCOIN_DATABASE_TABLES_NAMES_HPP -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/tables/optionals/address.hpp b/include/bitcoin/database/tables/optionals/address.hpp index 68c2738d0..138dbbf27 100644 --- a/include/bitcoin/database/tables/optionals/address.hpp +++ b/include/bitcoin/database/tables/optionals/address.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_OPTIONALS_ADDRESS_HPP #define LIBBITCOIN_DATABASE_TABLES_OPTIONALS_ADDRESS_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/optionals/filter_bk.hpp b/include/bitcoin/database/tables/optionals/filter_bk.hpp index 42021f4c2..4128cf042 100644 --- a/include/bitcoin/database/tables/optionals/filter_bk.hpp +++ b/include/bitcoin/database/tables/optionals/filter_bk.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_OPTIONALS_FILTER_BK_HPP #define LIBBITCOIN_DATABASE_TABLES_OPTIONALS_FILTER_BK_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/optionals/filter_tx.hpp b/include/bitcoin/database/tables/optionals/filter_tx.hpp index cc548677d..4fce3d9e0 100644 --- a/include/bitcoin/database/tables/optionals/filter_tx.hpp +++ b/include/bitcoin/database/tables/optionals/filter_tx.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_OPTIONALS_FILTER_TX_HPP #define LIBBITCOIN_DATABASE_TABLES_OPTIONALS_FILTER_TX_HPP -#include #include #include #include diff --git a/include/bitcoin/database/tables/point_set.hpp b/include/bitcoin/database/tables/point_set.hpp index d3deeb70d..f0dc1e9a2 100644 --- a/include/bitcoin/database/tables/point_set.hpp +++ b/include/bitcoin/database/tables/point_set.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_POINT_SET_HPP #define LIBBITCOIN_DATABASE_TABLES_POINT_SET_HPP -#include #include #include diff --git a/include/bitcoin/database/tables/schema.hpp b/include/bitcoin/database/tables/schema.hpp index 49ed49609..92170ef7b 100644 --- a/include/bitcoin/database/tables/schema.hpp +++ b/include/bitcoin/database/tables/schema.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_SCHEMA_HPP #define LIBBITCOIN_DATABASE_TABLES_SCHEMA_HPP -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/tables/states.hpp b/include/bitcoin/database/tables/states.hpp index 7a675a25a..b5056cdd7 100644 --- a/include/bitcoin/database/tables/states.hpp +++ b/include/bitcoin/database/tables/states.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_DATABASE_TABLES_STATES_HPP #define LIBBITCOIN_DATABASE_TABLES_STATES_HPP -#include #include namespace libbitcoin { diff --git a/include/bitcoin/database/types.hpp b/include/bitcoin/database/types.hpp index b6141ebe3..263556ba7 100644 --- a/include/bitcoin/database/types.hpp +++ b/include/bitcoin/database/types.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_DATABASE_TYPES_HPP #include -#include #include #include @@ -47,15 +46,18 @@ using point_links = std::vector; using two_counts = std::pair; using point_key = table::point::key; -struct header_state{ header_link link; code ec; }; -using header_states = std::vector; - -// TODO: define a system::chain::inpoint with added state. using inpoint = system::chain::point; using inpoints = std::set; using outpoint = system::chain::outpoint; using outpoints = std::set; +struct header_state { header_link link; code ec; }; +using header_states = std::vector; + +struct fee_rate { size_t bytes{}; uint64_t fee{}; }; +using fee_rates = std::vector; +using fee_rate_sets = std::vector; + } // namespace database } // namespace libbitcoin diff --git a/src/error.cpp b/src/error.cpp index d1cf1f45e..8e14571e2 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -18,7 +18,7 @@ */ #include -#include +#include namespace libbitcoin { namespace database { @@ -138,12 +138,15 @@ DEFINE_ERROR_T_MESSAGE_MAP(error) { txs_confirm, "txs_confirm" }, { txs_txs_put, "txs_txs_put" }, - // optional + // services + { not_found, "not_found" }, + { empty_block, "empty_block" }, + { query_canceled, "query_canceled" }, + { invalid_argument, "invalid_argument" }, + { missing_prevouts, "missing_prevouts" }, { merkle_proof, "merkle_proof" }, { merkle_interval, "merkle_interval" }, - { merkle_hashes, "merkle_hashes" }, - { merkle_arguments, "merkle_arguments" }, - { merkle_not_found, "merkle_not_found" } + { merkle_hashes, "merkle_hashes" } }; DEFINE_ERROR_T_CATEGORY(error, "database", "database code") diff --git a/src/file/rotator.cpp b/src/file/rotator.cpp index c451ed30f..d72a0388d 100644 --- a/src/file/rotator.cpp +++ b/src/file/rotator.cpp @@ -20,7 +20,6 @@ #include #include -#include #include namespace libbitcoin { diff --git a/src/file/utilities.cpp b/src/file/utilities.cpp index f9595ebeb..f4985e72e 100644 --- a/src/file/utilities.cpp +++ b/src/file/utilities.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/src/locks/file_lock.cpp b/src/locks/file_lock.cpp index 5c56c0fbc..d56c3dd82 100644 --- a/src/locks/file_lock.cpp +++ b/src/locks/file_lock.cpp @@ -19,7 +19,6 @@ #include #include -#include #include namespace libbitcoin { diff --git a/src/locks/flush_lock.cpp b/src/locks/flush_lock.cpp index d195c0f3f..0e73c84e4 100644 --- a/src/locks/flush_lock.cpp +++ b/src/locks/flush_lock.cpp @@ -19,7 +19,6 @@ #include #include -#include #include namespace libbitcoin { diff --git a/src/locks/interprocess_lock.cpp b/src/locks/interprocess_lock.cpp index c8b7b36b1..9f5ef3581 100644 --- a/src/locks/interprocess_lock.cpp +++ b/src/locks/interprocess_lock.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include diff --git a/src/memory/map.cpp b/src/memory/map.cpp index 27e982513..382c53333 100644 --- a/src/memory/map.cpp +++ b/src/memory/map.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include diff --git a/src/memory/utilities.cpp b/src/memory/utilities.cpp index c1b9f2ed2..e61823944 100644 --- a/src/memory/utilities.cpp +++ b/src/memory/utilities.cpp @@ -23,7 +23,6 @@ #else #include #endif -#include #include namespace libbitcoin { diff --git a/src/settings.cpp b/src/settings.cpp index ec2ef5a76..a901411c7 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -18,7 +18,6 @@ */ #include -#include #include namespace libbitcoin { diff --git a/test/error.cpp b/test/error.cpp index 231b25530..be391077c 100644 --- a/test/error.cpp +++ b/test/error.cpp @@ -713,51 +713,78 @@ BOOST_AUTO_TEST_CASE(error_t__code__txs_txs_put__true_expected_message) BOOST_REQUIRE_EQUAL(ec.message(), "txs_txs_put"); } -// optional +// services -BOOST_AUTO_TEST_CASE(error_t__code__merkle_proof__true_expected_message) +BOOST_AUTO_TEST_CASE(error_t__code__not_found__true_expected_message) { - constexpr auto value = error::merkle_proof; + constexpr auto value = error::not_found; const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "merkle_proof"); + BOOST_REQUIRE_EQUAL(ec.message(), "not_found"); } -BOOST_AUTO_TEST_CASE(error_t__code__merkle_interval__true_expected_message) +BOOST_AUTO_TEST_CASE(error_t__code__empty_block__true_expected_message) { - constexpr auto value = error::merkle_interval; + constexpr auto value = error::empty_block; const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "merkle_interval"); + BOOST_REQUIRE_EQUAL(ec.message(), "empty_block"); } -BOOST_AUTO_TEST_CASE(error_t__code__merkle_hashes__true_expected_message) +BOOST_AUTO_TEST_CASE(error_t__code__query_canceled__true_expected_message) { - constexpr auto value = error::merkle_hashes; + constexpr auto value = error::query_canceled; const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "merkle_hashes"); + BOOST_REQUIRE_EQUAL(ec.message(), "query_canceled"); +} + +BOOST_AUTO_TEST_CASE(error_t__code__invalid_argument__true_expected_message) +{ + constexpr auto value = error::invalid_argument; + const auto ec = code(value); + BOOST_REQUIRE(ec); + BOOST_REQUIRE(ec == value); + BOOST_REQUIRE_EQUAL(ec.message(), "invalid_argument"); +} + +BOOST_AUTO_TEST_CASE(error_t__code__missing_prevouts__true_expected_message) +{ + constexpr auto value = error::missing_prevouts; + const auto ec = code(value); + BOOST_REQUIRE(ec); + BOOST_REQUIRE(ec == value); + BOOST_REQUIRE_EQUAL(ec.message(), "missing_prevouts"); +} + +BOOST_AUTO_TEST_CASE(error_t__code__merkle_proof__true_expected_message) +{ + constexpr auto value = error::merkle_proof; + const auto ec = code(value); + BOOST_REQUIRE(ec); + BOOST_REQUIRE(ec == value); + BOOST_REQUIRE_EQUAL(ec.message(), "merkle_proof"); } -BOOST_AUTO_TEST_CASE(error_t__code__merkle_arguments__true_expected_message) +BOOST_AUTO_TEST_CASE(error_t__code__merkle_interval__true_expected_message) { - constexpr auto value = error::merkle_arguments; + constexpr auto value = error::merkle_interval; const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "merkle_arguments"); + BOOST_REQUIRE_EQUAL(ec.message(), "merkle_interval"); } -BOOST_AUTO_TEST_CASE(error_t__code__merkle_not_found__true_expected_message) +BOOST_AUTO_TEST_CASE(error_t__code__merkle_hashes__true_expected_message) { - constexpr auto value = error::merkle_not_found; + constexpr auto value = error::merkle_hashes; const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "merkle_not_found"); + BOOST_REQUIRE_EQUAL(ec.message(), "merkle_hashes"); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/query/estimate.cpp b/test/query/estimate.cpp new file mode 100644 index 000000000..74e5365fa --- /dev/null +++ b/test/query/estimate.cpp @@ -0,0 +1,33 @@ +/** + * 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 . + */ +#include "../test.hpp" +#include "../mocks/blocks.hpp" +#include "../mocks/chunk_store.hpp" + +BOOST_FIXTURE_TEST_SUITE(query_estimate_tests, test::directory_setup_fixture) + +// nop event handler. +////const auto events_handler = [](auto, auto) {}; + +BOOST_AUTO_TEST_CASE(query_estimate_test) +{ + BOOST_REQUIRE(true); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/query/services.cpp b/test/query/merkle.cpp similarity index 89% rename from test/query/services.cpp rename to test/query/merkle.cpp index 0f85e974b..648cc4631 100644 --- a/test/query/services.cpp +++ b/test/query/merkle.cpp @@ -20,7 +20,7 @@ #include "../mocks/blocks.hpp" #include "../mocks/chunk_store.hpp" -BOOST_FIXTURE_TEST_SUITE(query_services_tests, test::directory_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(query_merkle_tests, test::directory_setup_fixture) // nop event handler. const auto events_handler = [](auto, auto) {}; @@ -51,7 +51,7 @@ class merkle_accessor // interval_span -BOOST_AUTO_TEST_CASE(query_services__interval_span__uninitialized__max_size_t) +BOOST_AUTO_TEST_CASE(query_merkle__interval_span__uninitialized__max_size_t) { settings settings{}; settings.path = TEST_DIRECTORY; @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE(query_services__interval_span__uninitialized__max_size_t) BOOST_REQUIRE_EQUAL(query.interval_span(), max_size_t); } -BOOST_AUTO_TEST_CASE(query_services__interval_span__11__2048) +BOOST_AUTO_TEST_CASE(query_merkle__interval_span__11__2048) { settings settings{}; settings.interval_depth = 11; @@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(query_services__interval_span__11__2048) BOOST_REQUIRE_EQUAL(query.interval_span(), 2048u); } -BOOST_AUTO_TEST_CASE(query_services__interval_span__0__1) +BOOST_AUTO_TEST_CASE(query_merkle__interval_span__0__1) { settings settings{}; settings.interval_depth = 0; @@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(query_services__interval_span__0__1) // create_interval -BOOST_AUTO_TEST_CASE(query_services__create_interval__depth_0__block_hash) +BOOST_AUTO_TEST_CASE(query_merkle__create_interval__depth_0__block_hash) { settings settings{}; settings.interval_depth = 0; @@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(query_services__create_interval__depth_0__block_hash) BOOST_REQUIRE_EQUAL(query.create_interval(header3, 3).value(), test::block3.hash()); } -BOOST_AUTO_TEST_CASE(query_services__create_interval__depth_1__expected) +BOOST_AUTO_TEST_CASE(query_merkle__create_interval__depth_1__expected) { settings settings{}; settings.interval_depth = 1; @@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(query_services__create_interval__depth_1__expected) BOOST_REQUIRE_EQUAL(query.create_interval(header3, 3).value(), root02); } -BOOST_AUTO_TEST_CASE(query_services__create_interval__depth_2__expected) +BOOST_AUTO_TEST_CASE(query_merkle__create_interval__depth_2__expected) { settings settings{}; settings.interval_depth = 2; @@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE(query_services__create_interval__depth_2__expected) // get_confirmed_interval -BOOST_AUTO_TEST_CASE(query_services__get_confirmed_interval__not_multiple__no_value) +BOOST_AUTO_TEST_CASE(query_merkle__get_confirmed_interval__not_multiple__no_value) { settings settings{}; settings.interval_depth = 3; @@ -186,7 +186,7 @@ BOOST_AUTO_TEST_CASE(query_services__get_confirmed_interval__not_multiple__no_va } // Interval is set by create_interval(), integral to set(block). -BOOST_AUTO_TEST_CASE(query_services__get_confirmed_interval__multiple__expected_value) +BOOST_AUTO_TEST_CASE(query_merkle__get_confirmed_interval__multiple__expected_value) { settings settings{}; settings.interval_depth = 2; @@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(query_services__get_confirmed_interval__multiple__expected_ // merge_merkle -BOOST_AUTO_TEST_CASE(query_services__merge_merkle__empty_from__empty_to) +BOOST_AUTO_TEST_CASE(query_merkle__merge_merkle__empty_from__empty_to) { hashes to{}; merkle_accessor::merge_merkle(to, {}, 0); @@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(query_services__merge_merkle__empty_from__empty_to) BOOST_REQUIRE(to.empty()); } -BOOST_AUTO_TEST_CASE(query_services__push_merkle__two_leaves_target_zero__merges_one_sibling) +BOOST_AUTO_TEST_CASE(query_merkle__push_merkle__two_leaves_target_zero__merges_one_sibling) { hashes to{}; hashes from @@ -235,7 +235,7 @@ BOOST_AUTO_TEST_CASE(query_services__push_merkle__two_leaves_target_zero__merges BOOST_REQUIRE_EQUAL(to[0], system::merkle_root({ test::block1.hash() })); } -BOOST_AUTO_TEST_CASE(query_services__merge_merkle__three_leaves_target_two__handles_odd_length) +BOOST_AUTO_TEST_CASE(query_merkle__merge_merkle__three_leaves_target_two__handles_odd_length) { hashes to{}; hashes from @@ -250,7 +250,7 @@ BOOST_AUTO_TEST_CASE(query_services__merge_merkle__three_leaves_target_two__hand BOOST_REQUIRE_EQUAL(to[0], system::merkle_root({ test::genesis.hash(), test::block1.hash() })); } -BOOST_AUTO_TEST_CASE(query_services__merge_merkle__four_leaves_target_three__merges_two_siblings) +BOOST_AUTO_TEST_CASE(query_merkle__merge_merkle__four_leaves_target_three__merges_two_siblings) { hashes to{}; hashes from @@ -269,7 +269,7 @@ BOOST_AUTO_TEST_CASE(query_services__merge_merkle__four_leaves_target_three__mer // get_merkle_proof -BOOST_AUTO_TEST_CASE(query_services__get_merkle_proof__no_confirmed_blocks__error_merkle_proof) +BOOST_AUTO_TEST_CASE(query_merkle__get_merkle_proof__no_confirmed_blocks__error_merkle_proof) { settings settings{}; settings.interval_depth = 2; @@ -284,7 +284,7 @@ BOOST_AUTO_TEST_CASE(query_services__get_merkle_proof__no_confirmed_blocks__erro BOOST_REQUIRE(proof.empty()); } -BOOST_AUTO_TEST_CASE(query_services__get_merkle_proof__target_in_first_interval__expected) +BOOST_AUTO_TEST_CASE(query_merkle__get_merkle_proof__target_in_first_interval__expected) { settings settings{}; settings.interval_depth = 2; @@ -307,7 +307,7 @@ BOOST_AUTO_TEST_CASE(query_services__get_merkle_proof__target_in_first_interval_ BOOST_REQUIRE_EQUAL(proof[1], system::merkle_root({ test::genesis.hash(), test::block1.hash() })); } -BOOST_AUTO_TEST_CASE(query_services__get_merkle_proof__multiple_intervals__expected) +BOOST_AUTO_TEST_CASE(query_merkle__get_merkle_proof__multiple_intervals__expected) { settings settings{}; settings.interval_depth = 1; @@ -337,7 +337,7 @@ BOOST_AUTO_TEST_CASE(query_services__get_merkle_proof__multiple_intervals__expec // get_merkle_tree -BOOST_AUTO_TEST_CASE(query_services__get_merkle_tree__waypoint_zero__genesis) +BOOST_AUTO_TEST_CASE(query_merkle__get_merkle_tree__waypoint_zero__genesis) { settings settings{}; settings.interval_depth = 2; @@ -354,7 +354,7 @@ BOOST_AUTO_TEST_CASE(query_services__get_merkle_tree__waypoint_zero__genesis) BOOST_REQUIRE_EQUAL(tree[0], expected); } -BOOST_AUTO_TEST_CASE(query_services__get_merkle_tree__one_full_interval__expected_root) +BOOST_AUTO_TEST_CASE(query_merkle__get_merkle_tree__one_full_interval__expected_root) { settings settings{}; settings.interval_depth = 2; @@ -384,8 +384,9 @@ BOOST_AUTO_TEST_CASE(query_services__get_merkle_tree__one_full_interval__expecte } // get_merkle_root_and_proof +// get_merkle_proof -BOOST_AUTO_TEST_CASE(query_services__get_merkle_root_and_proof__target_equals_waypoint__success) +BOOST_AUTO_TEST_CASE(query_merkle__get_merkle_root_and_proof__target_equals_waypoint__success) { settings settings{}; settings.interval_depth = 2; @@ -415,10 +416,11 @@ BOOST_AUTO_TEST_CASE(query_services__get_merkle_root_and_proof__target_equals_wa BOOST_REQUIRE_EQUAL(proof.size(), 2u); BOOST_REQUIRE_EQUAL(proof[0], system::merkle_root({ test::block2.hash() })); BOOST_REQUIRE_EQUAL(proof[1], system::merkle_root({ test::genesis.hash(), test::block1.hash() })); + BOOST_REQUIRE_EQUAL(root, query.get_merkle_root(3)); BOOST_REQUIRE_EQUAL(root, expected); } -BOOST_AUTO_TEST_CASE(query_services__get_merkle_root_and_proof__target_less_than_waypoint__success) +BOOST_AUTO_TEST_CASE(query_merkle__get_merkle_root_and_proof__target_less_than_waypoint__success) { settings settings{}; settings.interval_depth = 2; @@ -445,13 +447,14 @@ BOOST_AUTO_TEST_CASE(query_services__get_merkle_root_and_proof__target_less_than test::block3.hash() }); BOOST_REQUIRE(!query.get_merkle_root_and_proof(root, proof, 1u, 3u)); - BOOST_REQUIRE_EQUAL(root, expected); BOOST_REQUIRE_EQUAL(proof.size(), 2u); BOOST_REQUIRE_EQUAL(proof[0], system::merkle_root({ test::genesis.hash() })); BOOST_REQUIRE_EQUAL(proof[1], system::merkle_root({ test::block2.hash(), test::block3.hash() })); + BOOST_REQUIRE_EQUAL(root, query.get_merkle_root(3)); + BOOST_REQUIRE_EQUAL(root, expected); } -BOOST_AUTO_TEST_CASE(query_services__get_merkle_root_and_proof__target_greater_than_waypoint__error_merkle_arguments) +BOOST_AUTO_TEST_CASE(query_merkle__get_merkle_root_and_proof__target_greater_than_waypoint__error_invalid_argument) { settings settings{}; settings.interval_depth = 2; @@ -463,10 +466,11 @@ BOOST_AUTO_TEST_CASE(query_services__get_merkle_root_and_proof__target_greater_t hashes proof{}; hash_digest root{}; - BOOST_REQUIRE_EQUAL(query.get_merkle_root_and_proof(root, proof, 5u, 3u), error::merkle_arguments); + BOOST_REQUIRE_EQUAL(query.get_merkle_root_and_proof(root, proof, 5u, 3u), error::invalid_argument); + BOOST_REQUIRE_EQUAL(query.get_merkle_root(3), system::null_hash); } -BOOST_AUTO_TEST_CASE(query_services__get_merkle_root_and_proof__waypoint_beyond_top__error_merkle_not_found) +BOOST_AUTO_TEST_CASE(query_merkle__get_merkle_root_and_proof__waypoint_beyond_top__error_not_found) { settings settings{}; settings.interval_depth = 2; @@ -478,7 +482,8 @@ BOOST_AUTO_TEST_CASE(query_services__get_merkle_root_and_proof__waypoint_beyond_ hashes proof{}; hash_digest root{}; - BOOST_REQUIRE_EQUAL(query.get_merkle_root_and_proof(root, proof, 0u, 100u), error::merkle_not_found); + BOOST_REQUIRE_EQUAL(query.get_merkle_root_and_proof(root, proof, 0u, 100u), error::not_found); + BOOST_REQUIRE_EQUAL(query.get_merkle_root(100), system::null_hash); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test.hpp b/test/test.hpp index aca5b40d8..7e8c1012c 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -23,7 +23,6 @@ #include #include -#include #include #define TEST_NAME \ diff --git a/tools/initchain/initchain.cpp b/tools/initchain/initchain.cpp index 2fa27727f..46513ac05 100644 --- a/tools/initchain/initchain.cpp +++ b/tools/initchain/initchain.cpp @@ -16,7 +16,6 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include #include int main(int, char**)