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
29 changes: 20 additions & 9 deletions include/bitcoin/database/impl/query/properties_block.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,31 @@ TEMPLATE
bool CLASS::get_context(system::chain::context& ctx,
const header_link& link) const NOEXCEPT
{
table::header::record_context header{};
table::header::record_context_timestamp header{};
if (!store_.header.get(link, header))
return false;

// Context for block/header.check and header.accept are filled from
// chain_state, not from the store.
// Context for header.check and header.accept are filled from chain_state.
// So these are not populated here as they are not expected to be used.
ctx =
{
header.ctx.flags, // [block.check, block.accept & block.connect]
{}, // [block.check] timestamp
header.ctx.mtp, // [block.check, header.accept]
header.ctx.height, // [block.check & block.accept]
{}, // [header.accept] minimum_block_version
{} // [header.accept] work_required
// [block.check, .accept, .connect]
.flags = header.ctx.flags,

// [block.check]
.timestamp = header.timestamp,

// [block.check, header.accept]
.median_time_past = header.ctx.mtp,

// [block.check & block.accept]
.height = header.ctx.height

// [header.accept]
// .minimum_block_version

// [header.accept]
// .work_required
};

return true;
Expand Down
15 changes: 15 additions & 0 deletions include/bitcoin/database/tables/archives/header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@ struct header
context ctx{};
};

struct record_context_timestamp
: public schema::header
{
inline bool from_data(reader& source) NOEXCEPT
{
context::from_data(source, ctx);
source.skip_bytes(link::size + sizeof(uint32_t));
timestamp = source.read_little_endian<uint32_t>();
return source;
}

context ctx{};
uint32_t timestamp{};
};

struct get_flags
: public schema::header
{
Expand Down
6 changes: 5 additions & 1 deletion test/query/properties_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ BOOST_AUTO_TEST_CASE(query_properties_block__get_context__genesis__default)

system::chain::context chain_ctx{};
BOOST_REQUIRE(query.get_context(chain_ctx, 0));
BOOST_REQUIRE_EQUAL(chain_ctx.timestamp, 0x495fab29_u32);

chain_ctx.timestamp = {};
BOOST_REQUIRE(chain_ctx == system::chain::context{});
}

Expand Down Expand Up @@ -147,7 +150,8 @@ BOOST_AUTO_TEST_CASE(query_properties_block__get_context__block1__expected)
BOOST_REQUIRE(ctx == expected);

system::chain::context chain_ctx{};
const system::chain::context chain_expected{ expected.flags, 0, expected.mtp, expected.height, 0, 0 };
constexpr auto expected_timestamp = 0x4966bc61_u32;
const system::chain::context chain_expected{ expected.flags, expected_timestamp, expected.mtp, expected.height, 0, 0 };
BOOST_REQUIRE(query.get_context(chain_ctx, 1));
BOOST_REQUIRE(chain_ctx == chain_expected);
}
Expand Down
Loading