diff --git a/include/bitcoin/node/protocols/protocol_block_in_31800.hpp b/include/bitcoin/node/protocols/protocol_block_in_31800.hpp index 35dd0003..96e5d661 100644 --- a/include/bitcoin/node/protocols/protocol_block_in_31800.hpp +++ b/include/bitcoin/node/protocols/protocol_block_in_31800.hpp @@ -82,7 +82,8 @@ class BCN_API protocol_block_in_31800 network::messages::peer::get_data create_get_data( const database::associations& map) const NOEXCEPT; - void announce(const code& ec, size_t height) const NOEXCEPT; + void announce(const code& ec, const system::hash_digest& hash, + size_t height) NOEXCEPT; bool archived(const code& ec, const system::hash_digest& hash, size_t height, size_t size) NOEXCEPT; void handle_archive_block(const code& ec, const system::hash_digest& hash, diff --git a/src/full_node.cpp b/src/full_node.cpp index 837626d2..1a153237 100644 --- a/src/full_node.cpp +++ b/src/full_node.cpp @@ -323,6 +323,12 @@ bool full_node::resume() NOEXCEPT return false; } + if (query_.is_fault_locked()) + { + LOGF("Cannot resume network, fault locked."); + return false; + } + LOGS("Resuming network."); const auto resumed = net::resume(); notify(error::success, chases::resume{}); @@ -349,12 +355,13 @@ void full_node::fault(const code& ec) NOEXCEPT { LOGF("Store fault (unrecoverable) '" << query_.get_fault().message() << "' following, " << ec.message()); + /* bool */ query_.set_fault_lock(); } else if (ec) { - // This is a resumable error condition, arising from calling fault(ec) - // when the cause did not originate from the memory map (!is_fault). + // The cause did not originate from the memory map (!is_fault). LOGF("Node fault, " << ec.message()); + /* bool */ query_.set_fault_lock(); } // If a call does not get all of the channels, subsequent failures do so. diff --git a/src/protocols/protocol_block_in_31800.cpp b/src/protocols/protocol_block_in_31800.cpp index 1016696f..6e549877 100644 --- a/src/protocols/protocol_block_in_31800.cpp +++ b/src/protocols/protocol_block_in_31800.cpp @@ -341,27 +341,38 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec, BIND(handle_archive_block, _1, hash, height, size))) return true; - announce(stored, height); + announce(stored, hash, height); return archived(stored, hash, height, size); } // not stranded -// A stored block is announced whether or not its channel has stopped. +// A stored block is announced, and a failure to store one is a fault, whether +// or not its channel has stopped. void protocol_block_in_31800::announce(const code& ec, - size_t height) const NOEXCEPT + const hash_digest& hash, size_t height) NOEXCEPT { - if (ec) + if (!ec) + { + notify(ec, chases::checked{ height }); + fire(events::block_archived, height); return; + } - notify(ec, chases::checked{ height }); - fire(events::block_archived, height); + if ((ec == error::duplicate_block) || + (ec == network::error::service_stopped)) + return; + + LOGF("Failure storing block [" << encode_hash(hash) << ":" << height + << "] from [" << opposite() << "] " << ec.message()); + + fault(ec); } // not stranded void protocol_block_in_31800::handle_archive_block(const code& ec, const hash_digest& hash, size_t height, size_t size) NOEXCEPT { - announce(ec, height); + announce(ec, hash, height); // Chaser may be stopped before protocol. if (stopped() || ec == network::error::service_stopped) @@ -388,10 +399,7 @@ bool protocol_block_in_31800::archived(const code& ec, if (ec && (ec != error::duplicate_block)) { - LOGF("Failure storing block [" << encode_hash(hash) << ":" << height - << "] from [" << opposite() << "] " << ec.message()); - - stop(fault(ec)); + stop(ec); return false; } diff --git a/test/full_node.cpp b/test/full_node.cpp index 1a85a135..b6fd6d41 100644 --- a/test/full_node.cpp +++ b/test/full_node.cpp @@ -326,6 +326,36 @@ BC_AUTO_TEST_CASE(full_node__fault__node_error__suspended) BC_REQUIRE(node_.suspended()); } +BC_AUTO_TEST_CASE(full_node__fault__node_error__fault_locked) +{ + BC_REQUIRE(initialize()); + BC_REQUIRE(!start()); + BC_REQUIRE(!run()); + BC_REQUIRE(!query_.is_fault_locked()); + node_.fault(error::orphan_header); + BC_REQUIRE(query_.is_fault_locked()); +} + +BC_AUTO_TEST_CASE(full_node__fault__success__not_fault_locked) +{ + BC_REQUIRE(initialize()); + BC_REQUIRE(!start()); + BC_REQUIRE(!run()); + node_.fault(error::success); + BC_REQUIRE(!query_.is_fault_locked()); +} + +BC_AUTO_TEST_CASE(full_node__resume__faulted__not_resumed) +{ + BC_REQUIRE(initialize()); + BC_REQUIRE(!start()); + BC_REQUIRE(!run()); + node_.fault(error::orphan_header); + BC_REQUIRE(node_.suspended()); + BC_REQUIRE(!node_.resume()); + BC_REQUIRE(node_.suspended()); +} + BC_AUTO_TEST_CASE(full_node__resume__suspended__resumed) { BC_REQUIRE(initialize());