From dd178d8b05564ce99573cdeb01e57ca8dd85d9d5 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 1 Jun 2024 01:15:23 -0400 Subject: [PATCH 1/4] Simplify genesis commit. --- include/bitcoin/database/impl/query/confirm.ipp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/include/bitcoin/database/impl/query/confirm.ipp b/include/bitcoin/database/impl/query/confirm.ipp index ab2fe01f..98f1f0fe 100644 --- a/include/bitcoin/database/impl/query/confirm.ipp +++ b/include/bitcoin/database/impl/query/confirm.ipp @@ -393,18 +393,13 @@ bool CLASS::initialize(const block& genesis) NOEXCEPT // ======================================================================== const auto scope = store_.get_transactor(); - const context ctx{}; - if (!set(genesis, ctx)) + if (!set(genesis, {})) return false; - constexpr auto fees = 0u; - constexpr auto sigops = 0u; const auto link = to_header(genesis.hash()); // Unsafe for allocation failure, but only used in store creation. - return set_strong(header_link{ 0 }) - && set_tx_connected(tx_link{ 0 }, ctx, fees, sigops) // tx valid. - && set_block_confirmable(link, fees) // rename, block valid step. + return set_strong(link) && push_candidate(link) && push_confirmed(link); // ======================================================================== From 8eadb4e61908ae2eb1e4014f82e7e4197e413921 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 1 Jun 2024 02:36:21 -0400 Subject: [PATCH 2/4] Add error::txs_confirm. --- include/bitcoin/database/error.hpp | 3 ++- src/error.cpp | 3 ++- test/error.cpp | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/bitcoin/database/error.hpp b/include/bitcoin/database/error.hpp index 0200e43f..96156cd4 100644 --- a/include/bitcoin/database/error.hpp +++ b/include/bitcoin/database/error.hpp @@ -119,7 +119,8 @@ enum error_t : uint8_t /// txs archive txs_header, - txs_txs_put + txs_txs_put, + txs_confirm }; // No current need for error_code equivalence mapping. diff --git a/src/error.cpp b/src/error.cpp index 1012f2c9..74d5026d 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -111,7 +111,8 @@ DEFINE_ERROR_T_MESSAGE_MAP(error) // tx archive { txs_header, "txs_header" }, - { txs_txs_put, "txs_txs_put" } + { txs_txs_put, "txs_txs_put" }, + { txs_confirm, "txs_confirm" } }; DEFINE_ERROR_T_CATEGORY(error, "database", "database code") diff --git a/test/error.cpp b/test/error.cpp index 9d4ecf89..df6b06f0 100644 --- a/test/error.cpp +++ b/test/error.cpp @@ -612,4 +612,13 @@ BOOST_AUTO_TEST_CASE(error_t__code__txs_txs_put__true_exected_message) BOOST_REQUIRE_EQUAL(ec.message(), "txs_txs_put"); } +BOOST_AUTO_TEST_CASE(error_t__code__txs_confirm__true_exected_message) +{ + constexpr auto value = error::txs_confirm; + const auto ec = code(value); + BOOST_REQUIRE(ec); + BOOST_REQUIRE(ec == value); + BOOST_REQUIRE_EQUAL(ec.message(), "txs_confirm"); +} + BOOST_AUTO_TEST_SUITE_END() From f4a05fc5b22df9812ca3b0deb92259b41909c3f8 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 1 Jun 2024 11:30:56 -0400 Subject: [PATCH 3/4] Add checkpointed confirmation with set txs (block). --- .../bitcoin/database/impl/query/archive.ipp | 17 ++++++--- .../bitcoin/database/impl/query/confirm.ipp | 35 +++++++++++-------- include/bitcoin/database/query.hpp | 12 ++++--- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/include/bitcoin/database/impl/query/archive.ipp b/include/bitcoin/database/impl/query/archive.ipp index 1e80ac14..f2213e71 100644 --- a/include/bitcoin/database/impl/query/archive.ipp +++ b/include/bitcoin/database/impl/query/archive.ipp @@ -941,20 +941,21 @@ txs_link CLASS::set_link(const transactions& txs, const header_link& key, size_t size) NOEXCEPT { txs_link out{}; - return set_code(out, txs, key, size) ? txs_link{} : out; + return set_code(out, txs, key, size, false) ? txs_link{} : out; } TEMPLATE code CLASS::set_code(const transactions& txs, const header_link& key, - size_t size) NOEXCEPT + size_t size, bool confirm) NOEXCEPT { txs_link out_fk{}; - return set_code(out_fk, txs, key, size); + return set_code(out_fk, txs, key, size, confirm); } +// protected TEMPLATE code CLASS::set_code(txs_link& out_fk, const transactions& txs, - const header_link& key, size_t size) NOEXCEPT + const header_link& key, size_t size, bool confirm) NOEXCEPT { if (key.is_terminal()) return error::txs_header; @@ -994,7 +995,13 @@ code CLASS::set_code(txs_link& out_fk, const transactions& txs, links }); - return out_fk.is_terminal() ? error::txs_txs_put : error::success; + if (out_fk.is_terminal()) + return error::txs_txs_put; + + if (confirm && !set_strong(key, links, true)) + return error::txs_confirm; + + return error::success; // ======================================================================== } diff --git a/include/bitcoin/database/impl/query/confirm.ipp b/include/bitcoin/database/impl/query/confirm.ipp index 98f1f0fe..0c46bfb6 100644 --- a/include/bitcoin/database/impl/query/confirm.ipp +++ b/include/bitcoin/database/impl/query/confirm.ipp @@ -344,6 +344,23 @@ code CLASS::block_confirmable(const header_link& link) const NOEXCEPT return error::success; } +// protected +TEMPLATE +bool CLASS::set_strong(const header_link& link, const tx_links& txs, + bool positive) NOEXCEPT +{ + return std::all_of(txs.begin(), txs.end(), [&](const tx_link& fk) NOEXCEPT + { + // Clean allocation failure (e.g. disk full), block not confirmed. + return store_.strong_tx.put(fk, table::strong_tx::record + { + {}, + link, + positive + }); + }); +} + TEMPLATE bool CLASS::set_strong(const header_link& link) NOEXCEPT { @@ -351,16 +368,10 @@ bool CLASS::set_strong(const header_link& link) NOEXCEPT if (txs.empty()) return false; - const table::strong_tx::record strong{ {}, link, true }; - // ======================================================================== const auto scope = store_.get_transactor(); - // Clean allocation failure (e.g. disk full), block not confirmed. - return std::all_of(txs.begin(), txs.end(), [&](const tx_link& fk) NOEXCEPT - { - return store_.strong_tx.put(fk, strong); - }); + return set_strong(link, txs, true); // ======================================================================== } @@ -371,16 +382,10 @@ bool CLASS::set_unstrong(const header_link& link) NOEXCEPT if (txs.empty()) return false; - const table::strong_tx::record strong{ {}, link, false }; - // ======================================================================== const auto scope = store_.get_transactor(); - // Clean allocation failure (e.g. disk full), block not unconfirmed. - return std::all_of(txs.begin(), txs.end(), [&](const tx_link& fk) NOEXCEPT - { - return store_.strong_tx.put(fk, strong); - }); + return set_strong(link, txs, false); // ======================================================================== } @@ -393,7 +398,7 @@ bool CLASS::initialize(const block& genesis) NOEXCEPT // ======================================================================== const auto scope = store_.get_transactor(); - if (!set(genesis, {})) + if (!set(genesis, context{})) return false; const auto link = to_header(genesis.hash()); diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index 2f8cf8a1..042c8163 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -350,11 +350,13 @@ class query header_link set_link(const block& block, const context& ctx) NOEXCEPT; header_link set_link(const block& block) NOEXCEPT; - txs_link set_link(const transactions& txs, const header_link& key, size_t size) NOEXCEPT; tx_link set_link(const transaction& tx) NOEXCEPT; - - code set_code(const transactions& txs, const header_link& key, size_t size) NOEXCEPT; + txs_link set_link(const transactions& txs, const header_link& key, + size_t size) NOEXCEPT; + code set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT; + code set_code(const transactions& txs, const header_link& key, size_t size, + bool confirm) NOEXCEPT; bool set_dissasociated(const header_link& key) NOEXCEPT; @@ -450,7 +452,9 @@ class query protected: code set_code(txs_link& out_fk, const transactions& txs, - const header_link& key, size_t size) NOEXCEPT; + const header_link& key, size_t size, bool confirm) NOEXCEPT; + bool set_strong(const header_link& link, const tx_links& txs, + bool positive) NOEXCEPT; /// Translate. /// ----------------------------------------------------------------------- From 1abaa4a37f6df846f1429d2e61da67b1071ec6aa Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 1 Jun 2024 11:54:47 -0400 Subject: [PATCH 4/4] Update tests for genesis non-validation. --- test/query/extent.cpp | 4 ++-- test/query/validate.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/query/extent.cpp b/test/query/extent.cpp index bd882c75..6af49ed1 100644 --- a/test/query/extent.cpp +++ b/test/query/extent.cpp @@ -78,8 +78,8 @@ BOOST_AUTO_TEST_CASE(query_extent__body_sizes__genesis__expected) BOOST_REQUIRE_EQUAL(query.candidate_body_size(), schema::height::minrow); BOOST_REQUIRE_EQUAL(query.confirmed_body_size(), schema::height::minrow); BOOST_REQUIRE_EQUAL(query.strong_tx_body_size(), schema::strong_tx::minrow); - BOOST_REQUIRE_EQUAL(query.validated_tx_body_size(), schema::validated_tx::minrow); - BOOST_REQUIRE_EQUAL(query.validated_bk_body_size(), schema::validated_bk::minrow); + BOOST_REQUIRE_EQUAL(query.validated_tx_body_size(), 0u); + BOOST_REQUIRE_EQUAL(query.validated_bk_body_size(), 0u); BOOST_REQUIRE_EQUAL(query.address_body_size(), schema::address::minrow); BOOST_REQUIRE_EQUAL(query.neutrino_body_size(), 0u); diff --git a/test/query/validate.cpp b/test/query/validate.cpp index 8b727d28..681df7cd 100644 --- a/test/query/validate.cpp +++ b/test/query/validate.cpp @@ -196,9 +196,9 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__confirmable__block_confirm BOOST_REQUIRE(query.set(test::block1, context{})); uint64_t fees{}; - BOOST_REQUIRE_EQUAL(query.get_header_state(0), error::block_confirmable); - BOOST_REQUIRE_EQUAL(query.get_block_state(0), error::block_confirmable); - BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 0), error::block_confirmable); + BOOST_REQUIRE_EQUAL(query.get_header_state(0), error::unvalidated); + BOOST_REQUIRE_EQUAL(query.get_block_state(0), error::unvalidated); + BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 0), error::unvalidated); BOOST_REQUIRE_EQUAL(fees, 0u); BOOST_REQUIRE(query.set_block_confirmable(1, 42));