Skip to content

Commit ed35a7a

Browse files
committed
Integrate chain block_view.
1 parent 656dd10 commit ed35a7a

3 files changed

Lines changed: 26 additions & 25 deletions

File tree

include/bitcoin/node/protocols/protocol_block_in_31800.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class BCN_API protocol_block_in_31800
7575
const network::messages::peer::block::cptr& message) NOEXCEPT;
7676

7777
private:
78-
code check(const system::chain::block& block,
78+
code check(const system::chain::block_view& block,
7979
const system::chain::context& ctx, bool bypass) const NOEXCEPT;
8080

8181
void send_get_data(const map_ptr& map, const job::ptr& job) NOEXCEPT;

src/protocols/protocol_block_in_106.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,26 @@ bool protocol_block_in_106::handle_receive_inventory(const code& ec,
123123

124124
// Process block responses in order as dictated by tracker.
125125
bool protocol_block_in_106::handle_receive_block(const code& ec,
126-
const block::cptr& message) NOEXCEPT
126+
const block::cptr& ) NOEXCEPT
127127
{
128128
BC_ASSERT(stranded());
129129

130130
if (stopped(ec))
131131
return false;
132132

133-
const auto& block_ptr = message->block_ptr;
134-
135-
// Unrequested block, may not have been announced via inventory.
136-
if (tracker_.ids.find(block_ptr->get_hash()) == tracker_.ids.end())
137-
{
138-
LOGP("Unrequested block [" << encode_hash(block_ptr->get_hash())
139-
<< "] from [" << opposite() << "].");
140-
return true;
141-
}
142-
143-
// Inventory backlog is limited to 500 per channel.
144-
organize(block_ptr, BIND(handle_organize, _1, _2, block_ptr));
133+
// TODO: add `chain::block get_block() const` method to message.
134+
////const auto& block_ptr = message->block_ptr;
135+
////
136+
////// Unrequested block, may not have been announced via inventory.
137+
////if (tracker_.ids.find(block_ptr->get_hash()) == tracker_.ids.end())
138+
////{
139+
//// LOGP("Unrequested block [" << encode_hash(block_ptr->get_hash())
140+
//// << "] from [" << opposite() << "].");
141+
//// return true;
142+
////}
143+
////
144+
////// Inventory backlog is limited to 500 per channel.
145+
////organize(block_ptr, BIND(handle_organize, _1, _2, block_ptr));
145146
return true;
146147
}
147148

src/protocols/protocol_block_in_31800.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
274274
// Preconditions.
275275
// ........................................................................
276276

277-
const auto& block = message->block_ptr;
278-
const auto& hash = block->get_hash();
277+
const auto& block = message->block;
278+
const auto hash = block.hash();
279279
const auto it = map_->find(hash);
280280
auto& query = archive();
281281

@@ -300,15 +300,15 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
300300
// only stored when a strong header has been stored, later to be found out
301301
// as invalid and not malleable. Stored invalidity prevents repeat
302302
// processing of the same invalid chain but is not necessary or desirable.
303-
if (const auto code = check(*block, it->context, bypass))
303+
if (const auto code = check(block, it->context, bypass))
304304
{
305305
if (code == system::error::invalid_transaction_commitment ||
306306
code == system::error::invalid_witness_commitment)
307307
{
308308
LOGR("Malleated block [" << encode_hash(hash) << ":" << height
309309
<< "] from [" << opposite() << "] " << code.message()
310-
<< " txs(" << block->transactions() << ")"
311-
<< " segregated(" << block->is_segregated() << ").");
310+
<< " txs(" << block.transactions() << ")"
311+
<< " segregated(" << block.is_segregated() << ").");
312312
stop(code);
313313
return false;
314314
}
@@ -330,7 +330,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
330330
// Commit block.txs.
331331
// ........................................................................
332332

333-
if (const auto code = query.set_code(*block, link, checked, bypass, height))
333+
if (const auto code = query.set_code(block, link, checked, bypass, height))
334334
{
335335
LOGF("Failure storing block [" << encode_hash(hash) << ":" << height
336336
<< "] from [" << opposite() << "] " << code.message());
@@ -348,7 +348,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
348348
notify(ec, chase::checked, height);
349349
fire(events::block_archived, height);
350350

351-
count(block->serialized_size(true));
351+
count(block.serialized_size(true));
352352
map_->erase(it);
353353
if (is_idle())
354354
{
@@ -359,10 +359,10 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
359359
return true;
360360
}
361361

362-
// Identity is correct unless error::invalid_witness_commitment or
363-
// error::invalid_transaction_commitment is returned. Only identity is required
364-
// under bypass. Header state is checked by organize.
365-
code protocol_block_in_31800::check(const chain::block& block,
362+
// Header is checked by organize, Check/Accept/Connect are called by validate.
363+
// While check could be called here, it's more optimal to defer to validate, as
364+
// requiring only identity here allows the use of the simplified block_view.
365+
code protocol_block_in_31800::check(const chain::block_view& block,
366366
const chain::context& ctx, bool) const NOEXCEPT
367367
{
368368
code ec{};

0 commit comments

Comments
 (0)