Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/bitcoin/node/protocols/protocol_block_in_31800.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 14 additions & 13 deletions src/protocols/protocol_block_in_106.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
22 changes: 11 additions & 11 deletions src/protocols/protocol_block_in_31800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}
Expand All @@ -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());
Expand All @@ -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())
{
Expand All @@ -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{};
Expand Down
Loading