From 8ddb982952fd01c0d7ea5b701ca7d52223b30de2 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 24 Jun 2024 18:08:26 -0400 Subject: [PATCH] Clean up codes, weak ptr fixes, add organizer::duplicate(). --- console/executor.cpp | 4 +- include/bitcoin/node/chasers/chaser_block.hpp | 4 + .../bitcoin/node/chasers/chaser_header.hpp | 4 + .../bitcoin/node/chasers/chaser_organize.hpp | 6 +- include/bitcoin/node/error.hpp | 27 ++- .../node/impl/chasers/chaser_organize.ipp | 54 ++---- .../protocols/protocol_block_in_31800.hpp | 2 +- src/chasers/chaser_block.cpp | 34 ++++ src/chasers/chaser_confirm.cpp | 62 +++---- src/chasers/chaser_header.cpp | 36 +++- src/chasers/chaser_validate.cpp | 22 +-- src/error.cpp | 23 +-- src/protocols/protocol_block_in_31800.cpp | 6 +- test/error.cpp | 165 +++++++----------- 14 files changed, 214 insertions(+), 235 deletions(-) diff --git a/console/executor.cpp b/console/executor.cpp index 56aa71e76..2b77f6b0d 100644 --- a/console/executor.cpp +++ b/console/executor.cpp @@ -303,7 +303,7 @@ void executor::scan_flags() const { const auto start = logger::now(); constexpr auto flag_bits = to_bits(sizeof(chain::flags)); - const auto error = code{ error::store_integrity }.message(); + const auto error = code{ database::error::integrity }.message(); const auto top = query_.get_top_candidate(); uint32_t flags{}; @@ -2660,7 +2660,7 @@ bool executor::do_run() { ec = error::success; if (!restore_store(true)) - ec = error::store_integrity; + ec = database::error::integrity; } if (ec) diff --git a/include/bitcoin/node/chasers/chaser_block.hpp b/include/bitcoin/node/chasers/chaser_block.hpp index ab1ddbd52..421116f09 100644 --- a/include/bitcoin/node/chasers/chaser_block.hpp +++ b/include/bitcoin/node/chasers/chaser_block.hpp @@ -48,6 +48,10 @@ class BCN_API chaser_block virtual bool get_block(system::chain::block::cptr& out, size_t height) const NOEXCEPT; + /// Determine if Block is a duplicate (success for not duplicate). + virtual code duplicate(size_t& height, + const system::hash_digest& hash) const NOEXCEPT; + /// Determine if Block is valid. virtual code validate(const system::chain::block& block, const chain_state& state) const NOEXCEPT; diff --git a/include/bitcoin/node/chasers/chaser_header.hpp b/include/bitcoin/node/chasers/chaser_header.hpp index 29249d0a2..fa3d1efed 100644 --- a/include/bitcoin/node/chasers/chaser_header.hpp +++ b/include/bitcoin/node/chasers/chaser_header.hpp @@ -51,6 +51,10 @@ class BCN_API chaser_header virtual bool get_block(system::chain::header::cptr& out, size_t height) const NOEXCEPT; + /// Determine if Block is a duplicate (success for not duplicate). + virtual code duplicate(size_t& height, + const system::hash_digest& hash) const NOEXCEPT; + /// Determine if Block is valid. virtual code validate(const system::chain::header& header, const chain_state& state) const NOEXCEPT; diff --git a/include/bitcoin/node/chasers/chaser_organize.hpp b/include/bitcoin/node/chasers/chaser_organize.hpp index 2144a71b2..2cb7dfdd6 100644 --- a/include/bitcoin/node/chasers/chaser_organize.hpp +++ b/include/bitcoin/node/chasers/chaser_organize.hpp @@ -70,6 +70,10 @@ class chaser_organize virtual bool get_block(typename Block::cptr& out, size_t height) const NOEXCEPT = 0; + /// Determine if Block is a duplicate (success for not duplicate). + virtual code duplicate(size_t& height, + const system::hash_digest& hash) const NOEXCEPT = 0; + /// Determine if Block is valid. virtual code validate(const Block& block, const chain_state& state) const NOEXCEPT = 0; @@ -95,7 +99,7 @@ class chaser_organize event_value value) NOEXCEPT; /// Organize a discovered Block. - virtual void do_organize(typename Block::cptr& block_ptr, + virtual void do_organize(typename Block::cptr block_ptr, const organize_handler& handler) NOEXCEPT; /// Reorganize following Block unconfirmability. diff --git a/include/bitcoin/node/error.hpp b/include/bitcoin/node/error.hpp index facc05586..9e7aa6cae 100644 --- a/include/bitcoin/node/error.hpp +++ b/include/bitcoin/node/error.hpp @@ -38,11 +38,8 @@ enum error_t : uint8_t { /// general success, - internal_error, - unexpected_event, /// database - store_integrity, store_uninitialized, store_reload, store_snapshot, @@ -56,40 +53,36 @@ enum error_t : uint8_t suspended_service, /// blockchain + branch_error, orphan_block, orphan_header, duplicate_block, duplicate_header, - malleated_block, - insufficient_work, - validation_bypass, - confirmation_bypass, + ////validation_bypass, + ////confirmation_bypass, - /// query + /// chasers set_block_unconfirmable, - ////set_block_link, get_height, get_branch_work, get_is_strong, invalid_branch_point, pop_candidate, push_candidate, - set_header_link, invalid_fork_point, get_candidate_chain_state, get_block, - set_dissasociated, get_unassociated, get_fork_work, to_confirmed, pop_confirmed, - set_confirmed, - block_confirmable, - set_txs_connected, + get_block_confirmable, + get_block_state, + set_strong, + set_unstrong, + set_organized, + set_block_confirmable, set_block_valid, - - /// query composite - node_push, node_confirm, node_validate, node_roll_back diff --git a/include/bitcoin/node/impl/chasers/chaser_organize.ipp b/include/bitcoin/node/impl/chasers/chaser_organize.ipp index f9a1fc915..4500d44bc 100644 --- a/include/bitcoin/node/impl/chasers/chaser_organize.ipp +++ b/include/bitcoin/node/impl/chasers/chaser_organize.ipp @@ -119,13 +119,12 @@ bool CLASS::handle_event(const code&, chase event_, event_value value) NOEXCEPT } TEMPLATE -void CLASS::do_organize(typename Block::cptr& block_ptr, +void CLASS::do_organize(typename Block::cptr block_ptr, const organize_handler& handler) NOEXCEPT { using namespace system; BC_ASSERT(stranded()); - // block_ptr is const auto& hash = block_ptr->get_hash(); const auto& header = get_header(*block_ptr); auto& query = archive(); @@ -146,45 +145,12 @@ void CLASS::do_organize(typename Block::cptr& block_ptr, return; } - const auto id = query.to_header(hash); - if (!id.is_terminal()) + code ec{}; + size_t height{}; + if ((ec = duplicate(height, hash))) { - size_t height{}; - if (!query.get_height(height, id)) - { - handler(fault(error::get_height), {}); - return; - } - - // block_unconfirmable is not set when merkle tree is malleable, in - // which case the header may be archived in an undetermined state. Not - // setting block_unconfirmable only delays ineviable invalidity - // discovery and consequential deorganization at that block. Though - // this may cycle until a strong candidate chain is located. - const auto ec = query.get_header_state(id); - if (ec == database::error::block_unconfirmable) - { - // This eventually stops the peer, but the full set of headers may - // still cycle through to become strong, despite this being stored - // as block_unconfirmable from a block validate or confirm failure. - // Block validation will then fail and this cycle will continue - // until a strong candidate chain is located. The cycle occurs - // because peers continue to send the same headers, which may - // indicate a local failure or peer failures. - handler(ec, height); - return; - } - - // With a candidate reorg that drops strong below a valid header chain, - // this will cause a sequence of headers to be bypassed, such that a - // parent of a block that doesn't exist will not be a candidate, which - // result in a failure of get_chain_state below, because it depends on - // candidate state. So get_chain_state needs to be chain independent. - if (!is_block() || ec != database::error::unassociated) - { - handler(error_duplicate(), height); - return; - } + handler(ec, height); + return; } // Obtain header chain state. @@ -200,11 +166,11 @@ void CLASS::do_organize(typename Block::cptr& block_ptr, // Roll chain state forward from archived parent to current header. const auto state = std::make_shared(*parent, header, settings_); + height = state->height(); // Validation and currency. // ........................................................................ - const auto height = state->height(); if (chain::checkpoint::is_conflict(checkpoints_, hash, height)) { handler(system::error::checkpoint_conflict, height); @@ -214,7 +180,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr, // blocks-first may return malleation error, in which case another peer may // return the good block of the same hash. headers-first cannot detect // malleation here, so the block_in protocol sends chase::malleated. - if (const auto ec = validate(*block_ptr, *state)) + if ((ec = validate(*block_ptr, *state))) { handler(ec, height); return; @@ -244,6 +210,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr, return; } + // branch_point is the highest tree-candidate common block. if (!get_is_strong(strong, work, branch_point)) { handler(fault(error::get_is_strong), height); @@ -265,7 +232,6 @@ void CLASS::do_organize(typename Block::cptr& block_ptr, // A milestone can only be set within a to-be-archived chain of candidate // headers/blocks. Once the milestone block is archived it is not useful. update_milestone(header, height, branch_point); - code ec{}; const auto top_candidate = state_->height(); if (branch_point > top_candidate) @@ -596,7 +562,7 @@ code CLASS::push_block(const system::hash_digest& key) NOEXCEPT { const auto handle = tree_.extract(key); if (!handle) - return error::internal_error; + return error::branch_error; const auto& value = handle.mapped(); return push_block(*value.block, value.state->context()); diff --git a/include/bitcoin/node/protocols/protocol_block_in_31800.hpp b/include/bitcoin/node/protocols/protocol_block_in_31800.hpp index 6480c23eb..08aa4621d 100644 --- a/include/bitcoin/node/protocols/protocol_block_in_31800.hpp +++ b/include/bitcoin/node/protocols/protocol_block_in_31800.hpp @@ -72,7 +72,7 @@ class BCN_API protocol_block_in_31800 /// Check incoming block message. virtual bool handle_receive_block(const code& ec, - const network::messages::block::cptr& message) NOEXCEPT; + const network::messages::block::cptr message) NOEXCEPT; private: using type_id = network::messages::inventory::type_id; diff --git a/src/chasers/chaser_block.cpp b/src/chasers/chaser_block.cpp index 9e0293a8e..37ecbc27b 100644 --- a/src/chasers/chaser_block.cpp +++ b/src/chasers/chaser_block.cpp @@ -47,6 +47,40 @@ bool chaser_block::get_block(block::cptr& out, size_t height) const NOEXCEPT return !is_null(out); } +code chaser_block::duplicate(size_t& height, + const system::hash_digest& hash) const NOEXCEPT +{ + height = max_size_t; + const auto& query = archive(); + const auto id = query.to_header(hash); + if (!id.is_terminal()) + { + // database::error::unassociated + // database::error::block_unconfirmable + // database::error::block_confirmable + // database::error::block_valid + // database::error::unknown_state + // database::error::unvalidated + const auto ec = query.get_block_state(id); + + // Most header states are duplicates, one implies fail. + if (ec == database::error::block_unconfirmable) + { + height = query.get_height(id); + return ec; + } + + // unassociated is only non-duplicate. + if (ec != database::error::unassociated) + { + height = query.get_height(id); + return error::duplicate_block; + } + } + + return error::success; +} + code chaser_block::validate(const block& block, const chain_state& state) const NOEXCEPT { diff --git a/src/chasers/chaser_confirm.cpp b/src/chasers/chaser_confirm.cpp index f99d7c2e6..4cae48587 100644 --- a/src/chasers/chaser_confirm.cpp +++ b/src/chasers/chaser_confirm.cpp @@ -98,8 +98,6 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT if (closed()) return; - // TODO: update specialized fault codes. - // Compute relative work. // ........................................................................ @@ -118,7 +116,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT if (fork.empty()) return; - // fork_point is the highest common block. + // fork_point is the highest candidate-confirmed common block. const auto fork_point = height - fork.size(); if (!get_is_strong(strong, work, fork_point)) { @@ -156,7 +154,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT popped.push_back(link); if (!query.set_unstrong_parallel(link)) { - fault(error::node_confirm); + fault(error::set_unstrong); return; } @@ -183,13 +181,13 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT if (closed()) return; + // database::error::unassociated + // database::error::block_unconfirmable + // database::error::block_confirmable + // database::error::block_valid + // database::error::unknown_state + // database::error::unvalidated auto ec = query.get_block_state(link); - if (ec == database::error::integrity) - { - fault(ec); - return; - } - if (ec == database::error::block_unconfirmable) { notify(ec, chase::unconfirmable, link); @@ -207,7 +205,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT // Required for block_confirmable and all confirmed blocks. if (!checked && !query.set_strong_parallel(link)) { - fault(error::set_confirmed); + fault(error::set_strong); return; } @@ -217,7 +215,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT if ((ec != database::error::block_confirmable) && !query.set_block_confirmable(link, uint64_t{})) { - fault(error::block_confirmable); + fault(error::set_block_confirmable); return; } @@ -226,7 +224,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT if (!set_organized(link, index)) { - fault(error::set_confirmed); + fault(error::set_organized); return; } } @@ -235,7 +233,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT ec = query.block_confirmable(link); if (ec == database::error::integrity) { - fault(error::node_confirm); + fault(error::get_block_confirmable); return; } @@ -252,9 +250,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT fire(events::block_unconfirmable, index); if (!roll_back(popped, link, fork_point, index)) - { fault(error::node_roll_back); - } return; } @@ -262,7 +258,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT // TODO: compute fees from validation records. if (!query.set_block_confirmable(link, uint64_t{})) { - fault(error::block_confirmable); + fault(error::set_block_confirmable); return; } @@ -271,7 +267,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT if (!set_organized(link, index)) { - fault(error::set_confirmed); + fault(error::set_organized); return; } } @@ -351,7 +347,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT popped_.push_back(link); if (!query.set_unstrong_parallel(link)) { - fault(error::node_confirm); + fault(error::set_unstrong); return; } @@ -379,12 +375,6 @@ void chaser_confirm::do_organize(size_t height) NOEXCEPT auto& query = archive(); const auto& link = fork_.back(); const auto ec = query.get_block_state(link); - if (ec == database::error::integrity) - { - fault(ec); - return; - } - if (ec == database::error::block_unconfirmable) { notify(ec, chase::unconfirmable, link); @@ -406,7 +396,7 @@ void chaser_confirm::do_organize(size_t height) NOEXCEPT // Checkpoint and milestone guarantee set_strong is always set. if (!checked && !query.set_strong_parallel(link)) { - fault(error::set_confirmed); + fault(error::set_strong); return; } @@ -416,7 +406,7 @@ void chaser_confirm::do_organize(size_t height) NOEXCEPT if ((ec != database::error::block_confirmable) && !query.set_block_confirmable(link, uint64_t{})) { - fault(error::block_confirmable); + fault(error::set_block_confirmable); return; } @@ -425,7 +415,7 @@ void chaser_confirm::do_organize(size_t height) NOEXCEPT if (!set_organized(link, height)) { - fault(error::set_confirmed); + fault(error::set_organized); } fork_.clear(); @@ -434,7 +424,7 @@ void chaser_confirm::do_organize(size_t height) NOEXCEPT if (!enqueue_block(link)) { - fault(error::node_validate); + fault(error::node_confirm); return; } } @@ -492,8 +482,8 @@ void chaser_confirm::handle_tx(const code& ec, const tx_link& tx, // handle_txs will only get invoked once, with a first error code, so // invoke fault here ensure that non-validation codes are not lost. - if (ec == error::store_integrity || ec == database::error::integrity) - fault(error::node_validate); + if (ec == database::error::integrity) + fault(error::node_confirm); // TODO: need to sort out bypass, validity, and fault codes. // Always allow the racer to finish, invokes handle_txs exactly once. @@ -553,7 +543,7 @@ void chaser_confirm::confirm_block(const code& ec, const header_link& link, // TODO: compute fees from validation records. if (!query.set_block_confirmable(link, uint64_t{})) { - fault(error::block_confirmable); + fault(error::set_block_confirmable); return; } @@ -561,7 +551,7 @@ void chaser_confirm::confirm_block(const code& ec, const header_link& link, fire(events::block_confirmed, height); if (!set_organized(link, height)) { - fault(error::set_confirmed); + fault(error::set_organized); return; } @@ -576,9 +566,9 @@ void chaser_confirm::confirm_block(const code& ec, const header_link& link, } // Prevent stall by bumping, as the event may have been missed. - const auto error = query.get_block_state(query.to_candidate(next)); - if ((error == database::error::block_valid) || - (error == database::error::block_confirmable)) + const auto code = query.get_block_state(query.to_candidate(next)); + if ((code == database::error::block_valid) || + (code == database::error::block_confirmable)) { do_validated(next); } diff --git a/src/chasers/chaser_header.cpp b/src/chasers/chaser_header.cpp index 8ee42f78c..bf30c9ff3 100644 --- a/src/chasers/chaser_header.cpp +++ b/src/chasers/chaser_header.cpp @@ -37,7 +37,7 @@ chaser_header::chaser_header(full_node& node) NOEXCEPT code chaser_header::start() NOEXCEPT { if (!initialize_milestone()) - return fault(error::store_integrity); + return fault(database::error::integrity); return chaser_organize
::start(); } @@ -54,6 +54,40 @@ bool chaser_header::get_block(header::cptr& out, size_t height) const NOEXCEPT return !is_null(out); } +code chaser_header::duplicate(size_t& height, + const system::hash_digest& hash) const NOEXCEPT +{ + // With a candidate reorg that drops strong below a valid header chain, + // this will cause a sequence of headers to be bypassed, such that a + // parent of a block that doesn't exist will not be a candidate, which + // result in a failure of get_chain_state, because it depends on candidate + // state. So get_chain_state needs to be chain independent. + + height = max_size_t; + const auto& query = archive(); + const auto id = query.to_header(hash); + if (!id.is_terminal()) + { + // database::error::block_unconfirmable + // database::error::block_confirmable + // database::error::block_valid + // database::error::unknown_state + // database::error::unvalidated + const auto ec = query.get_header_state(id); + + // All header states are duplicates, one implies fail. + if (ec == database::error::block_unconfirmable) + { + height = query.get_height(id); + return ec; + } + + return error::duplicate_header; + } + + return error::success; +} + code chaser_header::validate(const header& header, const chain_state& state) const NOEXCEPT { diff --git a/src/chasers/chaser_validate.cpp b/src/chasers/chaser_validate.cpp index d29ba59f8..8659f097b 100644 --- a/src/chasers/chaser_validate.cpp +++ b/src/chasers/chaser_validate.cpp @@ -146,13 +146,13 @@ void chaser_validate::do_bump(height_t) NOEXCEPT // index. It does not care about regressions that may be in process. const auto link = query.to_candidate(height); + // database::error::unassociated + // database::error::block_unconfirmable + // database::error::block_confirmable + // database::error::block_valid + // database::error::unknown_state + // database::error::unvalidated const auto ec = query.get_block_state(link); - if (ec == database::error::integrity) - { - fault(error::node_validate); - return; - } - if (ec == database::error::unassociated) { // Wait until the gap is filled. @@ -268,19 +268,19 @@ void chaser_validate::validate_tx(const context& ctx, const tx_link& link, const auto tx = query.get_transaction(link); if (!tx) { - ec = error::store_integrity; + ec = database::error::integrity; } else if (!query.populate(*tx)) { ec = query.set_tx_disconnected(link, ctx) ? invalid : - error::store_integrity; + database::error::integrity; fire(events::tx_invalidated, ctx.height); } else if (((invalid = tx->accept(ctx_))) || ((invalid = tx->connect(ctx_)))) { ec = query.set_tx_disconnected(link, ctx) ? invalid : - error::store_integrity; + database::error::integrity; fire(events::tx_invalidated, ctx.height); LOGR("Invalid tx [" << encode_hash(tx->hash(false)) << "] in block (" @@ -294,7 +294,7 @@ void chaser_validate::validate_tx(const context& ctx, const tx_link& link, // TODO: cache fee and sigops from validation stage. ec = query.set_tx_connected(link, ctx, tx->fee(), sigops) ? - error::success : error::store_integrity; + database::error::success : database::error::integrity; } POST(handle_tx, ec, link, racer); @@ -308,7 +308,7 @@ void chaser_validate::handle_tx(const code& ec, const tx_link& tx, // handle_txs will only get invoked once, with a first error code, so // invoke fault here ensure that non-validation codes are not lost. - if (ec == error::store_integrity || ec == database::error::integrity) + if (ec == database::error::integrity) fault(error::node_validate); // TODO: need to sort out bypass, validity, and fault codes. diff --git a/src/error.cpp b/src/error.cpp index 4112d021f..81af74d12 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -28,11 +28,8 @@ DEFINE_ERROR_T_MESSAGE_MAP(error) { // general { success, "success" }, - { internal_error, "internal error" }, - { unexpected_event, "unexpected event" }, // database - { store_integrity, "store integrity" }, { store_uninitialized, "store not initialized" }, { store_reload, "store reload" }, { store_snapshot, "store snapshot" }, @@ -46,40 +43,38 @@ DEFINE_ERROR_T_MESSAGE_MAP(error) { suspended_service, "sacrificed service" }, // blockchain + { branch_error, "branch error" }, { orphan_block, "orphan block" }, { orphan_header, "orphan header" }, { duplicate_block, "duplicate block" }, { duplicate_header, "duplicate header" }, - { malleated_block, "malleated block" }, - { insufficient_work, "insufficient work" }, - { validation_bypass, "validation bypass" }, - { confirmation_bypass, "confirmation bypass" }, + ////{ validation_bypass, "validation bypass" }, + ////{ confirmation_bypass, "confirmation bypass" }, /// query { set_block_unconfirmable, "set_block_unconfirmable" }, - ////{ set_block_link, "set_block_link" }, { get_height, "get_height" }, { get_branch_work, "get_branch_work" }, { get_is_strong, "get_is_strong" }, { invalid_branch_point, "invalid_branch_point" }, { pop_candidate, "pop_candidate" }, { push_candidate, "push_candidate" }, - { set_header_link, "set_header_link" }, { invalid_fork_point, "invalid_fork_point" }, { get_candidate_chain_state, "get_candidate_chain_state" }, { get_block, "get_block" }, - { set_dissasociated, "set_dissasociated" }, { get_unassociated, "get_unassociated" }, { get_fork_work, "get_fork_work" }, { to_confirmed, "to_confirmed" }, { pop_confirmed, "pop_confirmed" }, - { set_confirmed, "set_confirmed" }, - { block_confirmable, "block_confirmable" }, - { set_txs_connected, "set_txs_connected" }, + { get_block_confirmable, "get_block_confirmable" }, + { get_block_state, "get_block_state" }, + { set_strong, "set_strong" }, + { set_unstrong, "set_unstrong" }, + { set_organized, "set_organized" }, + { set_block_confirmable, "set_block_confirmable" }, { set_block_valid, "set_block_valid" }, /// query composite - { node_push, "node_push" }, { node_confirm, "node_confirm" }, { node_validate, "node_validate" }, { node_roll_back, "node_roll_back" } diff --git a/src/protocols/protocol_block_in_31800.cpp b/src/protocols/protocol_block_in_31800.cpp index 9c1a508ba..e378edd89 100644 --- a/src/protocols/protocol_block_in_31800.cpp +++ b/src/protocols/protocol_block_in_31800.cpp @@ -268,7 +268,7 @@ get_data protocol_block_in_31800::create_get_data( // ---------------------------------------------------------------------------- bool protocol_block_in_31800::handle_receive_block(const code& ec, - const block::cptr& message) NOEXCEPT + const block::cptr message) NOEXCEPT { BC_ASSERT(stranded()); @@ -279,7 +279,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec, // ........................................................................ auto& query = archive(); - const chain::block::cptr block_ptr{ message->block_ptr }; + const auto& block_ptr = message->block_ptr; const auto& hash = block_ptr->get_hash(); const auto it = map_->find(hash); @@ -321,7 +321,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec, LOGR("Malleated block [" << encode_hash(hash) << ":" << height << "] from [" << authority() << "] " << code.message()); - // event sent in order to re-obtain the correct block. + // event sent to re-obtain the correct block. notify(error::success, chase::malleated, link); stop(code); return false; diff --git a/test/error.cpp b/test/error.cpp index b29008c10..c81805868 100644 --- a/test/error.cpp +++ b/test/error.cpp @@ -34,35 +34,8 @@ BOOST_AUTO_TEST_CASE(error_t__code__success__false_exected_message) BOOST_REQUIRE_EQUAL(ec.message(), "success"); } -BOOST_AUTO_TEST_CASE(error_t__code__internal_error__true_exected_message) -{ - constexpr auto value = error::internal_error; - const auto ec = code(value); - BOOST_REQUIRE(ec); - BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "internal error"); -} - -BOOST_AUTO_TEST_CASE(error_t__code__unexpected_event__true_exected_message) -{ - constexpr auto value = error::unexpected_event; - const auto ec = code(value); - BOOST_REQUIRE(ec); - BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "unexpected event"); -} - // database -BOOST_AUTO_TEST_CASE(error_t__code__store_integrity__true_exected_message) -{ - constexpr auto value = error::store_integrity; - const auto ec = code(value); - BOOST_REQUIRE(ec); - BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "store integrity"); -} - BOOST_AUTO_TEST_CASE(error_t__code__store_uninitialized__true_exected_message) { constexpr auto value = error::store_uninitialized; @@ -148,6 +121,15 @@ BOOST_AUTO_TEST_CASE(error_t__code__suspended_service__true_exected_message) // blockchain +BOOST_AUTO_TEST_CASE(error_t__code__branch_error__true_exected_message) +{ + constexpr auto value = error::branch_error; + const auto ec = code(value); + BOOST_REQUIRE(ec); + BOOST_REQUIRE(ec == value); + BOOST_REQUIRE_EQUAL(ec.message(), "branch error"); +} + BOOST_AUTO_TEST_CASE(error_t__code__orphan_block__true_exected_message) { constexpr auto value = error::orphan_block; @@ -184,41 +166,23 @@ BOOST_AUTO_TEST_CASE(error_t__code__duplicate_header__true_exected_message) BOOST_REQUIRE_EQUAL(ec.message(), "duplicate header"); } -BOOST_AUTO_TEST_CASE(error_t__code__malleated_block__true_exected_message) -{ - constexpr auto value = error::malleated_block; - const auto ec = code(value); - BOOST_REQUIRE(ec); - BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "malleated block"); -} - -BOOST_AUTO_TEST_CASE(error_t__code__insufficient_work__true_exected_message) -{ - constexpr auto value = error::insufficient_work; - const auto ec = code(value); - BOOST_REQUIRE(ec); - BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "insufficient work"); -} - -BOOST_AUTO_TEST_CASE(error_t__code__validation_bypass__true_exected_message) -{ - constexpr auto value = error::validation_bypass; - const auto ec = code(value); - BOOST_REQUIRE(ec); - BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "validation bypass"); -} - -BOOST_AUTO_TEST_CASE(error_t__code__confirmation_bypass__true_exected_message) -{ - constexpr auto value = error::confirmation_bypass; - const auto ec = code(value); - BOOST_REQUIRE(ec); - BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "confirmation bypass"); -} +////BOOST_AUTO_TEST_CASE(error_t__code__validation_bypass__true_exected_message) +////{ +//// constexpr auto value = error::validation_bypass; +//// const auto ec = code(value); +//// BOOST_REQUIRE(ec); +//// BOOST_REQUIRE(ec == value); +//// BOOST_REQUIRE_EQUAL(ec.message(), "validation bypass"); +////} +//// +////BOOST_AUTO_TEST_CASE(error_t__code__confirmation_bypass__true_exected_message) +////{ +//// constexpr auto value = error::confirmation_bypass; +//// const auto ec = code(value); +//// BOOST_REQUIRE(ec); +//// BOOST_REQUIRE(ec == value); +//// BOOST_REQUIRE_EQUAL(ec.message(), "confirmation bypass"); +////} // query @@ -231,15 +195,6 @@ BOOST_AUTO_TEST_CASE(error_t__code__set_block_unconfirmable__true_exected_messag BOOST_REQUIRE_EQUAL(ec.message(), "set_block_unconfirmable"); } -////BOOST_AUTO_TEST_CASE(error_t__code__set_block_link__true_exected_message) -////{ -//// constexpr auto value = error::set_block_link; -//// const auto ec = code(value); -//// BOOST_REQUIRE(ec); -//// BOOST_REQUIRE(ec == value); -//// BOOST_REQUIRE_EQUAL(ec.message(), "set_block_link"); -////} - BOOST_AUTO_TEST_CASE(error_t__code__get_height__true_exected_message) { constexpr auto value = error::get_height; @@ -294,15 +249,6 @@ BOOST_AUTO_TEST_CASE(error_t__code__push_candidate__true_exected_message) BOOST_REQUIRE_EQUAL(ec.message(), "push_candidate"); } -BOOST_AUTO_TEST_CASE(error_t__code__set_header_link__true_exected_message) -{ - constexpr auto value = error::set_header_link; - const auto ec = code(value); - BOOST_REQUIRE(ec); - BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "set_header_link"); -} - BOOST_AUTO_TEST_CASE(error_t__code__invalid_fork_point__true_exected_message) { constexpr auto value = error::invalid_fork_point; @@ -330,15 +276,6 @@ BOOST_AUTO_TEST_CASE(error_t__code__get_block__true_exected_message) BOOST_REQUIRE_EQUAL(ec.message(), "get_block"); } -BOOST_AUTO_TEST_CASE(error_t__code__set_dissasociated__true_exected_message) -{ - constexpr auto value = error::set_dissasociated; - const auto ec = code(value); - BOOST_REQUIRE(ec); - BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "set_dissasociated"); -} - BOOST_AUTO_TEST_CASE(error_t__code__get_unassociated__true_exected_message) { constexpr auto value = error::get_unassociated; @@ -375,53 +312,71 @@ BOOST_AUTO_TEST_CASE(error_t__code__pop_confirmed__true_exected_message) BOOST_REQUIRE_EQUAL(ec.message(), "pop_confirmed"); } -BOOST_AUTO_TEST_CASE(error_t__code__set_confirmed__true_exected_message) +BOOST_AUTO_TEST_CASE(error_t__code__get_block_confirmable__true_exected_message) { - constexpr auto value = error::set_confirmed; + constexpr auto value = error::get_block_confirmable; const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "set_confirmed"); + BOOST_REQUIRE_EQUAL(ec.message(), "get_block_confirmable"); } -BOOST_AUTO_TEST_CASE(error_t__code__block_confirmable__true_exected_message) +BOOST_AUTO_TEST_CASE(error_t__code__get_block_state__true_exected_message) { - constexpr auto value = error::block_confirmable; + constexpr auto value = error::get_block_state; const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "block_confirmable"); + BOOST_REQUIRE_EQUAL(ec.message(), "get_block_state"); } -BOOST_AUTO_TEST_CASE(error_t__code__set_txs_connected__true_exected_message) +BOOST_AUTO_TEST_CASE(error_t__code__set_strong__true_exected_message) { - constexpr auto value = error::set_txs_connected; + constexpr auto value = error::set_strong; const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "set_txs_connected"); + BOOST_REQUIRE_EQUAL(ec.message(), "set_strong"); } -BOOST_AUTO_TEST_CASE(error_t__code__set_block_valid__true_exected_message) +BOOST_AUTO_TEST_CASE(error_t__code__set_unstrong__true_exected_message) { - constexpr auto value = error::set_block_valid; + constexpr auto value = error::set_unstrong; const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "set_block_valid"); + BOOST_REQUIRE_EQUAL(ec.message(), "set_unstrong"); } -// query composite +BOOST_AUTO_TEST_CASE(error_t__code__set_organized__true_exected_message) +{ + constexpr auto value = error::set_organized; + const auto ec = code(value); + BOOST_REQUIRE(ec); + BOOST_REQUIRE(ec == value); + BOOST_REQUIRE_EQUAL(ec.message(), "set_organized"); +} -BOOST_AUTO_TEST_CASE(error_t__code__node_push__true_exected_message) +BOOST_AUTO_TEST_CASE(error_t__code__set_block_confirmable__true_exected_message) { - constexpr auto value = error::node_push; + constexpr auto value = error::set_block_confirmable; const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value); - BOOST_REQUIRE_EQUAL(ec.message(), "node_push"); + BOOST_REQUIRE_EQUAL(ec.message(), "set_block_confirmable"); } +BOOST_AUTO_TEST_CASE(error_t__code__set_block_valid__true_exected_message) +{ + constexpr auto value = error::set_block_valid; + const auto ec = code(value); + BOOST_REQUIRE(ec); + BOOST_REQUIRE(ec == value); + BOOST_REQUIRE_EQUAL(ec.message(), "set_block_valid"); +} + +// query composite + BOOST_AUTO_TEST_CASE(error_t__code__node_confirm__true_exected_message) { constexpr auto value = error::node_confirm;