From c3ba3a10fb33167658ef051c48bc11eb1962a8f6 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 23 Feb 2026 16:50:17 -0500 Subject: [PATCH 1/9] Reorder txs interface table (fxs.count adjacent to fks). --- .../database/impl/query/archive_write.ipp | 2 +- .../bitcoin/database/tables/archives/txs.hpp | 164 +++++++++++------- test/query/archive_write.cpp | 18 +- test/tables/archives/txs.cpp | 24 +-- 4 files changed, 122 insertions(+), 86 deletions(-) diff --git a/include/bitcoin/database/impl/query/archive_write.ipp b/include/bitcoin/database/impl/query/archive_write.ipp index 014d0939..6b1e2cee 100644 --- a/include/bitcoin/database/impl/query/archive_write.ipp +++ b/include/bitcoin/database/impl/query/archive_write.ipp @@ -417,9 +417,9 @@ code CLASS::set_code(const block& block, const header_link& key, return store_.txs.put(to_txs(key), table::txs::put_group { {}, - count, light, heavy, + count, tx_fks, std::move(interval), depth diff --git a/include/bitcoin/database/tables/archives/txs.hpp b/include/bitcoin/database/tables/archives/txs.hpp index f2f9f6fa..e882d00b 100644 --- a/include/bitcoin/database/tables/archives/txs.hpp +++ b/include/bitcoin/database/tables/archives/txs.hpp @@ -32,6 +32,8 @@ namespace database { namespace table { // TODO: make heavy field variable size. +// TODO: fks can instead be stored as a count and coinbase fk, +// TODO: but will need to be disambiguated from compact blocks. /// Txs is a slab arraymap of tx fks (first is count), indexed by header.fk. struct txs @@ -46,6 +48,10 @@ struct txs static constexpr auto offset = bytes::bits; static_assert(offset < to_bits(bytes::size)); + static constexpr size_t skip_sizes = + bytes::size + + bytes::size; + static constexpr bytes::integer merge(bool is_interval, bytes::integer light) NOEXCEPT { @@ -74,26 +80,31 @@ struct txs inline link count() const NOEXCEPT { - return system::possible_narrow_cast(ct::size + - bytes::size + bytes::size + tx::size * tx_fks.size() + + return system::possible_narrow_cast( + skip_sizes + ct::size + (tx_fks.size() * tx::size) + (interval.has_value() ? schema::hash : zero) + to_int(is_genesis())); } inline bool from_data(reader& source) NOEXCEPT { - using namespace system; - tx_fks.resize(source.read_little_endian()); + // tx sizes const auto merged = source.read_little_endian(); heavy = source.read_little_endian(); + light = to_light(merged); + + // tx fks + tx_fks.resize(source.read_little_endian()); std::for_each(tx_fks.begin(), tx_fks.end(), [&](auto& fk) NOEXCEPT { fk = source.read_little_endian(); }); - light = to_light(merged); + // interval (when specified) interval.reset(); if (is_interval(merged)) interval = source.read_hash(); + + // depth (genesis only) depth = is_genesis() ? source.read_byte() : zero; BC_ASSERT(!source || source.get_read_position() == count()); return source; @@ -104,19 +115,24 @@ struct txs using namespace system; BC_ASSERT(tx_fks.size() < power2(to_bits(ct::size))); - const auto has_interval = interval.has_value(); - const auto merged = merge(has_interval, light); - const auto fks = possible_narrow_cast(tx_fks.size()); - sink.write_little_endian(fks); + // tx sizes + const auto merged = merge(interval.has_value(), light); sink.write_little_endian(merged); sink.write_little_endian(heavy); + + // tx fks + const auto number = possible_narrow_cast(tx_fks.size()); + sink.write_little_endian(number); std::for_each(tx_fks.begin(), tx_fks.end(), [&](const auto& fk) NOEXCEPT { sink.write_little_endian(fk); }); - if (has_interval) sink.write_bytes(interval.value()); + // interval (when specified) + if (interval.has_value()) sink.write_bytes(interval.value()); + + // depth (genesis only) if (is_genesis()) sink.write_byte(depth); BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; @@ -131,8 +147,8 @@ struct txs && depth == other.depth; } - bytes::integer light{}; // block.serialized_size(false) - bytes::integer heavy{}; // block.serialized_size(true) + bytes::integer light{}; + bytes::integer heavy{}; keys tx_fks{}; hash interval{}; uint8_t depth{}; @@ -149,36 +165,38 @@ struct txs inline link count() const NOEXCEPT { - return system::possible_narrow_cast(ct::size + - bytes::size + bytes::size + tx::size * number + + return system::possible_narrow_cast( + skip_sizes + ct::size + (number * tx::size) + (interval.has_value() ? schema::hash : zero) + to_int(is_zero(tx_fk))); } - // TODO: fks can instead be stored as a count and coinbase fk, - // TODO: but will need to be disambiguated from compact blocks. inline bool to_data(finalizer& sink) const NOEXCEPT { BC_ASSERT(number < system::power2(to_bits(ct::size))); - const auto has_interval = interval.has_value(); - const auto merged = merge(has_interval, light); - sink.write_little_endian(number); + // tx sizes + const auto merged = merge(interval.has_value(), light); sink.write_little_endian(merged); sink.write_little_endian(heavy); + // tx fks + sink.write_little_endian(number); for (auto fk = tx_fk; fk < (tx_fk + number); ++fk) sink.write_little_endian(fk); - if (has_interval) sink.write_bytes(interval.value()); + // interval (when specified) + if (interval.has_value()) sink.write_bytes(interval.value()); + + // depth (genesis only) if (is_genesis()) sink.write_byte(depth); BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; } - ct::integer number{}; bytes::integer light{}; bytes::integer heavy{}; + ct::integer number{}; tx::integer tx_fk{}; hash interval{}; uint8_t depth{}; @@ -195,10 +213,16 @@ struct txs inline bool from_data(reader& source) NOEXCEPT { - using namespace system; - const auto number = source.read_little_endian(); + // tx sizes const auto merged = source.read_little_endian(); - source.skip_bytes(bytes::size + tx::size * number); + source.skip_bytes(bytes::size); + + // tx fks + const auto number = source.read_little_endian(); + source.skip_bytes(number * tx::size); + + // interval + interval.reset(); if (is_interval(merged)) interval = source.read_hash(); return source; } @@ -219,10 +243,18 @@ struct txs // Stored at end since only read once (at startup). inline bool from_data(reader& source) NOEXCEPT { - const auto number = source.read_little_endian(); + // tx sizes const auto merged = source.read_little_endian(); - const auto skip_interval = is_interval(merged) ? schema::hash : zero; - source.skip_bytes(bytes::size + tx::size * number + skip_interval); + source.skip_bytes(bytes::size); + + // tx fks + const auto number = source.read_little_endian(); + source.skip_bytes(number * tx::size); + + // interval + source.skip_bytes(is_interval(merged) ? schema::hash : zero); + + // depth depth = source.read_byte(); return source; } @@ -241,8 +273,11 @@ struct txs inline bool from_data(reader& source) NOEXCEPT { + // tx sizes + source.skip_bytes(skip_sizes); + + // tx fks const auto number = source.read_little_endian(); - source.skip_bytes(bytes::size + bytes::size); for (position = zero; position < number; ++position) if (source.read_little_endian() == tx_fk) return source; @@ -266,9 +301,11 @@ struct txs inline bool from_data(reader& source) NOEXCEPT { - const auto number = source.read_little_endian(); - source.skip_bytes(bytes::size + bytes::size); - if (is_nonzero(number)) + // tx sizes + source.skip_bytes(skip_sizes); + + // tx fks + if (is_nonzero(source.read_little_endian())) { coinbase_fk = source.read_little_endian(); return source; @@ -292,9 +329,11 @@ struct txs inline bool from_data(reader& source) NOEXCEPT { - const auto number = source.read_little_endian(); - source.skip_bytes(bytes::size + bytes::size); - if (number > position) + // tx sizes + source.skip_bytes(skip_sizes); + + // tx fks + if (source.read_little_endian() > position) { source.skip_bytes(position * tx::size); tx_fk = source.read_little_endian(); @@ -312,11 +351,6 @@ struct txs struct get_sizes : public schema::txs { - static constexpr bytes::integer to_size(bytes::integer merged) NOEXCEPT - { - return system::set_right(merged, offset, false); - } - inline link count() const NOEXCEPT { BC_ASSERT(false); @@ -325,8 +359,8 @@ struct txs inline bool from_data(reader& source) NOEXCEPT { - source.skip_bytes(ct::size); - light = to_size(source.read_little_endian()); + // tx sizes + light = to_light(source.read_little_endian()); heavy = source.read_little_endian(); return source; } @@ -346,7 +380,10 @@ struct txs inline bool from_data(reader& source) NOEXCEPT { - // Read is cheap but unnecessary, since 0 is never set here. + // tx sizes + source.skip_bytes(skip_sizes); + + // tx fks associated = to_bool(source.read_little_endian()); return source; } @@ -365,8 +402,11 @@ struct txs inline bool from_data(reader& source) NOEXCEPT { + // tx sizes + source.skip_bytes(skip_sizes); + + // tx fks tx_fks.resize(source.read_little_endian()); - source.skip_bytes(bytes::size + bytes::size); std::for_each(tx_fks.begin(), tx_fks.end(), [&](auto& fk) NOEXCEPT { fk = source.read_little_endian(); @@ -389,16 +429,20 @@ struct txs inline bool from_data(reader& source) NOEXCEPT { - const auto number = source.read_little_endian(); - if (number <= one) - return source; + // tx sizes + source.skip_bytes(skip_sizes); - tx_fks.resize(sub1(number)); - source.skip_bytes(bytes::size + bytes::size + tx::size); - std::for_each(tx_fks.begin(), tx_fks.end(), [&](auto& fk) NOEXCEPT + // tx fks + const auto number = source.read_little_endian(); + if (number > one) { - fk = source.read_little_endian(); - }); + source.skip_bytes(one * tx::size); + tx_fks.resize(sub1(number)); + std::for_each(tx_fks.begin(), tx_fks.end(), [&](auto& fk) NOEXCEPT + { + fk = source.read_little_endian(); + }); + } return source; } @@ -417,6 +461,10 @@ struct txs inline bool from_data(reader& source) NOEXCEPT { + // tx sizes + source.skip_bytes(skip_sizes); + + // tx fks number = source.read_little_endian(); return source; } @@ -435,18 +483,18 @@ struct txs inline bool from_data(reader& source) NOEXCEPT { - number = source.read_little_endian(); - source.skip_bytes(bytes::size + bytes::size); + // tx sizes + source.skip_bytes(skip_sizes); - if (is_zero(number)) - { - source.invalidate(); - } - else + // tx fks + number = source.read_little_endian(); + if (is_nonzero(number)) { coinbase_fk = source.read_little_endian(); + return source; } + source.invalidate(); return source; } diff --git a/test/query/archive_write.cpp b/test/query/archive_write.cpp index 249dec29..a29c6259 100644 --- a/test/query/archive_write.cpp +++ b/test/query/archive_write.cpp @@ -536,9 +536,9 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block__get_block__expected) "ffffffffff" "ffffffffff"); const auto genesis_txs_body = system::base16_chunk( - "010000" // txs count (1) "1d0100" // size light (285) "1d0100" // size heavy (285) + "010000" // txs count (1) "00000000" // transaction[0] "ff"); // depth (255) @@ -557,12 +557,6 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block__get_block__expected) BOOST_REQUIRE(query.set(test::genesis, test::context, milestone, false)); BOOST_REQUIRE(query.is_block(test::genesis.hash())); - // Verify idempotentcy (these do not change store state). - ////BOOST_REQUIRE(query.set(test::genesis.header(), test::context, milestone, false)); - ////BOOST_REQUIRE(query.set(test::genesis.header(), test::context, milestone, false)); - ////BOOST_REQUIRE(query.set(test::genesis, test::context, milestone, false, false)); - ////BOOST_REQUIRE(query.set(test::genesis, test::context, milestone, false, false)); - table::header::record element1{}; BOOST_REQUIRE(store.header.get(query.to_header(test::genesis.hash()), element1)); BOOST_REQUIRE(!store.close(events_handler)); @@ -689,9 +683,9 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block_txs__get_block__expected) "ffffffffff" "ffffffffff"); const auto genesis_txs_body = system::base16_chunk( - "010000" // txs count (1) "1d0100" // size light (285) "1d0100" // size heavy (285) + "010000" // txs count (1) "00000000" // transaction[0] "ff"); // depth (255) @@ -713,12 +707,6 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block_txs__get_block__expected) BOOST_REQUIRE(query.is_block(test::genesis.hash())); BOOST_REQUIRE(query.is_associated(0)); - // Verify idempotentcy (these do not change store state). - ////BOOST_REQUIRE(query.set(test::genesis.header(), test::context, milestone)); - ////BOOST_REQUIRE(query.set(test::genesis.header(), test::context, milestone)); - ////BOOST_REQUIRE(query.set(test::genesis, test::context, milestone)); - ////BOOST_REQUIRE(query.set(test::genesis, test::context, milestone)); - table::header::record element1{}; BOOST_REQUIRE(store.header.get(query.to_header(test::genesis.hash()), element1)); BOOST_REQUIRE(!store.close(events_handler)); @@ -752,7 +740,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block_txs__get_block__expected) // ---------------------------------------------------------------------------- // METADATA IS SETTABLE ON CONST TEST OBJECTS. -// COPY CONSTRUCTION CREATES SAHRED POINTER REFERENCES. +// COPY CONSTRUCTION CREATES SHARED POINTER REFERENCES. // SO POPULATE ON CONST OBJECTS HAS SIDE EFFECTS IF THE OBJECTS SPAN TESTS. const auto& clean_(const auto& block_or_tx) NOEXCEPT { diff --git a/test/tables/archives/txs.cpp b/test/tables/archives/txs.cpp index d1179185..b96f28fa 100644 --- a/test/tables/archives/txs.cpp +++ b/test/tables/archives/txs.cpp @@ -68,15 +68,15 @@ const table::txs::slab slab3 }; const data_chunk expected0 { - // slab0 (count) [1] - 0x01, 0x00, 0x00, - // slab0 (light) [0x00] 0x00, 0x00, 0x00, // slab0 (heavy) [0x00] 0x00, 0x00, 0x00, + // slab0 (count) [1] + 0x01, 0x00, 0x00, + // slab0 (txs) 0x00, 0x00, 0x00, 0x00, @@ -85,44 +85,44 @@ const data_chunk expected0 }; const data_chunk expected1 { - // slab1 (count) [1] - 0x01, 0x00, 0x00, - // slab1 (light) [0x0000ab] 0xab, 0x00, 0x00, // slab1 (heavy) [0x0000cc] 0xcc, 0x00, 0x00, + // slab1 (count) [1] + 0x01, 0x00, 0x00, + // slab1 (txs) 0x11, 0x12, 0x34, 0x56 }; const data_chunk expected2 { - // slab2 (count) [2] - 0x02, 0x00, 0x00, - // slab2 (light) [0x00a00b] 0x0b, 0xa0, 0x00, // slab2 (heavy) [0x00cc00] 0x00, 0xcc, 0x00, + // slab2 (count) [2] + 0x02, 0x00, 0x00, + // slab2 0x21, 0x12, 0x34, 0x56, 0x22, 0x12, 0x34, 0x56 }; const data_chunk expected3 { - // slab3 (count) [3] - 0x03, 0x00, 0x00, - // slab3 (light) [0x09000b] 0x0b, 0x00, 0x09, // slab3 (heavy) [0xcc0000] 0x00, 0x00, 0xcc, + // slab3 (count) [3] + 0x03, 0x00, 0x00, + // slab3 0x31, 0x12, 0x34, 0x56, 0x32, 0x12, 0x34, 0x56, From f23a83ee2428f89d239930c16d7131c1e8189502 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 23 Feb 2026 17:55:16 -0500 Subject: [PATCH 2/9] Use txs count cast derived from schema size. --- include/bitcoin/database/impl/query/archive_write.ipp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/bitcoin/database/impl/query/archive_write.ipp b/include/bitcoin/database/impl/query/archive_write.ipp index 6b1e2cee..dad79bc6 100644 --- a/include/bitcoin/database/impl/query/archive_write.ipp +++ b/include/bitcoin/database/impl/query/archive_write.ipp @@ -381,7 +381,7 @@ code CLASS::set_code(const block& block, const header_link& key, if (is_zero(txs)) return error::txs_empty; - const auto count = possible_narrow_cast(txs); + const auto count = possible_narrow_cast>(txs); const auto tx_fks = store_.tx.allocate(count); if (tx_fks.is_terminal()) return error::tx_tx_allocate; From f17bcbac9f967bf98f42b4a410f12cfdc7ac7ed5 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 23 Feb 2026 17:56:04 -0500 Subject: [PATCH 3/9] Change txs count domain to 2 bytes. --- include/bitcoin/database/tables/schema.hpp | 24 ++++++++++------------ test/query/archive_write.cpp | 8 ++++---- test/tables/archives/txs.cpp | 8 ++++---- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/include/bitcoin/database/tables/schema.hpp b/include/bitcoin/database/tables/schema.hpp index 15fb8a76..a791f1c3 100644 --- a/include/bitcoin/database/tables/schema.hpp +++ b/include/bitcoin/database/tables/schema.hpp @@ -31,7 +31,7 @@ constexpr size_t bit = 1; // single bit flag. constexpr size_t code = 1; // validation state. constexpr size_t size = 3; // tx/block size/weight. constexpr size_t height_ = 3; // height record. -constexpr size_t count_ = 3; // txs count. +constexpr size_t count_ = 2; // txs count. constexpr size_t index = 3; // input/output index. constexpr size_t sigops = 3; // signature op count. constexpr size_t flags = 4; // fork flags. @@ -62,7 +62,6 @@ constexpr size_t doubles_ = 4; // doubles bucket (no actual keys). // record hashmap struct header { - // TODO: merge milestone with parent.pk. static constexpr size_t sk = schema::hash; static constexpr size_t pk = schema::block; using link = linkage; // reduced for strong_tx merge. @@ -71,7 +70,7 @@ struct header schema::flags + // context.flags schema::height_ + // context.height sizeof(uint32_t) + // context.mtp - schema::bit + // milestone + schema::bit + // milestone [TODO: merge into parent pk] pk + // parent.pk sizeof(uint32_t) + // version sizeof(uint32_t) + // timestamp @@ -91,13 +90,12 @@ struct header // record hashmap struct transaction { - // TODO: merge coinbase with something. static constexpr size_t sk = schema::hash; static constexpr size_t pk = schema::tx; using link = linkage; // reduced for prevout merge. using key = system::data_array; static constexpr size_t minsize = - schema::bit + // coinbase + schema::bit + // coinbase [TODO: merge into light] schema::size + // light schema::size + // heavy sizeof(uint32_t) + // locktime @@ -207,16 +205,16 @@ struct txs static constexpr size_t pk = schema::txs_; using link = linkage; static constexpr size_t minsize = + schema::size + // light + schema::size + // heavy count_ + // txs - schema::size + // block.serialized_size(false) - schema::size + // block.serialized_size(true) schema::transaction::pk;// coinbase tx - ////schema::bit + // is interval - merged bit into schema::size. - ////0 | schema::hash + // electrum interval hash (each 2048th block). + ////schema::bit + // is interval [merged into light] + ////0 | schema::hash + // interval hash [each 2048th block] static constexpr size_t minrow = minsize; static constexpr size_t size = max_size_t; - static_assert(minsize == 13u); - static_assert(minrow == 13u); + static_assert(minsize == 12u); + static_assert(minrow == 12u); static_assert(link::size == 5u); }; @@ -327,8 +325,8 @@ struct validated_tx schema::header::pk + sizeof(uint32_t) + schema::code + // TODO: change code to variable. - one + - one; + one + // variable: fee + one; // variable: sigops static constexpr size_t minrow = pk + sk + minsize; static constexpr size_t size = max_size_t; static constexpr size_t cell = link::size; diff --git a/test/query/archive_write.cpp b/test/query/archive_write.cpp index a29c6259..0dcbb3c6 100644 --- a/test/query/archive_write.cpp +++ b/test/query/archive_write.cpp @@ -518,7 +518,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block__get_block__expected) "4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73" // script "00"); // witness const auto genesis_txs_head = system::base16_chunk( - "0e00000000" // slab size + "0d00000000" // slab size "0000000000" // pk-> "ffffffffff" "ffffffffff" @@ -538,7 +538,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block__get_block__expected) const auto genesis_txs_body = system::base16_chunk( "1d0100" // size light (285) "1d0100" // size heavy (285) - "010000" // txs count (1) + "0100" // txs count (1) "00000000" // transaction[0] "ff"); // depth (255) @@ -665,7 +665,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block_txs__get_block__expected) "4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73" // script "00"); // witness const auto genesis_txs_head = system::base16_chunk( - "0e00000000" // slab size + "0d00000000" // slab size "0000000000" // pk-> "ffffffffff" "ffffffffff" @@ -685,7 +685,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block_txs__get_block__expected) const auto genesis_txs_body = system::base16_chunk( "1d0100" // size light (285) "1d0100" // size heavy (285) - "010000" // txs count (1) + "0100" // txs count (1) "00000000" // transaction[0] "ff"); // depth (255) diff --git a/test/tables/archives/txs.cpp b/test/tables/archives/txs.cpp index b96f28fa..803755a5 100644 --- a/test/tables/archives/txs.cpp +++ b/test/tables/archives/txs.cpp @@ -75,7 +75,7 @@ const data_chunk expected0 0x00, 0x00, 0x00, // slab0 (count) [1] - 0x01, 0x00, 0x00, + 0x01, 0x00, // slab0 (txs) 0x00, 0x00, 0x00, 0x00, @@ -92,7 +92,7 @@ const data_chunk expected1 0xcc, 0x00, 0x00, // slab1 (count) [1] - 0x01, 0x00, 0x00, + 0x01, 0x00, // slab1 (txs) 0x11, 0x12, 0x34, 0x56 @@ -106,7 +106,7 @@ const data_chunk expected2 0x00, 0xcc, 0x00, // slab2 (count) [2] - 0x02, 0x00, 0x00, + 0x02, 0x00, // slab2 0x21, 0x12, 0x34, 0x56, @@ -121,7 +121,7 @@ const data_chunk expected3 0x00, 0x00, 0xcc, // slab3 (count) [3] - 0x03, 0x00, 0x00, + 0x03, 0x00, // slab3 0x31, 0x12, 0x34, 0x56, From 718de2cf6976025e084cc2efd3e55b586e420060 Mon Sep 17 00:00:00 2001 From: Phillip Mienk Date: Mon, 23 Feb 2026 15:32:55 -0800 Subject: [PATCH 4/9] Test coverage suppression error output suggestion. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1c7270b..dc8c3b15 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -220,7 +220,7 @@ jobs: - name: Coveralls Calculation if: ${{ matrix.coverage == 'cov' }} run: | - lcov --ignore-errors version,gcov,mismatch --directory . --capture --output-file coverage.info + lcov --ignore-errors version,gcov,mismatch,mismatch --directory . --capture --output-file coverage.info lcov --ignore-errors unused --remove coverage.info "/usr/*" "${{ env.LIBBITCOIN_SRC_PATH }}prefix/*" "${{ github.workspace }}/examples/*" "${{ github.workspace }}/test/*" --output-file coverage.info lcov --list coverage.info From 3aa13b1c51c94bde272220b82d83554a3337a872 Mon Sep 17 00:00:00 2001 From: Phillip Mienk Date: Mon, 23 Feb 2026 16:00:31 -0800 Subject: [PATCH 5/9] Regenerate artifacts (coverage calculation change). --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc8c3b15..79e8baf5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -494,7 +494,7 @@ jobs: - name: Coveralls Calculation if: ${{ matrix.coverage == 'cov' }} run: | - lcov --ignore-errors version,gcov,mismatch --directory . --capture --output-file coverage.info + lcov --ignore-errors version,gcov,mismatch,mismatch --directory . --capture --output-file coverage.info lcov --ignore-errors unused --remove coverage.info "/usr/*" "${{ env.LIBBITCOIN_SRC_PATH }}prefix/*" "${{ github.workspace }}/examples/*" "${{ github.workspace }}/test/*" --output-file coverage.info lcov --list coverage.info @@ -731,7 +731,7 @@ jobs: - name: Coveralls Calculation if: ${{ matrix.coverage == 'cov' }} run: | - lcov --ignore-errors version,gcov,mismatch --directory . --capture --output-file coverage.info + lcov --ignore-errors version,gcov,mismatch,mismatch --directory . --capture --output-file coverage.info lcov --ignore-errors unused --remove coverage.info "/usr/*" "${{ env.LIBBITCOIN_SRC_PATH }}prefix/*" "${{ github.workspace }}/examples/*" "${{ github.workspace }}/test/*" --output-file coverage.info lcov --list coverage.info From aef40bf283a76c3044075ebf1770cadfbb6823db Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 23 Feb 2026 19:56:47 -0500 Subject: [PATCH 6/9] Merge coinbase flag into tx.heavy table field. --- .../database/tables/archives/transaction.hpp | 68 +- include/bitcoin/database/tables/schema.hpp | 6 +- test/query/archive_write.cpp | 1211 +++++++++-------- test/tables/archives/transaction.cpp | 6 +- 4 files changed, 654 insertions(+), 637 deletions(-) diff --git a/include/bitcoin/database/tables/archives/transaction.hpp b/include/bitcoin/database/tables/archives/transaction.hpp index 8b825f31..494b96ab 100644 --- a/include/bitcoin/database/tables/archives/transaction.hpp +++ b/include/bitcoin/database/tables/archives/transaction.hpp @@ -29,8 +29,6 @@ namespace libbitcoin { namespace database { namespace table { -// TODO: merge coinbase bit (saves about 1GB). - /// Transaction is a canonical record hash table. struct transaction : public hash_map @@ -39,13 +37,17 @@ struct transaction using outs = schema::outs::link; using out = schema::output::link; using ix = linkage; - using bytes = linkage; + using bytes = linkage; using hash_map::hashmap; + static constexpr auto offset = bytes::bits; + static_assert(offset < to_bits(bytes::size)); - static constexpr size_t skip_to_version = - schema::bit + - bytes::size + + static constexpr size_t skip_to_locktime = bytes::size + + bytes::size; + + static constexpr size_t skip_to_version = + skip_to_locktime + sizeof(uint32_t); static constexpr size_t skip_to_ins = @@ -56,13 +58,31 @@ struct transaction skip_to_ins + ix::size; + static constexpr bytes::integer merge(bool is_coinbase, + bytes::integer light) NOEXCEPT + { + BC_ASSERT_MSG(!system::get_right(light, offset), "overflow"); + return system::set_right(light, offset, is_coinbase); + } + + static constexpr bool is_coinbase(bytes::integer merged) NOEXCEPT + { + return system::get_right(merged, offset); + } + + static constexpr bytes::integer to_light(bytes::integer merged) NOEXCEPT + { + return system::set_right(merged, offset, false); + } + struct record : public schema::transaction { inline bool from_data(reader& source) NOEXCEPT { - coinbase = to_bool(source.read_byte()); - light = source.read_little_endian(); + const auto merged = source.read_little_endian(); + coinbase = is_coinbase(merged); + light = to_light(merged); heavy = source.read_little_endian(); locktime = source.read_little_endian(); version = source.read_little_endian(); @@ -76,8 +96,7 @@ struct transaction inline bool to_data(finalizer& sink) const NOEXCEPT { - sink.write_byte(to_int(coinbase)); - sink.write_little_endian(light); + sink.write_little_endian(merge(coinbase, light)); sink.write_little_endian(heavy); sink.write_little_endian(locktime); sink.write_little_endian(version); @@ -103,8 +122,8 @@ struct transaction } bool coinbase{}; - bytes::integer light{}; // tx.serialized_size(false) - bytes::integer heavy{}; // tx.serialized_size(true) + bytes::integer light{}; + bytes::integer heavy{}; uint32_t locktime{}; uint32_t version{}; ix::integer ins_count{}; @@ -118,12 +137,7 @@ struct transaction { inline bool from_data(reader& source) NOEXCEPT { - static constexpr size_t skip_size = - schema::bit + - bytes::size + - bytes::size; - - source.skip_bytes(skip_size); + source.skip_bytes(skip_to_locktime); locktime = source.read_little_endian(); version = source.read_little_endian(); ins_count = source.read_little_endian(); @@ -148,13 +162,12 @@ struct transaction inline bool to_data(finalizer& sink) const NOEXCEPT { using namespace system; - const auto light = possible_narrow_cast( - tx.serialized_size(false)); - const auto heavy = possible_narrow_cast - (tx.serialized_size(true)); - - sink.write_byte(to_int(tx.is_coinbase())); - sink.write_little_endian(light); + const auto coinbase = tx.is_coinbase(); + const auto light_ = tx.serialized_size(false); + const auto heavy_ = tx.serialized_size(true); + const auto light = possible_narrow_cast(light_); + const auto heavy = possible_narrow_cast(heavy_); + sink.write_little_endian(merge(coinbase, light)); sink.write_little_endian(heavy); sink.write_little_endian(tx.locktime()); sink.write_little_endian(tx.version()); @@ -304,7 +317,7 @@ struct transaction { inline bool from_data(reader& source) NOEXCEPT { - coinbase = to_bool(source.read_byte()); + coinbase = is_coinbase(source.read_little_endian()); return source; } @@ -316,8 +329,7 @@ struct transaction { inline bool from_data(reader& source) NOEXCEPT { - source.skip_byte(); - light = source.read_little_endian(); + light = to_light(source.read_little_endian()); heavy = source.read_little_endian(); return source; } diff --git a/include/bitcoin/database/tables/schema.hpp b/include/bitcoin/database/tables/schema.hpp index a791f1c3..66351268 100644 --- a/include/bitcoin/database/tables/schema.hpp +++ b/include/bitcoin/database/tables/schema.hpp @@ -95,7 +95,7 @@ struct transaction using link = linkage; // reduced for prevout merge. using key = system::data_array; static constexpr size_t minsize = - schema::bit + // coinbase [TODO: merge into light] + ////schema::bit + // coinbase (merged into light) schema::size + // light schema::size + // heavy sizeof(uint32_t) + // locktime @@ -108,8 +108,8 @@ struct transaction static constexpr size_t size = minsize; static constexpr size_t cell = link::size; static constexpr link count() NOEXCEPT { return 1; } - static_assert(minsize == 29u); - static_assert(minrow == 65u); + static_assert(minsize == 28u); + static_assert(minrow == 64u); static_assert(link::size == 4u); static_assert(cell == 4u); }; diff --git a/test/query/archive_write.cpp b/test/query/archive_write.cpp index 0dcbb3c6..5a355529 100644 --- a/test/query/archive_write.cpp +++ b/test/query/archive_write.cpp @@ -52,28 +52,28 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_header__mmap_get_header__expected) settings.path = TEST_DIRECTORY; store store{ settings }; query> query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.set(header, test::context, milestone)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.set(header, test::context, milestone)); table::header::record element1{}; - BOOST_REQUIRE(store.header.get(query.to_header(block_hash), element1)); + BOOST_CHECK(store.header.get(query.to_header(block_hash), element1)); const auto pointer = query.get_header(query.to_header(block_hash)); - BOOST_REQUIRE(pointer); - BOOST_REQUIRE(*pointer == header); + BOOST_CHECK(pointer); + BOOST_CHECK(*pointer == header); // must open/close mmap - BOOST_REQUIRE(!store.close(events_handler)); - BOOST_REQUIRE_EQUAL(element1.ctx.height, system::mask_left(test::context.height, byte_bits)); - BOOST_REQUIRE_EQUAL(element1.ctx.flags, test::context.flags); - BOOST_REQUIRE_EQUAL(element1.ctx.mtp, test::context.mtp); - BOOST_REQUIRE_EQUAL(element1.milestone, milestone); - BOOST_REQUIRE_EQUAL(element1.version, header.version()); - BOOST_REQUIRE_EQUAL(element1.parent_fk, schema::header::link::terminal); - BOOST_REQUIRE_EQUAL(element1.merkle_root, header.merkle_root()); - BOOST_REQUIRE_EQUAL(element1.timestamp, header.timestamp()); - BOOST_REQUIRE_EQUAL(element1.bits, header.bits()); - BOOST_REQUIRE_EQUAL(element1.nonce, header.nonce()); + BOOST_CHECK(!store.close(events_handler)); + BOOST_CHECK_EQUAL(element1.ctx.height, system::mask_left(test::context.height, byte_bits)); + BOOST_CHECK_EQUAL(element1.ctx.flags, test::context.flags); + BOOST_CHECK_EQUAL(element1.ctx.mtp, test::context.mtp); + BOOST_CHECK_EQUAL(element1.milestone, milestone); + BOOST_CHECK_EQUAL(element1.version, header.version()); + BOOST_CHECK_EQUAL(element1.parent_fk, schema::header::link::terminal); + BOOST_CHECK_EQUAL(element1.merkle_root, header.merkle_root()); + BOOST_CHECK_EQUAL(element1.timestamp, header.timestamp()); + BOOST_CHECK_EQUAL(element1.bits, header.bits()); + BOOST_CHECK_EQUAL(element1.nonce, header.nonce()); } BOOST_AUTO_TEST_CASE(query_archive_write__set_link_header__is_header__expected) @@ -132,31 +132,31 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_link_header__is_header__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); + BOOST_CHECK(!store.create(events_handler)); // store open/close flushes record count to head. - BOOST_REQUIRE(!query.is_header(header.hash())); - BOOST_REQUIRE(!query.is_associated(0)); - BOOST_REQUIRE(!query.set_code(link, header, test::context, milestone)); - BOOST_REQUIRE(!link.is_terminal()); - BOOST_REQUIRE(query.is_header(header.hash())); - BOOST_REQUIRE(!query.is_associated(0)); + BOOST_CHECK(!query.is_header(header.hash())); + BOOST_CHECK(!query.is_associated(0)); + BOOST_CHECK(!query.set_code(link, header, test::context, milestone)); + BOOST_CHECK(!link.is_terminal()); + BOOST_CHECK(query.is_header(header.hash())); + BOOST_CHECK(!query.is_associated(0)); table::header::record element1{}; - BOOST_REQUIRE(store.header.get(query.to_header(block_hash), element1)); - BOOST_REQUIRE(!store.close(events_handler)); - BOOST_REQUIRE_EQUAL(store.header_head(), expected_header_head); - BOOST_REQUIRE_EQUAL(store.header_body(), expected_header_body); - - BOOST_REQUIRE_EQUAL(element1.ctx.height, system::mask_left(test::context.height, byte_bits)); - BOOST_REQUIRE_EQUAL(element1.ctx.flags, test::context.flags); - BOOST_REQUIRE_EQUAL(element1.ctx.mtp, test::context.mtp); - BOOST_REQUIRE_EQUAL(element1.milestone, milestone); - BOOST_REQUIRE_EQUAL(element1.version, header.version()); - BOOST_REQUIRE_EQUAL(element1.parent_fk, schema::header::link::terminal); - BOOST_REQUIRE_EQUAL(element1.merkle_root, header.merkle_root()); - BOOST_REQUIRE_EQUAL(element1.timestamp, header.timestamp()); - BOOST_REQUIRE_EQUAL(element1.bits, header.bits()); - BOOST_REQUIRE_EQUAL(element1.nonce, header.nonce()); + BOOST_CHECK(store.header.get(query.to_header(block_hash), element1)); + BOOST_CHECK(!store.close(events_handler)); + BOOST_CHECK_EQUAL(store.header_head(), expected_header_head); + BOOST_CHECK_EQUAL(store.header_body(), expected_header_body); + + BOOST_CHECK_EQUAL(element1.ctx.height, system::mask_left(test::context.height, byte_bits)); + BOOST_CHECK_EQUAL(element1.ctx.flags, test::context.flags); + BOOST_CHECK_EQUAL(element1.ctx.mtp, test::context.mtp); + BOOST_CHECK_EQUAL(element1.milestone, milestone); + BOOST_CHECK_EQUAL(element1.version, header.version()); + BOOST_CHECK_EQUAL(element1.parent_fk, schema::header::link::terminal); + BOOST_CHECK_EQUAL(element1.merkle_root, header.merkle_root()); + BOOST_CHECK_EQUAL(element1.timestamp, header.timestamp()); + BOOST_CHECK_EQUAL(element1.bits, header.bits()); + BOOST_CHECK_EQUAL(element1.nonce, header.nonce()); } BOOST_AUTO_TEST_CASE(query_archive_write__set_tx__empty__expected) @@ -188,20 +188,20 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_tx__empty__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); + BOOST_CHECK(!store.create(events_handler)); // store open/close flushes record count to heads. - BOOST_REQUIRE(!query.set(tx)); - BOOST_REQUIRE(!store.close(events_handler)); - BOOST_REQUIRE_EQUAL(store.tx_head(), expected_head4_hash); - BOOST_REQUIRE_EQUAL(store.input_head(), expected_head5_array); - BOOST_REQUIRE_EQUAL(store.output_head(), expected_head5_array); - BOOST_REQUIRE_EQUAL(store.outs_head(), expected_head4_array); - BOOST_REQUIRE_EQUAL(store.tx_body().size(), schema::transaction::minrow); - BOOST_REQUIRE(store.point_body().empty()); - BOOST_REQUIRE(store.input_body().empty()); - BOOST_REQUIRE(store.output_body().empty()); - BOOST_REQUIRE(store.outs_body().empty()); + BOOST_CHECK(!query.set(tx)); + BOOST_CHECK(!store.close(events_handler)); + BOOST_CHECK_EQUAL(store.tx_head(), expected_head4_hash); + BOOST_CHECK_EQUAL(store.input_head(), expected_head5_array); + BOOST_CHECK_EQUAL(store.output_head(), expected_head5_array); + BOOST_CHECK_EQUAL(store.outs_head(), expected_head4_array); + BOOST_CHECK_EQUAL(store.tx_body().size(), schema::transaction::minrow); + BOOST_CHECK(store.point_body().empty()); + BOOST_CHECK(store.input_body().empty()); + BOOST_CHECK(store.output_body().empty()); + BOOST_CHECK(store.outs_body().empty()); } BOOST_AUTO_TEST_CASE(query_archive_write__set_link_tx__null_input__expected) @@ -231,47 +231,49 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_link_tx__null_input__expected) "ffffffff" "ffffffff"); const auto expected_tx_body = system::base16_chunk( - "ffffffff" // next-> + "ffffff7f" // next-> "601f0fa54d6de8362c17dc883cc047e1f3ae0523d732598a05e3010fac591f62" // sk (tx.hash(false)) - "01" // coinbase - "3c0000" // witless - "3c0000" // witness + "3c0080" // light (coinbase merged) + "3c0000" // heavy "14131211" // locktime "04030201" // version "010000" // ins_count "010000" // outs_count - "0000000000"); // outs_fk-> - const auto expected_outs_head = system::base16_chunk("0900000000"); + "00000000" // point_fk-> (ins_fk) + "00000000"); // outs_fk-> + const auto expected_outs_head = system::base16_chunk("01000000"); const auto expected_outs_body = system::base16_chunk( - "00000000" // spend0_fk-> "0000000000"); // output0_fk-> const auto expected_output_head = system::base16_chunk("0600000000"); const auto expected_output_body = system::base16_chunk( "00000000" // parent_fk-> "00" // value "00"); // script - const auto expected_point_body = system::base16_chunk(""); - const auto expected_spend_head = system::base16_chunk( - "01000000" // record count - "00000000" // pk-> - "ffffffff" - "ffffffff" - "ffffffff" - "ffffffff"); - const auto expected_spend_body = system::base16_chunk( - "ffffffff" // terminal-> - "00000000" // fp: point_stub - "ffffff" // fp: point_index (null) - "ffffffff" // point_fk-> - "00000000" // parent_fk-> - "00000000" // sequence - "0000000000"); // input_fk-> + const auto expected_point_body = system::base16_chunk( + "ffffffff" // next-> + "0000000000000000000000000000000000000000000000000000000000000000" + "ffffff"); // index + ////const auto expected_spend_head = system::base16_chunk( + //// "01000000" // record count + //// "00000000" // pk-> + //// "ffffffff" + //// "ffffffff" + //// "ffffffff" + //// "ffffffff"); + ////const auto expected_spend_body = system::base16_chunk( + //// "ffffffff" // terminal-> + //// "00000000" // fp: point_stub + //// "ffffff" // fp: point_index (null) + //// "ffffffff" // point_fk-> + //// "00000000" // parent_fk-> + //// "00000000" // sequence + //// "0000000000"); // input_fk-> const auto expected_input_head = system::base16_chunk("0200000000"); const auto expected_input_body = system::base16_chunk( "00" // script "00"); // witness constexpr auto tx_hash = system::base16_array("601f0fa54d6de8362c17dc883cc047e1f3ae0523d732598a05e3010fac591f62"); - BOOST_REQUIRE_EQUAL(tx_hash, tx.hash(false)); + BOOST_CHECK_EQUAL(tx_hash, tx.hash(false)); // data_chunk store. settings settings{}; @@ -280,22 +282,22 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_link_tx__null_input__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(!query.set_code(tx)); - BOOST_REQUIRE(!store.close(events_handler)); - - BOOST_REQUIRE_EQUAL(store.tx_head(), expected_tx_head); - BOOST_REQUIRE_EQUAL(store.input_head(), expected_input_head); - BOOST_REQUIRE_EQUAL(store.output_head(), expected_output_head); -//// BOOST_REQUIRE_EQUAL(store.outs_head(), expected_outs_head); -//// BOOST_REQUIRE_EQUAL(store.spend_head(), expected_spend_head); - -//// BOOST_REQUIRE_EQUAL(store.tx_body(), expected_tx_body); -//// BOOST_REQUIRE_EQUAL(store.point_body(), expected_point_body); - BOOST_REQUIRE_EQUAL(store.input_body(), expected_input_body); - BOOST_REQUIRE_EQUAL(store.output_body(), expected_output_body); -//// BOOST_REQUIRE_EQUAL(store.outs_body(), expected_outs_body); -//// BOOST_REQUIRE_EQUAL(store.spend_body(), expected_spend_body); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(!query.set_code(tx)); + BOOST_CHECK(!store.close(events_handler)); + + BOOST_CHECK_EQUAL(store.tx_head(), expected_tx_head); + BOOST_CHECK_EQUAL(store.input_head(), expected_input_head); + BOOST_CHECK_EQUAL(store.output_head(), expected_output_head); + BOOST_CHECK_EQUAL(store.outs_head(), expected_outs_head); + ////BOOST_CHECK_EQUAL(store.spend_head(), expected_spend_head); + + BOOST_CHECK_EQUAL(store.tx_body(), expected_tx_body); + BOOST_CHECK_EQUAL(store.point_body(), expected_point_body); + BOOST_CHECK_EQUAL(store.input_body(), expected_input_body); + BOOST_CHECK_EQUAL(store.output_body(), expected_output_body); + BOOST_CHECK_EQUAL(store.outs_body(), expected_outs_body); + ////BOOST_CHECK_EQUAL(store.spend_body(), expected_spend_body); } BOOST_AUTO_TEST_CASE(query_archive_write__set_tx__get_tx__expected) @@ -347,20 +349,18 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_tx__get_tx__expected) "ffffffff" "ffffffff"); const auto expected_tx_body = system::base16_chunk( - "ffffffff" // next-> + "ffffff7f" // next-> "d80f19b9c0f649081c0b279d9183b0fae35b41b72a34eb181001f82afe22043a" // sk (tx.hash(false)) - "00" // coinbase - "740000" // witless - "800000" // witness + "740000" // light (not coinbase) + "800000" // heavy "18000000" // locktime "2a000000" // version "020000" // ins_count "020000" // outs_count - "0000000000"); // outs_fk-> - const auto expected_outs_head = system::base16_chunk("1200000000"); + "00000000" // point_fk-> (ins_fk) + "00000000"); // outs_fk-> + const auto expected_outs_head = system::base16_chunk("02000000"); const auto expected_outs_body = system::base16_chunk( - "00000000" // spend0_fk-> - "01000000" // spend1_fk-> "0000000000" // output0_fk-> "0700000000"); // output1_fk-> const auto expected_output_head = system::base16_chunk("0e00000000"); @@ -372,31 +372,35 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_tx__get_tx__expected) "2a" // value "017a"); // script const auto expected_point_body = system::base16_chunk( + "ffffffff" // next-> "0100000000000000000000000000000000000000000000000000000000000000" - "0100000000000000000000000000000000000000000000000000000000000000"); - const auto expected_spend_head = system::base16_chunk( - "02000000" // record count - "00000000" // spend0_fk-> - "ffffffff" - "ffffffff" - "01000000" // spend1_fk-> - "ffffffff"); - const auto expected_spend_body = system::base16_chunk( - "ffffffff" // terminal-> - "01000000" // fp: point_stub - "180000" // fp: point_index - "00000000" // point_fk-> - "00000000" // parent_fk-> - "2a000000" // sequence - "0000000000" // input_fk-> - - "ffffffff" // terminal-> - "01000000" // fp: point_stub - "2a0000" // fp: point_index - "01000000" // point_fk-> - "00000000" // parent_fk-> - "18000000" // sequence - "0800000000"); // input_fk-> + "180000" // index + "ffffffff" // next-> + "0100000000000000000000000000000000000000000000000000000000000000" + "2a0000"); // index + ////const auto expected_spend_head = system::base16_chunk( + //// "02000000" // record count + //// "00000000" // spend0_fk-> + //// "ffffffff" + //// "ffffffff" + //// "01000000" // spend1_fk-> + //// "ffffffff"); + ////const auto expected_spend_body = system::base16_chunk( + //// "ffffffff" // terminal-> + //// "01000000" // fp: point_stub + //// "180000" // fp: point_index + //// "00000000" // point_fk-> + //// "00000000" // parent_fk-> + //// "2a000000" // sequence + //// "0000000000" // input_fk-> + //// + //// "ffffffff" // terminal-> + //// "01000000" // fp: point_stub + //// "2a0000" // fp: point_index + //// "01000000" // point_fk-> + //// "00000000" // parent_fk-> + //// "18000000" // sequence + //// "0800000000"); // input_fk-> const auto expected_input_head = system::base16_chunk("1000000000"); const auto expected_input_body = system::base16_chunk( "026a79" // script @@ -405,7 +409,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_tx__get_tx__expected) "0103424242"); // witness constexpr auto tx_hash = system::base16_array("d80f19b9c0f649081c0b279d9183b0fae35b41b72a34eb181001f82afe22043a"); - BOOST_REQUIRE_EQUAL(tx_hash, tx.hash(false)); + BOOST_CHECK_EQUAL(tx_hash, tx.hash(false)); // data_chunk store. settings settings{}; @@ -414,29 +418,29 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_tx__get_tx__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(!query.is_tx(tx.hash(false))); - BOOST_REQUIRE(query.set(tx)); - BOOST_REQUIRE(query.is_tx(tx.hash(false))); - - const auto pointer1 = query.get_transaction(query.to_tx(tx_hash), false); - BOOST_REQUIRE(pointer1); -//// BOOST_REQUIRE(*pointer1 == tx); - BOOST_REQUIRE_EQUAL(pointer1->hash(false), tx_hash); - BOOST_REQUIRE(!store.close(events_handler)); - - BOOST_REQUIRE_EQUAL(store.tx_head(), expected_tx_head); - BOOST_REQUIRE_EQUAL(store.input_head(), expected_input_head); - BOOST_REQUIRE_EQUAL(store.output_head(), expected_output_head); -//// BOOST_REQUIRE_EQUAL(store.outs_head(), expected_outs_head); -//// BOOST_REQUIRE_EQUAL(store.spend_head(), expected_spend_head); - -//// BOOST_REQUIRE_EQUAL(store.tx_body(), expected_tx_body); -//// BOOST_REQUIRE_EQUAL(store.point_body(), expected_point_body); - BOOST_REQUIRE_EQUAL(store.input_body(), expected_input_body); - BOOST_REQUIRE_EQUAL(store.output_body(), expected_output_body); -//// BOOST_REQUIRE_EQUAL(store.outs_body(), expected_outs_body); -//// BOOST_REQUIRE_EQUAL(store.spend_body(), expected_spend_body); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(!query.is_tx(tx.hash(false))); + BOOST_CHECK(query.set(tx)); + BOOST_CHECK(query.is_tx(tx.hash(false))); + + const auto pointer = query.get_transaction(query.to_tx(tx_hash), true); + BOOST_CHECK(pointer); + BOOST_CHECK(*pointer == tx); + BOOST_CHECK_EQUAL(pointer->hash(false), tx_hash); + BOOST_CHECK(!store.close(events_handler)); + + BOOST_CHECK_EQUAL(store.tx_head(), expected_tx_head); + BOOST_CHECK_EQUAL(store.input_head(), expected_input_head); + BOOST_CHECK_EQUAL(store.output_head(), expected_output_head); + BOOST_CHECK_EQUAL(store.outs_head(), expected_outs_head); + ////BOOST_CHECK_EQUAL(store.spend_head(), expected_spend_head); + + BOOST_CHECK_EQUAL(store.tx_body(), expected_tx_body); + BOOST_CHECK_EQUAL(store.point_body(), expected_point_body); + BOOST_CHECK_EQUAL(store.input_body(), expected_input_body); + BOOST_CHECK_EQUAL(store.output_body(), expected_output_body); + BOOST_CHECK_EQUAL(store.outs_body(), expected_outs_body); + ////BOOST_CHECK_EQUAL(store.spend_body(), expected_spend_body); } BOOST_AUTO_TEST_CASE(query_archive_write__set_block__get_block__expected) @@ -477,27 +481,28 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block__get_block__expected) "ffffffff" "ffffffff"); const auto genesis_tx_body = system::base16_chunk( - "ffffffff" // next-> + "ffffff7f" // next-> "3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a" // sk (tx.hash(false)) - "01" // coinbase - "cc0000" // witless - "cc0000" // witness + "cc0080" // light (coinbase merged) + "cc0000" // heavy "00000000" // locktime "01000000" // version "010000" // ins_count "010000" // outs_count - "0000000000"); // outs_fk-> - const auto genesis_outs_head = system::base16_chunk("0900000000"); + "00000000" // point_fk-> (ins_fk) + "00000000"); // outs_fk-> + const auto genesis_outs_head = system::base16_chunk("01000000"); const auto genesis_outs_body = system::base16_chunk( - "00000000" // spend0_fk-> "0000000000"); // output0_fk-> - const auto genesis_output_head = system::base16_chunk("5100000000"); const auto genesis_output_body = system::base16_chunk( "00000000" // parent_fk-> "ff00f2052a01000000" // value "434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"); // script - const auto genesis_point_body = system::base16_chunk(""); + const auto genesis_point_body = system::base16_chunk( + "ffffffff" // next-> + "0000000000000000000000000000000000000000000000000000000000000000" + "ffffff"); // index const auto genesis_spend_head = system::base16_chunk( "01000000" // record count "00000000" // spend0_fk-> @@ -550,40 +555,40 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block__get_block__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); + BOOST_CHECK(!store.create(events_handler)); // Set block (header/txs). - BOOST_REQUIRE(!query.is_block(test::genesis.hash())); - BOOST_REQUIRE(query.set(test::genesis, test::context, milestone, false)); - BOOST_REQUIRE(query.is_block(test::genesis.hash())); + BOOST_CHECK(!query.is_block(test::genesis.hash())); + BOOST_CHECK(query.set(test::genesis, test::context, milestone, false)); + BOOST_CHECK(query.is_block(test::genesis.hash())); table::header::record element1{}; - BOOST_REQUIRE(store.header.get(query.to_header(test::genesis.hash()), element1)); - BOOST_REQUIRE(!store.close(events_handler)); - - BOOST_REQUIRE_EQUAL(store.header_head(), genesis_header_head); - BOOST_REQUIRE_EQUAL(store.tx_head(), genesis_tx_head); - BOOST_REQUIRE_EQUAL(store.input_head(), genesis_input_head); - BOOST_REQUIRE_EQUAL(store.output_head(), genesis_output_head); -//// BOOST_REQUIRE_EQUAL(store.outs_head(), genesis_outs_head); -//// BOOST_REQUIRE_EQUAL(store.spend_head(), genesis_spend_head); - BOOST_REQUIRE_EQUAL(store.txs_head(), genesis_txs_head); - - BOOST_REQUIRE_EQUAL(store.header_body(), genesis_header_body); -//// BOOST_REQUIRE_EQUAL(store.tx_body(), genesis_tx_body); -//// BOOST_REQUIRE_EQUAL(store.point_body(), genesis_point_body); - BOOST_REQUIRE_EQUAL(store.input_body(), genesis_input_body); - BOOST_REQUIRE_EQUAL(store.output_body(), genesis_output_body); -//// BOOST_REQUIRE_EQUAL(store.spend_body(), genesis_spend_body); - BOOST_REQUIRE_EQUAL(store.txs_body(), genesis_txs_body); - - const auto pointer1 = query.get_block(query.to_header(test::genesis.hash()), false); - BOOST_REQUIRE(pointer1); -//// BOOST_REQUIRE(*pointer1 == test::genesis); + BOOST_CHECK(store.header.get(query.to_header(test::genesis.hash()), element1)); + BOOST_CHECK(!store.close(events_handler)); + + BOOST_CHECK_EQUAL(store.header_head(), genesis_header_head); + BOOST_CHECK_EQUAL(store.tx_head(), genesis_tx_head); + BOOST_CHECK_EQUAL(store.input_head(), genesis_input_head); + BOOST_CHECK_EQUAL(store.output_head(), genesis_output_head); + BOOST_CHECK_EQUAL(store.outs_head(), genesis_outs_head); + ////BOOST_CHECK_EQUAL(store.spend_head(), genesis_spend_head); + BOOST_CHECK_EQUAL(store.txs_head(), genesis_txs_head); + + BOOST_CHECK_EQUAL(store.header_body(), genesis_header_body); + BOOST_CHECK_EQUAL(store.tx_body(), genesis_tx_body); + BOOST_CHECK_EQUAL(store.point_body(), genesis_point_body); + BOOST_CHECK_EQUAL(store.input_body(), genesis_input_body); + BOOST_CHECK_EQUAL(store.output_body(), genesis_output_body); + ////BOOST_CHECK_EQUAL(store.spend_body(), genesis_spend_body); + BOOST_CHECK_EQUAL(store.txs_body(), genesis_txs_body); + + const auto pointer = query.get_block(query.to_header(test::genesis.hash()), false); + BOOST_CHECK(pointer); + BOOST_CHECK(*pointer == test::genesis); const auto hashes = query.get_tx_keys(query.to_header(test::genesis.hash())); - BOOST_REQUIRE_EQUAL(hashes.size(), 1u); - BOOST_REQUIRE_EQUAL(hashes, test::genesis.transaction_hashes(false)); + BOOST_CHECK_EQUAL(hashes.size(), 1u); + BOOST_CHECK_EQUAL(hashes, test::genesis.transaction_hashes(false)); } BOOST_AUTO_TEST_CASE(query_archive_write__set_block_txs__get_block__expected) @@ -624,27 +629,29 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block_txs__get_block__expected) "ffffffff" "ffffffff"); const auto genesis_tx_body = system::base16_chunk( - "ffffffff" // next-> + "ffffff7f" // next-> "3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a" // sk (tx.hash(false)) - "01" // coinbase - "cc0000" // witless - "cc0000" // witness + "cc0080" // light (coinbase merged) + "cc0000" // heavy "00000000" // locktime "01000000" // version "010000" // ins_count "010000" // outs_count - "0000000000"); // outs_fk-> - const auto genesis_outs_head = system::base16_chunk("0900000000"); + "00000000" // point_fk-> (ins_fk) + "00000000"); // outs_fk-> + const auto genesis_outs_head = system::base16_chunk("01000000"); const auto genesis_outs_body = system::base16_chunk( "00000000" // spend0_fk-> "0000000000"); // output0_fk-> - const auto genesis_output_head = system::base16_chunk("5100000000"); const auto genesis_output_body = system::base16_chunk( "00000000" // parent_fk-> "ff00f2052a01000000" // value "434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"); // script - const auto genesis_point_body = system::base16_chunk(""); + const auto genesis_point_body = system::base16_chunk( + "ffffffff" // next-> + "0000000000000000000000000000000000000000000000000000000000000000" + "ffffff"); // index const auto genesis_spend_head = system::base16_chunk( "01000000" // record count "00000000" // spend0_fk-> @@ -697,43 +704,43 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block_txs__get_block__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); + BOOST_CHECK(!store.create(events_handler)); // Set header and then txs. - BOOST_REQUIRE(!query.is_block(test::genesis.hash())); - BOOST_REQUIRE(query.set(test::genesis.header(), test::context, milestone)); - BOOST_REQUIRE(!query.is_associated(0)); - BOOST_REQUIRE(query.set(test::genesis, false, false)); - BOOST_REQUIRE(query.is_block(test::genesis.hash())); - BOOST_REQUIRE(query.is_associated(0)); + BOOST_CHECK(!query.is_block(test::genesis.hash())); + BOOST_CHECK(query.set(test::genesis.header(), test::context, milestone)); + BOOST_CHECK(!query.is_associated(0)); + BOOST_CHECK(query.set(test::genesis, false, false)); + BOOST_CHECK(query.is_block(test::genesis.hash())); + BOOST_CHECK(query.is_associated(0)); table::header::record element1{}; - BOOST_REQUIRE(store.header.get(query.to_header(test::genesis.hash()), element1)); - BOOST_REQUIRE(!store.close(events_handler)); - - BOOST_REQUIRE_EQUAL(store.header_head(), genesis_header_head); - BOOST_REQUIRE_EQUAL(store.tx_head(), genesis_tx_head); - BOOST_REQUIRE_EQUAL(store.input_head(), genesis_input_head); - BOOST_REQUIRE_EQUAL(store.output_head(), genesis_output_head); -//// BOOST_REQUIRE_EQUAL(store.outs_head(), genesis_outs_head); -//// BOOST_REQUIRE_EQUAL(store.spend_head(), genesis_spend_head); - BOOST_REQUIRE_EQUAL(store.txs_head(), genesis_txs_head); - - BOOST_REQUIRE_EQUAL(store.header_body(), genesis_header_body); -//// BOOST_REQUIRE_EQUAL(store.tx_body(), genesis_tx_body); -//// BOOST_REQUIRE_EQUAL(store.point_body(), genesis_point_body); - BOOST_REQUIRE_EQUAL(store.input_body(), genesis_input_body); - BOOST_REQUIRE_EQUAL(store.output_body(), genesis_output_body); -//// BOOST_REQUIRE_EQUAL(store.spend_body(), genesis_spend_body); - BOOST_REQUIRE_EQUAL(store.txs_body(), genesis_txs_body); - - const auto pointer1 = query.get_block(query.to_header(test::genesis.hash()), false); - BOOST_REQUIRE(pointer1); -//// BOOST_REQUIRE(*pointer1 == test::genesis); + BOOST_CHECK(store.header.get(query.to_header(test::genesis.hash()), element1)); + BOOST_CHECK(!store.close(events_handler)); + + BOOST_CHECK_EQUAL(store.header_head(), genesis_header_head); + BOOST_CHECK_EQUAL(store.tx_head(), genesis_tx_head); + BOOST_CHECK_EQUAL(store.input_head(), genesis_input_head); + BOOST_CHECK_EQUAL(store.output_head(), genesis_output_head); + BOOST_CHECK_EQUAL(store.outs_head(), genesis_outs_head); + ////BOOST_CHECK_EQUAL(store.spend_head(), genesis_spend_head); + BOOST_CHECK_EQUAL(store.txs_head(), genesis_txs_head); + + BOOST_CHECK_EQUAL(store.header_body(), genesis_header_body); + BOOST_CHECK_EQUAL(store.tx_body(), genesis_tx_body); + BOOST_CHECK_EQUAL(store.point_body(), genesis_point_body); + BOOST_CHECK_EQUAL(store.input_body(), genesis_input_body); + BOOST_CHECK_EQUAL(store.output_body(), genesis_output_body); + ////BOOST_CHECK_EQUAL(store.spend_body(), genesis_spend_body); + BOOST_CHECK_EQUAL(store.txs_body(), genesis_txs_body); + + const auto pointer = query.get_block(query.to_header(test::genesis.hash()), false); + BOOST_CHECK(pointer); + BOOST_CHECK(*pointer == test::genesis); const auto hashes = query.get_tx_keys(query.to_header(test::genesis.hash())); - BOOST_REQUIRE_EQUAL(hashes.size(), 1u); - BOOST_REQUIRE_EQUAL(hashes, test::genesis.transaction_hashes(false)); + BOOST_CHECK_EQUAL(hashes.size(), 1u); + BOOST_CHECK_EQUAL(hashes, test::genesis.transaction_hashes(false)); } // populate_with_metadata @@ -761,21 +768,21 @@ BOOST_AUTO_TEST_CASE(query_archive_write__populate_with_metadata__null_prevouts_ settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false, false)); - BOOST_REQUIRE(query.set(test::block3, test::context, false, false)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1, test::context, false, false)); + BOOST_CHECK(query.set(test::block2, test::context, false, false)); + BOOST_CHECK(query.set(test::block3, test::context, false, false)); const auto& copy = clean_(test::genesis); const auto& copy1 = clean_(test::block1); const auto& copy2 = clean_(test::block2); const auto& copy3 = clean_(test::block3); - BOOST_REQUIRE(query.populate_with_metadata(copy)); - BOOST_REQUIRE(query.populate_with_metadata(copy1)); - BOOST_REQUIRE(query.populate_with_metadata(copy2)); - BOOST_REQUIRE(query.populate_with_metadata(copy3)); + BOOST_CHECK(query.populate_with_metadata(copy)); + BOOST_CHECK(query.populate_with_metadata(copy1)); + BOOST_CHECK(query.populate_with_metadata(copy2)); + BOOST_CHECK(query.populate_with_metadata(copy3)); } BOOST_AUTO_TEST_CASE(query_archive_write__populate_with_metadata__partial_prevouts__false) @@ -784,32 +791,32 @@ BOOST_AUTO_TEST_CASE(query_archive_write__populate_with_metadata__partial_prevou settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1a, test::context, false, false)); - BOOST_REQUIRE(query.set(test::block2a, test::context, false, false)); - BOOST_REQUIRE(query.set(test::tx4)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1a, test::context, false, false)); + BOOST_CHECK(query.set(test::block2a, test::context, false, false)); + BOOST_CHECK(query.set(test::tx4)); const auto& block1a = clean_(test::block1a); // Block populate treates first tx as null point. - BOOST_REQUIRE( query.populate_with_metadata(block1a)); - BOOST_REQUIRE(!query.populate_with_metadata(*block1a.transactions_ptr()->at(0))); - BOOST_REQUIRE(!query.populate_with_metadata(*block1a.inputs_ptr()->at(0))); - BOOST_REQUIRE(!query.populate_with_metadata(*block1a.inputs_ptr()->at(2))); + BOOST_CHECK( query.populate_with_metadata(block1a)); + BOOST_CHECK(!query.populate_with_metadata(*block1a.transactions_ptr()->at(0))); + BOOST_CHECK(!query.populate_with_metadata(*block1a.inputs_ptr()->at(0))); + BOOST_CHECK(!query.populate_with_metadata(*block1a.inputs_ptr()->at(2))); // Block populate treates first tx as null point and other has missing prevouts. const auto& block2a = clean_(test::block2a); - BOOST_REQUIRE(!query.populate_with_metadata(block2a)); - BOOST_REQUIRE( query.populate_with_metadata(*block2a.transactions_ptr()->at(0))); - BOOST_REQUIRE(!query.populate_with_metadata(*block2a.transactions_ptr()->at(1))); - BOOST_REQUIRE( query.populate_with_metadata(*block2a.inputs_ptr()->at(0))); - BOOST_REQUIRE(!query.populate_with_metadata(*block2a.inputs_ptr()->at(3))); + BOOST_CHECK(!query.populate_with_metadata(block2a)); + BOOST_CHECK( query.populate_with_metadata(*block2a.transactions_ptr()->at(0))); + BOOST_CHECK(!query.populate_with_metadata(*block2a.transactions_ptr()->at(1))); + BOOST_CHECK( query.populate_with_metadata(*block2a.inputs_ptr()->at(0))); + BOOST_CHECK(!query.populate_with_metadata(*block2a.inputs_ptr()->at(3))); const auto& tx4 = clean_(test::tx4); - BOOST_REQUIRE(query.populate_with_metadata(tx4)); - BOOST_REQUIRE(query.populate_with_metadata(*tx4.inputs_ptr()->at(0))); - BOOST_REQUIRE(query.populate_with_metadata(*tx4.inputs_ptr()->at(1))); + BOOST_CHECK(query.populate_with_metadata(tx4)); + BOOST_CHECK(query.populate_with_metadata(*tx4.inputs_ptr()->at(0))); + BOOST_CHECK(query.populate_with_metadata(*tx4.inputs_ptr()->at(1))); } BOOST_AUTO_TEST_CASE(query_archive_write__populate_with_metadata__metadata__expected) @@ -818,52 +825,52 @@ BOOST_AUTO_TEST_CASE(query_archive_write__populate_with_metadata__metadata__expe settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1a, test::context, false, false)); - BOOST_REQUIRE(query.set(test::block2a, test::context, false, false)); - BOOST_REQUIRE(query.set(test::tx4)); - BOOST_REQUIRE(!query.is_coinbase(1)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1a, test::context, false, false)); + BOOST_CHECK(query.set(test::block2a, test::context, false, false)); + BOOST_CHECK(query.set(test::tx4)); + BOOST_CHECK(!query.is_coinbase(1)); // Genesis only has coinbase, which does not spend. const auto& genesis = clean_(test::genesis); - BOOST_REQUIRE(!genesis.inputs_ptr()->at(0)->prevout); - BOOST_REQUIRE( genesis.inputs_ptr()->at(0)->metadata.inside); - BOOST_REQUIRE( genesis.inputs_ptr()->at(0)->metadata.coinbase); - BOOST_REQUIRE_EQUAL(genesis.inputs_ptr()->at(0)->metadata.parent, 0u); + BOOST_CHECK(!genesis.inputs_ptr()->at(0)->prevout); + BOOST_CHECK( genesis.inputs_ptr()->at(0)->metadata.inside); + BOOST_CHECK( genesis.inputs_ptr()->at(0)->metadata.coinbase); + BOOST_CHECK_EQUAL(genesis.inputs_ptr()->at(0)->metadata.parent, 0u); - BOOST_REQUIRE(query.populate_with_metadata(genesis)); + BOOST_CHECK(query.populate_with_metadata(genesis)); - BOOST_REQUIRE(!genesis.inputs_ptr()->at(0)->prevout); - BOOST_REQUIRE( genesis.inputs_ptr()->at(0)->metadata.inside); - BOOST_REQUIRE( genesis.inputs_ptr()->at(0)->metadata.coinbase); - BOOST_REQUIRE_EQUAL(genesis.inputs_ptr()->at(0)->metadata.parent, 0u); + BOOST_CHECK(!genesis.inputs_ptr()->at(0)->prevout); + BOOST_CHECK( genesis.inputs_ptr()->at(0)->metadata.inside); + BOOST_CHECK( genesis.inputs_ptr()->at(0)->metadata.coinbase); + BOOST_CHECK_EQUAL(genesis.inputs_ptr()->at(0)->metadata.parent, 0u); // Transaction population. const auto& tx4 = clean_(test::tx4); - BOOST_REQUIRE(!tx4.inputs_ptr()->at(0)->prevout); - BOOST_REQUIRE( tx4.inputs_ptr()->at(0)->metadata.inside); - BOOST_REQUIRE( tx4.inputs_ptr()->at(0)->metadata.coinbase); - BOOST_REQUIRE_EQUAL(tx4.inputs_ptr()->at(0)->metadata.parent, 0u); - BOOST_REQUIRE(!tx4.inputs_ptr()->at(1)->prevout); - BOOST_REQUIRE( tx4.inputs_ptr()->at(1)->metadata.inside); - BOOST_REQUIRE( tx4.inputs_ptr()->at(1)->metadata.coinbase); - BOOST_REQUIRE_EQUAL(tx4.inputs_ptr()->at(1)->metadata.parent, 0u); + BOOST_CHECK(!tx4.inputs_ptr()->at(0)->prevout); + BOOST_CHECK( tx4.inputs_ptr()->at(0)->metadata.inside); + BOOST_CHECK( tx4.inputs_ptr()->at(0)->metadata.coinbase); + BOOST_CHECK_EQUAL(tx4.inputs_ptr()->at(0)->metadata.parent, 0u); + BOOST_CHECK(!tx4.inputs_ptr()->at(1)->prevout); + BOOST_CHECK( tx4.inputs_ptr()->at(1)->metadata.inside); + BOOST_CHECK( tx4.inputs_ptr()->at(1)->metadata.coinbase); + BOOST_CHECK_EQUAL(tx4.inputs_ptr()->at(1)->metadata.parent, 0u); - BOOST_REQUIRE(query.populate_with_metadata(tx4)); + BOOST_CHECK(query.populate_with_metadata(tx4)); // TODO: test non-coinbase and other parent. // spent/mtp are defaults, coinbase/parent are set (to non-default values). - BOOST_REQUIRE( tx4.inputs_ptr()->at(0)->prevout); - BOOST_REQUIRE(!tx4.inputs_ptr()->at(0)->metadata.inside); - BOOST_REQUIRE(!tx4.inputs_ptr()->at(0)->metadata.coinbase); - BOOST_REQUIRE_EQUAL(tx4.inputs_ptr()->at(0)->metadata.parent, 1u); - BOOST_REQUIRE( tx4.inputs_ptr()->at(1)->prevout); - BOOST_REQUIRE(!tx4.inputs_ptr()->at(1)->metadata.inside); - BOOST_REQUIRE(!tx4.inputs_ptr()->at(1)->metadata.coinbase); - BOOST_REQUIRE_EQUAL(tx4.inputs_ptr()->at(1)->metadata.parent, 1u); + BOOST_CHECK( tx4.inputs_ptr()->at(0)->prevout); + BOOST_CHECK(!tx4.inputs_ptr()->at(0)->metadata.inside); + BOOST_CHECK(!tx4.inputs_ptr()->at(0)->metadata.coinbase); + BOOST_CHECK_EQUAL(tx4.inputs_ptr()->at(0)->metadata.parent, 1u); + BOOST_CHECK( tx4.inputs_ptr()->at(1)->prevout); + BOOST_CHECK(!tx4.inputs_ptr()->at(1)->metadata.inside); + BOOST_CHECK(!tx4.inputs_ptr()->at(1)->metadata.coinbase); + BOOST_CHECK_EQUAL(tx4.inputs_ptr()->at(1)->metadata.parent, 1u); } // populate_without_metadata @@ -876,15 +883,15 @@ BOOST_AUTO_TEST_CASE(query_archive_write__populate_without_metadata__null_prevou settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false, false)); - BOOST_REQUIRE(query.set(test::block3, test::context, false, false)); - BOOST_REQUIRE(query.populate_without_metadata(test::genesis)); - BOOST_REQUIRE(query.populate_without_metadata(test::block1)); - BOOST_REQUIRE(query.populate_without_metadata(test::block2)); - BOOST_REQUIRE(query.populate_without_metadata(test::block3)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1, test::context, false, false)); + BOOST_CHECK(query.set(test::block2, test::context, false, false)); + BOOST_CHECK(query.set(test::block3, test::context, false, false)); + BOOST_CHECK(query.populate_without_metadata(test::genesis)); + BOOST_CHECK(query.populate_without_metadata(test::block1)); + BOOST_CHECK(query.populate_without_metadata(test::block2)); + BOOST_CHECK(query.populate_without_metadata(test::block3)); } BOOST_AUTO_TEST_CASE(query_archive_write__populate_without_metadata__partial_prevouts__false) @@ -893,28 +900,28 @@ BOOST_AUTO_TEST_CASE(query_archive_write__populate_without_metadata__partial_pre settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1a, test::context, false, false)); - BOOST_REQUIRE(query.set(test::block2a, test::context, false, false)); - BOOST_REQUIRE(query.set(test::tx4)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1a, test::context, false, false)); + BOOST_CHECK(query.set(test::block2a, test::context, false, false)); + BOOST_CHECK(query.set(test::tx4)); // Block populate treates first tx as null point. - BOOST_REQUIRE( query.populate_without_metadata(test::block1a)); - BOOST_REQUIRE(!query.populate_without_metadata(*test::block1a.transactions_ptr()->at(0))); - BOOST_REQUIRE(!query.populate_without_metadata(*test::block1a.inputs_ptr()->at(0))); - BOOST_REQUIRE(!query.populate_without_metadata(*test::block1a.inputs_ptr()->at(2))); + BOOST_CHECK( query.populate_without_metadata(test::block1a)); + BOOST_CHECK(!query.populate_without_metadata(*test::block1a.transactions_ptr()->at(0))); + BOOST_CHECK(!query.populate_without_metadata(*test::block1a.inputs_ptr()->at(0))); + BOOST_CHECK(!query.populate_without_metadata(*test::block1a.inputs_ptr()->at(2))); // Block populate treates first tx as null point and other has missing prevouts. - BOOST_REQUIRE(!query.populate_without_metadata(test::block2a)); - BOOST_REQUIRE( query.populate_without_metadata(*test::block2a.transactions_ptr()->at(0))); - BOOST_REQUIRE(!query.populate_without_metadata(*test::block2a.transactions_ptr()->at(1))); - BOOST_REQUIRE( query.populate_without_metadata(*test::block2a.inputs_ptr()->at(0))); - BOOST_REQUIRE(!query.populate_without_metadata(*test::block2a.inputs_ptr()->at(3))); - - BOOST_REQUIRE(query.populate_without_metadata(test::tx4)); - BOOST_REQUIRE(query.populate_without_metadata(*test::tx4.inputs_ptr()->at(0))); - BOOST_REQUIRE(query.populate_without_metadata(*test::tx4.inputs_ptr()->at(1))); + BOOST_CHECK(!query.populate_without_metadata(test::block2a)); + BOOST_CHECK( query.populate_without_metadata(*test::block2a.transactions_ptr()->at(0))); + BOOST_CHECK(!query.populate_without_metadata(*test::block2a.transactions_ptr()->at(1))); + BOOST_CHECK( query.populate_without_metadata(*test::block2a.inputs_ptr()->at(0))); + BOOST_CHECK(!query.populate_without_metadata(*test::block2a.inputs_ptr()->at(3))); + + BOOST_CHECK(query.populate_without_metadata(test::tx4)); + BOOST_CHECK(query.populate_without_metadata(*test::tx4.inputs_ptr()->at(0))); + BOOST_CHECK(query.populate_without_metadata(*test::tx4.inputs_ptr()->at(1))); } // ---------------------------------------------------------------------------- @@ -927,15 +934,15 @@ BOOST_AUTO_TEST_CASE(query_archive_write__is_coinbase__coinbase__true) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, context{}, false, false)); - BOOST_REQUIRE(query.set(test::block2, context{}, false, false)); - BOOST_REQUIRE(query.set(test::block3, context{}, false, false)); - BOOST_REQUIRE(query.is_coinbase(0)); - BOOST_REQUIRE(query.is_coinbase(1)); - BOOST_REQUIRE(query.is_coinbase(2)); - BOOST_REQUIRE(query.is_coinbase(3)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1, context{}, false, false)); + BOOST_CHECK(query.set(test::block2, context{}, false, false)); + BOOST_CHECK(query.set(test::block3, context{}, false, false)); + BOOST_CHECK(query.is_coinbase(0)); + BOOST_CHECK(query.is_coinbase(1)); + BOOST_CHECK(query.is_coinbase(2)); + BOOST_CHECK(query.is_coinbase(3)); } BOOST_AUTO_TEST_CASE(query_archive_write__is_coinbase__non_coinbase__false) @@ -944,16 +951,16 @@ BOOST_AUTO_TEST_CASE(query_archive_write__is_coinbase__non_coinbase__false) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1a, context{}, false, false)); - BOOST_REQUIRE(query.set(test::block2a, context{}, false, false)); - BOOST_REQUIRE(!query.is_coinbase(1)); - BOOST_REQUIRE(!query.is_coinbase(2)); - BOOST_REQUIRE(!query.is_coinbase(3)); - BOOST_REQUIRE(!query.is_coinbase(4)); - BOOST_REQUIRE(!query.is_coinbase(5)); - BOOST_REQUIRE(!query.is_coinbase(42)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1a, context{}, false, false)); + BOOST_CHECK(query.set(test::block2a, context{}, false, false)); + BOOST_CHECK(!query.is_coinbase(1)); + BOOST_CHECK(!query.is_coinbase(2)); + BOOST_CHECK(!query.is_coinbase(3)); + BOOST_CHECK(!query.is_coinbase(4)); + BOOST_CHECK(!query.is_coinbase(5)); + BOOST_CHECK(!query.is_coinbase(42)); } BOOST_AUTO_TEST_CASE(query_archive_write__is_milestone__genesis__false) @@ -962,10 +969,10 @@ BOOST_AUTO_TEST_CASE(query_archive_write__is_milestone__genesis__false) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(!query.is_milestone(0)); - BOOST_REQUIRE(!query.is_milestone(1)); + BOOST_CHECK_EQUAL(store.create(events_handler), error::success); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(!query.is_milestone(0)); + BOOST_CHECK(!query.is_milestone(1)); } BOOST_AUTO_TEST_CASE(query_archive_write__is_milestone__set__expected) @@ -974,13 +981,13 @@ BOOST_AUTO_TEST_CASE(query_archive_write__is_milestone__set__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, context{}, true, false)); - BOOST_REQUIRE(query.set(test::block2, context{}, false, false));; - BOOST_REQUIRE(!query.is_milestone(0)); - BOOST_REQUIRE(query.is_milestone(1)); - BOOST_REQUIRE(!query.is_milestone(2)); + BOOST_CHECK_EQUAL(store.create(events_handler), error::success); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1, context{}, true, false)); + BOOST_CHECK(query.set(test::block2, context{}, false, false));; + BOOST_CHECK(!query.is_milestone(0)); + BOOST_CHECK(query.is_milestone(1)); + BOOST_CHECK(!query.is_milestone(2)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_header__invalid_parent__expected) @@ -1026,12 +1033,12 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_header__invalid_parent__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); + BOOST_CHECK(!store.create(events_handler)); store.header_head() = expected_header_head; store.header_body() = expected_header_body; - BOOST_REQUIRE(!query.get_header(query.to_header(block_hash))); - BOOST_REQUIRE(!query.get_header(header_link::terminal)); + BOOST_CHECK(!query.get_header(query.to_header(block_hash))); + BOOST_CHECK(!query.get_header(header_link::terminal)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_header__default__expected) @@ -1089,21 +1096,21 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_header__default__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); + BOOST_CHECK(!store.create(events_handler)); ////store.header_head() = expected_header_head; ////store.header_body() = expected_header_body; - BOOST_REQUIRE(query.set(header, context{ 0x11121314, 0x01020304, 0x21222324 }, true)); - BOOST_REQUIRE_EQUAL(store.header_head(), expected_header_head); - BOOST_REQUIRE_EQUAL(store.header_body(), expected_header_body); + BOOST_CHECK(query.set(header, context{ 0x11121314, 0x01020304, 0x21222324 }, true)); + BOOST_CHECK_EQUAL(store.header_head(), expected_header_head); + BOOST_CHECK_EQUAL(store.header_body(), expected_header_body); const auto foo = query.to_header(block_hash); const auto pointer1 = query.get_header(foo); - BOOST_REQUIRE(pointer1); - BOOST_REQUIRE(*pointer1 == header); + BOOST_CHECK(pointer1); + BOOST_CHECK(*pointer1 == header); // Verify hash caching. - BOOST_REQUIRE_EQUAL(pointer1->hash(), block_hash); + BOOST_CHECK_EQUAL(pointer1->hash(), block_hash); } BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_keys__not_found__empty) @@ -1112,9 +1119,9 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_keys__not_found__empty) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.get_tx_keys(query.to_header(system::null_hash)).empty()); - BOOST_REQUIRE(!store.close(events_handler)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.get_tx_keys(query.to_header(system::null_hash)).empty()); + BOOST_CHECK(!store.close(events_handler)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_header_key__always__expected) @@ -1123,10 +1130,10 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_header_key__always__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE_EQUAL(query.get_header_key(0), test::genesis.hash()); - BOOST_REQUIRE_EQUAL(query.get_header_key(1), system::null_hash); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK_EQUAL(query.get_header_key(0), test::genesis.hash()); + BOOST_CHECK_EQUAL(query.get_header_key(1), system::null_hash); } BOOST_AUTO_TEST_CASE(query_archive_write__get_point_key__always__expected) @@ -1135,24 +1142,24 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_point_key__always__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE_EQUAL(query.get_point_hash(0), system::null_hash); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK_EQUAL(query.get_point_hash(0), system::null_hash); // tx4/5 prevouts are all block1a.tx1. - BOOST_REQUIRE(query.set(test::tx4)); - BOOST_REQUIRE(query.set(test::tx5)); -//// BOOST_REQUIRE_EQUAL(query.get_point_hash(0), test::block1a.transactions_ptr()->front()->hash(false)); - BOOST_REQUIRE_EQUAL(query.get_point_hash(1), test::block1a.transactions_ptr()->front()->hash(false)); - BOOST_REQUIRE_EQUAL(query.get_point_hash(2), test::block1a.transactions_ptr()->front()->hash(false)); -//// BOOST_REQUIRE_EQUAL(query.get_point_hash(3), system::null_hash); + BOOST_CHECK(query.set(test::tx4)); + BOOST_CHECK(query.set(test::tx5)); +//// BOOST_CHECK_EQUAL(query.get_point_hash(0), test::block1a.transactions_ptr()->front()->hash(false)); + BOOST_CHECK_EQUAL(query.get_point_hash(1), test::block1a.transactions_ptr()->front()->hash(false)); + BOOST_CHECK_EQUAL(query.get_point_hash(2), test::block1a.transactions_ptr()->front()->hash(false)); +//// BOOST_CHECK_EQUAL(query.get_point_hash(3), system::null_hash); // block1a adds three prevouts of two txs. - BOOST_REQUIRE(query.set(test::block1a, context{}, false, false)); -//// BOOST_REQUIRE_EQUAL(query.get_point_hash(3), system::one_hash); - BOOST_REQUIRE_EQUAL(query.get_point_hash(4), system::one_hash); -//// BOOST_REQUIRE_EQUAL(query.get_point_hash(5), test::two_hash); -//// BOOST_REQUIRE_EQUAL(query.get_point_hash(6), system::null_hash); + BOOST_CHECK(query.set(test::block1a, context{}, false, false)); +//// BOOST_CHECK_EQUAL(query.get_point_hash(3), system::one_hash); + BOOST_CHECK_EQUAL(query.get_point_hash(4), system::one_hash); +//// BOOST_CHECK_EQUAL(query.get_point_hash(5), test::two_hash); +//// BOOST_CHECK_EQUAL(query.get_point_hash(6), system::null_hash); } BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_key__always__expected) @@ -1161,15 +1168,15 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_key__always__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE_EQUAL(query.get_tx_key(0), test::genesis.transactions_ptr()->front()->hash(false)); - BOOST_REQUIRE_EQUAL(query.get_tx_key(1), system::null_hash); - BOOST_REQUIRE(query.set(test::tx4)); - BOOST_REQUIRE(query.set(test::tx5)); - BOOST_REQUIRE_EQUAL(query.get_tx_key(1), test::tx4.hash(false)); - BOOST_REQUIRE_EQUAL(query.get_tx_key(2), test::tx5.hash(false)); - BOOST_REQUIRE_EQUAL(query.get_tx_key(3), system::null_hash); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK_EQUAL(query.get_tx_key(0), test::genesis.transactions_ptr()->front()->hash(false)); + BOOST_CHECK_EQUAL(query.get_tx_key(1), system::null_hash); + BOOST_CHECK(query.set(test::tx4)); + BOOST_CHECK(query.set(test::tx5)); + BOOST_CHECK_EQUAL(query.get_tx_key(1), test::tx4.hash(false)); + BOOST_CHECK_EQUAL(query.get_tx_key(2), test::tx5.hash(false)); + BOOST_CHECK_EQUAL(query.get_tx_key(3), system::null_hash); } BOOST_AUTO_TEST_CASE(query_archive_write__get_height1__always__expected) @@ -1178,28 +1185,28 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_height1__always__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, context{ 0, 1, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block2, context{ 0, 2, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block3, context{ 0, 3, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block2a, context{ 0, 2, 0 }, false, false)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1, context{ 0, 1, 0 }, false, false)); + BOOST_CHECK(query.set(test::block2, context{ 0, 2, 0 }, false, false)); + BOOST_CHECK(query.set(test::block3, context{ 0, 3, 0 }, false, false)); + BOOST_CHECK(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); + BOOST_CHECK(query.set(test::block2a, context{ 0, 2, 0 }, false, false)); size_t out{}; - BOOST_REQUIRE(query.get_height(out, 0)); - BOOST_REQUIRE_EQUAL(out, 0u); - BOOST_REQUIRE(query.get_height(out, 1)); - BOOST_REQUIRE_EQUAL(out, 1u); - BOOST_REQUIRE(query.get_height(out, 2)); - BOOST_REQUIRE_EQUAL(out, 2u); - BOOST_REQUIRE(query.get_height(out, 3)); - BOOST_REQUIRE_EQUAL(out, 3u); - BOOST_REQUIRE(query.get_height(out, 4)); - BOOST_REQUIRE_EQUAL(out, 1u); - BOOST_REQUIRE(query.get_height(out, 5)); - BOOST_REQUIRE_EQUAL(out, 2u); - BOOST_REQUIRE(!query.get_height(out, 6)); + BOOST_CHECK(query.get_height(out, 0)); + BOOST_CHECK_EQUAL(out, 0u); + BOOST_CHECK(query.get_height(out, 1)); + BOOST_CHECK_EQUAL(out, 1u); + BOOST_CHECK(query.get_height(out, 2)); + BOOST_CHECK_EQUAL(out, 2u); + BOOST_CHECK(query.get_height(out, 3)); + BOOST_CHECK_EQUAL(out, 3u); + BOOST_CHECK(query.get_height(out, 4)); + BOOST_CHECK_EQUAL(out, 1u); + BOOST_CHECK(query.get_height(out, 5)); + BOOST_CHECK_EQUAL(out, 2u); + BOOST_CHECK(!query.get_height(out, 6)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_height2__always__expected) @@ -1208,28 +1215,28 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_height2__always__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, context{ 0, 1, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block2, context{ 0, 2, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block3, context{ 0, 3, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block2a, context{ 0, 2, 0 }, false, false)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1, context{ 0, 1, 0 }, false, false)); + BOOST_CHECK(query.set(test::block2, context{ 0, 2, 0 }, false, false)); + BOOST_CHECK(query.set(test::block3, context{ 0, 3, 0 }, false, false)); + BOOST_CHECK(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); + BOOST_CHECK(query.set(test::block2a, context{ 0, 2, 0 }, false, false)); size_t out{}; - BOOST_REQUIRE(query.get_height(out, test::genesis.hash())); - BOOST_REQUIRE_EQUAL(out, 0u); - BOOST_REQUIRE(query.get_height(out, test::block1.hash())); - BOOST_REQUIRE_EQUAL(out, 1u); - BOOST_REQUIRE(query.get_height(out, test::block2.hash())); - BOOST_REQUIRE_EQUAL(out, 2u); - BOOST_REQUIRE(query.get_height(out, test::block3.hash())); - BOOST_REQUIRE_EQUAL(out, 3u); - BOOST_REQUIRE(query.get_height(out, test::block1a.hash())); - BOOST_REQUIRE_EQUAL(out, 1u); - BOOST_REQUIRE(query.get_height(out, test::block2a.hash())); - BOOST_REQUIRE_EQUAL(out, 2u); - BOOST_REQUIRE(!query.get_height(out, system::one_hash)); + BOOST_CHECK(query.get_height(out, test::genesis.hash())); + BOOST_CHECK_EQUAL(out, 0u); + BOOST_CHECK(query.get_height(out, test::block1.hash())); + BOOST_CHECK_EQUAL(out, 1u); + BOOST_CHECK(query.get_height(out, test::block2.hash())); + BOOST_CHECK_EQUAL(out, 2u); + BOOST_CHECK(query.get_height(out, test::block3.hash())); + BOOST_CHECK_EQUAL(out, 3u); + BOOST_CHECK(query.get_height(out, test::block1a.hash())); + BOOST_CHECK_EQUAL(out, 1u); + BOOST_CHECK(query.get_height(out, test::block2a.hash())); + BOOST_CHECK_EQUAL(out, 2u); + BOOST_CHECK(!query.get_height(out, system::one_hash)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_height__not_strong__false) @@ -1238,12 +1245,12 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_height__not_strong__false) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::tx4)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::tx4)); size_t out{}; - BOOST_REQUIRE(!query.get_tx_height(out, 1)); + BOOST_CHECK(!query.get_tx_height(out, 1)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_position__confirmed__expected) @@ -1252,40 +1259,40 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_position__confirmed__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block2a, context{ 0, 2, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block3a, context{ 0, 3, 0 }, false, false)); - BOOST_REQUIRE(query.set_strong(1)); - BOOST_REQUIRE(query.set_strong(2)); - BOOST_REQUIRE(query.set_strong(3)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); + BOOST_CHECK(query.set(test::block2a, context{ 0, 2, 0 }, false, false)); + BOOST_CHECK(query.set(test::block3a, context{ 0, 3, 0 }, false, false)); + BOOST_CHECK(query.set_strong(1)); + BOOST_CHECK(query.set_strong(2)); + BOOST_CHECK(query.set_strong(3)); size_t out{}; const auto foo = query.get_tx_position(out, 0); - BOOST_REQUIRE(foo); - BOOST_REQUIRE_EQUAL(out, 0u); - - BOOST_REQUIRE(!query.get_tx_position(out, 1)); - BOOST_REQUIRE(!query.get_tx_position(out, 2)); - BOOST_REQUIRE(!query.get_tx_position(out, 3)); - BOOST_REQUIRE(!query.get_tx_position(out, 4)); - BOOST_REQUIRE(query.push_confirmed(1, false)); - BOOST_REQUIRE(query.push_confirmed(2, false)); - BOOST_REQUIRE(query.push_confirmed(3, false)); - - BOOST_REQUIRE_EQUAL(out, 0u); - BOOST_REQUIRE(query.get_tx_position(out, 0)); - BOOST_REQUIRE_EQUAL(out, 0u); - BOOST_REQUIRE(query.get_tx_position(out, 1)); - BOOST_REQUIRE_EQUAL(out, 0u); - BOOST_REQUIRE(query.get_tx_position(out, 2)); - BOOST_REQUIRE_EQUAL(out, 0u); - BOOST_REQUIRE(query.get_tx_position(out, 3)); - BOOST_REQUIRE_EQUAL(out, 1u); - BOOST_REQUIRE(query.get_tx_position(out, 4)); - BOOST_REQUIRE_EQUAL(out, 0u); - BOOST_REQUIRE(!query.get_tx_position(out, 5)); + BOOST_CHECK(foo); + BOOST_CHECK_EQUAL(out, 0u); + + BOOST_CHECK(!query.get_tx_position(out, 1)); + BOOST_CHECK(!query.get_tx_position(out, 2)); + BOOST_CHECK(!query.get_tx_position(out, 3)); + BOOST_CHECK(!query.get_tx_position(out, 4)); + BOOST_CHECK(query.push_confirmed(1, false)); + BOOST_CHECK(query.push_confirmed(2, false)); + BOOST_CHECK(query.push_confirmed(3, false)); + + BOOST_CHECK_EQUAL(out, 0u); + BOOST_CHECK(query.get_tx_position(out, 0)); + BOOST_CHECK_EQUAL(out, 0u); + BOOST_CHECK(query.get_tx_position(out, 1)); + BOOST_CHECK_EQUAL(out, 0u); + BOOST_CHECK(query.get_tx_position(out, 2)); + BOOST_CHECK_EQUAL(out, 0u); + BOOST_CHECK(query.get_tx_position(out, 3)); + BOOST_CHECK_EQUAL(out, 1u); + BOOST_CHECK(query.get_tx_position(out, 4)); + BOOST_CHECK_EQUAL(out, 0u); + BOOST_CHECK(!query.get_tx_position(out, 5)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_position__always__expected) @@ -1294,42 +1301,42 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_position__always__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block2a, context{ 0, 2, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::block3a, context{ 0, 3, 0 }, false, false)); - BOOST_REQUIRE(query.set(test::tx4)); - BOOST_REQUIRE(query.set_strong(1)); - BOOST_REQUIRE(query.set_strong(2)); - BOOST_REQUIRE(query.set_strong(3)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); + BOOST_CHECK(query.set(test::block2a, context{ 0, 2, 0 }, false, false)); + BOOST_CHECK(query.set(test::block3a, context{ 0, 3, 0 }, false, false)); + BOOST_CHECK(query.set(test::tx4)); + BOOST_CHECK(query.set_strong(1)); + BOOST_CHECK(query.set_strong(2)); + BOOST_CHECK(query.set_strong(3)); size_t out{}; - BOOST_REQUIRE(query.get_tx_position(out, 0)); - BOOST_REQUIRE_EQUAL(out, 0u); - - BOOST_REQUIRE(!query.get_tx_position(out, 1)); - BOOST_REQUIRE(!query.get_tx_position(out, 2)); - BOOST_REQUIRE(!query.get_tx_position(out, 3)); - BOOST_REQUIRE(!query.get_tx_position(out, 4)); - BOOST_REQUIRE(query.push_confirmed(1, false)); - BOOST_REQUIRE(query.push_confirmed(2, false)); - BOOST_REQUIRE(query.push_confirmed(3, false)); - - BOOST_REQUIRE_EQUAL(out, 0u); - BOOST_REQUIRE(query.get_tx_position(out, 0)); - BOOST_REQUIRE_EQUAL(out, 0u); - BOOST_REQUIRE(query.get_tx_position(out, 1)); - BOOST_REQUIRE_EQUAL(out, 0u); - BOOST_REQUIRE(query.get_tx_position(out, 2)); - BOOST_REQUIRE_EQUAL(out, 0u); - BOOST_REQUIRE(query.get_tx_position(out, 3)); - BOOST_REQUIRE_EQUAL(out, 1u); - BOOST_REQUIRE(query.get_tx_position(out, 4)); - BOOST_REQUIRE_EQUAL(out, 0u); + BOOST_CHECK(query.get_tx_position(out, 0)); + BOOST_CHECK_EQUAL(out, 0u); + + BOOST_CHECK(!query.get_tx_position(out, 1)); + BOOST_CHECK(!query.get_tx_position(out, 2)); + BOOST_CHECK(!query.get_tx_position(out, 3)); + BOOST_CHECK(!query.get_tx_position(out, 4)); + BOOST_CHECK(query.push_confirmed(1, false)); + BOOST_CHECK(query.push_confirmed(2, false)); + BOOST_CHECK(query.push_confirmed(3, false)); + + BOOST_CHECK_EQUAL(out, 0u); + BOOST_CHECK(query.get_tx_position(out, 0)); + BOOST_CHECK_EQUAL(out, 0u); + BOOST_CHECK(query.get_tx_position(out, 1)); + BOOST_CHECK_EQUAL(out, 0u); + BOOST_CHECK(query.get_tx_position(out, 2)); + BOOST_CHECK_EQUAL(out, 0u); + BOOST_CHECK(query.get_tx_position(out, 3)); + BOOST_CHECK_EQUAL(out, 1u); + BOOST_CHECK(query.get_tx_position(out, 4)); + BOOST_CHECK_EQUAL(out, 0u); // tx4 is unconfirmed. - BOOST_REQUIRE(!query.get_tx_position(out, 5)); + BOOST_CHECK(!query.get_tx_position(out, 5)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_sizes__coinbase__204) @@ -1338,14 +1345,14 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_sizes__coinbase__204) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); size_t light{}; size_t heavy{}; - BOOST_REQUIRE(query.get_tx_sizes(light, heavy, 0)); - BOOST_REQUIRE_EQUAL(light, 204u); - BOOST_REQUIRE_EQUAL(heavy, 204u); + BOOST_CHECK(query.get_tx_sizes(light, heavy, 0)); + BOOST_CHECK_EQUAL(light, 204u); + BOOST_CHECK_EQUAL(heavy, 204u); } BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_count__coinbase__1) @@ -1354,9 +1361,9 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_tx_count__coinbase__1) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE_EQUAL(query.get_tx_count(0), 1u); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK_EQUAL(query.get_tx_count(0), 1u); } BOOST_AUTO_TEST_CASE(query_archive_write__get_input__not_found__nullptr) @@ -1365,9 +1372,9 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_input__not_found__nullptr) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(!query.get_input(query.to_tx(system::null_hash), 0u, false)); - BOOST_REQUIRE(!store.close(events_handler)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(!query.get_input(query.to_tx(system::null_hash), 0u, false)); + BOOST_CHECK(!store.close(events_handler)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_input__genesis__expected) @@ -1379,13 +1386,13 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_input__genesis__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.set(test::genesis, test::context, false, false)); const auto tx = test::genesis.transactions_ptr()->front(); const auto input = tx->inputs_ptr()->front(); -//// BOOST_REQUIRE(*input == *query.get_input(query.to_tx(tx->hash(false)), 0u)); -//// BOOST_REQUIRE(*input == *query.get_input(0)); + ////BOOST_CHECK(*input == *query.get_input(query.to_tx(tx->hash(false)), 0u)); + ////BOOST_CHECK(*input == *query.get_input(0)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_inputs__tx_not_found__nullptr) @@ -1394,9 +1401,9 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_inputs__tx_not_found__nullptr) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(!query.get_inputs(1, false)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(!query.get_inputs(1, false)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_inputs__found__expected) @@ -1405,10 +1412,10 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_inputs__found__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::tx4)); - BOOST_REQUIRE_EQUAL(query.get_inputs(1, false)->size(), 2u); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::tx4)); + BOOST_CHECK_EQUAL(query.get_inputs(1, false)->size(), 2u); } BOOST_AUTO_TEST_CASE(query_archive_write__get_output__not_found__nullptr) @@ -1417,11 +1424,11 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_output__not_found__nullptr) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(!query.get_output(query.to_tx(system::null_hash), 0u)); - BOOST_REQUIRE(!query.get_output(query.to_output(system::chain::point{ system::null_hash, 0u }))); - BOOST_REQUIRE(!query.get_output(0)); - BOOST_REQUIRE(!store.close(events_handler)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(!query.get_output(query.to_tx(system::null_hash), 0u)); + BOOST_CHECK(!query.get_output(query.to_output(system::chain::point{ system::null_hash, 0u }))); + BOOST_CHECK(!query.get_output(0)); + BOOST_CHECK(!store.close(events_handler)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_output__genesis__expected) @@ -1433,14 +1440,14 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_output__genesis__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.set(test::genesis, test::context, false, false)); const auto tx = test::genesis.transactions_ptr()->front(); const auto output1 = tx->outputs_ptr()->front(); - BOOST_REQUIRE(*output1 == *query.get_output(query.to_tx(tx->hash(false)), 0u)); - BOOST_REQUIRE(*output1 == *query.get_output(query.to_output(tx->hash(false), 0u))); - BOOST_REQUIRE(*output1 == *query.get_output(0)); + BOOST_CHECK(*output1 == *query.get_output(query.to_tx(tx->hash(false)), 0u)); + BOOST_CHECK(*output1 == *query.get_output(query.to_output(tx->hash(false), 0u))); + BOOST_CHECK(*output1 == *query.get_output(0)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_outputs__tx_not_found__nullptr) @@ -1449,9 +1456,9 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_outputs__tx_not_found__nullptr) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(!query.get_outputs(1)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(!query.get_outputs(1)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_outputs__found__expected) @@ -1460,10 +1467,10 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_outputs__found__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::tx4)); - BOOST_REQUIRE_EQUAL(query.get_outputs(1)->size(), 1u); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::tx4)); + BOOST_CHECK_EQUAL(query.get_outputs(1)->size(), 1u); } BOOST_AUTO_TEST_CASE(query_archive_write__get_transactions__tx_not_found__nullptr) @@ -1472,10 +1479,10 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_transactions__tx_not_found__nullpt settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::tx4)); - BOOST_REQUIRE(!query.get_transactions(3, false)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::tx4)); + BOOST_CHECK(!query.get_transactions(3, false)); } BOOST_AUTO_TEST_CASE(query_archive_write__get_transactions__found__expected) @@ -1484,14 +1491,14 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_transactions__found__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1a, test::context, false, false)); - BOOST_REQUIRE(query.set(test::block2a, test::context, false, false)); - BOOST_REQUIRE(query.set(test::tx4)); - BOOST_REQUIRE_EQUAL(query.get_transactions(0, false)->size(), 1u); - BOOST_REQUIRE_EQUAL(query.get_transactions(1, false)->size(), 1u); - BOOST_REQUIRE_EQUAL(query.get_transactions(2, false)->size(), 2u); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1a, test::context, false, false)); + BOOST_CHECK(query.set(test::block2a, test::context, false, false)); + BOOST_CHECK(query.set(test::tx4)); + BOOST_CHECK_EQUAL(query.get_transactions(0, false)->size(), 1u); + BOOST_CHECK_EQUAL(query.get_transactions(1, false)->size(), 1u); + BOOST_CHECK_EQUAL(query.get_transactions(2, false)->size(), 2u); } BOOST_AUTO_TEST_CASE(query_archive_write__get_spenders__unspent_or_not_found__expected) @@ -1500,36 +1507,36 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_spenders__unspent_or_not_found__ex settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false, false)); - BOOST_REQUIRE(query.set(test::block3, test::context, false, false)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); + BOOST_CHECK(query.set(test::block1, test::context, false, false)); + BOOST_CHECK(query.set(test::block2, test::context, false, false)); + BOOST_CHECK(query.set(test::block3, test::context, false, false)); // Caller should always test for nullptr. - BOOST_REQUIRE(query.get_spenders(output_link::terminal, true)->empty()); - //BOOST_REQUIRE(query.get_spenders_index(tx_link::terminal, 0, true)->empty()); - //BOOST_REQUIRE(query.get_spenders_index(tx_link::terminal, 1, true)->empty()); - - BOOST_REQUIRE(query.get_spenders(query.to_output(0, 0), true)->empty()); - BOOST_REQUIRE(query.get_spenders(query.to_output(0, 1), true)->empty()); - //BOOST_REQUIRE(query.get_spenders_index(0, 0, true)->empty()); - //BOOST_REQUIRE(query.get_spenders_index(0, 1, true)->empty()); - - BOOST_REQUIRE(query.get_spenders(query.to_output(1, 0), true)->empty()); - BOOST_REQUIRE(query.get_spenders(query.to_output(1, 1), true)->empty()); - //BOOST_REQUIRE(query.get_spenders_index(1, 0, true)->empty()); - //BOOST_REQUIRE(query.get_spenders_index(1, 1, true)->empty()); - - BOOST_REQUIRE(query.get_spenders(query.to_output(2, 0), true)->empty()); - BOOST_REQUIRE(query.get_spenders(query.to_output(2, 1), true)->empty()); - //BOOST_REQUIRE(query.get_spenders_index(2, 0, true)->empty()); - //BOOST_REQUIRE(query.get_spenders_index(2, 1, true)->empty()); - - BOOST_REQUIRE(query.get_spenders(query.to_output(3, 0), true)->empty()); - BOOST_REQUIRE(query.get_spenders(query.to_output(3, 1), true)->empty()); - //BOOST_REQUIRE(query.get_spenders_index(3, 0, true)->empty()); - //BOOST_REQUIRE(query.get_spenders_index(3, 1, true)->empty()); + BOOST_CHECK(query.get_spenders(output_link::terminal, true)->empty()); + ////BOOST_CHECK(query.get_spenders_index(tx_link::terminal, 0, true)->empty()); + ////BOOST_CHECK(query.get_spenders_index(tx_link::terminal, 1, true)->empty()); + + BOOST_CHECK(query.get_spenders(query.to_output(0, 0), true)->empty()); + BOOST_CHECK(query.get_spenders(query.to_output(0, 1), true)->empty()); + ////BOOST_CHECK(query.get_spenders_index(0, 0, true)->empty()); + ////BOOST_CHECK(query.get_spenders_index(0, 1, true)->empty()); + + BOOST_CHECK(query.get_spenders(query.to_output(1, 0), true)->empty()); + BOOST_CHECK(query.get_spenders(query.to_output(1, 1), true)->empty()); + ////BOOST_CHECK(query.get_spenders_index(1, 0, true)->empty()); + ////BOOST_CHECK(query.get_spenders_index(1, 1, true)->empty()); + + BOOST_CHECK(query.get_spenders(query.to_output(2, 0), true)->empty()); + BOOST_CHECK(query.get_spenders(query.to_output(2, 1), true)->empty()); + ////BOOST_CHECK(query.get_spenders_index(2, 0, true)->empty()); + ////BOOST_CHECK(query.get_spenders_index(2, 1, true)->empty()); + + BOOST_CHECK(query.get_spenders(query.to_output(3, 0), true)->empty()); + BOOST_CHECK(query.get_spenders(query.to_output(3, 1), true)->empty()); + ////BOOST_CHECK(query.get_spenders_index(3, 0, true)->empty()); + ////BOOST_CHECK(query.get_spenders_index(3, 1, true)->empty()); } ////BOOST_AUTO_TEST_CASE(query_archive_write__get_spenders__found_and_spent__expected) @@ -1538,54 +1545,54 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_spenders__unspent_or_not_found__ex //// settings.path = TEST_DIRECTORY; //// test::chunk_store store{ settings }; //// test::query_accessor query{ store }; -//// BOOST_REQUIRE(!store.create(events_handler)); -//// BOOST_REQUIRE(query.initialize(test::genesis)); +//// BOOST_CHECK(!store.create(events_handler)); +//// BOOST_CHECK(query.initialize(test::genesis)); //// //// // Neither of the two block1a outputs spent yet. -//// BOOST_REQUIRE(query.set(test::block1a, test::context, false, false)); -//// BOOST_REQUIRE(query.get_spenders(query.to_output(1, 0), true)->empty()); -//// BOOST_REQUIRE(query.get_spenders(query.to_output(1, 1), true)->empty()); -//// BOOST_REQUIRE(query.get_spenders(query.to_output(1, 2), true)->empty()); -//// BOOST_REQUIRE(query.get_spenders_index(1, 0, true)->empty()); -//// BOOST_REQUIRE(query.get_spenders_index(1, 1, true)->empty()); -//// BOOST_REQUIRE(query.get_spenders_index(1, 2, true)->empty()); +//// BOOST_CHECK(query.set(test::block1a, test::context, false, false)); +//// BOOST_CHECK(query.get_spenders(query.to_output(1, 0), true)->empty()); +//// BOOST_CHECK(query.get_spenders(query.to_output(1, 1), true)->empty()); +//// BOOST_CHECK(query.get_spenders(query.to_output(1, 2), true)->empty()); +//// BOOST_CHECK(query.get_spenders_index(1, 0, true)->empty()); +//// BOOST_CHECK(query.get_spenders_index(1, 1, true)->empty()); +//// BOOST_CHECK(query.get_spenders_index(1, 2, true)->empty()); //// //// // Each of the two outputs of block1a spent once. -//// BOOST_REQUIRE(query.set(test::block2a, test::context, false, false)); +//// BOOST_CHECK(query.set(test::block2a, test::context, false, false)); //// -//// BOOST_REQUIRE_EQUAL(query.get_spenders(query.to_output(1, 0), true)->size(), 1u); -//// BOOST_REQUIRE_EQUAL(query.get_spenders(query.to_output(1, 1), true)->size(), 1u); -//// BOOST_REQUIRE(query.get_spenders(query.to_output(1, 2), true)->empty()); -//// BOOST_REQUIRE_EQUAL(query.get_spenders_index(1, 0, true)->size(), 1u); -//// BOOST_REQUIRE_EQUAL(query.get_spenders_index(1, 1, true)->size(), 1u); -//// BOOST_REQUIRE_EQUAL(query.get_spenders_index(1, 2, true)->size(), 0u); +//// BOOST_CHECK_EQUAL(query.get_spenders(query.to_output(1, 0), true)->size(), 1u); +//// BOOST_CHECK_EQUAL(query.get_spenders(query.to_output(1, 1), true)->size(), 1u); +//// BOOST_CHECK(query.get_spenders(query.to_output(1, 2), true)->empty()); +//// BOOST_CHECK_EQUAL(query.get_spenders_index(1, 0, true)->size(), 1u); +//// BOOST_CHECK_EQUAL(query.get_spenders_index(1, 1, true)->size(), 1u); +//// BOOST_CHECK_EQUAL(query.get_spenders_index(1, 2, true)->size(), 0u); //// //// // Match the two spenders. //// const auto block_inputs = test::block2a.transactions_ptr()->front()->inputs_ptr(); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0), true)->front() == *(*block_inputs).front()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1), true)->front() == *(*block_inputs).back()); -//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *(*block_inputs).front()); -//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *(*block_inputs).back()); +//// BOOST_CHECK(*query.get_spenders(query.to_output(1, 0), true)->front() == *(*block_inputs).front()); +//// BOOST_CHECK(*query.get_spenders(query.to_output(1, 1), true)->front() == *(*block_inputs).back()); +//// BOOST_CHECK(*query.get_spenders(1, 0)->front() == *(*block_inputs).front()); +//// BOOST_CHECK(*query.get_spenders(1, 1)->front() == *(*block_inputs).back()); //// //// // Each of the two outputs of block1a spent twice (two unconfirmed double spends). -//// BOOST_REQUIRE(query.set(test::tx4)); -//// BOOST_REQUIRE_EQUAL(query.get_spenders(query.to_output(1, 0), true)->size(), 2u); -//// BOOST_REQUIRE_EQUAL(query.get_spenders(query.to_output(1, 1), true)->size(), 2u); -//// BOOST_REQUIRE(query.get_spenders(query.to_output(1, 2), true)->empty()); -//// BOOST_REQUIRE_EQUAL(query.get_spenders_index(1, 0, true)->size(), 2u); -//// BOOST_REQUIRE_EQUAL(query.get_spenders_index(1, 1, true)->size(), 2u); -//// BOOST_REQUIRE_EQUAL(query.get_spenders_index(1, 2, true)->size(), 0u); +//// BOOST_CHECK(query.set(test::tx4)); +//// BOOST_CHECK_EQUAL(query.get_spenders(query.to_output(1, 0), true)->size(), 2u); +//// BOOST_CHECK_EQUAL(query.get_spenders(query.to_output(1, 1), true)->size(), 2u); +//// BOOST_CHECK(query.get_spenders(query.to_output(1, 2), true)->empty()); +//// BOOST_CHECK_EQUAL(query.get_spenders_index(1, 0, true)->size(), 2u); +//// BOOST_CHECK_EQUAL(query.get_spenders_index(1, 1, true)->size(), 2u); +//// BOOST_CHECK_EQUAL(query.get_spenders_index(1, 2, true)->size(), 0u); //// //// // Match the four spenders. //// const auto tx_inputs = test::tx4.inputs_ptr(); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0), true)->front() == *(*tx_inputs).front()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1), true)->front() == *(*tx_inputs).back()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0), true)->back() == *(*block_inputs).front()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1), true)->back() == *(*block_inputs).back()); -//// BOOST_REQUIRE(*query.get_spenders_index(1, 0, true)->front() == *(*tx_inputs).front()); -//// BOOST_REQUIRE(*query.get_spenders_index(1, 1, true)->front() == *(*tx_inputs).back()); -//// BOOST_REQUIRE(*query.get_spenders_index(1, 0, true)->back() == *(*block_inputs).front()); -//// BOOST_REQUIRE(*query.get_spenders_index(1, 1, true)->back() == *(*block_inputs).back()); +//// BOOST_CHECK(*query.get_spenders(query.to_output(1, 0), true)->front() == *(*tx_inputs).front()); +//// BOOST_CHECK(*query.get_spenders(query.to_output(1, 1), true)->front() == *(*tx_inputs).back()); +//// BOOST_CHECK(*query.get_spenders(query.to_output(1, 0), true)->back() == *(*block_inputs).front()); +//// BOOST_CHECK(*query.get_spenders(query.to_output(1, 1), true)->back() == *(*block_inputs).back()); +//// BOOST_CHECK(*query.get_spenders_index(1, 0, true)->front() == *(*tx_inputs).front()); +//// BOOST_CHECK(*query.get_spenders_index(1, 1, true)->front() == *(*tx_inputs).back()); +//// BOOST_CHECK(*query.get_spenders_index(1, 0, true)->back() == *(*block_inputs).front()); +//// BOOST_CHECK(*query.get_spenders_index(1, 1, true)->back() == *(*block_inputs).back()); ////} BOOST_AUTO_TEST_CASE(query_archive_write__get_value__genesis__expected) @@ -1594,12 +1601,12 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_value__genesis__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; - BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.initialize(test::genesis)); + BOOST_CHECK(!store.create(events_handler)); + BOOST_CHECK(query.initialize(test::genesis)); uint64_t value{}; - BOOST_REQUIRE(query.get_value(value, query.to_output(0, 0))); - BOOST_REQUIRE_EQUAL(value, 5000000000u); + BOOST_CHECK(query.get_value(value, query.to_output(0, 0))); + BOOST_CHECK_EQUAL(value, 5000000000u); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/tables/archives/transaction.cpp b/test/tables/archives/transaction.cpp index e265ab2b..cf9ea223 100644 --- a/test/tables/archives/transaction.cpp +++ b/test/tables/archives/transaction.cpp @@ -46,8 +46,7 @@ const data_chunk expected_file 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // record - 0x00, - 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, // coinbase merged (false) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -66,8 +65,7 @@ const data_chunk expected_file 0x22, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, // record - 0x01, - 0x01, 0x12, 0x34, + 0x01, 0x12, 0xb4, // coinbase merged (true) 0x02, 0x12, 0x34, 0x03, 0x12, 0x34, 0x56, 0x04, 0x12, 0x34, 0x56, From daa092a7bca0cc344bc8b2357d7a4c2e8d45b3f7 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 23 Feb 2026 22:02:06 -0500 Subject: [PATCH 7/9] Merge header.milestone into header.parent_fk, style. --- .../database/tables/archives/header.hpp | 143 +++++++++++------- include/bitcoin/database/tables/schema.hpp | 10 +- test/query/archive_read.cpp | 5 +- test/query/archive_write.cpp | 14 +- test/tables/archives/header.cpp | 6 +- 5 files changed, 105 insertions(+), 73 deletions(-) diff --git a/include/bitcoin/database/tables/archives/header.hpp b/include/bitcoin/database/tables/archives/header.hpp index cc9a03e5..00cf4951 100644 --- a/include/bitcoin/database/tables/archives/header.hpp +++ b/include/bitcoin/database/tables/archives/header.hpp @@ -33,7 +33,51 @@ namespace table { struct header : public hash_map { + using head = schema::header::link; using hash_map::hashmap; + static constexpr auto offset = head::bits; + static_assert(offset < to_bits(head::size)); + + static constexpr size_t skip_to_height = + context::flag_t::size; + + static constexpr size_t skip_to_mtp = + skip_to_height + + context::height_t::size; + + static constexpr size_t skip_to_parent = + skip_to_mtp + + sizeof(uint32_t); + + static constexpr size_t skip_to_version = + skip_to_parent + + link::size; + + static constexpr size_t skip_to_timestamp = + skip_to_version + + sizeof(uint32_t); + + static constexpr size_t skip_to_bits = + skip_to_timestamp + + sizeof(uint32_t); + + static constexpr head::integer merge(bool milestone, + head::integer parent_fk) NOEXCEPT + { + using namespace system; + BC_ASSERT_MSG(!get_right(parent_fk, offset), "overflow"); + return set_right(parent_fk, offset, milestone); + } + + static constexpr bool is_milestone(link::integer merged) NOEXCEPT + { + return system::get_right(merged, offset); + } + + static constexpr link::integer to_parent(link::integer merged) NOEXCEPT + { + return system::set_right(merged, offset, false); + } struct record : public schema::header @@ -41,8 +85,9 @@ struct header inline bool from_data(reader& source) NOEXCEPT { context::from_data(source, ctx); - milestone = to_bool(source.read_byte()); - parent_fk = source.read_little_endian(); + const auto merged = source.read_little_endian(); + milestone = is_milestone(merged); + parent_fk = to_parent(merged); version = source.read_little_endian(); timestamp = source.read_little_endian(); bits = source.read_little_endian(); @@ -55,8 +100,7 @@ struct header inline bool to_data(finalizer& sink) const NOEXCEPT { context::to_data(sink, ctx); - sink.write_byte(to_int(milestone)); - sink.write_little_endian(parent_fk); + sink.write_little_endian(merge(milestone, parent_fk)); sink.write_little_endian(version); sink.write_little_endian(timestamp); sink.write_little_endian(bits); @@ -96,8 +140,7 @@ struct header inline bool to_data(finalizer& sink) const NOEXCEPT { context::to_data(sink, ctx); - sink.write_byte(to_int(milestone)); - sink.write_little_endian(parent_fk); + sink.write_little_endian(merge(milestone, parent_fk)); sink.write_little_endian(header.version()); sink.write_little_endian(header.timestamp()); sink.write_little_endian(header.bits()); @@ -144,45 +187,56 @@ struct header key key{}; }; - struct get_version + struct record_context : public schema::header { inline bool from_data(reader& source) NOEXCEPT { - source.skip_bytes(context::size + schema::bit + link::size); - version = source.read_little_endian(); + context::from_data(source, ctx); return source; } - uint32_t version{}; + context ctx{}; }; - struct get_timestamp + struct get_flags : public schema::header { + using flag_t = context::flag_t; inline bool from_data(reader& source) NOEXCEPT { - source.skip_bytes(context::size + schema::bit + link::size + - sizeof(uint32_t)); - timestamp = source.read_little_endian(); + flags = source.read_little_endian(); return source; } - uint32_t timestamp{}; + flag_t::integer flags{}; }; - struct get_bits + struct get_height : public schema::header { + using height_t = context::height_t; inline bool from_data(reader& source) NOEXCEPT { - source.skip_bytes(context::size + schema::bit + link::size + - sizeof(uint32_t) + sizeof(uint32_t)); - bits = source.read_little_endian(); + source.skip_bytes(skip_to_height); + height = source.read_little_endian(); return source; } - uint32_t bits{}; + height_t::integer height{}; + }; + + struct get_mtp + : public schema::header + { + inline bool from_data(reader& source) NOEXCEPT + { + source.skip_bytes(skip_to_mtp); + mtp = source.read_little_endian(); + return source; + } + + context::mtp_t mtp{}; }; struct get_parent_fk @@ -190,54 +244,51 @@ struct header { inline bool from_data(reader& source) NOEXCEPT { - source.skip_bytes(context::size + schema::bit); - parent_fk = source.read_little_endian(); + source.skip_bytes(skip_to_parent); + parent_fk = to_parent(source.read_little_endian()); return source; } link::integer parent_fk{}; }; - struct get_flags + struct get_version : public schema::header { - using flag_t = context::flag_t; - inline bool from_data(reader& source) NOEXCEPT { - flags = source.read_little_endian(); + source.skip_bytes(skip_to_version); + version = source.read_little_endian(); return source; } - flag_t::integer flags{}; + uint32_t version{}; }; - struct get_height + struct get_timestamp : public schema::header { - using height_t = context::height_t; - inline bool from_data(reader& source) NOEXCEPT { - source.skip_bytes(context::flag_t::size); - height = source.read_little_endian(); + source.skip_bytes(skip_to_timestamp); + timestamp = source.read_little_endian(); return source; } - height_t::integer height{}; + uint32_t timestamp{}; }; - struct get_mtp + struct get_bits : public schema::header { inline bool from_data(reader& source) NOEXCEPT { - source.skip_bytes(context::flag_t::size + context::height_t::size); - mtp = source.read_little_endian(); + source.skip_bytes(skip_to_bits); + bits = source.read_little_endian(); return source; } - context::mtp_t mtp{}; + uint32_t bits{}; }; struct get_milestone @@ -245,8 +296,8 @@ struct header { inline bool from_data(reader& source) NOEXCEPT { - source.skip_bytes(context::size); - milestone = to_bool(source.read_byte()); + source.skip_bytes(skip_to_parent); + milestone = is_milestone(source.read_little_endian()); return source; } @@ -261,7 +312,7 @@ struct header source.rewind_bytes(sk); key = source.read_hash(); context::from_data(source, ctx); - source.skip_bytes(schema::bit + link::size + sizeof(uint32_t)); + source.skip_bytes(skip_to_timestamp - skip_to_parent); timestamp = source.read_little_endian(); return source; } @@ -270,18 +321,6 @@ struct header context ctx{}; uint32_t timestamp{}; }; - - struct record_context - : public schema::header - { - inline bool from_data(reader& source) NOEXCEPT - { - context::from_data(source, ctx); - return source; - } - - context ctx{}; - }; }; } // namespace table diff --git a/include/bitcoin/database/tables/schema.hpp b/include/bitcoin/database/tables/schema.hpp index 66351268..b973ec54 100644 --- a/include/bitcoin/database/tables/schema.hpp +++ b/include/bitcoin/database/tables/schema.hpp @@ -64,13 +64,13 @@ struct header { static constexpr size_t sk = schema::hash; static constexpr size_t pk = schema::block; - using link = linkage; // reduced for strong_tx merge. - using key = system::data_array; + using link = linkage; // reduced for milestone + using key = system::data_array; // ...and strong_tx merges. static constexpr size_t minsize = schema::flags + // context.flags schema::height_ + // context.height sizeof(uint32_t) + // context.mtp - schema::bit + // milestone [TODO: merge into parent pk] + ///schema::bit + // milestone (merged into parent pk) pk + // parent.pk sizeof(uint32_t) + // version sizeof(uint32_t) + // timestamp @@ -81,8 +81,8 @@ struct header static constexpr size_t size = minsize; static constexpr size_t cell = sizeof(unsigned_type); static constexpr link count() NOEXCEPT { return 1; } - static_assert(minsize == 63u); - static_assert(minrow == 98u); + static_assert(minsize == 62u); + static_assert(minrow == 97u); static_assert(link::size == 3u); static_assert(cell == 4u); }; diff --git a/test/query/archive_read.cpp b/test/query/archive_read.cpp index 4176a1c4..aa3e1cfd 100644 --- a/test/query/archive_read.cpp +++ b/test/query/archive_read.cpp @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(query_archive_read__get_header__invalid_parent__expected) "14131211" // flags "040302" // height "24232221" // mtp - "424242" // previous_block_hash (header_fk - invalid) + "424242" // previous_block_hash (header_fk - invalid) (milestone false) "34333231" // version "44434241" // timestamp "54535251" // bits @@ -187,8 +187,7 @@ BOOST_AUTO_TEST_CASE(query_archive_read__get_header__default__expected) "14131211" // flags "040302" // height "24232221" // mtp - "01" // milestone - "ffff7f" // previous_block_hash (header_fk - terminal) + "ffffff" // previous_block_hash (header_fk - terminal) (milestone true) "34333231" // version "44434241" // timestamp "54535251" // bits diff --git a/test/query/archive_write.cpp b/test/query/archive_write.cpp index 5a355529..63142eda 100644 --- a/test/query/archive_write.cpp +++ b/test/query/archive_write.cpp @@ -118,8 +118,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_link_header__is_header__expected) "04030201" // flags "141312" // height "24232221" // mtp - "01" // milestone - "ffff7f" // previous_block_hash (header_fk - not found) + "ffffff" // previous_block_hash (header_fk - not found) (milestone true) "34333231" // version "44434241" // timestamp "54535251" // bits @@ -463,8 +462,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block__get_block__expected) "04030201" // flags "141312" // height "24232221" // mtp - "01" // milestone - "ffff7f" // previous_block_hash (header_fk - not found) + "ffffff" // previous_block_hash (header_fk - not found) (milestone true) "01000000" // version "29ab5f49" // timestamp "ffff001d" // bits @@ -611,8 +609,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block_txs__get_block__expected) "04030201" // flags "141312" // height "24232221" // mtp - "01" // milestone - "ffff7f" // previous_block_hash (header_fk - not found) + "ffffff" // previous_block_hash (header_fk - not found) (milestone true) "01000000" // version "29ab5f49" // timestamp "ffff001d" // bits @@ -1021,7 +1018,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_header__invalid_parent__expected) "14131211" // flags "040302" // height "24232221" // mtp - "424242" // previous_block_hash (header_fk - invalid) + "424242" // previous_block_hash (header_fk - invalid) (milestone false) "34333231" // version "44434241" // timestamp "54535251" // bits @@ -1083,8 +1080,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__get_header__default__expected) "14131211" // flags "040302" // height "24232221" // mtp - "01" // milestone - "ffff7f" // previous_block_hash (header_fk - terminal) + "ffffff" // previous_block_hash (header_fk - terminal) (milestone true) "34333231" // version "44434241" // timestamp "54535251" // bits diff --git a/test/tables/archives/header.cpp b/test/tables/archives/header.cpp index b1b765c3..fe146da5 100644 --- a/test/tables/archives/header.cpp +++ b/test/tables/archives/header.cpp @@ -64,8 +64,7 @@ const data_chunk expected_file 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, - 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, // milestone merged (false) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -86,8 +85,7 @@ const data_chunk expected_file 0x02, 0x12, 0x34, 0x56, 0x01, 0x12, 0x34, 0x03, 0x12, 0x34, 0x56, - 0x01, - 0x04, 0x12, 0x34, + 0x04, 0x12, 0xb4, // milestone merged (true) 0x05, 0x12, 0x34, 0x56, 0x06, 0x12, 0x34, 0x56, 0x07, 0x12, 0x34, 0x56, From 446d9877f2a1647629ef895eb0273d42edf65bba Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 23 Feb 2026 22:02:30 -0500 Subject: [PATCH 8/9] Comments, style. --- .../bitcoin/database/tables/archives/txs.hpp | 2 +- include/bitcoin/database/tables/schema.hpp | 32 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/bitcoin/database/tables/archives/txs.hpp b/include/bitcoin/database/tables/archives/txs.hpp index e882d00b..fd6e7106 100644 --- a/include/bitcoin/database/tables/archives/txs.hpp +++ b/include/bitcoin/database/tables/archives/txs.hpp @@ -31,7 +31,7 @@ namespace libbitcoin { namespace database { namespace table { -// TODO: make heavy field variable size. +// TODO: interval could move to count and sizes made variable. // TODO: fks can instead be stored as a count and coinbase fk, // TODO: but will need to be disambiguated from compact blocks. diff --git a/include/bitcoin/database/tables/schema.hpp b/include/bitcoin/database/tables/schema.hpp index b973ec54..335caa25 100644 --- a/include/bitcoin/database/tables/schema.hpp +++ b/include/bitcoin/database/tables/schema.hpp @@ -121,8 +121,8 @@ struct input static constexpr size_t pk = schema::put; using link = linkage; static constexpr size_t minsize = - 1u + // variable_size (minimum 1, average 1) - 1u; // variable_size (minimum 1, average 1) + one + // script size (variable) + one; // witness size (variable) static constexpr size_t minrow = minsize; static constexpr size_t size = max_size_t; static_assert(minsize == 2u); @@ -138,12 +138,12 @@ struct output using link = linkage; static constexpr size_t minsize = schema::transaction::pk + // parent->tx (address navigation) - 5u + // variable_size (minimum 1, average 5) - 1u; // variable_size (minimum 1, average 1) + one + // value (variable) + one; // script size (variable) static constexpr size_t minrow = minsize; static constexpr size_t size = max_size_t; - static_assert(minsize == 10u); - static_assert(minrow == 10u); + static_assert(minsize == 6u); + static_assert(minrow == 6u); static_assert(link::size == 5u); }; @@ -209,8 +209,8 @@ struct txs schema::size + // heavy count_ + // txs schema::transaction::pk;// coinbase tx - ////schema::bit + // is interval [merged into light] - ////0 | schema::hash + // interval hash [each 2048th block] + ////schema::bit + // is interval (merged into light) + ////0 | schema::hash + // interval hash (each 2048th block) static constexpr size_t minrow = minsize; static constexpr size_t size = max_size_t; static_assert(minsize == 12u); @@ -244,7 +244,7 @@ struct strong_tx using link = linkage; using key = system::data_array; static constexpr size_t minsize = - ////schema::bit + // merged bit into header::pk. + ////schema::bit + // positive (merged bit into header::pk) schema::header::pk; static constexpr size_t minrow = pk + sk + minsize; static constexpr size_t size = minsize; @@ -286,10 +286,10 @@ struct prevout static constexpr size_t pk = schema::prevout_; using link = linkage; static constexpr size_t minsize = - ////schema::bit + // merged bit into transaction::pk. - one + // varint(conflict-count) - schema::transaction::pk + // prevout_tx - one; // varint(sequence) + ////schema::bit + // coinbase (merged into transaction::pk). + one + // conflict-count (variable) + schema::transaction::pk + // prevout_tx + one; // sequence (variable) static constexpr size_t minrow = minsize; static constexpr size_t size = max_size_t; static_assert(minsize == 6u); @@ -324,9 +324,9 @@ struct validated_tx schema::flags + schema::header::pk + sizeof(uint32_t) + - schema::code + // TODO: change code to variable. - one + // variable: fee - one; // variable: sigops + schema::code + // TODO: change to variable. + one + // fee (variable) + one; // sigops (variable) static constexpr size_t minrow = pk + sk + minsize; static constexpr size_t size = max_size_t; static constexpr size_t cell = link::size; From f889b354183757399c2e12cb954e90c33a307b78 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 23 Feb 2026 22:36:21 -0500 Subject: [PATCH 9/9] Remove bogus assertions. --- include/bitcoin/database/impl/query/validate.ipp | 1 - include/bitcoin/database/tables/archives/txs.hpp | 2 -- 2 files changed, 3 deletions(-) diff --git a/include/bitcoin/database/impl/query/validate.ipp b/include/bitcoin/database/impl/query/validate.ipp index 5060ed2d..e86dc220 100644 --- a/include/bitcoin/database/impl/query/validate.ipp +++ b/include/bitcoin/database/impl/query/validate.ipp @@ -377,7 +377,6 @@ bool CLASS::set_tx_state(const tx_link& link, const context& ctx, uint64_t fee, size_t sigops, schema::tx_state state) NOEXCEPT { using sigs = linkage; - BC_ASSERT(sigops(to_bits(sigs::size))); // ======================================================================== const auto scope = store_.get_transactor(); diff --git a/include/bitcoin/database/tables/archives/txs.hpp b/include/bitcoin/database/tables/archives/txs.hpp index fd6e7106..235da282 100644 --- a/include/bitcoin/database/tables/archives/txs.hpp +++ b/include/bitcoin/database/tables/archives/txs.hpp @@ -173,8 +173,6 @@ struct txs inline bool to_data(finalizer& sink) const NOEXCEPT { - BC_ASSERT(number < system::power2(to_bits(ct::size))); - // tx sizes const auto merged = merge(interval.has_value(), light); sink.write_little_endian(merged);