Skip to content

Commit

Permalink
Merge pull request #504 from evoskuil/master
Browse files Browse the repository at this point in the history
Disable parallel confirmable methods.
  • Loading branch information
evoskuil committed Jun 26, 2024
2 parents 34b3e50 + 70a6fbe commit 85e0576
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 71 deletions.
130 changes: 68 additions & 62 deletions include/bitcoin/database/impl/query/confirm.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions test/query/translate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 85e0576

Please sign in to comment.