@@ -157,8 +157,6 @@ void protocol_block_in::handle_fetch_block_locator(const code& ec,
157157 if (stopped (ec))
158158 return ;
159159
160- const auto & last_hash = message->start_hashes ().front ();
161-
162160 if (ec)
163161 {
164162 LOG_ERROR (LOG_NODE)
@@ -171,14 +169,25 @@ void protocol_block_in::handle_fetch_block_locator(const code& ec,
171169 if (message->start_hashes ().empty ())
172170 return ;
173171
172+ const auto & last_hash = message->start_hashes ().front ();
173+
174174 // TODO: move get_headers to a derived class protocol_block_in_31800.
175175 const auto use_headers = negotiated_version () >= version::level::headers;
176- const auto default_size = use_headers ? " 2000 " : " 500 " ;
176+ const auto request_type = ( use_headers ? " headers " : " inventory " ) ;
177177
178- LOG_DEBUG (LOG_NODE)
179- << " Ask [" << authority () << " ] for headers from ["
180- << encode_hash (last_hash) << " ] through [" <<
181- (stop_hash == null_hash ? default_size : encode_hash (stop_hash)) << " ]" ;
178+ if (stop_hash == null_hash)
179+ {
180+ LOG_DEBUG (LOG_NODE)
181+ << " Ask [" << authority () << " ] for " << request_type << " after ["
182+ << encode_hash (last_hash) << " ]" ;
183+ }
184+ else
185+ {
186+ LOG_DEBUG (LOG_NODE)
187+ << " Ask [" << authority () << " ] for " << request_type << " from ["
188+ << encode_hash (last_hash) << " ] through ["
189+ << encode_hash (stop_hash) << " ]" ;
190+ }
182191
183192 // Save the locator top to prevent a redundant future request.
184193 last_locator_top_.store (last_hash);
@@ -202,6 +211,15 @@ bool protocol_block_in::handle_receive_headers(const code& ec,
202211 if (stopped (ec))
203212 return false ;
204213
214+ // We don't want to request a batch of headers out of order.
215+ if (!message->is_sequential ())
216+ {
217+ LOG_WARNING (LOG_NODE)
218+ << " Block headers out of order from [" << authority () << " ]." ;
219+ stop (error::channel_stopped);
220+ return false ;
221+ }
222+
205223 // There is no benefit to this use of headers, in fact it is suboptimal.
206224 // In v3 headers will be used to build block tree before getting blocks.
207225 const auto response = std::make_shared<get_data>();
0 commit comments