Skip to content
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
1 change: 1 addition & 0 deletions include/bitcoin/database/tables/envelope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct BCD_API envelope
system::chain::checkpoint bip9_bit2_active_checkpoint{};
system::chain::checkpoint top_checkpoint{};
system::chain::checkpoint milestone{};
system::chain::script signet_challenge{};

/// Database settings.
uint16_t interval_depth{};
Expand Down
4 changes: 3 additions & 1 deletion include/bitcoin/database/tables/schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ namespace schema {
/// 4.0.13.0 Scanned and filtered block state flags, presilent batch tables.
/// 4.0.14.0 Scan table head of scan starts, scan and tx counts at the latch.
/// 4.0.15.0 Wtxid buckets and filter k in the envelope.
constexpr std::array<uint32_t, 4> version{ 4, 0, 16, 0 };
/// 4.0.16.0 Strong headmap.
/// 4.0.17.0 Signet fork and challenge in the envelope.
constexpr std::array<uint32_t, 4> version{ 4, 0, 17, 0 };

/// Values.
/// -----------------------------------------------------------------------
Expand Down
11 changes: 9 additions & 2 deletions src/tables/envelope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ string_list envelope::apply(system::settings& bitcoin, settings& database,
assign(bitcoin.bip9_bit1_active_checkpoint, bip9_bit1_active_checkpoint, "bip9_bit1_active_checkpoint");
assign(bitcoin.bip9_bit2_active_checkpoint, bip9_bit2_active_checkpoint, "bip9_bit2_active_checkpoint");
assign(bitcoin.milestone, milestone, "milestone");
assign(bitcoin.signet_challenge, signet_challenge, "signet_challenge");

if (bitcoin.top_checkpoint() != top_checkpoint)
changed.push_back("top_checkpoint");
Expand Down Expand Up @@ -161,6 +162,7 @@ envelope::envelope(const system::settings& bitcoin, const settings& database,
bip9_bit2_active_checkpoint(bitcoin.bip9_bit2_active_checkpoint),
top_checkpoint(bitcoin.top_checkpoint()),
milestone(bitcoin.milestone),
signet_challenge(bitcoin.signet_challenge),
limited_blocks(limited),
silent_start_height(silent)
{
Expand Down Expand Up @@ -204,6 +206,7 @@ bool envelope::from_data(reader& source) NOEXCEPT
forks.difficult = to_bool(source.read_byte());
forks.time_warp_patch = to_bool(source.read_byte());
forks.block_storm_patch = to_bool(source.read_byte());
forks.signet = to_bool(source.read_byte());
forks.ltc_time_warp_patch = to_bool(source.read_byte());
forks.ltc_retarget_overflow_patch = to_bool(source.read_byte());
forks.ltc_scrypt_proof_of_work = to_bool(source.read_byte());
Expand Down Expand Up @@ -244,6 +247,7 @@ bool envelope::from_data(reader& source) NOEXCEPT
bip9_bit2_active_checkpoint = read_checkpoint();
top_checkpoint = read_checkpoint();
milestone = read_checkpoint();
signet_challenge = chain::script{ source, true };

interval_depth = source.read_little_endian<uint16_t>();
header_buckets = source.read_little_endian<uint32_t>();
Expand Down Expand Up @@ -298,6 +302,7 @@ bool envelope::to_data(flipper& sink) const NOEXCEPT
sink.write_byte(to_int<uint8_t>(forks.difficult));
sink.write_byte(to_int<uint8_t>(forks.time_warp_patch));
sink.write_byte(to_int<uint8_t>(forks.block_storm_patch));
sink.write_byte(to_int<uint8_t>(forks.signet));
sink.write_byte(to_int<uint8_t>(forks.ltc_time_warp_patch));
sink.write_byte(to_int<uint8_t>(forks.ltc_retarget_overflow_patch));
sink.write_byte(to_int<uint8_t>(forks.ltc_scrypt_proof_of_work));
Expand Down Expand Up @@ -338,6 +343,7 @@ bool envelope::to_data(flipper& sink) const NOEXCEPT
write_checkpoint(bip9_bit2_active_checkpoint);
write_checkpoint(top_checkpoint);
write_checkpoint(milestone);
signet_challenge.to_data(sink, true);

sink.write_little_endian<uint16_t>(interval_depth);
sink.write_little_endian<uint32_t>(header_buckets);
Expand Down Expand Up @@ -368,7 +374,7 @@ bool envelope::to_data(flipper& sink) const NOEXCEPT

size_t envelope::serialized_size() const NOEXCEPT
{
constexpr auto forks_size = 24_size;
constexpr auto forks_size = 25_size;
constexpr auto fixed = (4 * sizeof(uint32_t)) + sizeof(uint16_t) +
(7 * sizeof(uint32_t)) + (10 * sizeof(uint8_t)) + forks_size +
sizeof(uint64_t) + (18 * sizeof(uint32_t));
Expand All @@ -391,7 +397,8 @@ size_t envelope::serialized_size() const NOEXCEPT
checkpoint_size(bip9_bit1_active_checkpoint) +
checkpoint_size(bip9_bit2_active_checkpoint) +
checkpoint_size(top_checkpoint) +
checkpoint_size(milestone);
checkpoint_size(milestone) +
signet_challenge.serialized_size(true);
}

} // namespace database
Expand Down
20 changes: 18 additions & 2 deletions test/tables/envelope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BOOST_AUTO_TEST_SUITE(envelope_tests)

using namespace system;

constexpr auto default_size = 365_size;
constexpr auto default_size = 367_size;

static data_chunk to_chunk(const envelope& instance)
{
Expand Down Expand Up @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(envelope__serialized_size__default__expected)
BOOST_AUTO_TEST_CASE(envelope__to_data__default__expected_version)
{
const envelope instance{};
BOOST_REQUIRE_EQUAL(instance.schema, system::config::version(4, 0, 16, 0));
BOOST_REQUIRE_EQUAL(instance.schema, system::config::version(4, 0, 17, 0));
BOOST_REQUIRE_EQUAL(to_chunk(instance).front(), schema::version.front());
}

Expand Down Expand Up @@ -193,6 +193,22 @@ BOOST_AUTO_TEST_CASE(envelope__from_data__regtest__round_trip)
BOOST_REQUIRE(out == instance);
}

BOOST_AUTO_TEST_CASE(envelope__from_data__signet__round_trip)
{
const system::settings bitcoin{ chain::selection::signet };
const database::settings configuration{ chain::selection::signet };
const envelope instance{ bitcoin, configuration, false, 42 };
BOOST_REQUIRE(instance.forks.signet);
BOOST_REQUIRE(instance.signet_challenge == bitcoin.signet_challenge);

auto data = to_chunk(instance);
BOOST_REQUIRE_EQUAL(data.size(), instance.serialized_size());

envelope out{};
BOOST_REQUIRE(from_chunk(out, data));
BOOST_REQUIRE(out == instance);
}

BOOST_AUTO_TEST_CASE(envelope__initialize__mainnet__expected)
{
const system::settings bitcoin{ chain::selection::mainnet };
Expand Down
Loading