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
12 changes: 6 additions & 6 deletions include/bitcoin/node/protocols/protocol_header_in_70014.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ class BCN_API protocol_header_in_70014
virtual bool handle_receive_compact_transactions(const code& ec,
const compact_transactions::cptr& message) NOEXCEPT;
virtual void handle_organize_compact(const code& ec, size_t height,
const compact_block::cptr& message) NOEXCEPT;
const compact_block::cptr& message, const gate_t::ptr& gate) NOEXCEPT;
virtual void do_organize_compact(const code& ec,
const compact_block::cptr& message) NOEXCEPT;
const compact_block::cptr& message, const gate_t::ptr& gate) NOEXCEPT;
virtual void handle_submit_compact(const code& ec, size_t index,
const system::hash_digest& hash, size_t height, size_t pooled,
size_t count) NOEXCEPT;
size_t count, const gate_t::ptr& gate) NOEXCEPT;
virtual void do_submit_compact(const code& ec,
const system::hash_digest& hash, size_t height, size_t pooled,
size_t count) NOEXCEPT;
size_t count, const gate_t::ptr& gate) NOEXCEPT;

private:
bool scan(fill& block) NOEXCEPT;
Expand All @@ -95,11 +95,11 @@ class BCN_API protocol_header_in_70014

void upgrade() NOEXCEPT;
void request() NOEXCEPT;
void identify() NOEXCEPT;
void identify(const gate_t::ptr& gate) NOEXCEPT;
bool resolve(const database::header_link& link) NOEXCEPT;
bool matched(const database::header_link& link) const NOEXCEPT;
void collect(const compact_block& message,
const database::header_link& link) NOEXCEPT;
const database::header_link& link, const gate_t::ptr& gate) NOEXCEPT;

// These are protected by strand.
bool compact_{};
Expand Down
33 changes: 17 additions & 16 deletions src/protocols/protocol_header_in_70014.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,28 @@ bool protocol_header_in_70014::handle_receive_compact_block(const code& ec,
if (link.is_terminal())
{
organize_compact(header,
BIND(handle_organize_compact, _1, _2, message));
BIND(handle_organize_compact, _1, _2, message, gate()));
return true;
}

collect(*message, link);
collect(*message, link, gate());
return true;
}

// not stranded
void protocol_header_in_70014::handle_organize_compact(const code& ec,
size_t, const compact_block::cptr& message) NOEXCEPT
size_t, const compact_block::cptr& message,
const gate_t::ptr& gate) NOEXCEPT
{
// Chaser may be stopped before protocol.
if (stopped() || ec == network::error::service_stopped)
return;

POST(do_organize_compact, ec, message);
POST(do_organize_compact, ec, message, gate);
}

void protocol_header_in_70014::do_organize_compact(const code& ec,
const compact_block::cptr& message) NOEXCEPT
const compact_block::cptr& message, const gate_t::ptr& gate) NOEXCEPT
{
BC_ASSERT(stranded());

Expand All @@ -171,14 +172,14 @@ void protocol_header_in_70014::do_organize_compact(const code& ec,
// The header of a weak branch is not stored.
const auto link = archive().to_header(hash);
if (!link.is_terminal())
collect(*message, link);
collect(*message, link, gate);
}

// Collect (short ids).
// ----------------------------------------------------------------------------

void protocol_header_in_70014::collect(const compact_block& message,
const database::header_link& link) NOEXCEPT
const database::header_link& link, const gate_t::ptr& gate) NOEXCEPT
{
BC_ASSERT(stranded());
const auto& query = archive();
Expand Down Expand Up @@ -220,7 +221,7 @@ void protocol_header_in_70014::collect(const compact_block& message,

fill_.emplace(std::move(block));
if (fill_->missing.empty())
identify();
identify(gate);
else
request();
}
Expand Down Expand Up @@ -376,14 +377,14 @@ bool protocol_header_in_70014::handle_receive_compact_transactions(
}

block.missing.clear();
identify();
identify(gate());
return true;
}

// Identify and submit.
// ----------------------------------------------------------------------------

void protocol_header_in_70014::identify() NOEXCEPT
void protocol_header_in_70014::identify(const gate_t::ptr& gate) NOEXCEPT
{
BC_ASSERT(stranded());

Expand Down Expand Up @@ -428,7 +429,7 @@ void protocol_header_in_70014::identify() NOEXCEPT
const auto count = block.txs.size();
submit_compact(unpooled, block.links, block.link,
BIND(handle_submit_compact, _1, _2, block.hash, block.height,
count - block.unpooled.size(), count));
count - block.unpooled.size(), count, gate));
fill_.reset();
}

Expand Down Expand Up @@ -486,19 +487,19 @@ bool protocol_header_in_70014::is_malleated64(const fill& block) NOEXCEPT

// not stranded
void protocol_header_in_70014::handle_submit_compact(const code& ec, size_t,
const hash_digest& hash, size_t height, size_t pooled,
size_t count) NOEXCEPT
const hash_digest& hash, size_t height, size_t pooled, size_t count,
const gate_t::ptr& gate) NOEXCEPT
{
// Chaser may be stopped before protocol.
if (stopped() || ec == network::error::service_stopped)
return;

POST(do_submit_compact, ec, hash, height, pooled, count);
POST(do_submit_compact, ec, hash, height, pooled, count, gate);
}

void protocol_header_in_70014::do_submit_compact(const code& ec,
const hash_digest& hash, size_t height, size_t pooled,
size_t count) NOEXCEPT
const hash_digest& hash, size_t height, size_t pooled, size_t count,
const gate_t::ptr&) NOEXCEPT
{
BC_ASSERT(stranded());

Expand Down
41 changes: 41 additions & 0 deletions test/functional/p2p_compact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,47 @@ BOOST_AUTO_TEST_CASE(functional_p2p_compact__compact_block__short_id__requested_
BOOST_REQUIRE(associated(block.hash()));
}

BOOST_AUTO_TEST_CASE(functional_p2p_compact__compact_block__replayed_while_organizing__requested_once)
{
BOOST_REQUIRE(handshake(full_node));

const auto& block = block1();
send(shortened(block), node_version->value);
send(shortened(block), node_version->value);
send(ping{ 42 }, node_version->value);

receive(get_compact_transactions::command);
BOOST_REQUIRE(!received(get_compact_transactions::command, pong::command));
}

BOOST_AUTO_TEST_CASE(functional_p2p_compact__compact_block__replayed_while_submitting__not_requested)
{
BOOST_REQUIRE(handshake(full_node));

const auto& block = block1();
send(shortened(block), node_version->value);
receive(get_compact_transactions::command);

send(compact_transactions{ block.hash(), { block.transactions_ptr()->front() } }, node_version->value);
send(shortened(block), node_version->value);
send(ping{ 42 }, node_version->value);

BOOST_REQUIRE(!received(get_compact_transactions::command, pong::command));
BOOST_REQUIRE(associated(block.hash()));
}

// An unstored parent is resolved by header synchronization.
BOOST_AUTO_TEST_CASE(functional_p2p_compact__compact_block__orphan__not_stopped)
{
BOOST_REQUIRE(handshake(full_node));

const auto& block = block2();
send(prefilled(block, block.transactions_ptr()->front()), node_version->value);
send(ping{ 42 }, node_version->value);

BOOST_REQUIRE(!receive(pong::command).empty());
}

// The pool holds none of the block, so it is downloaded (not requested).
BOOST_FIXTURE_TEST_CASE(functional_p2p_compact__compact_block__short_id_unpooled__not_requested, p2p_compact_pooled_setup_fixture)
{
Expand Down
Loading