diff --git a/include/bitcoin/database/impl/query/properties_block.ipp b/include/bitcoin/database/impl/query/properties_block.ipp index aa2962b17..4bb647da0 100644 --- a/include/bitcoin/database/impl/query/properties_block.ipp +++ b/include/bitcoin/database/impl/query/properties_block.ipp @@ -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; diff --git a/include/bitcoin/database/tables/archives/header.hpp b/include/bitcoin/database/tables/archives/header.hpp index 5c9517da9..46adbfecb 100644 --- a/include/bitcoin/database/tables/archives/header.hpp +++ b/include/bitcoin/database/tables/archives/header.hpp @@ -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(); + return source; + } + + context ctx{}; + uint32_t timestamp{}; + }; + struct get_flags : public schema::header { diff --git a/test/query/properties_block.cpp b/test/query/properties_block.cpp index b94d90ff9..71043e9a9 100644 --- a/test/query/properties_block.cpp +++ b/test/query/properties_block.cpp @@ -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{}); } @@ -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); }