From 909be527d9e3948cc74d154794c8859358b6b6e8 Mon Sep 17 00:00:00 2001 From: Jonathan Giszczak Date: Thu, 17 Jun 2021 09:18:13 -0500 Subject: [PATCH 1/3] Add p2p-always-resync option. --- plugins/net_plugin/net_plugin.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index 1510d04cf12..099d86dfa5a 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -249,6 +249,7 @@ namespace eosio { uint32_t max_nodes_per_host = 1; bool p2p_accept_transactions = true; bool p2p_reject_incomplete_blocks = true; + bool p2p_always_resync = false; /// Peer clock may be no more than 1 second skewed from our clock, including network latency. const std::chrono::system_clock::duration peer_authentication_interval{std::chrono::seconds{1}}; @@ -2920,7 +2921,15 @@ namespace eosio { g.unlock(); if( blk_num < last_sent_lib ) { fc_ilog( logger, "received block ${n} less than sent lib ${lib}", ("n", blk_num)("lib", last_sent_lib) ); - close(); + if(my_impl->p2p_always_resync) { + fc_ilog( logger, "attempting to resync with peer that is sending blocks less than sent lib ${lib}", ("lib", last_sent_lib) ); + enqueue( (sync_request_message) {0, 0} ); + send_handshake(); + cancel_wait(); + } + else { + close(); + } } else { fc_ilog( logger, "received block ${n} less than lib ${lib}", ("n", blk_num)("lib", lib) ); enqueue( (sync_request_message) {0, 0} ); @@ -3971,6 +3980,7 @@ namespace eosio { " _port \tremote port number of peer\n\n" " _lip \tlocal IP address connected to peer\n\n" " _lport \tlocal port number connected to peer\n\n") + ( "p2p-always-resync", bpo::value()->default_value(false), "Always attempt to resync even when peer sends blocks earlier than this node's last irreversible block") ( "p2p-keepalive-interval-ms", bpo::value()->default_value(def_keepalive_interval), "peer heartbeat keepalive message interval in milliseconds") ( "p2p-tls-security-group-ca-file", bpo::value(), "Certificate Authority's certificate file used for verifying peers TLS connection when security groups feature enabled" ) ( "p2p-tls-own-certificate-file", bpo::value(), "Certificate file that will be used to authenticate running node if TLS is enabled") @@ -3998,6 +4008,7 @@ namespace eosio { my->max_nodes_per_host = options.at( "p2p-max-nodes-per-host" ).as(); my->p2p_accept_transactions = options.at( "p2p-accept-transactions" ).as(); my->p2p_reject_incomplete_blocks = options.at("p2p-reject-incomplete-blocks").as(); + my->p2p_always_resync = options.at( "p2p-always-resync" ).as(); my->use_socket_read_watermark = options.at( "use-socket-read-watermark" ).as(); my->keepalive_interval = std::chrono::milliseconds( options.at( "p2p-keepalive-interval-ms" ).as() ); From cc31665e75082d2b3e199ccbd45bfee8ba54a105 Mon Sep 17 00:00:00 2001 From: Jonathan Giszczak Date: Thu, 17 Jun 2021 14:34:30 -0500 Subject: [PATCH 2/3] Whitespace change to trigger new build. --- plugins/net_plugin/net_plugin.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index 099d86dfa5a..b5cc5cca6d5 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -2919,6 +2919,7 @@ namespace eosio { std::unique_lock g( conn_mtx ); const auto last_sent_lib = last_handshake_sent.last_irreversible_block_num; g.unlock(); + if( blk_num < last_sent_lib ) { fc_ilog( logger, "received block ${n} less than sent lib ${lib}", ("n", blk_num)("lib", last_sent_lib) ); if(my_impl->p2p_always_resync) { From 6ffc69b2ee5888f71715b744f5ee5563e131f6f4 Mon Sep 17 00:00:00 2001 From: Jonathan Giszczak Date: Mon, 28 Jun 2021 18:56:57 -0500 Subject: [PATCH 3/3] Eliminate p2p-always-resync option and always resync. --- plugins/net_plugin/net_plugin.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index b5cc5cca6d5..a3d6db31658 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -249,7 +249,6 @@ namespace eosio { uint32_t max_nodes_per_host = 1; bool p2p_accept_transactions = true; bool p2p_reject_incomplete_blocks = true; - bool p2p_always_resync = false; /// Peer clock may be no more than 1 second skewed from our clock, including network latency. const std::chrono::system_clock::duration peer_authentication_interval{std::chrono::seconds{1}}; @@ -2920,23 +2919,12 @@ namespace eosio { const auto last_sent_lib = last_handshake_sent.last_irreversible_block_num; g.unlock(); - if( blk_num < last_sent_lib ) { - fc_ilog( logger, "received block ${n} less than sent lib ${lib}", ("n", blk_num)("lib", last_sent_lib) ); - if(my_impl->p2p_always_resync) { - fc_ilog( logger, "attempting to resync with peer that is sending blocks less than sent lib ${lib}", ("lib", last_sent_lib) ); - enqueue( (sync_request_message) {0, 0} ); - send_handshake(); - cancel_wait(); - } - else { - close(); - } - } else { - fc_ilog( logger, "received block ${n} less than lib ${lib}", ("n", blk_num)("lib", lib) ); - enqueue( (sync_request_message) {0, 0} ); - send_handshake(); - cancel_wait(); - } + fc_ilog( logger, "received block ${n} less than ${which}lib ${lib}", + ("n", blk_num)("which", blk_num < last_sent_lib ? "sent " : "") + ("lib", blk_num < last_sent_lib ? last_sent_lib : lib) ); + enqueue( (sync_request_message) {0, 0} ); + send_handshake(); + cancel_wait(); pending_message_buffer.advance_read_ptr( message_length ); return true; @@ -3981,7 +3969,6 @@ namespace eosio { " _port \tremote port number of peer\n\n" " _lip \tlocal IP address connected to peer\n\n" " _lport \tlocal port number connected to peer\n\n") - ( "p2p-always-resync", bpo::value()->default_value(false), "Always attempt to resync even when peer sends blocks earlier than this node's last irreversible block") ( "p2p-keepalive-interval-ms", bpo::value()->default_value(def_keepalive_interval), "peer heartbeat keepalive message interval in milliseconds") ( "p2p-tls-security-group-ca-file", bpo::value(), "Certificate Authority's certificate file used for verifying peers TLS connection when security groups feature enabled" ) ( "p2p-tls-own-certificate-file", bpo::value(), "Certificate file that will be used to authenticate running node if TLS is enabled") @@ -4009,7 +3996,6 @@ namespace eosio { my->max_nodes_per_host = options.at( "p2p-max-nodes-per-host" ).as(); my->p2p_accept_transactions = options.at( "p2p-accept-transactions" ).as(); my->p2p_reject_incomplete_blocks = options.at("p2p-reject-incomplete-blocks").as(); - my->p2p_always_resync = options.at( "p2p-always-resync" ).as(); my->use_socket_read_watermark = options.at( "use-socket-read-watermark" ).as(); my->keepalive_interval = std::chrono::milliseconds( options.at( "p2p-keepalive-interval-ms" ).as() );