From 148f76900b154448fbad8e28af87210aca32e8a2 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Wed, 26 Apr 2017 16:17:23 -0700 Subject: [PATCH] Revert block orphan scaveging (recursion, not worth the code). --- .../node/protocols/protocol_block_in.hpp | 2 - src/protocols/protocol_block_in.cpp | 49 +++---------------- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/include/bitcoin/node/protocols/protocol_block_in.hpp b/include/bitcoin/node/protocols/protocol_block_in.hpp index b80882cc..b0b49c78 100644 --- a/include/bitcoin/node/protocols/protocol_block_in.hpp +++ b/include/bitcoin/node/protocols/protocol_block_in.hpp @@ -58,8 +58,6 @@ class BCN_API protocol_block_in bool handle_receive_inventory(const code& ec, inventory_const_ptr message); bool handle_receive_not_found(const code& ec, not_found_const_ptr message); void handle_store_block(const code& ec, block_const_ptr message); - void handle_orphan_block(const code& ec, size_t position, - block_const_ptr message); void handle_fetch_block_locator(const code& ec, get_headers_ptr message, const hash_digest& stop_hash); diff --git a/src/protocols/protocol_block_in.cpp b/src/protocols/protocol_block_in.cpp index cf84899e..fb6eeca9 100644 --- a/src/protocols/protocol_block_in.cpp +++ b/src/protocols/protocol_block_in.cpp @@ -324,39 +324,6 @@ bool protocol_block_in::handle_receive_block(const code& ec, return true; } -void protocol_block_in::handle_orphan_block(const code& ec, - size_t position, block_const_ptr message) -{ - if (stopped(ec)) - return; - - const auto& txs = message->transactions(); - - if (!ec && position > 0) - { - BITCOIN_ASSERT(position < txs.size()); - const auto encoded = encode_hash(txs[position].hash()); - - LOG_DEBUG(LOG_NODE) - << "Scavenged transaction [" << encoded << "] from [" - << authority() << "]."; - } - - // Start by incrementing past the presumed coinbase, and so-on. - if (++position >= txs.size()) - { - // Ask the peer for blocks from the chain top up to this orphan. - send_get_blocks(message->hash()); - return; - } - - // TODO: store txs in shared pointer list within block. - auto tx = std::make_shared(txs[position]); - - // Recursion is broken up by the organizer's priority pool transition. - chain_.organize(tx, BIND3(handle_orphan_block, _1, position, message)); -} - // The block has been saved to the block chain (or not). // This will be picked up by subscription in block_out and will cause the block // to be announced to non-originating peers. @@ -367,18 +334,16 @@ void protocol_block_in::handle_store_block(const code& ec, return; const auto hash = message->header().hash(); - const auto encoded = encode_hash(hash); + // Ask the peer for blocks from the chain top up to this orphan. if (ec == error::orphan_block) - { - LOG_DEBUG(LOG_NODE) - << "Scavenging orphan block [" << encoded << "] from [" - << authority() << "]"; - handle_orphan_block(error::success, 0, message); - return; - } + send_get_blocks(hash); + + const auto encoded = encode_hash(hash); - if (ec == error::duplicate_block || ec == error::insufficient_work) + if (ec == error::orphan_block || + ec == error::duplicate_block || + ec == error::insufficient_work) { LOG_DEBUG(LOG_NODE) << "Captured block [" << encoded << "] from [" << authority()