diff --git a/include/bitcoin/database/error.hpp b/include/bitcoin/database/error.hpp index 0e8a5505..56f337c9 100644 --- a/include/bitcoin/database/error.hpp +++ b/include/bitcoin/database/error.hpp @@ -34,8 +34,6 @@ enum error_t : uint8_t { /// general success, - canceled, - limited, unknown_state, /// integrity (internal fault) @@ -136,6 +134,8 @@ enum error_t : uint8_t /// services not_found, empty_block, + depth_limited, + invalid_cursor, query_canceled, invalid_argument, missing_prevouts, diff --git a/include/bitcoin/database/impl/query/address/address_history.ipp b/include/bitcoin/database/impl/query/address/address_history.ipp index 5d095586..75065cbb 100644 --- a/include/bitcoin/database/impl/query/address/address_history.ipp +++ b/include/bitcoin/database/impl/query/address/address_history.ipp @@ -285,7 +285,7 @@ code CLASS::parallel_history_transform(const stopper& cancel, bool turbo, return error::integrity; if (cancel) - return error::canceled; + return error::query_canceled; history::filter_sort_and_dedup(out); return error::success; diff --git a/include/bitcoin/database/impl/query/address/address_outpoints.ipp b/include/bitcoin/database/impl/query/address/address_outpoints.ipp index b8ff090e..eb402cf7 100644 --- a/include/bitcoin/database/impl/query/address/address_outpoints.ipp +++ b/include/bitcoin/database/impl/query/address/address_outpoints.ipp @@ -166,7 +166,7 @@ code CLASS::parallel_outpoint_transform(const stopper& cancel, bool turbo, return error::integrity; if (cancel) - return error::canceled; + return error::query_canceled; // Remove default/null points. out.erase(std::remove_if(out.begin(), out.end(), diff --git a/include/bitcoin/database/impl/query/address/address_unspent.ipp b/include/bitcoin/database/impl/query/address/address_unspent.ipp index 2b102eb6..ae553af9 100644 --- a/include/bitcoin/database/impl/query/address/address_unspent.ipp +++ b/include/bitcoin/database/impl/query/address/address_unspent.ipp @@ -203,7 +203,7 @@ code CLASS::parallel_unspent_transform(const stopper& cancel, bool turbo, return error::integrity; if (cancel) - return error::canceled; + return error::query_canceled; unspent::filter_sort_and_dedup(out); return error::success; diff --git a/include/bitcoin/database/impl/query/navigate/navigate_reverse.ipp b/include/bitcoin/database/impl/query/navigate/navigate_reverse.ipp index 1d081ea3..46e00661 100644 --- a/include/bitcoin/database/impl/query/navigate/navigate_reverse.ipp +++ b/include/bitcoin/database/impl/query/navigate/navigate_reverse.ipp @@ -68,7 +68,7 @@ code CLASS::to_touched_txs(const stopper& cancel, tx_links& out, for (const auto& output: std::views::reverse(outputs)) { if (cancel) - return error::canceled; + return error::query_canceled; if (const auto tx = to_output_tx(output); tx.is_terminal()) return error::integrity; @@ -113,13 +113,13 @@ code CLASS::to_address_outputs(const stopper& cancel, address_link& cursor, for (cursor = it.get(); it; ++it) { if (cancel) - return error::canceled; + return error::query_canceled; if (it.get() == end) return error::success; if (is_zero(limit--)) - return error::limited; + return error::depth_limited; table::address::record address{}; if (!store_.address.get(it, address)) @@ -128,7 +128,7 @@ code CLASS::to_address_outputs(const stopper& cancel, address_link& cursor, out.push_back(address.output_fk); } - return end.is_terminal() ? error::success : error::not_found; + return end.is_terminal() ? error::success : error::invalid_cursor; } // input|output|prevout->tx[parent] diff --git a/src/error.cpp b/src/error.cpp index 5c38c198..57f731bc 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -28,8 +28,6 @@ DEFINE_ERROR_T_MESSAGE_MAP(error) { // general { success, "success" }, - { canceled, "canceled" }, - { limited, "limited" }, { unknown_state, "unknown state" }, // integrity (internal fault) @@ -128,6 +126,8 @@ DEFINE_ERROR_T_MESSAGE_MAP(error) // services { not_found, "not_found" }, { empty_block, "empty_block" }, + { depth_limited, "depth_limited" }, + { invalid_cursor, "invalid_cursor" }, { query_canceled, "query_canceled" }, { invalid_argument, "invalid_argument" }, { missing_prevouts, "missing_prevouts" }, diff --git a/test/error.cpp b/test/error.cpp index 34d50656..d180af54 100644 --- a/test/error.cpp +++ b/test/error.cpp @@ -32,24 +32,6 @@ BOOST_AUTO_TEST_CASE(error_t__code__success__false_expected_message) BOOST_REQUIRE_EQUAL(ec.message(), "success"); } -BOOST_AUTO_TEST_CASE(error_t__code__canceled__true_expected_message) -{ - constexpr auto value = error::canceled; - const auto ec = code(value); - BOOST_REQUIRE(ec); - BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "canceled"); -} - -BOOST_AUTO_TEST_CASE(error_t__code__limited__true_expected_message) -{ - constexpr auto value = error::limited; - const auto ec = code(value); - BOOST_REQUIRE(ec); - BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "limited"); -} - BOOST_AUTO_TEST_CASE(error_t__code__unknown_state__true_expected_message) { constexpr auto value = error::unknown_state; @@ -728,6 +710,24 @@ BOOST_AUTO_TEST_CASE(error_t__code__empty_block__true_expected_message) BOOST_REQUIRE_EQUAL(ec.message(), "empty_block"); } +BOOST_AUTO_TEST_CASE(error_t__code__depth_limited__true_expected_message) +{ + constexpr auto value = error::depth_limited; + const auto ec = code(value); + BOOST_REQUIRE(ec); + BOOST_REQUIRE(ec == value); + BOOST_REQUIRE_EQUAL(ec.message(), "depth_limited"); +} + +BOOST_AUTO_TEST_CASE(error_t__code__invalid_cursor__true_expected_message) +{ + constexpr auto value = error::invalid_cursor; + const auto ec = code(value); + BOOST_REQUIRE(ec); + BOOST_REQUIRE(ec == value); + BOOST_REQUIRE_EQUAL(ec.message(), "invalid_cursor"); +} + BOOST_AUTO_TEST_CASE(error_t__code__query_canceled__true_expected_message) { constexpr auto value = error::query_canceled; diff --git a/test/query/address/address_history.cpp b/test/query/address/address_history.cpp index f55ac605..37e3eab4 100644 --- a/test/query/address/address_history.cpp +++ b/test/query/address/address_history.cpp @@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(query_address__get_history__turbo_block1a_address0__expecte BOOST_CHECK_EQUAL(out.at(7).fee, history::missing_prevout); // tx7 } -BOOST_AUTO_TEST_CASE(query_address__get_history__limited__limited_empty) +BOOST_AUTO_TEST_CASE(query_address__get_history__limited__depth_limited_empty) { settings settings{}; settings.path = TEST_DIRECTORY; @@ -132,11 +132,11 @@ BOOST_AUTO_TEST_CASE(query_address__get_history__limited__limited_empty) const auto& hash = test::block1a_address0; // Limited returned when limit precludes reaching the address cursor (or terminal). - BOOST_CHECK_EQUAL(query.get_history(cancel, cursor, out, hash, 0, true), error::limited); + BOOST_CHECK_EQUAL(query.get_history(cancel, cursor, out, hash, 0, true), error::depth_limited); BOOST_CHECK(out.empty()); cursor = address_link::terminal; - BOOST_CHECK_EQUAL(query.get_history(cancel, cursor, out, hash, 8, true), error::limited); + BOOST_CHECK_EQUAL(query.get_history(cancel, cursor, out, hash, 8, true), error::depth_limited); BOOST_CHECK(out.empty()); cursor = address_link::terminal; @@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(query_address__get_unconfirmed_history__turbo_block1a_addre BOOST_CHECK_EQUAL(out.at(3).fee, 0u); // coinbase (archived with null single point). } -BOOST_AUTO_TEST_CASE(query_address__get_unconfirmed_history__limited__limited_empty) +BOOST_AUTO_TEST_CASE(query_address__get_unconfirmed_history__limited__depth_limited_empty) { settings settings{}; settings.path = TEST_DIRECTORY; @@ -238,11 +238,11 @@ BOOST_AUTO_TEST_CASE(query_address__get_unconfirmed_history__limited__limited_em const auto& hash = test::block1a_address0; // Limited returned when limit precludes reaching the address cursor (or terminal). - BOOST_CHECK_EQUAL(query.get_unconfirmed_history(cancel, cursor, out, hash, 0, true), error::limited); + BOOST_CHECK_EQUAL(query.get_unconfirmed_history(cancel, cursor, out, hash, 0, true), error::depth_limited); BOOST_CHECK(out.empty()); cursor = address_link::terminal; - BOOST_CHECK_EQUAL(query.get_unconfirmed_history(cancel, cursor, out, hash, 8, true), error::limited); + BOOST_CHECK_EQUAL(query.get_unconfirmed_history(cancel, cursor, out, hash, 8, true), error::depth_limited); BOOST_CHECK(out.empty()); cursor = address_link::terminal; @@ -295,7 +295,7 @@ BOOST_AUTO_TEST_CASE(query_address__get_confirmed_history__turbo_block1a_address BOOST_CHECK_EQUAL(out.at(3).fee, history::missing_prevout); // tx6 } -BOOST_AUTO_TEST_CASE(query_address__get_confirmed_history__limited__limited_empty) +BOOST_AUTO_TEST_CASE(query_address__get_confirmed_history__limited__depth_limited_empty) { settings settings{}; settings.path = TEST_DIRECTORY; @@ -310,11 +310,11 @@ BOOST_AUTO_TEST_CASE(query_address__get_confirmed_history__limited__limited_empt const auto& hash = test::block1a_address0; // Limited returned when limit precludes reaching address cursor (or terminal). - BOOST_CHECK_EQUAL(query.get_confirmed_history(cancel, cursor, out, hash, 0, true), error::limited); + BOOST_CHECK_EQUAL(query.get_confirmed_history(cancel, cursor, out, hash, 0, true), error::depth_limited); BOOST_CHECK(out.empty()); cursor = address_link::terminal; - BOOST_CHECK_EQUAL(query.get_confirmed_history(cancel, cursor, out, hash, 8, true), error::limited); + BOOST_CHECK_EQUAL(query.get_confirmed_history(cancel, cursor, out, hash, 8, true), error::depth_limited); BOOST_CHECK(out.empty()); cursor = address_link::terminal; diff --git a/test/query/address/address_outpoints.cpp b/test/query/address/address_outpoints.cpp index 296727e5..8b46e796 100644 --- a/test/query/address/address_outpoints.cpp +++ b/test/query/address/address_outpoints.cpp @@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE(query_address__get_address_outpoints1__genesis__expected) BOOST_REQUIRE(*out.begin() == query.get_outpoint(query.to_output(0, 0))); } -BOOST_AUTO_TEST_CASE(query_address__get_address_outpoints1__cancel__canceled_false) +BOOST_AUTO_TEST_CASE(query_address__get_address_outpoints1__cancel__query_canceled_false) { settings settings{}; settings.path = TEST_DIRECTORY; @@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(query_address__get_address_outpoints1__cancel__canceled_fal outpoints out{}; std::atomic_bool cancel{ true }; - BOOST_REQUIRE_EQUAL(query.get_address_outpoints(cancel, out, test::genesis_address0), error::canceled); + BOOST_REQUIRE_EQUAL(query.get_address_outpoints(cancel, out, test::genesis_address0), error::query_canceled); BOOST_REQUIRE(out.empty()); } diff --git a/test/query/navigate/navigate_reverse.cpp b/test/query/navigate/navigate_reverse.cpp index 3910580b..e3634fa2 100644 --- a/test/query/navigate/navigate_reverse.cpp +++ b/test/query/navigate/navigate_reverse.cpp @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(query_navigate__to_address_outputs3__terminal__not_reduced) BOOST_REQUIRE_EQUAL(out.at(5), 81u); } -BOOST_AUTO_TEST_CASE(query_navigate__to_address_outputs3__limit__limited) +BOOST_AUTO_TEST_CASE(query_navigate__to_address_outputs3__limit__depth_limited) { settings settings{}; settings.path = TEST_DIRECTORY; @@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE(query_navigate__to_address_outputs3__limit__limited) output_links out{}; address_link end{}; const std::atomic_bool cancel{}; - BOOST_REQUIRE_EQUAL(query.to_address_outputs(cancel, end, out, test::block1a_address0, 4), error::limited); + BOOST_REQUIRE_EQUAL(query.to_address_outputs(cancel, end, out, test::block1a_address0, 4), error::depth_limited); // The limit is applied before deduplication. // There are 6 instances of the `script{ { { opcode::pick } } }` output, limited to 4. @@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(query_navigate__to_address_outputs3__limit__limited) ////BOOST_REQUIRE_EQUAL(out.at(5), 81u); } -BOOST_AUTO_TEST_CASE(query_navigate__to_address_outputs3__stop_mismatch__populated_not_found) +BOOST_AUTO_TEST_CASE(query_navigate__to_address_outputs3__stop_mismatch__populated_invalid_cursor) { settings settings{}; settings.path = TEST_DIRECTORY; @@ -215,7 +215,7 @@ BOOST_AUTO_TEST_CASE(query_navigate__to_address_outputs3__stop_mismatch__populat address_link cursor{ 4242 }; const std::atomic_bool cancel{}; const auto ec = query.to_address_outputs(cancel, cursor, out, test::block1a_address0); - BOOST_REQUIRE_EQUAL(ec, error::not_found); + BOOST_REQUIRE_EQUAL(ec, error::invalid_cursor); // The end was not found but the full list is returned. BOOST_REQUIRE_EQUAL(out.size(), 6u);