Skip to content

Commit

Permalink
Revert block orphan scaveging (recursion, not worth the code).
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed May 1, 2017
1 parent 62c5270 commit 148f769
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 44 deletions.
2 changes: 0 additions & 2 deletions include/bitcoin/node/protocols/protocol_block_in.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
49 changes: 7 additions & 42 deletions src/protocols/protocol_block_in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const message::transaction>(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.
Expand All @@ -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()
Expand Down

0 comments on commit 148f769

Please sign in to comment.