From 70a6fbe7769b17a70364c3b4882ac81cae0e26da Mon Sep 17 00:00:00 2001 From: evoskuil Date: Wed, 26 Jun 2024 17:51:55 -0400 Subject: [PATCH] Disable parallel confirmable methods. --- .../bitcoin/database/impl/query/confirm.ipp | 130 +++++++++--------- test/query/translate.cpp | 16 +-- 2 files changed, 75 insertions(+), 71 deletions(-) diff --git a/include/bitcoin/database/impl/query/confirm.ipp b/include/bitcoin/database/impl/query/confirm.ipp index e73c4d14..fec0a03b 100644 --- a/include/bitcoin/database/impl/query/confirm.ipp +++ b/include/bitcoin/database/impl/query/confirm.ipp @@ -322,6 +322,74 @@ code CLASS::unspent_duplicates(const tx_link& coinbase, return is_zero(unspent) ? error::integrity : error::success; } +// protected +TEMPLATE +spend_sets CLASS::to_spend_sets(const header_link& link) const NOEXCEPT +{ + const auto txs = to_transactions(link); + if (txs.empty()) + return {}; + + // Coinbase optimization. + spend_sets out{ txs.size() }; + out.front().tx = txs.front(); + if (is_one(out.size())) + return out; + + spend_sets sets{}; + sets.reserve(sub1(txs.size())); + for (auto tx = std::next(txs.begin()); tx != txs.end(); ++tx) + sets.push_back(to_spend_set(*tx)); + + return sets; +} + +// Used by node for ASIO concurrency by tx. +TEMPLATE +code CLASS::tx_confirmable(const tx_link& link, + const context& ctx) const NOEXCEPT +{ + code ec{}; + const auto set = to_spend_set(link); + for (const auto& spend: set.spends) + { + if ((ec = unspendable_prevout(spend.point_fk, spend.sequence, + set.version, ctx))) + return ec; + + if (is_spent_prevout(spend.prevout(), link)) + return error::confirmed_double_spend; + } + + return error::success; +} + +// Used by node for sequential by block (unsed). +// split(0) 403 secs for 400k-410k +TEMPLATE +code CLASS::block_confirmable(const header_link& link) const NOEXCEPT +{ + context ctx{}; + if (!get_context(ctx, link)) + return error::integrity; + + code ec{}; + const auto txs = to_transactions(link); + if (txs.empty()) + return ec; + + if ((ec = unspent_duplicates(txs.front(), ctx))) + return ec; + + for (auto tx = std::next(txs.begin()); tx != txs.end(); ++tx) + if ((ec = tx_confirmable(*tx, ctx))) + return ec; + + return ec; +} + +#if defined(UNDEFINED) + // protected TEMPLATE spend_sets CLASS::to_spend_sets(const header_link& link) const NOEXCEPT @@ -407,68 +475,6 @@ code CLASS::block_confirmable(const header_link& link) const NOEXCEPT return ec; } -// Used by node for ASIO concurrency by tx. -TEMPLATE -code CLASS::tx_confirmable(const tx_link& link, - const context& ctx) const NOEXCEPT -{ - code ec{}; - const auto set = to_spend_set(link); - for (const auto& spend: set.spends) - { - if ((ec = unspendable_prevout(spend.point_fk, spend.sequence, - set.version, ctx))) - return ec; - - if (is_spent_prevout(spend.prevout(), link)) - return error::confirmed_double_spend; - } - - return error::success; -} - -#if defined(UNDEFINED) - -// protected -TEMPLATE -spend_sets CLASS::to_spend_sets( - const header_link& link) const NOEXCEPT -{ - const auto txs = to_transactions(link); - if (txs.size() <= one) - return {}; - - spend_sets sets{}; - sets.reserve(sub1(txs.size())); - for (auto tx = std::next(txs.begin()); tx != txs.end(); ++tx) - sets.push_back(to_spend_set(*tx)); - - return sets; -} - -// split(0) 403 secs for 400k-410k -TEMPLATE -code CLASS::block_confirmable(const header_link& link) const NOEXCEPT -{ - context ctx{}; - if (!get_context(ctx, link)) - return error::integrity; - - code ec{}; - const auto txs = to_transactions(link); - if (txs.empty()) - return ec; - - if ((ec = unspent_duplicates(txs.front(), ctx))) - return ec; - - for (auto tx = std::next(txs.begin()); tx != txs.end(); ++tx) - if ((ec = tx_confirmable(*tx, ctx))) - return ec; - - return ec; -} - // split(1) 446 secs for 400k-410k TEMPLATE code CLASS::block_confirmable(const header_link& link) const NOEXCEPT diff --git a/test/query/translate.cpp b/test/query/translate.cpp index ad8f5a4a..983ada10 100644 --- a/test/query/translate.cpp +++ b/test/query/translate.cpp @@ -488,16 +488,14 @@ BOOST_AUTO_TEST_CASE(query_translate__to_spend_sets__populated__expected) "02000000""b1""0179" "03000000""b2""0179")); - // to_spend_sets keys on first-tx-ness, so only one input despite two points (second point). + // to_spend_sets keys on first-tx-ness, so only one input despite two points. const auto spends = query.to_spend_sets_(2); - BOOST_REQUIRE_EQUAL(spends.size(), 2u); - BOOST_REQUIRE_EQUAL(spends[0].tx, 2u); - BOOST_REQUIRE_EQUAL(spends[1].tx, 3u); - BOOST_REQUIRE_EQUAL(spends[0].spends.size(), 0u); - BOOST_REQUIRE_EQUAL(spends[1].spends.size(), 1u); - BOOST_REQUIRE_EQUAL(spends[1].spends[0].point_fk, 1u); - BOOST_REQUIRE_EQUAL(spends[1].spends[0].point_index, 0u); - BOOST_REQUIRE_EQUAL(spends[1].spends[0].sequence, 0xb2u); + BOOST_REQUIRE_EQUAL(spends.size(), 1u); + BOOST_REQUIRE_EQUAL(spends[0].tx, 3u); + BOOST_REQUIRE_EQUAL(spends[0].spends.size(), 1u); + BOOST_REQUIRE_EQUAL(spends[0].spends[0].point_fk, 1u); + BOOST_REQUIRE_EQUAL(spends[0].spends[0].point_index, 0u); + BOOST_REQUIRE_EQUAL(spends[0].spends[0].sequence, 0xb2u); } // to_output_tx/to_output/to_tx_outputs/to_block_outputs