From c6dbb792eb7244418937a33b48941f25d41aa8bf Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sun, 2 Jun 2024 14:13:18 -0400 Subject: [PATCH 1/2] Add error::txs_empty. --- include/bitcoin/database/error.hpp | 1 + src/error.cpp | 1 + test/error.cpp | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/include/bitcoin/database/error.hpp b/include/bitcoin/database/error.hpp index 96156cd4..5a659c7b 100644 --- a/include/bitcoin/database/error.hpp +++ b/include/bitcoin/database/error.hpp @@ -118,6 +118,7 @@ enum error_t : uint8_t tx_tx_commit, /// txs archive + txs_empty, txs_header, txs_txs_put, txs_confirm diff --git a/src/error.cpp b/src/error.cpp index 74d5026d..a27f0905 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -110,6 +110,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error) { tx_tx_commit, "tx_tx_commit" }, // tx archive + { txs_empty, "txs_empty" }, { txs_header, "txs_header" }, { txs_txs_put, "txs_txs_put" }, { txs_confirm, "txs_confirm" } diff --git a/test/error.cpp b/test/error.cpp index df6b06f0..e2167fd7 100644 --- a/test/error.cpp +++ b/test/error.cpp @@ -603,6 +603,15 @@ BOOST_AUTO_TEST_CASE(error_t__code__txs_header__true_exected_message) BOOST_REQUIRE_EQUAL(ec.message(), "txs_header"); } +BOOST_AUTO_TEST_CASE(error_t__code__txs_empty__true_exected_message) +{ + constexpr auto value = error::txs_empty; + const auto ec = code(value); + BOOST_REQUIRE(ec); + BOOST_REQUIRE(ec == value); + BOOST_REQUIRE_EQUAL(ec.message(), "txs_empty"); +} + BOOST_AUTO_TEST_CASE(error_t__code__txs_txs_put__true_exected_message) { constexpr auto value = error::txs_txs_put; From e32eb7cf30141fe486ee77f8c68142bf70f9251c Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sun, 2 Jun 2024 14:13:42 -0400 Subject: [PATCH 2/2] Check for txs.empty() upon association. --- include/bitcoin/database/impl/query/archive.ipp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/bitcoin/database/impl/query/archive.ipp b/include/bitcoin/database/impl/query/archive.ipp index ced0f21d..a7535575 100644 --- a/include/bitcoin/database/impl/query/archive.ipp +++ b/include/bitcoin/database/impl/query/archive.ipp @@ -965,6 +965,9 @@ code CLASS::set_code(txs_link& out_fk, const transactions& txs, if (key.is_terminal()) return error::txs_header; + if (txs.empty()) + return error::txs_empty; + ////// GUARD (block (txs) redundancy) ////// This is only fully effective if there is a single database thread. ////// Guard must be lifted for an existing top malleable association so