Skip to content

Commit

Permalink
GH-1091 Call blk_send_branch directly with requested blocks instead o…
Browse files Browse the repository at this point in the history
…f via last handshake. The last handshake could be very old causing way too many blocks to be sent.
  • Loading branch information
heifner committed Jan 13, 2025
1 parent 7ff8ebf commit 65431db
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ namespace eosio {
}
/** @} */

void blk_send_branch( const block_id_type& msg_head_id, bool include_msg_head );
void blk_send_branch( const block_id_type& msg_head_id );
void blk_send_branch( uint32_t msg_head_num, uint32_t fork_db_root_num, uint32_t head_num );

void enqueue( const net_message& msg );
Expand Down Expand Up @@ -1470,7 +1470,7 @@ namespace eosio {
}

// called from connection strand
void connection::blk_send_branch( const block_id_type& msg_head_id, bool include_msg_head ) {
void connection::blk_send_branch( const block_id_type& msg_head_id ) {
uint32_t head_num = my_impl->get_chain_head_num();

peer_dlog(this, "head_num = ${h}",("h",head_num));
Expand Down Expand Up @@ -1510,12 +1510,9 @@ namespace eosio {
no_retry = benign_other;
enqueue( go_away_message( benign_other ) );
} else {
// if peer on fork, start at their last fork_db_root_num, otherwise we can start at msg_head+1, unless include_msg_head
if (on_fork) {
// if peer on fork, start at their last fork_db_root_num, otherwise we can start at msg_head+1
if (on_fork)
msg_head_num = 0;
} else if (include_msg_head) {
--msg_head_num;
}
blk_send_branch( msg_head_num, fork_db_root_num, head_num );
}
}
Expand Down Expand Up @@ -3709,15 +3706,18 @@ namespace eosio {
case catch_up : {
const block_id_type& id = msg.req_blocks.ids.empty() ? block_id_type() : msg.req_blocks.ids.back();
peer_dlog( this, "received request_message:catch_up #${bn}:${id}", ("bn", block_header::num_from_id(id))("id",id) );
blk_send_branch( id, false );
blk_send_branch( id );
break;
}
case normal : {
if (protocol_version >= proto_block_nack) {
if (!msg.req_blocks.ids.empty()) {
const block_id_type& id = msg.req_blocks.ids.back();
peer_dlog( this, "received request_message:normal #${bn}:${id}", ("bn", block_header::num_from_id(id))("id",id) );
blk_send_branch( id, true );
uint32_t head_num = my_impl->get_chain_head_num();
auto msg_head_num = block_header::num_from_id(id);
// --msg_head_num since blk_send_branch adds one to request and we need to start at msg_head_num
blk_send_branch( --msg_head_num, 0, head_num );
return;
}
}
Expand Down

0 comments on commit 65431db

Please sign in to comment.