Skip to content

Commit

Permalink
Merge pull request #528 from evoskuil/master
Browse files Browse the repository at this point in the history
Stub in changes to neutrino queries.
  • Loading branch information
evoskuil authored Jan 5, 2025
2 parents eca8684 + dbc1a1c commit ab4072d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 44 deletions.
46 changes: 36 additions & 10 deletions include/bitcoin/database/impl/query/optional.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ bool CLASS::to_minimum_unspent_outputs(output_links& out,
// ----------------------------------------------------------------------------

TEMPLATE
bool CLASS::get_filter(filter& out, const header_link& link) const NOEXCEPT
bool CLASS::get_filter_body(filter& out, const header_link& link) const NOEXCEPT
{
table::neutrino::get_filter neutrino{};
if (!store_.neutrino.find(link, neutrino))
Expand All @@ -199,8 +199,8 @@ bool CLASS::get_filter_head(hash_digest& out,
}

TEMPLATE
bool CLASS::set_filter(const header_link& link, const hash_digest& filter_head,
const filter& filter) NOEXCEPT
bool CLASS::set_filter_body(const header_link&,
const filter&) NOEXCEPT
{
////// GUARD (filter redundancy)
////// This is only fully effective if there is a single database thread.
Expand All @@ -210,14 +210,40 @@ bool CLASS::set_filter(const header_link& link, const hash_digest& filter_head,
// ========================================================================
const auto scope = store_.get_transactor();

// Clean single allocation failure (e.g. disk full).
return store_.neutrino.put(link, table::neutrino::put_ref
{
{},
filter_head,
filter
});
////// Clean single allocation failure (e.g. disk full).
////return store_.neutrino.put(link, table::neutrino::put_ref
////{
//// {},
//// filter_head,
//// filter
////});
// ========================================================================

return false;
}

TEMPLATE
bool CLASS::set_filter_head(const header_link&,
const hash_digest&) NOEXCEPT
{
////// GUARD (filter redundancy)
////// This is only fully effective if there is a single database thread.
////if (!to_filter(link).is_terminal())
//// return true;

// ========================================================================
const auto scope = store_.get_transactor();

////// Clean single allocation failure (e.g. disk full).
////return store_.neutrino.put(link, table::neutrino::put_ref
////{
//// {},
//// filter_head,
//// filter
////});
// ========================================================================

return false;
}

////// Buffer (surrogate-keyed).
Expand Down
10 changes: 5 additions & 5 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,11 @@ class query
uint64_t value) const NOEXCEPT;

/// Neutrino, set during validation with prevouts (surrogate-keyed).
bool get_filter(filter& out, const header_link& link) const NOEXCEPT;
bool get_filter_head(hash_digest& out,
const header_link& link) const NOEXCEPT;
bool set_filter(const header_link& link, const hash_digest& head,
const filter& body) NOEXCEPT;
bool get_filter_body(filter& out, const header_link& link) const NOEXCEPT;
bool get_filter_head(hash_digest& out, const header_link& link) const NOEXCEPT;
bool set_filter_body(const header_link& link, const filter& body) NOEXCEPT;
bool set_filter_head(const header_link& link,
const hash_digest& head) NOEXCEPT;

protected:
/// Translate.
Expand Down
58 changes: 29 additions & 29 deletions test/query/optional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,35 +142,35 @@ BOOST_AUTO_TEST_CASE(query_optional__to_minimum_unspent_outputs__below__included
BOOST_REQUIRE_EQUAL(out.front(), 0);
}

BOOST_AUTO_TEST_CASE(query_optional__set_filter__get_filter_and_head__expected)
{
const auto& filter_head0 = system::null_hash;
const auto filter0 = system::base16_chunk("0102030405060708090a0b0c0d0e0f");
const auto& filter_head1 = system::one_hash;
const auto filter1 = system::base16_chunk("102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f0");

settings settings{};
settings.path = TEST_DIRECTORY;
test::chunk_store store{ settings };
test::query_accessor query{ store };
BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success);
BOOST_REQUIRE(query.initialize(test::genesis));
BOOST_REQUIRE(query.set(test::block1a, context{}, false, false));
BOOST_REQUIRE(query.set_filter(0, filter_head0, filter0));
BOOST_REQUIRE(query.set_filter(1, filter_head1, filter1));

hash_digest head{};
BOOST_REQUIRE(query.get_filter_head(head, 0));
BOOST_REQUIRE_EQUAL(head, filter_head0);
BOOST_REQUIRE(query.get_filter_head(head, 1));
BOOST_REQUIRE_EQUAL(head, filter_head1);

system::data_chunk out{};
BOOST_REQUIRE(query.get_filter(out, 0));
BOOST_REQUIRE_EQUAL(out, filter0);
BOOST_REQUIRE(query.get_filter(out, 1));
BOOST_REQUIRE_EQUAL(out, filter1);
}
////BOOST_AUTO_TEST_CASE(query_optional__set_filter__get_filter_and_head__expected)
////{
//// const auto& filter_head0 = system::null_hash;
//// const auto filter0 = system::base16_chunk("0102030405060708090a0b0c0d0e0f");
//// const auto& filter_head1 = system::one_hash;
//// const auto filter1 = system::base16_chunk("102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f0");
////
//// settings settings{};
//// settings.path = TEST_DIRECTORY;
//// test::chunk_store store{ settings };
//// test::query_accessor query{ store };
//// BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success);
//// BOOST_REQUIRE(query.initialize(test::genesis));
//// BOOST_REQUIRE(query.set(test::block1a, context{}, false, false));
//// BOOST_REQUIRE(query.set_filter(0, filter_head0, filter0));
//// BOOST_REQUIRE(query.set_filter(1, filter_head1, filter1));
////
//// hash_digest head{};
//// BOOST_REQUIRE(query.get_filter_head(head, 0));
//// BOOST_REQUIRE_EQUAL(head, filter_head0);
//// BOOST_REQUIRE(query.get_filter_head(head, 1));
//// BOOST_REQUIRE_EQUAL(head, filter_head1);
////
//// system::data_chunk out{};
//// BOOST_REQUIRE(query.get_filter(out, 0));
//// BOOST_REQUIRE_EQUAL(out, filter0);
//// BOOST_REQUIRE(query.get_filter(out, 1));
//// BOOST_REQUIRE_EQUAL(out, filter1);
////}

////BOOST_AUTO_TEST_CASE(query_optional__set_buffered_tx__get_buffered_tx__expected)
////{
Expand Down

0 comments on commit ab4072d

Please sign in to comment.