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

Add bip30_deactivate hash to state populations, adapt to system. #427

Merged
merged 3 commits into from
Mar 29, 2024
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
4 changes: 2 additions & 2 deletions include/bitcoin/database/impl/query/archive.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ header_link CLASS::set_link(const block& block,
// Map chain context into database context.
return set_link(block, context
{
system::possible_narrow_cast<context::flag::integer>(ctx.forks),
system::possible_narrow_cast<context::flag::integer>(ctx.flags),
system::possible_narrow_cast<context::block::integer>(ctx.height),
ctx.median_time_past
});
Expand All @@ -654,7 +654,7 @@ header_link CLASS::set_link(const header& header,
// Map chain context into database context.
return set_link(header, context
{
system::possible_narrow_cast<context::flag::integer>(ctx.forks),
system::possible_narrow_cast<context::flag::integer>(ctx.flags),
system::possible_narrow_cast<context::block::integer>(ctx.height),
ctx.median_time_past
});
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/database/impl/query/confirm.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ TEMPLATE
inline error::error_t CLASS::spendable_prevout(const tx_link& link,
uint32_t sequence, const context& ctx) const NOEXCEPT
{
constexpr auto bip68_rule = system::chain::forks::bip68_rule;
constexpr auto bip68_rule = system::chain::flags::bip68_rule;

context out{};
if (!get_context(out, to_block(link)))
Expand Down Expand Up @@ -245,7 +245,7 @@ TEMPLATE
error::error_t CLASS::locked_prevout(const point_link& link, uint32_t sequence,
const context& ctx) const NOEXCEPT
{
if (!script::is_enabled(ctx.flags, system::chain::forks::bip68_rule))
if (!script::is_enabled(ctx.flags, system::chain::flags::bip68_rule))
return error::success;

// Get hash from point, search for prevout tx and get its link.
Expand Down
26 changes: 22 additions & 4 deletions include/bitcoin/database/impl/query/context.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,19 @@ bool CLASS::get_candidate_timestamp(uint32_t& time, size_t height,
}

TEMPLATE
bool CLASS::populate_candidate_bip9(chain_state::data& data,
bool CLASS::populate_candidate_hash(chain_state::data& data,
const chain_state::map& map, const header& header,
size_t header_height) const NOEXCEPT
{
if (map.bip30_deactivate_height != chain_state::map::unrequested)
{
if (header_height == map.bip30_deactivate_height)
data.bip30_deactivate_hash = header.hash();
else
data.bip30_deactivate_hash = get_header_key(
to_candidate(map.bip30_deactivate_height));
}

if (map.bip9_bit0_height != chain_state::map::unrequested)
{
if (header_height == map.bip9_bit0_height)
Expand Down Expand Up @@ -196,7 +205,7 @@ bool CLASS::populate_candidate_all(chain_state::data& data,

return !link.is_terminal() &&
populate_candidate_work(data, header, height) &&
populate_candidate_bip9(data, map, header, height) &&
populate_candidate_hash(data, map, header, height) &&
populate_candidate_bits(data, map, header, height) &&
populate_candidate_versions(data, map, header, height) &&
populate_candidate_timestamps(data, map, header, height);
Expand Down Expand Up @@ -282,10 +291,19 @@ bool CLASS::get_confirmed_timestamp(uint32_t& time, size_t height,
}

TEMPLATE
bool CLASS::populate_confirmed_bip9(chain_state::data& data,
bool CLASS::populate_confirmed_hash(chain_state::data& data,
const chain_state::map& map, const header& header,
size_t header_height) const NOEXCEPT
{
if (map.bip30_deactivate_height != chain_state::map::unrequested)
{
if (header_height == map.bip30_deactivate_height)
data.bip30_deactivate_hash = header.hash();
else
data.bip30_deactivate_hash = get_header_key(
to_candidate(map.bip30_deactivate_height));
}

if (map.bip9_bit0_height != chain_state::map::unrequested)
{
if (header_height == map.bip9_bit0_height)
Expand Down Expand Up @@ -398,7 +416,7 @@ bool CLASS::populate_confirmed_all(chain_state::data& data,

return !link.is_terminal() &&
populate_confirmed_work(data, header, height) &&
populate_confirmed_bip9(data, map, header, height) &&
populate_confirmed_hash(data, map, header, height) &&
populate_confirmed_bits(data, map, header, height) &&
populate_confirmed_versions(data, map, header, height) &&
populate_confirmed_timestamps(data, map, header, height);
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class query
const header& header, size_t header_height) const NOEXCEPT;

// This is currently based on archived activation only.
bool populate_candidate_bip9(chain_state::data& data,
bool populate_candidate_hash(chain_state::data& data,
const chain_state::map& map, const header& header,
size_t header_height) const NOEXCEPT;

Expand Down Expand Up @@ -440,7 +440,7 @@ class query
const header& header, size_t header_height) const NOEXCEPT;

// This is currently based on archived activation only.
bool populate_confirmed_bip9(chain_state::data& data,
bool populate_confirmed_hash(chain_state::data& data,
const chain_state::map& map, const header& header,
size_t header_height) const NOEXCEPT;

Expand Down
4 changes: 2 additions & 2 deletions test/query/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ struct query_archive_setup_fixture

BOOST_FIXTURE_TEST_SUITE(query_archive_tests, query_archive_setup_fixture)

// ensure context::flags is same size as chain_context::forks.
static_assert(is_same_type<database::context::flag::integer, decltype(system::chain::context{}.forks)>);
// ensure context::flags is same size as chain_context::flags.
static_assert(is_same_type<database::context::flag::integer, decltype(system::chain::context{}.flags)>);

// nop event handler.
const auto events = [](auto, auto) {};
Expand Down
2 changes: 1 addition & 1 deletion test/query/confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_mature__coinbase__expected)
BOOST_REQUIRE(query.is_mature(query.to_spend(2, 0), 101));
}

constexpr auto bip68 = system::chain::forks::bip68_rule;
constexpr auto bip68 = system::chain::flags::bip68_rule;

BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__bad_link__integrity)
{
Expand Down
18 changes: 9 additions & 9 deletions test/query/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(query_context__get_candidate_chain_state__genesis__expected

const auto state = query.get_candidate_chain_state(system_settings);
BOOST_REQUIRE(state);
BOOST_REQUIRE_EQUAL(state->forks(), expected.forks);
BOOST_REQUIRE_EQUAL(state->flags(), expected.flags);
BOOST_REQUIRE_EQUAL(state->height(), expected.height);
BOOST_REQUIRE_EQUAL(state->timestamp(), expected.timestamp);
BOOST_REQUIRE_EQUAL(state->work_required(), expected.work_required);
Expand All @@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(query_context__get_candidate_chain_state__block1__expected)
const system::settings system_settings{ system::chain::selection::mainnet };
const system::chain::context expected
{
131211u, // forks
131211u, // flags
test::block1.header().timestamp(), // timestamp
test::genesis.header().timestamp(), // mtp
1u, // height
Expand All @@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE(query_context__get_candidate_chain_state__block1__expected)
// Not actually contributory.
const database::context context
{
expected.forks,
expected.flags,
system::possible_narrow_cast<uint32_t>(expected.height),
expected.median_time_past
};
Expand All @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(query_context__get_candidate_chain_state__block1__expected)

const auto state = query.get_candidate_chain_state(system_settings);
BOOST_REQUIRE(state);
BOOST_REQUIRE_EQUAL(state->forks(), expected.forks);
BOOST_REQUIRE_EQUAL(state->flags(), expected.flags);
BOOST_REQUIRE_EQUAL(state->height(), expected.height);
BOOST_REQUIRE_EQUAL(state->timestamp(), expected.timestamp);
BOOST_REQUIRE_EQUAL(state->work_required(), expected.work_required);
Expand All @@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(query_context__get_confirmed_chain_state__testnet_genesis__
const uint256_t expected_cumulative_work{};
const system::chain::context expected
{
131211u,
131210u,
genesis.header().timestamp(),
0u,
0u,
Expand All @@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE(query_context__get_confirmed_chain_state__testnet_genesis__

const auto state = query.get_confirmed_chain_state(system_settings);
BOOST_REQUIRE(state);
BOOST_REQUIRE_EQUAL(state->forks(), expected.forks);
BOOST_REQUIRE_EQUAL(state->flags(), expected.flags);
BOOST_REQUIRE_EQUAL(state->height(), expected.height);
BOOST_REQUIRE_EQUAL(state->timestamp(), expected.timestamp);
BOOST_REQUIRE_EQUAL(state->work_required(), expected.work_required);
Expand All @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(query_context__get_confirmed_chain_state__block1__expected)
const system::settings system_settings{ system::chain::selection::mainnet };
const system::chain::context expected
{
131211u, // forks
131211u, // flags
test::block1.header().timestamp(), // timestamp
test::genesis.header().timestamp(), // mtp
1u, // height
Expand All @@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(query_context__get_confirmed_chain_state__block1__expected)
// Not actually contributory.
const database::context context
{
expected.forks,
expected.flags,
system::possible_narrow_cast<uint32_t>(expected.height),
expected.median_time_past
};
Expand All @@ -183,7 +183,7 @@ BOOST_AUTO_TEST_CASE(query_context__get_confirmed_chain_state__block1__expected)

const auto state = query.get_confirmed_chain_state(system_settings);
BOOST_REQUIRE(state);
BOOST_REQUIRE_EQUAL(state->forks(), expected.forks);
BOOST_REQUIRE_EQUAL(state->flags(), expected.flags);
BOOST_REQUIRE_EQUAL(state->height(), expected.height);
BOOST_REQUIRE_EQUAL(state->timestamp(), expected.timestamp);
BOOST_REQUIRE_EQUAL(state->work_required(), expected.work_required);
Expand Down
10 changes: 5 additions & 5 deletions test/query/initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,15 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_unassociated_above__gapped_candidate_
const auto it2 = unassociated0.find(test::block2.hash());
BOOST_REQUIRE(it2 != unassociated0.end());
BOOST_REQUIRE_EQUAL(it2->link, 2u);
BOOST_REQUIRE_EQUAL(it2->context.forks, context2.flags);
BOOST_REQUIRE_EQUAL(it2->context.flags, context2.flags);
BOOST_REQUIRE_EQUAL(it2->context.timestamp, test::block2.header().timestamp());
BOOST_REQUIRE_EQUAL(it2->context.median_time_past, context2.mtp);
BOOST_REQUIRE_EQUAL(it2->context.height, context2.height);

const auto it3 = unassociated0.find(test::block3.hash());
BOOST_REQUIRE(it3 != unassociated0.end());
BOOST_REQUIRE_EQUAL(it3->link, 3u);
BOOST_REQUIRE_EQUAL(it3->context.forks, context3.flags);
BOOST_REQUIRE_EQUAL(it3->context.flags, context3.flags);
BOOST_REQUIRE_EQUAL(it3->context.timestamp, test::block3.header().timestamp());
BOOST_REQUIRE_EQUAL(it3->context.median_time_past, context3.mtp);
BOOST_REQUIRE_EQUAL(it3->context.height, context3.height);
Expand All @@ -405,14 +405,14 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_unassociated_above__gapped_candidate_

const auto it2s = unassociated1.find(context2.height);
BOOST_REQUIRE(it2s != unassociated1.pos_end());
BOOST_REQUIRE_EQUAL(it2s->context.forks, context2.flags);
BOOST_REQUIRE_EQUAL(it2s->context.flags, context2.flags);
BOOST_REQUIRE_EQUAL(it2s->context.timestamp, test::block2.header().timestamp());
BOOST_REQUIRE_EQUAL(it2s->context.median_time_past, context2.mtp);
BOOST_REQUIRE_EQUAL(it2s->context.height, context2.height);

const auto it3s = unassociated1.find(context3.height);
BOOST_REQUIRE(it3s != unassociated1.pos_end());
BOOST_REQUIRE_EQUAL(it3s->context.forks, context3.flags);
BOOST_REQUIRE_EQUAL(it3s->context.flags, context3.flags);
BOOST_REQUIRE_EQUAL(it3s->context.timestamp, test::block3.header().timestamp());
BOOST_REQUIRE_EQUAL(it3s->context.median_time_past, context3.mtp);
BOOST_REQUIRE_EQUAL(it3s->context.height, context3.height);
Expand All @@ -423,7 +423,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_unassociated_above__gapped_candidate_

const auto it3a = unassociated2.find(test::block3.hash());
BOOST_REQUIRE(it3a != unassociated2.end());
BOOST_REQUIRE_EQUAL(it3a->context.forks, context3.flags);
BOOST_REQUIRE_EQUAL(it3a->context.flags, context3.flags);
BOOST_REQUIRE_EQUAL(it3a->context.timestamp, test::block3.header().timestamp());
BOOST_REQUIRE_EQUAL(it3a->context.median_time_past, context3.mtp);
BOOST_REQUIRE_EQUAL(it3a->context.height, context3.height);
Expand Down