Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated set_link fns, pass block ref for set_code(txs). #544

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 17 additions & 63 deletions include/bitcoin/database/impl/query/archive.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -678,14 +678,6 @@ typename CLASS::inputs_ptr CLASS::get_spenders(const tx_link& link,
// ----------------------------------------------------------------------------
// The only multitable write query (except initialize/genesis).

// deprecated
TEMPLATE
tx_link CLASS::set_link(const transaction& tx) NOEXCEPT
{
tx_link tx_fk{};
return set_code(tx_fk, tx) ? tx_link{} : tx_fk;
}

TEMPLATE
code CLASS::set_code(const transaction& tx) NOEXCEPT
{
Expand Down Expand Up @@ -876,16 +868,6 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT
// set header
// ----------------------------------------------------------------------------

// deprecated
TEMPLATE
header_link CLASS::set_link(const header& header, const auto& ctx,
bool milestone) NOEXCEPT
{
header_link header_fk{};
return set_code(header_fk, header, ctx, milestone) ? header_link{} :
header_fk;
}

TEMPLATE
code CLASS::set_code(const header& header, const context& ctx,
bool milestone) NOEXCEPT
Expand Down Expand Up @@ -954,16 +936,6 @@ code CLASS::set_code(header_link& out_fk, const header& header,
// set block
// ----------------------------------------------------------------------------

// deprecated
TEMPLATE
header_link CLASS::set_link(const block& block, const auto& ctx,
bool milestone, bool strong) NOEXCEPT
{
header_link header_fk{};
return set_code(header_fk, block, ctx, milestone, strong) ? header_link{} :
header_fk;
}

TEMPLATE
code CLASS::set_code(const block& block, const context& ctx, bool milestone,
bool strong) NOEXCEPT
Expand Down Expand Up @@ -998,34 +970,22 @@ code CLASS::set_code(header_link& out_fk, const block& block,
const context& ctx, bool milestone, bool strong) NOEXCEPT
{
const auto ec = set_code(out_fk, block.header(), ctx, milestone);
if (ec)
return ec;

const auto size = block.serialized_size(true);
return set_code(*block.transactions_ptr(), out_fk, size, strong);
return ec ? ec : set_code(block, out_fk, strong);
}

// set txs from block
// ----------------------------------------------------------------------------

// deprecated
// This sets only the txs of a block with header/context already archived.
TEMPLATE
header_link CLASS::set_link(const block& block, bool strong) NOEXCEPT
{
header_link header_fk{};
return set_code(header_fk, block, strong) ? header_link{} : header_fk;
}
// Block MUST be kept in scope until all transactions are written. ~block()
// releases all memory for parts of itself, due to the custom allocator.

// This sets only the txs of a block with header/context already archived.
TEMPLATE
code CLASS::set_code(const block& block, bool strong) NOEXCEPT
{
header_link unused{};
return set_code(unused, block, strong);
}

// This sets only the txs of a block with header/context already archived.
TEMPLATE
code CLASS::set_code(header_link& out_fk, const block& block,
bool strong) NOEXCEPT
Expand All @@ -1034,40 +994,34 @@ code CLASS::set_code(header_link& out_fk, const block& block,
if (out_fk.is_terminal())
return error::txs_header;

txs_link unused{};
const auto size = block.serialized_size(true);
return set_code(unused, *block.transactions_ptr(), out_fk, size, strong);
return set_code(block, out_fk, strong);
}


// set txs
// ----------------------------------------------------------------------------

// deprecated
TEMPLATE
txs_link CLASS::set_link(const transactions& txs, const header_link& key,
size_t size, bool strong) NOEXCEPT
code CLASS::set_code(const block& block, const header_link& key,
bool strong) NOEXCEPT
{
txs_link txs_fk{};
return set_code(txs_fk, txs, key, size, strong) ? txs_link{} : txs_fk;
txs_link unused{};
return set_code(unused, block, key, strong, block.serialized_size(true));
}

TEMPLATE
code CLASS::set_code(const transactions& txs, const header_link& key,
size_t block_size, bool strong) NOEXCEPT
code CLASS::set_code(const block& block, const header_link& key,
bool strong, size_t block_size) NOEXCEPT
{
txs_link unused{};
return set_code(unused, txs, key, block_size, strong);
return set_code(unused, block, key, strong, block_size);
}

TEMPLATE
code CLASS::set_code(txs_link& out_fk, const transactions& txs,
const header_link& key, size_t block_size, bool strong) NOEXCEPT
code CLASS::set_code(txs_link& out_fk, const block& block,
const header_link& key, bool strong, size_t block_size) NOEXCEPT
{
if (key.is_terminal())
return error::txs_header;

if (txs.empty())
const auto count = block.transactions();
if (is_zero(count))
return error::txs_empty;

////// GUARD (block (txs) redundancy)
Expand All @@ -1079,8 +1033,8 @@ code CLASS::set_code(txs_link& out_fk, const transactions& txs,
code ec{};
tx_link tx_fk{};
tx_links links{};
links.reserve(txs.size());
for (const auto& tx: txs)
links.reserve(count);
for (const auto& tx: *block.transactions_ptr())
{
// Each tx is set under a distinct transactor.
if ((ec = set_code(tx_fk, *tx)))
Expand Down
22 changes: 6 additions & 16 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ class query
/// Set transaction.
code set_code(const transaction& tx) NOEXCEPT;
code set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT;
tx_link set_link(const transaction& tx) NOEXCEPT;

/// Set header (headers-first).
code set_code(const header& header, const context& ctx,
Expand All @@ -413,8 +412,6 @@ class query
const context& ctx, bool milestone, bool=false) NOEXCEPT;
code set_code(header_link& out_fk, const header& header,
const chain_context& ctx, bool milestone, bool=false) NOEXCEPT;
header_link set_link(const header& header, const auto& ctx,
bool milestone) NOEXCEPT;

/// Set full block (blocks-first).
code set_code(const block& block, const context& ctx, bool milestone,
Expand All @@ -425,22 +422,15 @@ class query
bool milestone, bool strong) NOEXCEPT;
code set_code(header_link& out_fk, const block& block,
const chain_context& ctx, bool milestone, bool strong) NOEXCEPT;
header_link set_link(const block& block, const auto& ctx, bool milestone,
bool strong) NOEXCEPT;

/// Set txs (headers-first).
code set_code(const transactions& txs, const header_link& key,
size_t block_size, bool strong) NOEXCEPT;
code set_code(txs_link& out_fk, const transactions& txs,
const header_link& key, size_t block_size, bool strong) NOEXCEPT;
txs_link set_link(const transactions& txs, const header_link& key,
size_t block_size, bool strong) NOEXCEPT;

/// Set block.txs (headers-first).
code set_code(const block& block, bool strong) NOEXCEPT;
code set_code(header_link& out_fk, const block& block,
bool strong) NOEXCEPT;
header_link set_link(const block& block, bool strong) NOEXCEPT;
code set_code(header_link& out_fk, const block& block, bool strong) NOEXCEPT;
code set_code(const block& block, const header_link& key, bool strong) NOEXCEPT;
code set_code(const block& block, const header_link& key, bool strong,
size_t block_size) NOEXCEPT;
code set_code(txs_link& out_fk, const block& block, const header_link& key,
bool strong, size_t block_size) NOEXCEPT;

/// Chain state.
/// -----------------------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions test/query/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_link_header__is_header__expected)
"64636261" // nonce
"119192939495969798999a9b9c9d9e9f229192939495969798999a9b9c9d9e9f"); //merkle_root

header_link link{};
settings settings{};
settings.header_buckets = 10;
settings.path = TEST_DIRECTORY;
Expand All @@ -147,7 +148,8 @@ BOOST_AUTO_TEST_CASE(query_archive__set_link_header__is_header__expected)
// store open/close flushes record count to head.
BOOST_REQUIRE(!query.is_header(header.hash()));
BOOST_REQUIRE(!query.is_associated(0));
BOOST_REQUIRE(!query.set_link(header, test::context, milestone).is_terminal());
BOOST_REQUIRE(!query.set_code(link, header, test::context, milestone));
BOOST_REQUIRE(!link.is_terminal());
BOOST_REQUIRE(query.is_header(header.hash()));
BOOST_REQUIRE(!query.is_associated(0));
table::header::record element1{};
Expand Down Expand Up @@ -284,6 +286,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_link_tx__null_input__expected)
BOOST_REQUIRE_EQUAL(tx_hash, tx.hash(false));

// data_chunk store.
tx_link link{};
settings settings{};
settings.tx_buckets = 5;
settings.point_buckets = 5;
Expand All @@ -292,9 +295,8 @@ BOOST_AUTO_TEST_CASE(query_archive__set_link_tx__null_input__expected)
test::chunk_store store{ settings };
test::query_accessor query{ store };
BOOST_REQUIRE(!store.create(events_handler));
const auto link = query.set_link(tx);
BOOST_REQUIRE(!query.set_code(link, tx));
BOOST_REQUIRE(!link.is_terminal());
////BOOST_REQUIRE_EQUAL(query.set_link(tx), link);
BOOST_REQUIRE(!store.close(events_handler));

BOOST_REQUIRE_EQUAL(store.tx_head(), expected_tx_head);
Expand Down
5 changes: 4 additions & 1 deletion test/query/translate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ BOOST_AUTO_TEST_CASE(query_translate__to_header__always__expected)
settings.path = TEST_DIRECTORY;
test::chunk_store store{ settings };
test::query_accessor query{ store };
header_link link{};

BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success);
BOOST_REQUIRE_EQUAL(query.to_header(test::genesis.hash()), header_link::terminal);
BOOST_REQUIRE(query.initialize(test::genesis));
BOOST_REQUIRE_EQUAL(query.to_header(test::genesis.hash()), 0u);
BOOST_REQUIRE_EQUAL(query.to_header(test::block1.hash()), header_link::terminal);
BOOST_REQUIRE_EQUAL(query.set_link(test::block1.header(), test::context, false), 1u);
BOOST_REQUIRE_EQUAL(query.set_code(link, test::block1.header(), test::context, false), error::success);
BOOST_REQUIRE_EQUAL(link, 1u);
BOOST_REQUIRE_EQUAL(query.to_header(test::block1.hash()), 1u);
}

Expand Down
Loading