@@ -254,7 +254,7 @@ get_data protocol_block_in_31800::create_get_data(
254254 // bip144: get_data uses witness type_id but inv does not.
255255 std::for_each (map.pos_begin (), map.pos_end (), [&](const auto & item) NOEXCEPT
256256 {
257- data.items .emplace_back (block_type_ , item.hash );
257+ data.items .emplace_back (to_block_type (item) , item.hash );
258258 });
259259
260260 return data;
@@ -277,8 +277,6 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
277277 const auto & block = message->block ;
278278 const auto hash = block.hash ();
279279 const auto it = map_->find (hash);
280- auto & query = archive ();
281-
282280 if (it == map_->end ())
283281 {
284282 // Allow unrequested block, not counted toward performance.
@@ -287,15 +285,21 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
287285 return true ;
288286 }
289287
288+ auto & query = archive ();
290289 const auto link = it->link ;
291290 const auto height = it->context .height ;
291+ const auto checked = is_under_checkpoint (height);
292+ const auto bypass = checked || query.is_milestone (link);
293+ if (bypass && node_pruned_ && block.is_segregated ())
294+ {
295+ LOGR (" Unexpected witness from [" << opposite () << " ]." );
296+ stop (system::error::unexpected_witness);
297+ return false ;
298+ }
292299
293300 // Identify block.
294301 // ........................................................................
295302
296- const auto checked = is_under_checkpoint (height);
297- const auto bypass = checked || query.is_milestone (link);
298-
299303 // Tx commitments and malleation are checked under bypass. Invalidity is
300304 // only stored when a strong header has been stored, later to be found out
301305 // as invalid and not malleable. Stored invalidity prevents repeat
@@ -363,11 +367,16 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
363367// While check could be called here, it's more optimal to defer to validate, as
364368// requiring only identity here allows the use of the simplified block_view.
365369code protocol_block_in_31800::identify (const chain::block_view& block,
366- const chain::context& ctx, bool ) const NOEXCEPT
370+ const chain::context& ctx, bool bypass ) const NOEXCEPT
367371{
368- code ec{};
372+ if (const auto ec = block.identify ())
373+ return ec;
374+
375+ // Bypass witness commitment check for stripped blocks.
376+ if (bypass && node_pruned_)
377+ return error::success;
369378
370- if (((ec = block. identify ())) || (( ec = block.identify (ctx)) ))
379+ if (const auto ec = block.identify (ctx))
371380 return ec;
372381
373382 return error::success;
@@ -420,14 +429,24 @@ void protocol_block_in_31800::handle_get_hashes(const code& ec,
420429 POST (send_get_data, map, job);
421430}
422431
423- // checkpoint
432+ // utility
424433// ----------------------------------------------------------------------------
425434
426435bool protocol_block_in_31800::is_under_checkpoint (size_t height) const NOEXCEPT
427436{
428437 return height <= top_checkpoint_height_;
429438}
430439
440+ type_id protocol_block_in_31800::to_block_type (
441+ const association& item) const NOEXCEPT
442+ {
443+ const auto stripped = node_pruned_ &&
444+ (is_under_checkpoint (item.context .height ) ||
445+ archive ().is_milestone (item.link ));
446+
447+ return stripped ? type_id::block : block_type_;
448+ }
449+
431450BC_POP_WARNING ()
432451BC_POP_WARNING ()
433452BC_POP_WARNING ()
0 commit comments