From f56ba2947ab47ac4ceda8547418fcdbcaf87fdd5 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Wed, 12 Jun 2024 14:44:52 -0400 Subject: [PATCH] Normalize object setting functions, deprecate set_link() variants. --- include/bitcoin/database/error.hpp | 3 + .../bitcoin/database/impl/query/archive.ipp | 220 ++++++++++++------ .../bitcoin/database/impl/query/confirm.ipp | 2 +- .../bitcoin/database/impl/query/validate.ipp | 7 +- include/bitcoin/database/query.hpp | 130 +++++++---- .../database/tables/archives/header.hpp | 22 +- src/error.cpp | 5 +- test/error.cpp | 11 + test/query/archive.cpp | 138 +++++------ test/query/confirm.cpp | 94 ++++---- test/query/context.cpp | 2 +- test/query/initialize.cpp | 74 +++--- test/query/optional.cpp | 2 +- test/query/translate.cpp | 66 +++--- test/query/validate.cpp | 68 +++--- test/tables/archives/header.cpp | 6 +- 16 files changed, 487 insertions(+), 363 deletions(-) diff --git a/include/bitcoin/database/error.hpp b/include/bitcoin/database/error.hpp index 5a659c7b..d0684d75 100644 --- a/include/bitcoin/database/error.hpp +++ b/include/bitcoin/database/error.hpp @@ -117,6 +117,9 @@ enum error_t : uint8_t tx_address_put, tx_tx_commit, + /// header archive + header_put, + /// txs archive txs_empty, txs_header, diff --git a/include/bitcoin/database/impl/query/archive.ipp b/include/bitcoin/database/impl/query/archive.ipp index 8f09bd27..b029645a 100644 --- a/include/bitcoin/database/impl/query/archive.ipp +++ b/include/bitcoin/database/impl/query/archive.ipp @@ -137,47 +137,42 @@ inline bool CLASS::is_associated(const header_link& link) const NOEXCEPT TEMPLATE bool CLASS::set(const header& header, const chain_context& ctx, - bool bypass) NOEXCEPT + bool milestone) NOEXCEPT { - return !set_link(header, ctx, bypass).is_terminal(); + return !set_code(header, ctx, milestone); } TEMPLATE -bool CLASS::set(const header& header, const context& ctx, bool bypass) NOEXCEPT +bool CLASS::set(const header& header, const context& ctx, bool milestone) NOEXCEPT { - return !set_link(header, ctx, bypass).is_terminal(); + return !set_code(header, ctx, milestone); } TEMPLATE -bool CLASS::set(const block& block, const chain_context& ctx, - bool bypass) NOEXCEPT +bool CLASS::set(const block& block, const chain_context& ctx, bool milestone, + bool strong) NOEXCEPT { - return !set_link(block, ctx, bypass).is_terminal(); + return !set_code(block, ctx, milestone, strong); } TEMPLATE -bool CLASS::set(const block& block, const context& ctx, bool bypass) NOEXCEPT +bool CLASS::set(const block& block, const context& ctx, bool milestone, + bool strong) NOEXCEPT { - return !set_link(block, ctx, bypass).is_terminal(); + return !set_code(block, ctx, milestone, strong); } TEMPLATE -bool CLASS::set(const hash_digest& point_hash) NOEXCEPT +bool CLASS::set(const transaction& tx) NOEXCEPT { - return !set_link(point_hash).is_terminal(); + return !set_code(tx); } TEMPLATE -bool CLASS::set(const block& block) NOEXCEPT +bool CLASS::set(const block& block, bool strong) NOEXCEPT { // This sets only the txs of a block with header/context already archived. - return !set_link(block).is_terminal(); -} - -TEMPLATE -bool CLASS::set(const transaction& tx) NOEXCEPT -{ - return !set_link(tx).is_terminal(); + return !set_code(block, strong); } TEMPLATE @@ -684,7 +679,9 @@ typename CLASS::inputs_ptr CLASS::get_spenders(const tx_link& link, // set transaction // ---------------------------------------------------------------------------- +// The only multitable write query (except initialize/genesis). +// deprecated TEMPLATE tx_link CLASS::set_link(const transaction& tx) NOEXCEPT { @@ -692,7 +689,13 @@ tx_link CLASS::set_link(const transaction& tx) NOEXCEPT return set_code(tx_fk, tx) ? tx_link{} : tx_fk; } -// The only multitable write query (except initialize/genesis). +TEMPLATE +code CLASS::set_code(const transaction& tx) NOEXCEPT +{ + tx_link unused{}; + return set_code(unused, tx); +} + TEMPLATE code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT { @@ -700,13 +703,8 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT if (tx.is_empty()) return error::tx_empty; - const auto key = tx.hash(false); - - ////// GUARD (tx redundancy) - ////// This is only fully effective if there is a single database thread. - ////out_fk = to_tx(key); - ////if (!out_fk.is_terminal()) - //// return error::success; + // tx.get_hash() assumes cached or is not thread safe. + const auto& key = tx.get_hash(false); // Declare puts record. const auto& ins = *tx.inputs_ptr(); @@ -754,7 +752,6 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT const auto& prevout = in->point(); const auto& hash = prevout.hash(); - // TODO: consider table removal. // Create prevout hash in point table. point_link hash_fk{}; if (hash != null_hash) @@ -881,123 +878,193 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT // set header // ---------------------------------------------------------------------------- +// deprecated TEMPLATE -header_link CLASS::set_link(const header& header, const chain_context& ctx, - bool bypass) NOEXCEPT +header_link CLASS::set_link(const header& header, const auto& ctx, + bool milestone) NOEXCEPT +{ + header_link header_fk{}; + return set_code(header_fk, header, ctx, milestone) ? header_link{} : + header_fk; +} + +TEMPLATE +code CLASS::set_code(const header& header, const context& ctx, + bool milestone) NOEXCEPT +{ + header_link unused{}; + return set_code(unused, header, ctx, milestone); +} + +TEMPLATE +code CLASS::set_code(const header& header, const chain_context& ctx, + bool milestone) NOEXCEPT +{ + header_link unused{}; + return set_code(unused, header, ctx, milestone); +} + +TEMPLATE +code CLASS::set_code(header_link& out_fk, const header& header, + const chain_context& ctx, bool milestone) NOEXCEPT { // Map chain context into database context. - return set_link(header, context + return set_code(out_fk, header, context { system::possible_narrow_cast(ctx.flags), system::possible_narrow_cast(ctx.height), ctx.median_time_past - }, bypass); + }, milestone); } TEMPLATE -header_link CLASS::set_link(const header& header, const context& ctx, - bool bypass) NOEXCEPT +code CLASS::set_code(header_link& out_fk, const header& header, + const context& ctx, bool milestone) NOEXCEPT { // header.get_hash() assumes cached or is not thread safe. - const auto key = header.get_hash(); + const auto& key = header.get_hash(); ////// GUARD (header redundancy) ////// This is only fully effective if there is a single database thread. - ////auto header_fk = to_header(key); - ////if (!header_fk.is_terminal()) - //// return header_fk; + ////out_fk = to_header(key); + ////if (!out_fk.is_terminal()) + //// return error::success; // Parent must be missing iff its hash is null. - const auto& parent_sk = header.previous_block_hash(); - const auto parent_fk = to_header(parent_sk); - if (parent_fk.is_terminal() != (parent_sk == system::null_hash)) - return {}; + const auto& previous = header.previous_block_hash(); + const auto parent_fk = to_header(previous); + if (parent_fk.is_terminal() != (previous == system::null_hash)) + return system::error::orphan_block; // ======================================================================== const auto scope = store_.get_transactor(); // Clean single allocation failure (e.g. disk full). - return store_.header.put_link(key, table::header::record_put_ref + out_fk = store_.header.put_link(key, table::header::record_put_ref { {}, ctx, - bypass, + milestone, parent_fk, header }); + + return out_fk.is_terminal() ? error::header_put : error::success; // ======================================================================== } // set block // ---------------------------------------------------------------------------- -// TODO: add confirm option and pass to txs. +// deprecated TEMPLATE -header_link CLASS::set_link(const block& block, const chain_context& ctx, - bool bypass) NOEXCEPT +header_link CLASS::set_link(const block& block, const auto& ctx, + bool milestone, bool strong) NOEXCEPT +{ + header_link header_fk{}; + return set_code(header_fk, block, ctx, milestone, strong) ? header_link{} : + header_fk; +} + +TEMPLATE +code CLASS::set_code(const block& block, const context& ctx, bool milestone, + bool strong) NOEXCEPT +{ + header_link unused{}; + return set_code(unused, block, ctx, milestone, strong); +} + +TEMPLATE +code CLASS::set_code(const block& block, const chain_context& ctx, + bool milestone, bool strong) NOEXCEPT +{ + header_link unused{}; + return set_code(unused, block, ctx, milestone, strong); +} + +TEMPLATE +code CLASS::set_code(header_link& out_fk, const block& block, + const chain_context& ctx, bool milestone, bool strong) NOEXCEPT { // Map chain context into database context. - return set_link(block, context + return set_code(out_fk, block, context { system::possible_narrow_cast(ctx.flags), system::possible_narrow_cast(ctx.height), ctx.median_time_past - }, bypass); + }, milestone, strong); } TEMPLATE -header_link CLASS::set_link(const block& block, const context& ctx, - bool bypass) NOEXCEPT +code CLASS::set_code(header_link& out_fk, const block& block, + const context& ctx, bool milestone, bool strong) NOEXCEPT { - const auto header_fk = set_link(block.header(), ctx, bypass); - if (header_fk.is_terminal()) - return {}; + const auto ec = set_code(out_fk, block.header(), ctx, milestone); + if (ec) + return ec; - constexpr auto confirm = false; const auto size = block.serialized_size(true); - return set_code(*block.transactions_ptr(), header_fk, size, confirm) ? - header_link{} : header_fk; + return set_code(*block.transactions_ptr(), out_fk, size, strong); } -// set/unset txs +// set txs from block // ---------------------------------------------------------------------------- +// deprecated // This sets only the txs of a block with header/context already archived. TEMPLATE -header_link CLASS::set_link(const block& block) NOEXCEPT +header_link CLASS::set_link(const block& block, bool strong) NOEXCEPT { - // block.get_hash() assumes cached or is not thread safe. - const auto header_fk = to_header(block.get_hash()); - if (header_fk.is_terminal()) - return {}; + header_link header_fk{}; + return set_code(header_fk, block, strong) ? header_link{} : header_fk; +} + +// This sets only the txs of a block with header/context already archived. +TEMPLATE +code CLASS::set_code(const block& block, bool strong) NOEXCEPT +{ + header_link unused{}; + return set_code(unused, block, strong); +} + +// This sets only the txs of a block with header/context already archived. +TEMPLATE +code CLASS::set_code(header_link& out_fk, const block& block, + bool strong) NOEXCEPT +{ + out_fk = to_header(block.get_hash()); + if (out_fk.is_terminal()) + return error::txs_header; - constexpr auto confirm = false; + txs_link unused{}; const auto size = block.serialized_size(true); - return set_code(*block.transactions_ptr(), header_fk, size, confirm) ? - header_link{} : header_fk; + return set_code(unused, *block.transactions_ptr(), out_fk, size, strong); } + +// set txs +// ---------------------------------------------------------------------------- + +// deprecated TEMPLATE txs_link CLASS::set_link(const transactions& txs, const header_link& key, - size_t size) NOEXCEPT + size_t size, bool strong) NOEXCEPT { - constexpr auto confirm = false; txs_link txs_fk{}; - return set_code(txs_fk, txs, key, size, confirm) ? txs_link{} : txs_fk; + return set_code(txs_fk, txs, key, size, strong) ? txs_link{} : txs_fk; } TEMPLATE code CLASS::set_code(const transactions& txs, const header_link& key, - size_t size, bool confirm) NOEXCEPT + size_t block_size, bool strong) NOEXCEPT { txs_link unused{}; - return set_code(unused, txs, key, size, confirm); + return set_code(unused, txs, key, block_size, strong); } -// protected TEMPLATE code CLASS::set_code(txs_link& out_fk, const transactions& txs, - const header_link& key, size_t size, bool confirm) NOEXCEPT + const header_link& key, size_t block_size, bool strong) NOEXCEPT { if (key.is_terminal()) return error::txs_header; @@ -1027,7 +1094,7 @@ code CLASS::set_code(txs_link& out_fk, const transactions& txs, } using bytes = linkage::integer; - const auto wire = system::possible_narrow_cast(size); + const auto wire = system::possible_narrow_cast(block_size); const auto malleable = block::is_malleable64(txs); // ======================================================================== @@ -1035,7 +1102,7 @@ code CLASS::set_code(txs_link& out_fk, const transactions& txs, constexpr auto positive = true; // Clean allocation failure (e.g. disk full), see set_strong() comments. - if (confirm && !set_strong(key, links, positive)) + if (strong && !set_strong(key, links, positive)) return error::txs_confirm; // Header link is the key for the txs table. @@ -1052,6 +1119,9 @@ code CLASS::set_code(txs_link& out_fk, const transactions& txs, // ======================================================================== } +// unset txs +// ---------------------------------------------------------------------------- + TEMPLATE bool CLASS::set_dissasociated(const header_link& key) NOEXCEPT { diff --git a/include/bitcoin/database/impl/query/confirm.ipp b/include/bitcoin/database/impl/query/confirm.ipp index ec52d13f..d8ea0196 100644 --- a/include/bitcoin/database/impl/query/confirm.ipp +++ b/include/bitcoin/database/impl/query/confirm.ipp @@ -440,7 +440,7 @@ bool CLASS::initialize(const block& genesis) NOEXCEPT // ======================================================================== const auto scope = store_.get_transactor(); - if (!set(genesis, context{}, true)) + if (!set(genesis, context{}, false, false)) return false; const auto link = to_header(genesis.hash()); diff --git a/include/bitcoin/database/impl/query/validate.ipp b/include/bitcoin/database/impl/query/validate.ipp index dc3bf07d..91e38c5d 100644 --- a/include/bitcoin/database/impl/query/validate.ipp +++ b/include/bitcoin/database/impl/query/validate.ipp @@ -143,13 +143,14 @@ bool CLASS::get_work(uint256_t& work, const header_link& link) const NOEXCEPT } TEMPLATE -bool CLASS::get_bypass(bool& bypass, const header_link& link) const NOEXCEPT +bool CLASS::get_milestone(bool& milestone, + const header_link& link) const NOEXCEPT { - table::header::get_bypass header{}; + table::header::get_milestone header{}; if (!store_.header.get(link, header)) return false; - bypass = header.bypass; + milestone = header.milestone; return true; } diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index e86cdd5c..0412ca23 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -240,8 +240,10 @@ class query foreign_point to_spend_key(const spend_link& link) const NOEXCEPT; /// point to put (forward navigation) - spend_link to_spend(const tx_link& link, uint32_t input_index) const NOEXCEPT; - output_link to_output(const tx_link& link, uint32_t output_index) const NOEXCEPT; + spend_link to_spend(const tx_link& link, + uint32_t input_index) const NOEXCEPT; + output_link to_output(const tx_link& link, + uint32_t output_index) const NOEXCEPT; output_link to_prevout(const spend_link& link) const NOEXCEPT; /// block/tx to block/s (reverse navigation) @@ -284,13 +286,16 @@ class query inline bool is_malleable64(const header_link& link) const NOEXCEPT; inline bool is_associated(const header_link& link) const NOEXCEPT; - bool set(const header& header, const chain_context& ctx, bool bypass) NOEXCEPT; - bool set(const header& header, const context& ctx, bool bypass) NOEXCEPT; - bool set(const block& block, const chain_context& ctx, bool bypass) NOEXCEPT; - bool set(const block& block, const context& ctx, bool bypass) NOEXCEPT; - bool set(const block& block) NOEXCEPT; - bool set(const hash_digest& point_hash) NOEXCEPT; + bool set(const header& header, const chain_context& ctx, + bool milestone) NOEXCEPT; + bool set(const header& header, const context& ctx, + bool milestone) NOEXCEPT; + bool set(const block& block, const chain_context& ctx, + bool milestone, bool strong) NOEXCEPT; + bool set(const block& block, const context& ctx, + bool milestone, bool strong) NOEXCEPT; bool set(const transaction& tx) NOEXCEPT; + bool set(const block& block, bool strong) NOEXCEPT; /// False implies not fully populated, input.metadata is not populated. bool populate(const input& input) const NOEXCEPT; @@ -320,7 +325,8 @@ class query bool get_height(size_t& out, const hash_digest& key) const NOEXCEPT; bool get_height(size_t& out, const header_link& link) const NOEXCEPT; bool get_value(uint64_t& out, const output_link& link) const NOEXCEPT; - bool get_unassociated(association& out, const header_link& link) const NOEXCEPT; + bool get_unassociated(association& out, + const header_link& link) const NOEXCEPT; inputs_ptr get_inputs(const tx_link& link) const NOEXCEPT; outputs_ptr get_outputs(const tx_link& link) const NOEXCEPT; @@ -340,37 +346,61 @@ class query inputs_ptr get_spenders(const output_link& link) const NOEXCEPT; output::cptr get_output(const point& prevout) const NOEXCEPT; - output::cptr get_output(const tx_link& link, uint32_t output_index) const NOEXCEPT; - input::cptr get_input(const tx_link& link, uint32_t input_index) const NOEXCEPT; - inputs_ptr get_spenders(const tx_link& link, uint32_t output_index) const NOEXCEPT; + output::cptr get_output(const tx_link& link, + uint32_t output_index) const NOEXCEPT; + input::cptr get_input(const tx_link& link, + uint32_t input_index) const NOEXCEPT; + inputs_ptr get_spenders(const tx_link& link, + uint32_t output_index) const NOEXCEPT; /// Set transaction. - tx_link set_link(const transaction& tx) NOEXCEPT; + code set_code(const transaction& tx) NOEXCEPT; code set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT; + tx_link set_link(const transaction& tx) NOEXCEPT; - /// Set header. - header_link set_link(const header& header, const context& ctx, bool bypass) NOEXCEPT; - header_link set_link(const header& header, const chain_context& ctx, bool bypass) NOEXCEPT; - ////code set_code(header_link& out_fk, const block& block, const chain_context& ctx, - //// bool bypass) NOEXCEPT; - - /// Set full block (header and all transactions). - header_link set_link(const block& block, const context& ctx, bool bypass) NOEXCEPT; - header_link set_link(const block& block, const chain_context& ctx, bool bypass) NOEXCEPT; - ////code set_code(header_link& out_fk, const header& header, const chain_context& ctx, - //// bool bypass) NOEXCEPT; + /// Set header (headers-first). + code set_code(const header& header, const context& ctx, + bool milestone) NOEXCEPT; + code set_code(const header& header, const chain_context& ctx, + bool milestone) NOEXCEPT; + code set_code(header_link& out_fk, const header& header, + const context& ctx, bool milestone) NOEXCEPT; + code set_code(header_link& out_fk, const header& header, + const chain_context& ctx, bool milestone) NOEXCEPT; + header_link set_link(const header& header, const auto& ctx, + bool milestone) NOEXCEPT; + + /// Set full block (blocks-first). + code set_code(const block& block, const context& ctx, bool milestone, + bool strong) NOEXCEPT; + code set_code(const block& block, const chain_context& ctx, bool milestone, + bool strong) NOEXCEPT; + code set_code(header_link& out_fk, const block& block, const context& ctx, + bool milestone, bool strong) NOEXCEPT; + code set_code(header_link& out_fk, const block& block, + const chain_context& ctx, bool milestone, bool strong) NOEXCEPT; + header_link set_link(const block& block, const auto& ctx, bool milestone, + bool strong) NOEXCEPT; + + /// Set txs (headers-first). + code set_code(const transactions& txs, const header_link& key, + size_t block_size, bool strong) NOEXCEPT; + code set_code(txs_link& out_fk, const transactions& txs, + const header_link& key, size_t block_size, bool strong) NOEXCEPT; + txs_link set_link(const transactions& txs, const header_link& key, + size_t block_size, bool strong) NOEXCEPT; - /// Set txs of a block (with header/context already archived). - header_link set_link(const block& block) NOEXCEPT; - txs_link set_link(const transactions& txs, const header_link& key, size_t size) NOEXCEPT; - code set_code(const transactions& txs, const header_link& key, size_t size, bool confirm) NOEXCEPT; + /// Set block.txs (headers-first). + code set_code(const block& block, bool strong) NOEXCEPT; + code set_code(header_link& out_fk, const block& block, + bool strong) NOEXCEPT; + header_link set_link(const block& block, bool strong) NOEXCEPT; - /// Disassociate txs of block from its header (unset). + /// Disassociate txs of block from its header (malleable64 found invalid). bool set_dissasociated(const header_link& key) NOEXCEPT; /// Chain state. /// ----------------------------------------------------------------------- - chain_state_ptr get_chain_state(const system::settings& settings, const hash_digest& hash) const NOEXCEPT; chain_state_ptr get_candidate_chain_state( @@ -393,16 +423,17 @@ class query code get_tx_state(uint64_t& fee, size_t& sigops, const tx_link& link, const context& ctx) const NOEXCEPT; - bool get_timestamp(uint32_t& timestamp, const header_link& link) const NOEXCEPT; - bool get_version(uint32_t& version, const header_link& link) const NOEXCEPT; bool get_bits(uint32_t& bits, const header_link& link) const NOEXCEPT; bool get_work(uint256_t& work, const header_link& link) const NOEXCEPT; bool get_context(context& ctx, const header_link& link) const NOEXCEPT; - bool get_bypass(bool& bypass, const header_link& link) const NOEXCEPT; + bool get_version(uint32_t& version, const header_link& link) const NOEXCEPT; + bool get_milestone(bool& milestone, const header_link& link) const NOEXCEPT; + bool get_timestamp(uint32_t& timestamp, + const header_link& link) const NOEXCEPT; - bool set_block_confirmable(const header_link& link, uint64_t fees) NOEXCEPT; bool set_block_valid(const header_link& link) NOEXCEPT; bool set_block_unconfirmable(const header_link& link) NOEXCEPT; + bool set_block_confirmable(const header_link& link, uint64_t fees) NOEXCEPT; // set_txs_connected is FOR PERFORMANCE EVALUATION ONLY. bool set_txs_connected(const header_link& link) NOEXCEPT; @@ -448,21 +479,23 @@ class query /// ----------------------------------------------------------------------- /// Address, set internal to tx (natural-keyed). - bool get_confirmed_balance(uint64_t& out, const hash_digest& key) const NOEXCEPT; - bool to_address_outputs(output_links& out, const hash_digest& key) const NOEXCEPT; - bool to_unspent_outputs(output_links& out, const hash_digest& key) const NOEXCEPT; + bool get_confirmed_balance(uint64_t& out, + const hash_digest& key) const NOEXCEPT; + bool to_address_outputs(output_links& out, + const hash_digest& key) const NOEXCEPT; + bool to_unspent_outputs(output_links& out, + const hash_digest& key) const NOEXCEPT; bool to_minimum_unspent_outputs(output_links& out, const hash_digest& key, uint64_t value) const NOEXCEPT; /// Neutrino, set during validation with prevouts (surrogate-keyed). bool get_filter(filter& out, const header_link& link) const NOEXCEPT; - bool get_filter_head(hash_digest& out, const header_link& link) const NOEXCEPT; + bool get_filter_head(hash_digest& out, + const header_link& link) const NOEXCEPT; bool set_filter(const header_link& link, const hash_digest& head, const filter& body) NOEXCEPT; protected: - code set_code(txs_link& out_fk, const transactions& txs, - const header_link& key, size_t size, bool confirm) NOEXCEPT; bool set_strong(const header_link& link, const tx_links& txs, bool positive) NOEXCEPT; @@ -479,8 +512,8 @@ class query // Critical path inline header_links to_blocks(const tx_link& link) const NOEXCEPT; - inline strong_pair to_strong(const hash_digest& tx_hash) const NOEXCEPT; inline strong_pairs to_strongs(const hash_digest& tx_hash) const NOEXCEPT; + inline strong_pair to_strong(const hash_digest& tx_hash) const NOEXCEPT; /// Validate. /// ----------------------------------------------------------------------- @@ -506,7 +539,8 @@ class query inline error::error_t spent_prevout(const foreign_point& point, const tx_link& self) const NOEXCEPT; inline error::error_t unspendable_prevout(const point_link& link, - uint32_t sequence, uint32_t version, const context& ctx) const NOEXCEPT; + uint32_t sequence, uint32_t version, + const context& ctx) const NOEXCEPT; inline error::error_t unspent_duplicates(const tx_link& link, const context& ctx) const NOEXCEPT; @@ -521,13 +555,15 @@ class query const chain_state::map& map, header_link link) const NOEXCEPT; bool populate_timestamps(chain_state::data& data, const chain_state::map& map, header_link link) const NOEXCEPT; - bool populate_retarget(chain_state::data& data, const chain_state::map& map, - header_link link) const NOEXCEPT; + bool populate_retarget(chain_state::data& data, + const chain_state::map& map, header_link link) const NOEXCEPT; bool populate_hashes(chain_state::data& data, const chain_state::map& map) const NOEXCEPT; - bool populate_work(chain_state::data& data, header_link link) const NOEXCEPT; - bool populate_all(chain_state::data& data, const system::settings& settings, - const header_link& link, size_t height) const NOEXCEPT; + bool populate_work(chain_state::data& data, + header_link link) const NOEXCEPT; + bool populate_all(chain_state::data& data, + const system::settings& settings, const header_link& link, + size_t height) const NOEXCEPT; /// candidate blocks diff --git a/include/bitcoin/database/tables/archives/header.hpp b/include/bitcoin/database/tables/archives/header.hpp index 82bee397..45e0c0fa 100644 --- a/include/bitcoin/database/tables/archives/header.hpp +++ b/include/bitcoin/database/tables/archives/header.hpp @@ -43,7 +43,7 @@ struct header inline bool from_data(reader& source) NOEXCEPT { context::from_data(source, ctx); - bypass = to_bool(source.read_byte()); + milestone = to_bool(source.read_byte()); parent_fk = source.read_little_endian(); version = source.read_little_endian(); timestamp = source.read_little_endian(); @@ -57,7 +57,7 @@ struct header inline bool to_data(finalizer& sink) const NOEXCEPT { context::to_data(sink, ctx); - sink.write_byte(to_int(bypass)); + sink.write_byte(to_int(milestone)); sink.write_little_endian(parent_fk); sink.write_little_endian(version); sink.write_little_endian(timestamp); @@ -71,7 +71,7 @@ struct header inline bool operator==(const record& other) const NOEXCEPT { return ctx == other.ctx - && bypass == other.bypass + && milestone == other.milestone && parent_fk == other.parent_fk && version == other.version && timestamp == other.timestamp @@ -81,7 +81,7 @@ struct header } context ctx{}; - bool bypass{}; + bool milestone{}; link::integer parent_fk{}; uint32_t version{}; uint32_t timestamp{}; @@ -98,7 +98,7 @@ struct header { BC_ASSERT(header); context::to_data(sink, ctx); - sink.write_byte(to_int(bypass)); + sink.write_byte(to_int(milestone)); sink.write_little_endian(parent_fk); sink.write_little_endian(header->version()); sink.write_little_endian(header->timestamp()); @@ -110,7 +110,7 @@ struct header } const context ctx{}; - const bool bypass{}; + const bool milestone{}; const link::integer parent_fk{}; system::chain::header::cptr header{}; }; @@ -123,7 +123,7 @@ struct header inline bool to_data(finalizer& sink) const NOEXCEPT { context::to_data(sink, ctx); - sink.write_byte(to_int(bypass)); + sink.write_byte(to_int(milestone)); sink.write_little_endian(parent_fk); sink.write_little_endian(header.version()); sink.write_little_endian(header.timestamp()); @@ -135,7 +135,7 @@ struct header } const context& ctx{}; - const bool bypass{}; + const bool milestone{}; const link::integer parent_fk{}; const system::chain::header& header; }; @@ -265,17 +265,17 @@ struct header uint32_t mtp{}; }; - struct get_bypass + struct get_milestone : public schema::header { inline bool from_data(reader& source) NOEXCEPT { source.skip_bytes(context::size); - bypass = to_bool(source.read_byte()); + milestone = to_bool(source.read_byte()); return source; } - bool bypass{}; + bool milestone{}; }; struct get_check_context diff --git a/src/error.cpp b/src/error.cpp index a27f0905..a0b79285 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -109,7 +109,10 @@ DEFINE_ERROR_T_MESSAGE_MAP(error) { tx_address_put, "tx_address_put" }, { tx_tx_commit, "tx_tx_commit" }, - // tx archive + // header archive + { header_put, "header_put" }, + + // txs archive { txs_empty, "txs_empty" }, { txs_header, "txs_header" }, { txs_txs_put, "txs_txs_put" }, diff --git a/test/error.cpp b/test/error.cpp index e2167fd7..b88bd5b2 100644 --- a/test/error.cpp +++ b/test/error.cpp @@ -592,6 +592,17 @@ BOOST_AUTO_TEST_CASE(error_t__code__tx_tx_commit__true_exected_message) BOOST_REQUIRE_EQUAL(ec.message(), "tx_tx_commit"); } +// header archive + +BOOST_AUTO_TEST_CASE(error_t__code__header_put__true_exected_message) +{ + constexpr auto value = error::header_put; + const auto ec = code(value); + BOOST_REQUIRE(ec); + BOOST_REQUIRE(ec == value); + BOOST_REQUIRE_EQUAL(ec.message(), "header_put"); +} + // txs archive BOOST_AUTO_TEST_CASE(error_t__code__txs_header__true_exected_message) diff --git a/test/query/archive.cpp b/test/query/archive.cpp index d3d1988d..07fe7ac4 100644 --- a/test/query/archive.cpp +++ b/test/query/archive.cpp @@ -51,7 +51,7 @@ const auto events_handler = [](auto, auto) {}; // slow test (mmap) BOOST_AUTO_TEST_CASE(query_archive__set_header__mmap_get_header__expected) { - constexpr auto bypass = false; + constexpr auto milestone = false; constexpr auto parent = system::null_hash; constexpr auto merkle_root = system::base16_array("119192939495969798999a9b9c9d9e9f229192939495969798999a9b9c9d9e9f"); constexpr auto block_hash = system::base16_array("85d0b02a16f6d645aa865fad4a8666f5e7bb2b0c4392a5d675496d6c3defa1f2"); @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_header__mmap_get_header__expected) store store{ settings }; query> query{ store }; BOOST_REQUIRE(!store.create(events_handler)); - BOOST_REQUIRE(query.set(header, test::context, bypass)); + BOOST_REQUIRE(query.set(header, test::context, milestone)); table::header::record element1{}; BOOST_REQUIRE(store.header.get(query.to_header(block_hash), element1)); @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_header__mmap_get_header__expected) 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.bypass, bypass); + BOOST_REQUIRE_EQUAL(element1.milestone, milestone); BOOST_REQUIRE_EQUAL(element1.version, header.version()); BOOST_REQUIRE_EQUAL(element1.parent_fk, linkage::terminal); BOOST_REQUIRE_EQUAL(element1.merkle_root, header.merkle_root()); @@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_header__mmap_get_header__expected) BOOST_AUTO_TEST_CASE(query_archive__set_link_header__is_header__expected) { - constexpr auto bypass = true; + constexpr auto milestone = true; constexpr auto merkle_root = system::base16_array("119192939495969798999a9b9c9d9e9f229192939495969798999a9b9c9d9e9f"); constexpr auto block_hash = system::base16_array("85d0b02a16f6d645aa865fad4a8666f5e7bb2b0c4392a5d675496d6c3defa1f2"); const system::chain::header header @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_link_header__is_header__expected) "04030201" // flags "141312" // height "24232221" // mtp - "01" // bypass + "01" // milestone "ffffff" // previous_block_hash (header_fk - not found) "34333231" // version "44434241" // timestamp @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_link_header__is_header__expected) // 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_link(header, test::context, bypass).is_terminal()); + BOOST_REQUIRE(!query.set_link(header, test::context, milestone).is_terminal()); BOOST_REQUIRE(query.is_header(header.hash())); BOOST_REQUIRE(!query.is_associated(0)); table::header::record element1{}; @@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_link_header__is_header__expected) 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.bypass, bypass); + BOOST_REQUIRE_EQUAL(element1.milestone, milestone); BOOST_REQUIRE_EQUAL(element1.version, header.version()); BOOST_REQUIRE_EQUAL(element1.parent_fk, linkage::terminal); BOOST_REQUIRE_EQUAL(element1.merkle_root, header.merkle_root()); @@ -459,7 +459,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_tx__get_tx__expected) BOOST_AUTO_TEST_CASE(query_archive__set_block__get_block__expected) { - constexpr auto bypass = true; + constexpr auto milestone = true; const auto genesis_header_head = system::base16_chunk( "010000" // record count "ffffff" // bucket[0]... @@ -473,7 +473,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_block__get_block__expected) "04030201" // flags "141312" // height "24232221" // mtp - "01" // bypass + "01" // milestone "ffffff" // previous_block_hash (header_fk - not found) "01000000" // version "29ab5f49" // timestamp @@ -570,14 +570,14 @@ BOOST_AUTO_TEST_CASE(query_archive__set_block__get_block__expected) // Set block (header/txs). BOOST_REQUIRE(!query.is_block(test::genesis.hash())); - BOOST_REQUIRE(query.set(test::genesis, test::context, bypass)); + 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, bypass)); - ////BOOST_REQUIRE(query.set(test::genesis.header(), test::context, bypass)); - ////BOOST_REQUIRE(query.set(test::genesis, test::context, bypass)); - ////BOOST_REQUIRE(query.set(test::genesis, test::context, bypass)); + ////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)); @@ -611,7 +611,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_block__get_block__expected) BOOST_AUTO_TEST_CASE(query_archive__set_block_txs__get_block__expected) { - constexpr auto bypass = true; + constexpr auto milestone = true; const auto genesis_header_head = system::base16_chunk( "010000" // record count "ffffff" // bucket[0]... @@ -625,7 +625,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_block_txs__get_block__expected) "04030201" // flags "141312" // height "24232221" // mtp - "01" // bypass + "01" // milestone "ffffff" // previous_block_hash (header_fk - not found) "01000000" // version "29ab5f49" // timestamp @@ -721,17 +721,17 @@ BOOST_AUTO_TEST_CASE(query_archive__set_block_txs__get_block__expected) // Set header and then txs. BOOST_REQUIRE(!query.is_block(test::genesis.hash())); - BOOST_REQUIRE(query.set(test::genesis.header(), test::context, bypass)); + BOOST_REQUIRE(query.set(test::genesis.header(), test::context, milestone)); BOOST_REQUIRE(!query.is_associated(0)); - BOOST_REQUIRE(query.set(test::genesis)); + BOOST_REQUIRE(query.set(test::genesis, false)); 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, bypass)); - ////BOOST_REQUIRE(query.set(test::genesis.header(), test::context, bypass)); - ////BOOST_REQUIRE(query.set(test::genesis, test::context, bypass)); - ////BOOST_REQUIRE(query.set(test::genesis, test::context, bypass)); + ////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)); @@ -782,7 +782,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_block_txs__get_block__expected) //// BOOST_REQUIRE_EQUAL(store.create(events_handler)); //// //// // Assemble block. -//// BOOST_REQUIRE(query.set(test::genesis.header(), test::context, false)); +//// BOOST_REQUIRE(query.set(test::genesis.header(), test::context, false, false)); //// BOOST_REQUIRE(query.set(*test::genesis.transactions_ptr()->front())); //// BOOST_REQUIRE(query.set(query.to_header(test::genesis.hash()), tx_links{ 0 })); //// @@ -804,7 +804,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_block_txs__get_block__expected) //// BOOST_REQUIRE_EQUAL(store.create(events_handler)); //// //// // Assemble block. -//// BOOST_REQUIRE(query.set(test::genesis.header(), test::context, false)); +//// BOOST_REQUIRE(query.set(test::genesis.header(), test::context, false, false)); //// BOOST_REQUIRE(query.set(*test::genesis.transactions_ptr()->front())); //// const auto tx_hashes = hashes{ test::genesis.transactions_ptr()->front()->hash(false) }; //// BOOST_REQUIRE(query.set(query.to_header(test::genesis.hash()), tx_hashes)); @@ -822,9 +822,9 @@ BOOST_AUTO_TEST_CASE(query_archive__populate__null_prevouts__true) 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)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); - BOOST_REQUIRE(query.set(test::block3, test::context, false)); + 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)); system::chain::block copy{ test::genesis }; BOOST_REQUIRE(query.populate(copy)); @@ -855,8 +855,8 @@ BOOST_AUTO_TEST_CASE(query_archive__populate__partial_prevouts__false) test::query_accessor query{ store }; BOOST_REQUIRE(!store.create(events_handler)); BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(!query.set_link(test::block1a, test::context, false).is_terminal()); - BOOST_REQUIRE(!query.set_link(test::block2a, test::context, false).is_terminal()); + BOOST_REQUIRE(!query.set_link(test::block1a, test::context, false, false).is_terminal()); + BOOST_REQUIRE(!query.set_link(test::block2a, test::context, false, false).is_terminal()); BOOST_REQUIRE(query.set(test::tx4)); system::chain::block copy1{ test::block1a }; @@ -887,9 +887,9 @@ BOOST_AUTO_TEST_CASE(query_archive__is_coinbase__coinbase__true) 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)); - BOOST_REQUIRE(query.set(test::block2, context{}, false)); - BOOST_REQUIRE(query.set(test::block3, context{}, false)); + 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)); @@ -904,8 +904,8 @@ BOOST_AUTO_TEST_CASE(query_archive__is_coinbase__non_coinbase__false) 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)); - BOOST_REQUIRE(query.set(test::block2a, context{}, false)); + 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)); @@ -922,8 +922,8 @@ BOOST_AUTO_TEST_CASE(query_archive__is_malleable64__non_malleable__false) 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)); - BOOST_REQUIRE(query.set(test::block2a, context{}, false)); + BOOST_REQUIRE(query.set(test::block1a, context{}, false, false)); + BOOST_REQUIRE(query.set(test::block2a, context{}, false, false)); BOOST_REQUIRE(!query.is_malleable64(1)); BOOST_REQUIRE(!query.is_malleable64(2)); @@ -960,9 +960,9 @@ BOOST_AUTO_TEST_CASE(query_archive__is_malleable64__malleable__true) // Store 4 blocks. BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE_EQUAL(query.set_link(block1, database::context{}, false), 1u); - BOOST_REQUIRE_EQUAL(query.set_link(block2, database::context{}, false), 2u); - BOOST_REQUIRE_EQUAL(query.set_link(block3, database::context{}, false), 3u); + BOOST_REQUIRE_EQUAL(query.set_link(block1, database::context{}, false, false), 1u); + BOOST_REQUIRE_EQUAL(query.set_link(block2, database::context{}, false, false), 2u); + BOOST_REQUIRE_EQUAL(query.set_link(block3, database::context{}, false, false), 3u); // All are associated. BOOST_REQUIRE(query.is_associated(0)); @@ -1003,9 +1003,9 @@ BOOST_AUTO_TEST_CASE(query_archive__is_malleable64__malleable__true) BOOST_REQUIRE(query.is_malleated64(block3)); // Reassociate the same transaction sets (first(n), disassociated (0), second(n)) - BOOST_REQUIRE(!query.set_link(*block1.transactions_ptr(), 1, block1.serialized_size(true)).is_terminal()); - BOOST_REQUIRE(!query.set_link(*block2.transactions_ptr(), 2, block2.serialized_size(false)).is_terminal()); - BOOST_REQUIRE(!query.set_link(*block3.transactions_ptr(), 3, block3.serialized_size(true)).is_terminal()); + BOOST_REQUIRE(!query.set_link(*block1.transactions_ptr(), 1, block1.serialized_size(true), false).is_terminal()); + BOOST_REQUIRE(!query.set_link(*block2.transactions_ptr(), 2, block2.serialized_size(false), false).is_terminal()); + BOOST_REQUIRE(!query.set_link(*block3.transactions_ptr(), 3, block3.serialized_size(true), false).is_terminal()); // Verify all 3 are reassociated. BOOST_REQUIRE(query.is_associated(1)); @@ -1129,7 +1129,7 @@ BOOST_AUTO_TEST_CASE(query_archive__get_header__default__expected) "14131211" // flags "040302" // height "24232221" // mtp - "01" // bypass + "01" // milestone "ffffff" // previous_block_hash (header_fk - terminal) "34333231" // version "44434241" // timestamp @@ -1194,7 +1194,7 @@ BOOST_AUTO_TEST_CASE(query_archive__get_point_key__always__expected) BOOST_REQUIRE_EQUAL(query.get_point_key(1), system::null_hash); // block1a adds three prevouts of two txs. - BOOST_REQUIRE(query.set(test::block1a, context{}, false)); + BOOST_REQUIRE(query.set(test::block1a, context{}, false, false)); BOOST_REQUIRE_EQUAL(query.get_point_key(1), system::one_hash); BOOST_REQUIRE_EQUAL(query.get_point_key(2), test::two_hash); BOOST_REQUIRE_EQUAL(query.get_point_key(3), system::null_hash); @@ -1225,11 +1225,11 @@ BOOST_AUTO_TEST_CASE(query_archive__get_height1__always__expected) 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)); - BOOST_REQUIRE(query.set(test::block2, context{ 0, 2, 0 }, false)); - BOOST_REQUIRE(query.set(test::block3, context{ 0, 3, 0 }, false)); - BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false)); - BOOST_REQUIRE(query.set(test::block2a, context{ 0, 2, 0 }, false)); + 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)); size_t out{}; BOOST_REQUIRE(query.get_height(out, 0)); @@ -1255,11 +1255,11 @@ BOOST_AUTO_TEST_CASE(query_archive__get_height2__always__expected) 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)); - BOOST_REQUIRE(query.set(test::block2, context{ 0, 2, 0 }, false)); - BOOST_REQUIRE(query.set(test::block3, context{ 0, 3, 0 }, false)); - BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false)); - BOOST_REQUIRE(query.set(test::block2a, context{ 0, 2, 0 }, false)); + 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)); size_t out{}; BOOST_REQUIRE(query.get_height(out, test::genesis.hash())); @@ -1299,9 +1299,9 @@ BOOST_AUTO_TEST_CASE(query_archive__get_tx_position__confirmed__expected) 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)); - BOOST_REQUIRE(query.set(test::block2a, context{ 0, 2, 0 }, false)); - BOOST_REQUIRE(query.set(test::block3a, context{ 0, 3, 0 }, 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_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)); @@ -1340,9 +1340,9 @@ BOOST_AUTO_TEST_CASE(query_archive__get_tx_position__always__expected) 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)); - BOOST_REQUIRE(query.set(test::block2a, context{ 0, 2, 0 }, false)); - BOOST_REQUIRE(query.set(test::block3a, context{ 0, 3, 0 }, 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_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)); @@ -1398,7 +1398,7 @@ BOOST_AUTO_TEST_CASE(query_archive__get_input__genesis__expected) 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)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); const auto tx = test::genesis.transactions_ptr()->front(); const auto& input = *tx->inputs_ptr()->front(); @@ -1453,7 +1453,7 @@ BOOST_AUTO_TEST_CASE(query_archive__get_output__genesis__expected) 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)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); const auto tx = test::genesis.transactions_ptr()->front(); const auto& output1 = *tx->outputs_ptr()->front(); @@ -1505,8 +1505,8 @@ BOOST_AUTO_TEST_CASE(query_archive__get_transactions__found__expected) 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)); - BOOST_REQUIRE(query.set(test::block2a, test::context, false)); + 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)->size(), 1u); BOOST_REQUIRE_EQUAL(query.get_transactions(1)->size(), 1u); @@ -1521,8 +1521,8 @@ BOOST_AUTO_TEST_CASE(query_archive__get_point__null_point__expected) 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)); - BOOST_REQUIRE(query.set(test::block2a, test::context, false)); + BOOST_REQUIRE(query.set(test::block1a, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2a, test::context, false, false)); BOOST_REQUIRE(!query.get_point(spend_link::terminal)); BOOST_REQUIRE(query.get_point(query.to_spend(0, 0))->is_null()); BOOST_REQUIRE(*query.get_point(query.to_spend(1, 0)) == test::block1a.inputs_ptr()->at(0)->point()); @@ -1542,9 +1542,9 @@ BOOST_AUTO_TEST_CASE(query_archive__get_spenders__unspent_or_not_found__expected 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)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); - BOOST_REQUIRE(query.set(test::block3, test::context, false)); + 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)); // Caller should always test for nullptr. BOOST_REQUIRE(query.get_spenders(output_link::terminal)->empty()); diff --git a/test/query/confirm.cpp b/test/query/confirm.cpp index 8a38c0dc..93d4b8b8 100644 --- a/test/query/confirm.cpp +++ b/test/query/confirm.cpp @@ -63,8 +63,8 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_candidate_block__push_pop_candidate__expe 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{ 0, 1, 0 }, false)); - BOOST_REQUIRE(query.set(test::block2, context{ 0, 2, 0 }, false)); + 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.is_candidate_header(0)); BOOST_REQUIRE(!query.is_candidate_header(1)); BOOST_REQUIRE(!query.is_candidate_header(2)); @@ -97,8 +97,8 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_confirmed_block__push_pop_confirmed__expe 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{ 0, 1, 0 }, false)); - BOOST_REQUIRE(query.set(test::block2, context{ 0, 2, 0 }, false)); + 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.is_confirmed_block(0)); BOOST_REQUIRE(!query.is_confirmed_block(1)); BOOST_REQUIRE(!query.is_confirmed_block(2)); @@ -128,8 +128,8 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_confirmed_tx__confirm__expected) 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{ 0, 1, 0 }, false)); - BOOST_REQUIRE(query.set(test::block2, context{ 0, 2, 0 }, false)); + 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.is_confirmed_tx(0)); BOOST_REQUIRE(!query.is_confirmed_tx(1)); BOOST_REQUIRE(!query.is_confirmed_tx(2)); @@ -154,8 +154,8 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_confirmed_input__confirm__expected) 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{ 0, 1, 0 }, false)); - BOOST_REQUIRE(query.set(test::block2, context{ 0, 2, 0 }, false)); + 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.is_confirmed_input(query.to_spend(0, 0))); BOOST_REQUIRE(!query.is_confirmed_input(query.to_spend(1, 0))); @@ -180,8 +180,8 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_confirmed_output__confirm__expected) 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{ 0, 1, 0 }, false)); - BOOST_REQUIRE(query.set(test::block2, context{ 0, 2, 0 }, false)); + 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.is_confirmed_output(query.to_output(0, 0))); BOOST_REQUIRE(!query.is_confirmed_output(query.to_output(1, 0))); @@ -218,9 +218,9 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_spent_output__strong_confirmed__true) 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::block1a, context{ 0, 1, 0 }, false)); - BOOST_REQUIRE(query.set(test::block2a, context{ 0, 2, 0 }, false)); - BOOST_REQUIRE(query.set(test::block3a, context{ 0, 3, 0 }, 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_REQUIRE(query.set(test::block3a, context{ 0, 3, 0 }, false, false)); BOOST_REQUIRE(!query.is_spent_output(query.to_output(0, 0))); // genesis BOOST_REQUIRE(!query.is_spent_output(query.to_output(1, 0))); // block1a BOOST_REQUIRE(!query.is_spent_output(query.to_output(1, 1))); // block1a @@ -257,7 +257,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_strong_spend__weak__false) 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{}, false)); + BOOST_REQUIRE(query.set(test::block1, context{}, false, false)); BOOST_REQUIRE(!query.is_strong_spend(query.to_spend(1, 0))); BOOST_REQUIRE(query.set_strong(1)); BOOST_REQUIRE(query.is_strong_spend(query.to_spend(1, 0))); @@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_strong__weak__false) 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{}, false)); + BOOST_REQUIRE(query.set(test::block1, context{}, false, false)); BOOST_REQUIRE(!query.is_strong(1)); BOOST_REQUIRE(query.set_strong(1)); BOOST_REQUIRE(query.is_strong(1)); @@ -297,7 +297,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_spent__unspent__false) 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{}, false)); + BOOST_REQUIRE(query.set(test::block1, context{}, false, false)); BOOST_REQUIRE(!query.is_spent(query.to_spend(0, 0))); // unspendable BOOST_REQUIRE(!query.is_spent(query.to_spend(1, 0))); // unspent BOOST_REQUIRE(!query.is_spent(query.to_spend(2, 0))); // non-existent @@ -312,7 +312,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_spent__unconfirmed_double_spend__false) BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1a, context{}, false)); + BOOST_REQUIRE(query.set(test::block1a, context{}, false, false)); BOOST_REQUIRE(query.set_strong(1)); BOOST_REQUIRE(!query.is_spent(query.to_spend(0, 0))); // unspendable BOOST_REQUIRE(!query.is_spent(query.to_spend(1, 0))); // spent by self (and missing) @@ -321,7 +321,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_spent__unconfirmed_double_spend__false) BOOST_REQUIRE(!query.is_spent(query.to_spend(2, 0))); // missing tx BOOST_REQUIRE(!query.is_spent(query.to_spend(2, 1))); // missing tx - BOOST_REQUIRE(query.set(test::block2a, context{}, false)); + BOOST_REQUIRE(query.set(test::block2a, context{}, false, false)); BOOST_REQUIRE(!query.is_spent(query.to_spend(2, 0))); // unconfirmed self BOOST_REQUIRE(!query.is_spent(query.to_spend(2, 1))); // unconfirmed self @@ -334,7 +334,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_spent__unconfirmed_double_spend__false) BOOST_REQUIRE(!query.is_spent(query.to_spend(2, 0))); // confirmed self, unconfirmed BOOST_REQUIRE(!query.is_spent(query.to_spend(2, 1))); // confirmed self, unconfirmed - BOOST_REQUIRE(query.set(test::block3a, context{}, false)); + BOOST_REQUIRE(query.set(test::block3a, context{}, false, false)); BOOST_REQUIRE(!query.is_spent(query.to_spend(2, 0))); // confirmed self, unconfirmed(2) BOOST_REQUIRE(!query.is_spent(query.to_spend(2, 1))); // confirmed self, unconfirmed(2) @@ -363,11 +363,11 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_spent__confirmed_double_spend__true) 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::block1a, context{}, false)); + BOOST_REQUIRE(query.set(test::block1a, context{}, false, false)); BOOST_REQUIRE(query.set_strong(1)); - BOOST_REQUIRE(query.set(test::block2a, context{}, false)); + BOOST_REQUIRE(query.set(test::block2a, context{}, false, false)); BOOST_REQUIRE(query.set_strong(2)); - BOOST_REQUIRE(query.set(test::block3a, context{}, false)); + BOOST_REQUIRE(query.set(test::block3a, context{}, false, false)); BOOST_REQUIRE(query.set_strong(3)); BOOST_REQUIRE(query.is_spent(query.to_spend(2, 0))); // confirmed self and confirmed (double spent) BOOST_REQUIRE(query.is_spent(query.to_spend(2, 1))); // confirmed self and confirmed (double spent) @@ -417,7 +417,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_mature__non_coinbase_strong_above__true) 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::block1a, context{ 0, 1, 0 }, false)); + BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); BOOST_REQUIRE(query.set(test::tx4)); // Is not actually mature at height zero, but strong is presumed to always @@ -434,7 +434,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_mature__non_coinbase__true) 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::block1a, context{ 0, 1, 0 }, false)); + BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); BOOST_REQUIRE(query.set(test::tx4)); BOOST_REQUIRE(query.set_strong(1)); BOOST_REQUIRE(query.is_mature(query.to_spend(2, 0), 1)); @@ -448,7 +448,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__is_mature__coinbase__expected) 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::block1b, context{ 0, 1, 0 }, false)); + BOOST_REQUIRE(query.set(test::block1b, context{ 0, 1, 0 }, false, false)); BOOST_REQUIRE(query.set_strong(1)); BOOST_REQUIRE(query.set(test::tx2b)); BOOST_REQUIRE(!query.is_mature(query.to_spend(2, 0), 100)); @@ -465,7 +465,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__bad_link__integrity) 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{ bip68, 1, 0 }, false)); + BOOST_REQUIRE(query.set(test::block1, context{ bip68, 1, 0 }, false, false)); BOOST_REQUIRE_EQUAL(query.block_confirmable(2), error::integrity); } @@ -477,9 +477,9 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__null_points__success) 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{ bip68 }, false)); - BOOST_REQUIRE(query.set(test::block2, context{ bip68 }, false)); - BOOST_REQUIRE(query.set(test::block3, context{ bip68 }, false)); + BOOST_REQUIRE(query.set(test::block1, context{ bip68 }, false, false)); + BOOST_REQUIRE(query.set(test::block2, context{ bip68 }, false, false)); + BOOST_REQUIRE(query.set(test::block3, context{ bip68 }, false, false)); // block1/2/3 at links 1/2/3 confirming at heights 1/2/3. // blocks have only coinbase txs, all txs should be set strong before calling @@ -497,7 +497,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__missing_prevouts__integri 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::block1a, context{ bip68, 1, 0 }, false)); + BOOST_REQUIRE(query.set(test::block1a, context{ bip68, 1, 0 }, false, false)); // block1a is missing all three input prevouts. BOOST_REQUIRE(query.set_strong(1)); @@ -514,7 +514,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__spend_gensis__coinbase_ma BOOST_REQUIRE(query.initialize(test::genesis)); // block_spend_genesis spends the genesis output. - BOOST_REQUIRE(query.set(test::block_spend_genesis, context{ 0, 101, 0 }, false)); + BOOST_REQUIRE(query.set(test::block_spend_genesis, context{ 0, 101, 0 }, false, false)); BOOST_REQUIRE(query.set_strong(1)); // 1 + 100 = 101 (maturity, except genesis) @@ -531,12 +531,12 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__immature_prevouts__coinba BOOST_REQUIRE(query.initialize(test::genesis)); // block1b has only a coinbase tx. - BOOST_REQUIRE(query.set(test::block1b, context{ bip68, 1, 0 }, false)); + BOOST_REQUIRE(query.set(test::block1b, context{ bip68, 1, 0 }, false, false)); BOOST_REQUIRE(query.set_strong(1)); BOOST_REQUIRE_EQUAL(query.block_confirmable(1), error::success); // block2b prematurely spends block1b's coinbase outputs. - BOOST_REQUIRE(query.set(test::block2b, context{ 0, 100, 0 }, false)); + BOOST_REQUIRE(query.set(test::block2b, context{ 0, 100, 0 }, false, false)); BOOST_REQUIRE(query.set_strong(2)); BOOST_REQUIRE_EQUAL(query.block_confirmable(2), error::success); } @@ -551,12 +551,12 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__mature_prevouts__success) BOOST_REQUIRE(query.initialize(test::genesis)); // block1b has only a coinbase tx. - BOOST_REQUIRE(query.set(test::block1b, context{ bip68, 1, 0 }, false)); + BOOST_REQUIRE(query.set(test::block1b, context{ bip68, 1, 0 }, false, false)); BOOST_REQUIRE(query.set_strong(1)); BOOST_REQUIRE_EQUAL(query.block_confirmable(1), error::success); // block2b spends block1b's coinbase outputs. - BOOST_REQUIRE(query.set(test::block2b, context{ 0, 101, 0 }, false)); + BOOST_REQUIRE(query.set(test::block2b, context{ 0, 101, 0 }, false, false)); BOOST_REQUIRE(query.set_strong(2)); BOOST_REQUIRE_EQUAL(query.block_confirmable(2), error::success); } @@ -571,11 +571,11 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__spend_non_coinbase__succe BOOST_REQUIRE(query.initialize(test::genesis)); // block1a has non-coinbase tx/outputs. - BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false)); + BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); BOOST_REQUIRE(query.set_strong(1)); // block_spend_1a spends both block1a outputs. - BOOST_REQUIRE(query.set(test::block_spend_1a, context{ 0, 2, 0 }, false)); + BOOST_REQUIRE(query.set(test::block_spend_1a, context{ 0, 2, 0 }, false, false)); BOOST_REQUIRE(query.set_strong(2)); // Maturity applies only to coinbase prevouts. @@ -597,7 +597,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__spend_non_coinbase__succe //// BOOST_REQUIRE(query.set_strong(1)); //// //// // block_spend_internal_2b spends first block1a output and first own output. -//// BOOST_REQUIRE(query.set(test::block_spend_internal_2b, context{ 0, 100, 0 }, false)); +//// BOOST_REQUIRE(query.set(test::block_spend_internal_2b, context{ 0, 100, 0 }, false, false)); //// ////BOOST_REQUIRE(query.set_strong(2)); //// //// // Not confirmable because tx not strong. @@ -618,10 +618,10 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__spend_non_coinbase__succe //// BOOST_REQUIRE(query.initialize(test::genesis)); //// //// // block1b has coinbase tx/outputs. -//// BOOST_REQUIRE(query.set(test::block1b, context{ 0, 1, 0 }, false)); +//// BOOST_REQUIRE(query.set(test::block1b, context{ 0, 1, 0 }, false, false)); //// BOOST_REQUIRE(query.set_strong(1)); //// -//// BOOST_REQUIRE(query.set(test::block_spend_internal_2b, context{ 0, 101, 0 }, false)); +//// BOOST_REQUIRE(query.set(test::block_spend_internal_2b, context{ 0, 101, 0 }, false, false)); //// ////BOOST_REQUIRE(query.set_strong(2)); //// //// // Not confirmable because tx not strong. @@ -645,15 +645,15 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__spend_non_coinbase__succe //// BOOST_REQUIRE(query.initialize(test::genesis)); //// //// // block1a has non-coinbase tx/outputs. -//// BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false)); +//// BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); //// BOOST_REQUIRE(query.set_strong(1)); //// //// // block2a spends both block1a outputs (though not itself confirmable is set strong). -//// BOOST_REQUIRE(query.set(test::block2a, context{ 0, 2, 0 }, false)); +//// BOOST_REQUIRE(query.set(test::block2a, context{ 0, 2, 0 }, false, false)); //// BOOST_REQUIRE(query.set_strong(2)); //// //// // block_spend_1a (also) spends both block1a outputs (and is otherwise confirmable). -//// BOOST_REQUIRE(query.set(test::block_spend_1a, context{ bip68, 3, 0 }, false)); +//// BOOST_REQUIRE(query.set(test::block_spend_1a, context{ bip68, 3, 0 }, false, false)); //// BOOST_REQUIRE(query.set_strong(3)); //// //// // Not confirmable because of intervening block2a implies double spend. @@ -670,14 +670,14 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__spend_non_coinbase__succe //// BOOST_REQUIRE(query.initialize(test::genesis)); //// //// // block1a has non-coinbase tx/outputs. -//// BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false)); +//// BOOST_REQUIRE(query.set(test::block1a, context{ 0, 1, 0 }, false, false)); //// BOOST_REQUIRE(query.set_strong(1)); //// //// // tx5 spends first block1a output. //// BOOST_REQUIRE(query.set(test::tx5)); //// //// // block_spend_1a (also) spends both block1a outputs. -//// BOOST_REQUIRE(query.set(test::block_spend_1a, context{ 0, 2, 0 }, false)); +//// BOOST_REQUIRE(query.set(test::block_spend_1a, context{ 0, 2, 0 }, false, false)); //// BOOST_REQUIRE(query.set_strong(2)); //// //// // Confirmable because of intervening tx5 is unconfirmed double spend. @@ -705,8 +705,8 @@ BOOST_AUTO_TEST_CASE(query_confirm__set_strong__set_unstrong__expected) 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{ 0, 1, 0 }, false)); - BOOST_REQUIRE(query.set(test::block2, context{ 0, 2, 0 }, false)); + 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.push_confirmed(1)); BOOST_REQUIRE(query.push_confirmed(2)); diff --git a/test/query/context.cpp b/test/query/context.cpp index 407bf77c..332c30b2 100644 --- a/test/query/context.cpp +++ b/test/query/context.cpp @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(query_context__get_candidate_chain_state__block1__expected) 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)); + BOOST_REQUIRE(query.set(test::block1, context, true, false)); BOOST_REQUIRE(query.push_candidate(query.to_header(test::block1.hash()))); const auto state = query.get_candidate_chain_state(system_settings); diff --git a/test/query/initialize.cpp b/test/query/initialize.cpp index 287f9c8a..c60b5e5a 100644 --- a/test/query/initialize.cpp +++ b/test/query/initialize.cpp @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__is_initialized__unconfirmed__false) test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.set(test::genesis, test::context, false)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); BOOST_REQUIRE(query.push_candidate(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(!query.is_initialized()); } @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__is_initialized__candidate__false) test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.set(test::genesis, test::context, false)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); BOOST_REQUIRE(query.push_candidate(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(!query.is_initialized()); } @@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__is_initialized__confirmed__false) test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.set(test::genesis, test::context, false)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(!query.is_initialized()); } @@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__is_initialized__candidate_and_confirmed__ test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.set(test::genesis, test::context, false)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); BOOST_REQUIRE(query.push_candidate(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(query.is_initialized()); @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_top__genesis_confirmed__0) test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.set(test::genesis, test::context, false)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::genesis.hash()))); ////BOOST_REQUIRE(query.push_candidate(query.to_header(genesis.hash()))); BOOST_REQUIRE_EQUAL(query.get_top_confirmed(), 0u); @@ -149,9 +149,9 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_top__three_blocks_confirmed__2) test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.set(test::genesis, test::context, false)); - BOOST_REQUIRE(query.set(test::block1, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2, test::context, false, false)); BOOST_REQUIRE(query.push_candidate(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1.hash()))); @@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_top_candidate__genesis_candidated__0) test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.set(test::genesis, test::context, false)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); BOOST_REQUIRE(query.push_candidate(query.to_header(test::genesis.hash()))); ////BOOST_REQUIRE(query.push_confirmed(query.to_header(test::genesis.hash()))); BOOST_REQUIRE_EQUAL(query.get_top_candidate(), 0u); @@ -182,9 +182,9 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_top__three_blocks_candidated__2) test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.set(test::genesis, test::context, false)); - BOOST_REQUIRE(query.set(test::block1, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2, test::context, false, false)); BOOST_REQUIRE(query.push_candidate(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(query.push_candidate(query.to_header(test::block1.hash()))); @@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_fork__initialized__0) test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.set(test::genesis, test::context, false)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); BOOST_REQUIRE(query.push_candidate(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::genesis.hash()))); BOOST_REQUIRE_EQUAL(query.get_fork(), 0u); @@ -215,9 +215,9 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_fork__candidate_ahead__expected) test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.set(test::genesis, test::context, false)); - BOOST_REQUIRE(query.set(test::block1, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2, test::context, false, false)); BOOST_REQUIRE(query.push_candidate(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(query.push_candidate(query.to_header(test::block1.hash()))); @@ -233,9 +233,9 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_fork__confirmed_ahead__expected) test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); - BOOST_REQUIRE(query.set(test::genesis, test::context, false)); - BOOST_REQUIRE(query.set(test::block1, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); + BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2, test::context, false, false)); BOOST_REQUIRE(query.push_candidate(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::genesis.hash()))); BOOST_REQUIRE(query.push_candidate(query.to_header(test::block1.hash()))); @@ -285,9 +285,9 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_top_associated_from__non_candidate__e 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, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); - BOOST_REQUIRE(query.set(test::block3, test::context, false)); + 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.push_candidate(query.to_header(test::block1.hash()))); BOOST_REQUIRE(query.push_candidate(query.to_header(test::block2.hash()))); BOOST_REQUIRE_EQUAL(query.get_top_associated(), 2u); @@ -307,9 +307,9 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_top_associated_from__gapped_candidate 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, test::context, false)); + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); BOOST_REQUIRE(query.set(test::block2.header(), test::context, false)); // header only - BOOST_REQUIRE(query.set(test::block3, test::context, false)); + BOOST_REQUIRE(query.set(test::block3, test::context, false, false)); BOOST_REQUIRE(query.push_candidate(query.to_header(test::block1.hash()))); BOOST_REQUIRE(query.push_candidate(query.to_header(test::block2.hash()))); BOOST_REQUIRE(query.push_candidate(query.to_header(test::block3.hash()))); @@ -360,7 +360,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_unassociated_above__gapped_candidate_ 0x21222323 // mtp }; BOOST_REQUIRE(query.initialize(test::genesis)); // associated - BOOST_REQUIRE(query.set(test::block1, test::context, false)); // associated + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); // associated BOOST_REQUIRE(query.set(test::block2.header(), context2, false)); // header only BOOST_REQUIRE(query.set(test::block3.header(), context3, false)); // header only BOOST_REQUIRE(query.push_candidate(query.to_header(test::block1.hash()))); @@ -433,17 +433,17 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_unassociated_above__gapped_candidate_ BOOST_REQUIRE_EQUAL(unassociated3.size(), 0u); // There are two unassociated blocks above block 1 (new fork point). - BOOST_REQUIRE(query.set(test::block1)); + BOOST_REQUIRE(query.set(test::block1, false)); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1.hash()))); BOOST_REQUIRE_EQUAL(query.get_all_unassociated().size(), 2u); // There is one unassociated block above block 2 (new fork point). - BOOST_REQUIRE(query.set(test::block2)); + BOOST_REQUIRE(query.set(test::block2, false)); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2.hash()))); BOOST_REQUIRE_EQUAL(query.get_all_unassociated().size(), 1u); // There are no unassociated blocks above block 3 (new fork point). - BOOST_REQUIRE(query.set(test::block3)); + BOOST_REQUIRE(query.set(test::block3, false)); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block3.hash()))); BOOST_REQUIRE_EQUAL(query.get_all_unassociated().size(), 0u); } @@ -471,7 +471,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_unassociated_count_above__gapped_cand 0x21222323 // mtp }; BOOST_REQUIRE(query.initialize(test::genesis)); // associated - BOOST_REQUIRE(query.set(test::block1, test::context, false)); // associated + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); // associated BOOST_REQUIRE(query.set(test::block2.header(), context2, false)); // header only BOOST_REQUIRE(query.set(test::block3.header(), context3, false)); // header only BOOST_REQUIRE(query.push_candidate(query.to_header(test::block1.hash()))); @@ -500,7 +500,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_unassociated_count_above__gapped_cand BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(3, 1), 0u); // There is one unassociated block at block 2. - BOOST_REQUIRE(query.set(test::block3)); // associated + BOOST_REQUIRE(query.set(test::block3, false)); // associated BOOST_REQUIRE_EQUAL(query.get_unassociated_count(), 1u); BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(0), 1u); BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(1), 1u); @@ -508,7 +508,7 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_unassociated_count_above__gapped_cand BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(3), 0u); // There are no unassociated blocks. - BOOST_REQUIRE(query.set(test::block2)); // associated + BOOST_REQUIRE(query.set(test::block2, false)); // associated BOOST_REQUIRE_EQUAL(query.get_unassociated_count(), 0u); BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(0), 0u); BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(1), 0u); @@ -537,9 +537,9 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_candidate_hashes__gapped__expected) 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, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); - BOOST_REQUIRE(query.set(test::block3, test::context, false)); + 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.push_candidate(query.to_header(test::block1.hash()))); BOOST_REQUIRE(query.push_candidate(query.to_header(test::block2.hash()))); BOOST_REQUIRE(query.push_candidate(query.to_header(test::block3.hash()))); @@ -571,9 +571,9 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_confirmed_hashes__gapped__expected) 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, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); - BOOST_REQUIRE(query.set(test::block3, test::context, false)); + 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.push_confirmed(query.to_header(test::block1.hash()))); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2.hash()))); BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block3.hash()))); diff --git a/test/query/optional.cpp b/test/query/optional.cpp index 821eef32..cf184bd2 100644 --- a/test/query/optional.cpp +++ b/test/query/optional.cpp @@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(query_optional__set_filter__get_filter_and_head__expected) 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::block1a, context{}, false)); + BOOST_REQUIRE(query.set(test::block1a, context{}, false, false)); BOOST_REQUIRE(query.set_filter(0, filter_head0, filter0)); BOOST_REQUIRE(query.set_filter(1, filter_head1, filter1)); diff --git a/test/query/translate.cpp b/test/query/translate.cpp index e263ced3..b2e9f7df 100644 --- a/test/query/translate.cpp +++ b/test/query/translate.cpp @@ -55,8 +55,8 @@ BOOST_AUTO_TEST_CASE(query_translate__to_candidate__always__expected) // initialize pushes the genesis candidate. BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2, test::context, false, false)); BOOST_REQUIRE_EQUAL(query.to_candidate(0), 0u); BOOST_REQUIRE_EQUAL(query.to_candidate(1), header_link::terminal); BOOST_REQUIRE_EQUAL(query.to_candidate(2), header_link::terminal); @@ -95,8 +95,8 @@ BOOST_AUTO_TEST_CASE(query_translate__to_confirmed__always__expected) // initialize pushes the genesis confirmed. BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2, test::context, false, false)); BOOST_REQUIRE_EQUAL(query.to_confirmed(0), 0u); BOOST_REQUIRE_EQUAL(query.to_confirmed(1), header_link::terminal); BOOST_REQUIRE_EQUAL(query.to_confirmed(2), header_link::terminal); @@ -151,7 +151,7 @@ BOOST_AUTO_TEST_CASE(query_translate__to_coinbase__always__expected) BOOST_REQUIRE(query.initialize(test::genesis)); BOOST_REQUIRE_EQUAL(query.to_coinbase(0), 0u); BOOST_REQUIRE(query.to_coinbase(1).is_terminal()); - BOOST_REQUIRE(query.set(test::block1, test::context, false)); + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); BOOST_REQUIRE_EQUAL(query.to_coinbase(1), 1u); } @@ -167,9 +167,9 @@ BOOST_AUTO_TEST_CASE(query_translate__to_point__null_points__empty_points_table) // The four blocks have only null points, which are not archived. BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); - BOOST_REQUIRE(query.set(test::block3, test::context, false)); + 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(store.point_body().empty()); } @@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(query_translate__to_point__points__expected) 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::block1a, test::context, false)); + BOOST_REQUIRE(query.set(test::block1a, test::context, false, false)); const auto point_body = system::base16_chunk ( @@ -206,8 +206,8 @@ BOOST_AUTO_TEST_CASE(query_translate__to_tx__txs__expected) 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, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2, test::context, false, false)); // All four blocks have one transaction. BOOST_REQUIRE_EQUAL(query.to_tx(test::genesis.transactions_ptr()->front()->hash(true)), 0u); @@ -239,12 +239,12 @@ BOOST_AUTO_TEST_CASE(query_translate__to_spend_tx__to_spend__expected) accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); - BOOST_REQUIRE(query.set(test::block3, test::context, false)); + 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)); // block1a has no true coinbase. - BOOST_REQUIRE(query.set(test::block1a, test::context, false)); + BOOST_REQUIRE(query.set(test::block1a, test::context, false, false)); // First 4 blocks have one transaction with 1 input, block1a has 3. BOOST_REQUIRE_EQUAL(query.to_spend_tx(0), 0u); @@ -410,7 +410,7 @@ BOOST_AUTO_TEST_CASE(query_translate__to_non_coinbase_spends__populated__expecte system::base16_chunk("00000000""ff00f2052a01000000""434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac")); // coinbase only (null and first). - BOOST_REQUIRE(query.set(test::block1b, context{ 0, 1, 0 }, false)); + BOOST_REQUIRE(query.set(test::block1b, context{ 0, 1, 0 }, false, false)); BOOST_REQUIRE(query.to_non_coinbase_spends(0).empty()); BOOST_REQUIRE(query.to_non_coinbase_spends(1).empty()); BOOST_REQUIRE(query.to_non_coinbase_spends(2).empty()); @@ -428,7 +428,7 @@ BOOST_AUTO_TEST_CASE(query_translate__to_non_coinbase_spends__populated__expecte "01000000""b1""0179")); // 2 inputs (block1b and tx2b). - BOOST_REQUIRE(query.set(test::block_spend_internal_2b, context{ 0, 101, 0 }, false)); + BOOST_REQUIRE(query.set(test::block_spend_internal_2b, context{ 0, 101, 0 }, false, false)); BOOST_REQUIRE(query.to_non_coinbase_spends(0).empty()); BOOST_REQUIRE(query.to_non_coinbase_spends(1).empty()); @@ -469,10 +469,10 @@ BOOST_AUTO_TEST_CASE(query_translate__to_output_tx__to_output__expected) 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, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); - BOOST_REQUIRE(query.set(test::block3, test::context, false)); - BOOST_REQUIRE(query.set(test::block1a, test::context, false)); + 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.set(test::block1a, test::context, false, false)); // All 5 blocks have one transaction with 1 output. BOOST_REQUIRE_EQUAL(query.to_output_tx(0 * 0x51), 0u); @@ -534,8 +534,8 @@ BOOST_AUTO_TEST_CASE(query_translate__to_prevout_tx__to_prevout__expected) 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::block1a, test::context, false)); - BOOST_REQUIRE(query.set(test::block2a, test::context, false)); + BOOST_REQUIRE(query.set(test::block1a, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2a, test::context, false, false)); // inputs in link order. BOOST_REQUIRE_EQUAL(query.to_prevout_tx(0), tx_link::terminal); @@ -653,8 +653,8 @@ BOOST_AUTO_TEST_CASE(query_translate__to_block__set_strong__expected) accessor query{ store }; BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); BOOST_REQUIRE(query.initialize(test::genesis)); - BOOST_REQUIRE(query.set(test::block1, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); + BOOST_REQUIRE(query.set(test::block1, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2, test::context, false, false)); // for to_strong/to_strongs const auto hash0 = test::genesis.transaction_hashes(false).front(); @@ -750,10 +750,10 @@ BOOST_AUTO_TEST_CASE(query_translate__to_parent__always__expected) 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, test::context, false)); - BOOST_REQUIRE(query.set(test::block2, test::context, false)); - BOOST_REQUIRE(query.set(test::block1a, test::context, false)); - BOOST_REQUIRE(query.set(test::block2a, test::context, false)); + 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::block1a, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2a, test::context, false, false)); BOOST_REQUIRE_EQUAL(query.to_parent(0), header_link::terminal); BOOST_REQUIRE_EQUAL(query.to_parent(1), 0u); BOOST_REQUIRE_EQUAL(query.to_parent(2), 1u); @@ -772,8 +772,8 @@ BOOST_AUTO_TEST_CASE(query_translate__to_txs__always__expected) 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::block1a, test::context, false)); - BOOST_REQUIRE(query.set(test::block2a, test::context, false)); + BOOST_REQUIRE(query.set(test::block1a, test::context, false, false)); + BOOST_REQUIRE(query.set(test::block2a, test::context, false, false)); const tx_links expected_links2{ 2, 3 }; BOOST_REQUIRE_EQUAL(query.to_transactions(0), tx_links{ 0 }); @@ -795,8 +795,8 @@ BOOST_AUTO_TEST_CASE(query_translate__to_spenders__point__expected) 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::block1a, test::context, false)); - BOOST_REQUIRE(query.set(test::block2a, test::context, false)); + 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.to_spenders({ test::genesis.hash(), 0 }).empty()); diff --git a/test/query/validate.cpp b/test/query/validate.cpp index b045a4af..c7e4ccc2 100644 --- a/test/query/validate.cpp +++ b/test/query/validate.cpp @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_bits__genesis__expected) BOOST_REQUIRE_EQUAL(bits, 0x1d00ffff_u32); } -BOOST_AUTO_TEST_CASE(query_validate__get_bypass__genesis__true) +BOOST_AUTO_TEST_CASE(query_validate__get_milestone__genesis__false) { settings settings{}; settings.path = TEST_DIRECTORY; @@ -97,13 +97,13 @@ BOOST_AUTO_TEST_CASE(query_validate__get_bypass__genesis__true) BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); BOOST_REQUIRE(query.initialize(test::genesis)); - bool bypass{}; - BOOST_REQUIRE(!query.get_bypass(bypass, 1)); - BOOST_REQUIRE(query.get_bypass(bypass, 0)); - BOOST_REQUIRE(bypass); + bool milestone{}; + BOOST_REQUIRE(!query.get_milestone(milestone, 1)); + BOOST_REQUIRE(query.get_milestone(milestone, 0)); + BOOST_REQUIRE(!milestone); } -BOOST_AUTO_TEST_CASE(query_validate__get_bypass__set__expected) +BOOST_AUTO_TEST_CASE(query_validate__get_milestone__set__expected) { settings settings{}; settings.path = TEST_DIRECTORY; @@ -111,16 +111,16 @@ BOOST_AUTO_TEST_CASE(query_validate__get_bypass__set__expected) 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{}, false)); - BOOST_REQUIRE(query.set(test::block2, context{}, true)); - - bool bypass{}; - BOOST_REQUIRE(query.get_bypass(bypass, 0)); - BOOST_REQUIRE(bypass); - BOOST_REQUIRE(query.get_bypass(bypass, 1)); - BOOST_REQUIRE(!bypass); - BOOST_REQUIRE(query.get_bypass(bypass, 2)); - BOOST_REQUIRE(bypass); + BOOST_REQUIRE(query.set(test::block1, context{}, true, false)); + BOOST_REQUIRE(query.set(test::block2, context{}, false, false)); + + bool milestone{}; + BOOST_REQUIRE(query.get_milestone(milestone, 0)); + BOOST_REQUIRE(!milestone); + BOOST_REQUIRE(query.get_milestone(milestone, 1)); + BOOST_REQUIRE(milestone); + BOOST_REQUIRE(query.get_milestone(milestone, 2)); + BOOST_REQUIRE(!milestone); } BOOST_AUTO_TEST_CASE(query_validate__get_context__genesis__default) @@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_context__block1__expected) BOOST_REQUIRE(query.initialize(test::genesis)); const context expected{ 12, 34, 56 }; - BOOST_REQUIRE(query.set(test::block1, expected, false)); + BOOST_REQUIRE(query.set(test::block1, expected, false, false)); context ctx{}; BOOST_REQUIRE(query.get_context(ctx, 1)); @@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unvalidated_link__unvalida 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{}, false)); + BOOST_REQUIRE(query.set(test::block1, context{}, false, false)); uint64_t fees{}; BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::unvalidated); @@ -228,7 +228,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__confirmable__block_confirm 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{}, false)); + BOOST_REQUIRE(query.set(test::block1, context{}, false, false)); uint64_t fees{}; BOOST_REQUIRE_EQUAL(query.get_header_state(0), error::unvalidated); @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__valid__block_valid) 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{}, false)); + BOOST_REQUIRE(query.set(test::block1, context{}, false, false)); uint64_t fees{}; BOOST_REQUIRE(query.set_block_valid(1)); @@ -269,7 +269,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unconfirmable__block_uncon 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{}, false)); + BOOST_REQUIRE(query.set(test::block1, context{}, false, false)); uint64_t fees{}; BOOST_REQUIRE(query.set_block_unconfirmable(1)); @@ -303,7 +303,7 @@ BOOST_AUTO_TEST_CASE(query_validate__get_tx_state__unvalidated__unvalidated) 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{}, false)); + BOOST_REQUIRE(query.set(test::block1, context{}, false, false)); uint64_t fee{}; size_t sigops{}; @@ -321,9 +321,9 @@ BOOST_AUTO_TEST_CASE(query_validate__get_tx_state__connected_out_of_context__unv 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{}, false)); - BOOST_REQUIRE(query.set(test::block2, context{}, false)); - BOOST_REQUIRE(query.set(test::block3, context{}, false)); + 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)); uint64_t fee{}; size_t sigops{}; @@ -349,9 +349,9 @@ BOOST_AUTO_TEST_CASE(query_validate__get_tx_state__connected_in_context__tx_conn 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{}, false)); - BOOST_REQUIRE(query.set(test::block2, context{}, false)); - BOOST_REQUIRE(query.set(test::block3, context{}, false)); + 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)); uint64_t fee{}; size_t sigops{}; @@ -378,9 +378,9 @@ BOOST_AUTO_TEST_CASE(query_validate__get_tx_state__connected_in_context__tx_prec 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{}, false)); - BOOST_REQUIRE(query.set(test::block2, context{}, false)); - BOOST_REQUIRE(query.set(test::block3, context{}, false)); + 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)); uint64_t fee{}; size_t sigops{}; @@ -400,9 +400,9 @@ BOOST_AUTO_TEST_CASE(query_validate__get_tx_state__connected_in_context__tx_disc 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{}, false)); - BOOST_REQUIRE(query.set(test::block2, context{}, false)); - BOOST_REQUIRE(query.set(test::block3, context{}, false)); + 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)); uint64_t fee{}; size_t sigops{}; diff --git a/test/tables/archives/header.cpp b/test/tables/archives/header.cpp index 3aa1a760..0a90874f 100644 --- a/test/tables/archives/header.cpp +++ b/test/tables/archives/header.cpp @@ -33,7 +33,7 @@ constexpr table::header::record expected 0x00341201_u32, // height 0x56341203_u32 // mtp }, - true, // bypass + true, // milestone 0x00341204_u32, // parent_fk 0x56341205_u32, // version 0x56341206_u32, // timestamp @@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(header__put_ptr__get__expected) { {}, expected.ctx, - expected.bypass, + expected.milestone, expected.parent_fk, system::to_shared(expected_header) }; @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(header__put_ref__get__expected) { {}, expected.ctx, - expected.bypass, + expected.milestone, expected.parent_fk, expected_header };