Skip to content

Commit

Permalink
Change get_milestone() to is_milestone().
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Jun 12, 2024
1 parent f56ba29 commit abbcb77
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 48 deletions.
7 changes: 7 additions & 0 deletions include/bitcoin/database/impl/query/archive.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ inline bool CLASS::is_coinbase(const tx_link& link) const NOEXCEPT
return store_.tx.get(link, tx) && tx.coinbase;
}

TEMPLATE
inline bool CLASS::is_milestone(const header_link& link) const NOEXCEPT
{
table::header::get_milestone header{};
return store_.header.get(link, header) && header.milestone;
}

TEMPLATE
inline bool CLASS::is_malleated64(const block& block) const NOEXCEPT
{
Expand Down
12 changes: 0 additions & 12 deletions include/bitcoin/database/impl/query/validate.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,6 @@ bool CLASS::get_work(uint256_t& work, const header_link& link) const NOEXCEPT
return result;
}

TEMPLATE
bool CLASS::get_milestone(bool& milestone,
const header_link& link) const NOEXCEPT
{
table::header::get_milestone header{};
if (!store_.header.get(link, header))
return false;

milestone = header.milestone;
return true;
}

////TEMPLATE
////bool CLASS::get_check_context(context& ctx, hash_digest& hash,
//// uint32_t& timestamp, const header_link& link) const NOEXCEPT
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class query
inline bool is_malleated64(const block& block) const NOEXCEPT;
inline bool is_malleable64(const header_link& link) const NOEXCEPT;
inline bool is_associated(const header_link& link) const NOEXCEPT;
inline bool is_milestone(const header_link& link) const NOEXCEPT;

bool set(const header& header, const chain_context& ctx,
bool milestone) NOEXCEPT;
Expand Down Expand Up @@ -427,7 +428,6 @@ class query
bool get_work(uint256_t& work, const header_link& link) const NOEXCEPT;
bool get_context(context& ctx, const header_link& link) const NOEXCEPT;
bool get_version(uint32_t& version, const header_link& link) const NOEXCEPT;
bool get_milestone(bool& milestone, const header_link& link) const NOEXCEPT;
bool get_timestamp(uint32_t& timestamp,
const header_link& link) const NOEXCEPT;

Expand Down
27 changes: 27 additions & 0 deletions test/query/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,33 @@ BOOST_AUTO_TEST_CASE(query_archive__is_malleable64__malleable__true)
BOOST_REQUIRE_EQUAL(query.get_candidate_size(42), candidate_size);
}

BOOST_AUTO_TEST_CASE(query_archive__is_milestone__genesis__false)
{
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.is_milestone(0));
BOOST_REQUIRE(!query.is_milestone(1));
}

BOOST_AUTO_TEST_CASE(query_archive__is_milestone__set__expected)
{
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::block1, context{}, true, false));
BOOST_REQUIRE(query.set(test::block2, context{}, false, false));;
BOOST_REQUIRE(!query.is_milestone(0));
BOOST_REQUIRE(query.is_milestone(1));
BOOST_REQUIRE(!query.is_milestone(2));
}

BOOST_AUTO_TEST_CASE(query_archive__get_header__invalid_parent__expected)
{
constexpr auto root = system::base16_array("119192939495969798999a9b9c9d9e9f229192939495969798999a9b9c9d9e9f");
Expand Down
35 changes: 0 additions & 35 deletions test/query/validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,41 +88,6 @@ BOOST_AUTO_TEST_CASE(query_validate__get_bits__genesis__expected)
BOOST_REQUIRE_EQUAL(bits, 0x1d00ffff_u32);
}

BOOST_AUTO_TEST_CASE(query_validate__get_milestone__genesis__false)
{
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));

bool milestone{};
BOOST_REQUIRE(!query.get_milestone(milestone, 1));
BOOST_REQUIRE(query.get_milestone(milestone, 0));
BOOST_REQUIRE(!milestone);
}

BOOST_AUTO_TEST_CASE(query_validate__get_milestone__set__expected)
{
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::block1, context{}, true, false));
BOOST_REQUIRE(query.set(test::block2, context{}, false, false));

bool milestone{};
BOOST_REQUIRE(query.get_milestone(milestone, 0));
BOOST_REQUIRE(!milestone);
BOOST_REQUIRE(query.get_milestone(milestone, 1));
BOOST_REQUIRE(milestone);
BOOST_REQUIRE(query.get_milestone(milestone, 2));
BOOST_REQUIRE(!milestone);
}

BOOST_AUTO_TEST_CASE(query_validate__get_context__genesis__default)
{
settings settings{};
Expand Down

0 comments on commit abbcb77

Please sign in to comment.