diff --git a/include/bitcoin/node/protocols/protocol_block_in_31800.hpp b/include/bitcoin/node/protocols/protocol_block_in_31800.hpp index 012a9ffc..3013cb1b 100644 --- a/include/bitcoin/node/protocols/protocol_block_in_31800.hpp +++ b/include/bitcoin/node/protocols/protocol_block_in_31800.hpp @@ -75,7 +75,7 @@ class BCN_API protocol_block_in_31800 const network::messages::peer::block::cptr& message) NOEXCEPT; private: - code check(const system::chain::block& block, + code check(const system::chain::block_view& block, const system::chain::context& ctx, bool bypass) const NOEXCEPT; void send_get_data(const map_ptr& map, const job::ptr& job) NOEXCEPT; diff --git a/src/protocols/protocol_block_in_106.cpp b/src/protocols/protocol_block_in_106.cpp index 54227df3..b39588e3 100644 --- a/src/protocols/protocol_block_in_106.cpp +++ b/src/protocols/protocol_block_in_106.cpp @@ -123,25 +123,26 @@ bool protocol_block_in_106::handle_receive_inventory(const code& ec, // Process block responses in order as dictated by tracker. bool protocol_block_in_106::handle_receive_block(const code& ec, - const block::cptr& message) NOEXCEPT + const block::cptr& ) NOEXCEPT { BC_ASSERT(stranded()); if (stopped(ec)) return false; - const auto& block_ptr = message->block_ptr; - - // Unrequested block, may not have been announced via inventory. - if (tracker_.ids.find(block_ptr->get_hash()) == tracker_.ids.end()) - { - LOGP("Unrequested block [" << encode_hash(block_ptr->get_hash()) - << "] from [" << opposite() << "]."); - return true; - } - - // Inventory backlog is limited to 500 per channel. - organize(block_ptr, BIND(handle_organize, _1, _2, block_ptr)); + // TODO: add `chain::block get_block() const` method to message. + ////const auto& block_ptr = message->block_ptr; + //// + ////// Unrequested block, may not have been announced via inventory. + ////if (tracker_.ids.find(block_ptr->get_hash()) == tracker_.ids.end()) + ////{ + //// LOGP("Unrequested block [" << encode_hash(block_ptr->get_hash()) + //// << "] from [" << opposite() << "]."); + //// return true; + ////} + //// + ////// Inventory backlog is limited to 500 per channel. + ////organize(block_ptr, BIND(handle_organize, _1, _2, block_ptr)); return true; } diff --git a/src/protocols/protocol_block_in_31800.cpp b/src/protocols/protocol_block_in_31800.cpp index d5afee49..c9f4f5f3 100644 --- a/src/protocols/protocol_block_in_31800.cpp +++ b/src/protocols/protocol_block_in_31800.cpp @@ -274,8 +274,8 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec, // Preconditions. // ........................................................................ - const auto& block = message->block_ptr; - const auto& hash = block->get_hash(); + const auto& block = message->block; + const auto hash = block.hash(); const auto it = map_->find(hash); auto& query = archive(); @@ -300,15 +300,15 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec, // only stored when a strong header has been stored, later to be found out // as invalid and not malleable. Stored invalidity prevents repeat // processing of the same invalid chain but is not necessary or desirable. - if (const auto code = check(*block, it->context, bypass)) + if (const auto code = check(block, it->context, bypass)) { if (code == system::error::invalid_transaction_commitment || code == system::error::invalid_witness_commitment) { LOGR("Malleated block [" << encode_hash(hash) << ":" << height << "] from [" << opposite() << "] " << code.message() - << " txs(" << block->transactions() << ")" - << " segregated(" << block->is_segregated() << ")."); + << " txs(" << block.transactions() << ")" + << " segregated(" << block.is_segregated() << ")."); stop(code); return false; } @@ -330,7 +330,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec, // Commit block.txs. // ........................................................................ - if (const auto code = query.set_code(*block, link, checked, bypass, height)) + if (const auto code = query.set_code(block, link, checked, bypass, height)) { LOGF("Failure storing block [" << encode_hash(hash) << ":" << height << "] from [" << opposite() << "] " << code.message()); @@ -348,7 +348,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec, notify(ec, chase::checked, height); fire(events::block_archived, height); - count(block->serialized_size(true)); + count(block.serialized_size(true)); map_->erase(it); if (is_idle()) { @@ -359,10 +359,10 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec, return true; } -// Identity is correct unless error::invalid_witness_commitment or -// error::invalid_transaction_commitment is returned. Only identity is required -// under bypass. Header state is checked by organize. -code protocol_block_in_31800::check(const chain::block& block, +// Header is checked by organize, Check/Accept/Connect are called by validate. +// While check could be called here, it's more optimal to defer to validate, as +// requiring only identity here allows the use of the simplified block_view. +code protocol_block_in_31800::check(const chain::block_view& block, const chain::context& ctx, bool) const NOEXCEPT { code ec{};