Skip to content

Commit

Permalink
Merge pull request #466 from AntelopeIO/GH-456-fork-check-beta4
Browse files Browse the repository at this point in the history
[1.0-beta4] P2P: Fix fork check on connection
  • Loading branch information
heifner authored Aug 2, 2024
2 parents 410d5ef + c2528c8 commit 5c6eba5
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ namespace eosio {
unknown_block = !my_id;
on_fork = my_id != msg_head_id;
} catch( ... ) {
on_fork = true;
unknown_block = true;
}
}
if( unknown_block ) {
Expand Down Expand Up @@ -2343,17 +2343,18 @@ namespace eosio {
c->enqueue( note );
}
c->peer_syncing_from_us = false;
bool on_fork = true;
try {
controller& cc = my_impl->chain_plug->chain();
on_fork = cc.fork_block_id_for_num( msg.fork_head_num ) != msg.fork_head_id; // thread-safe
std::optional<block_id_type> fork_head_id = cc.fork_block_id_for_num( msg.fork_head_num ); // thread-safe
if (fork_head_id && fork_head_id != msg.fork_head_id) { // possible for LIB to move and fork_head_num not be found if running with no block-log
peer_dlog(c, "Sending catch_up request_message sync 4, fhead ${fh} != msg.fhead ${mfh}",
("fh", *fork_head_id)("mfh", msg.fork_head_id));
request_message req;
req.req_blocks.mode = catch_up;
req.req_trx.mode = none;
c->enqueue( req );
}
} catch( ... ) {}
if( on_fork ) {
request_message req;
req.req_blocks.mode = catch_up;
req.req_trx.mode = none;
c->enqueue( req );
}
return;
} else {
c->peer_syncing_from_us = false;
Expand Down Expand Up @@ -3513,22 +3514,19 @@ namespace eosio {
peer_dlog( this, "handshake check lib_num = ${ln}, peer_lib = ${pl}", ("ln", lib_num)("pl", peer_lib) );

if( peer_lib <= lib_num && peer_lib > 0 ) {
bool on_fork = false;
try {
controller& cc = my_impl->chain_plug->chain();
std::optional<block_id_type> peer_lib_id = cc.fork_block_id_for_num( peer_lib ); // thread-safe
if (!peer_lib_id) {
// can be not found if running with a truncated block log
peer_dlog( this, "peer last irreversible block ${pl} is unknown", ("pl", peer_lib) );
} else if (msg.last_irreversible_block_id != peer_lib_id) {
peer_wlog( this, "Peer chain is forked, sending: forked go away" );
no_retry = go_away_reason::forked;
enqueue( go_away_message( go_away_reason::forked ) );
}
on_fork = (msg.last_irreversible_block_id != peer_lib_id);
} catch( ... ) {
peer_wlog( this, "caught an exception getting block id for ${pl}", ("pl", peer_lib) );
on_fork = true;
}
if( on_fork ) {
peer_wlog( this, "Peer chain is forked, sending: forked go away" );
no_retry = go_away_reason::forked;
enqueue( go_away_message( go_away_reason::forked ) );
}
}

Expand Down

0 comments on commit 5c6eba5

Please sign in to comment.