Skip to content

Commit

Permalink
Merge 7871a3a into 8f9b277
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Feb 29, 2024
2 parents 8f9b277 + 7871a3a commit 2fe739e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/bitcoin/database/impl/query/validate.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ code CLASS::get_header_state(const header_link& link) const NOEXCEPT
return to_block_code(valid.code);
}

TEMPLATE
code CLASS::get_block_state(const header_link& link) const NOEXCEPT
{
const auto fk = store_.validated_bk.first(link);
if (fk.is_terminal())
return is_associated(link) ? error::unvalidated : error::unassociated;

table::validated_bk::slab_get_code valid{};
if (!store_.validated_bk.get(fk, valid))
return error::integrity;

// Should only be pre/confirmable if associated (not verified).
// Fees only valid if block_preconfirmable or block_confirmable.
return to_block_code(valid.code);
}

TEMPLATE
code CLASS::get_block_state(uint64_t& fees,
const header_link& link) const NOEXCEPT
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class query
/// -----------------------------------------------------------------------

code get_header_state(const header_link& link) const NOEXCEPT;
code get_block_state(const header_link& link) const NOEXCEPT;
code get_block_state(uint64_t& fees, const header_link& link) const NOEXCEPT;
code get_tx_state(const tx_link& link, const context& ctx) const NOEXCEPT;
code get_tx_state(uint64_t& fee, size_t& sigops, const tx_link& link,
Expand Down
7 changes: 7 additions & 0 deletions test/query/validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__invalid_link__unassociated

uint64_t fees{};
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::unvalidated);
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::unassociated);
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::unassociated);
BOOST_REQUIRE_EQUAL(fees, 0u);
}
Expand All @@ -162,6 +163,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unassociated_link__unassoc

uint64_t fees{};
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::unvalidated);
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::unassociated);
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::unassociated);
BOOST_REQUIRE_EQUAL(fees, 0u);
}
Expand All @@ -178,6 +180,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unvalidated_link__unvalida

uint64_t fees{};
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::unvalidated);
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::unvalidated);
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::unvalidated);
BOOST_REQUIRE_EQUAL(fees, 0u);
}
Expand All @@ -194,11 +197,13 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__confirmable__block_confirm

uint64_t fees{};
BOOST_REQUIRE_EQUAL(query.get_header_state(0), error::block_confirmable);
BOOST_REQUIRE_EQUAL(query.get_block_state(0), error::block_confirmable);
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 0), error::block_confirmable);
BOOST_REQUIRE_EQUAL(fees, 0u);

BOOST_REQUIRE(query.set_block_confirmable(1, 42));
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::block_confirmable);
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::block_confirmable);
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::block_confirmable);
BOOST_REQUIRE_EQUAL(fees, 42u);
}
Expand All @@ -216,6 +221,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__preconfirmable__block_prec
uint64_t fees{};
BOOST_REQUIRE(query.set_block_preconfirmable(1));
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::block_preconfirmable);
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::block_preconfirmable);
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::block_preconfirmable);
BOOST_REQUIRE_EQUAL(fees, 0u);
}
Expand All @@ -233,6 +239,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unconfirmable__block_uncon
uint64_t fees{};
BOOST_REQUIRE(query.set_block_unconfirmable(1));
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::block_unconfirmable);
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::block_unconfirmable);
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::block_unconfirmable);
BOOST_REQUIRE_EQUAL(fees, 0u);
}
Expand Down

0 comments on commit 2fe739e

Please sign in to comment.