提交 2c8a55a2 编写于 作者: P Phil Mesnier

#2454 add a check for old version based on git commit id

上级 1a3584e3
...@@ -262,6 +262,7 @@ namespace eosio { ...@@ -262,6 +262,7 @@ namespace eosio {
*/ */
chain::signature_type sign_compact(const chain::public_key_type& signer, const fc::sha256& digest) const; chain::signature_type sign_compact(const chain::public_key_type& signer, const fc::sha256& digest) const;
bool is_old_version (uint16_t v);
}; };
const fc::string logger_name("net_plugin_impl"); const fc::string logger_name("net_plugin_impl");
...@@ -419,6 +420,7 @@ namespace eosio { ...@@ -419,6 +420,7 @@ namespace eosio {
int16_t sent_handshake_count; int16_t sent_handshake_count;
bool connecting; bool connecting;
bool syncing; bool syncing;
bool backwards_compatibility;
int write_depth; int write_depth;
string peer_addr; string peer_addr;
unique_ptr<boost::asio::steady_timer> response_expected; unique_ptr<boost::asio::steady_timer> response_expected;
...@@ -610,6 +612,7 @@ namespace eosio { ...@@ -610,6 +612,7 @@ namespace eosio {
sent_handshake_count(0), sent_handshake_count(0),
connecting(false), connecting(false),
syncing(false), syncing(false),
backwards_compatibility(false),
write_depth(0), write_depth(0),
peer_addr(endpoint), peer_addr(endpoint),
response_expected(), response_expected(),
...@@ -633,6 +636,7 @@ namespace eosio { ...@@ -633,6 +636,7 @@ namespace eosio {
sent_handshake_count(0), sent_handshake_count(0),
connecting(true), connecting(true),
syncing(false), syncing(false),
backwards_compatibility(false),
write_depth(0), write_depth(0),
peer_addr(), peer_addr(),
response_expected(), response_expected(),
...@@ -1317,16 +1321,21 @@ namespace eosio { ...@@ -1317,16 +1321,21 @@ namespace eosio {
if (head < peer_lib) { if (head < peer_lib) {
fc_dlog(logger, "sync check state 1"); fc_dlog(logger, "sync check state 1");
// wait for receipt of a notice message before initiating sync // wait for receipt of a notice message before initiating sync
if (c->backwards_compatibility) {
start_sync( c, peer_lib);
}
return; return;
} }
if (lib_num > msg.head_num ) { if (lib_num > msg.head_num ) {
fc_dlog(logger, "sync check state 2"); fc_dlog(logger, "sync check state 2");
notice_message note; if (msg.generation > 1 || !c->backwards_compatibility) {
note.known_trx.pending = lib_num; notice_message note;
note.known_trx.mode = last_irr_catch_up; note.known_trx.pending = lib_num;
note.known_blocks.mode = last_irr_catch_up; note.known_trx.mode = last_irr_catch_up;
note.known_blocks.pending = head; note.known_blocks.mode = last_irr_catch_up;
c->enqueue( note ); note.known_blocks.pending = head;
c->enqueue( note );
}
c->syncing = true; c->syncing = true;
return; return;
} }
...@@ -1338,12 +1347,14 @@ namespace eosio { ...@@ -1338,12 +1347,14 @@ namespace eosio {
} }
else { else {
fc_dlog(logger, "sync check state 4"); fc_dlog(logger, "sync check state 4");
notice_message note; if (msg.generation > 1 || !c->backwards_compatibility) {
note.known_trx.mode = none; notice_message note;
note.known_blocks.mode = catch_up; note.known_trx.mode = none;
note.known_blocks.pending = head; note.known_blocks.mode = catch_up;
note.known_blocks.ids.push_back(head_id); note.known_blocks.pending = head;
c->enqueue( note ); note.known_blocks.ids.push_back(head_id);
c->enqueue( note );
}
c->syncing = true; c->syncing = true;
return; return;
} }
...@@ -1994,6 +2005,7 @@ namespace eosio { ...@@ -1994,6 +2005,7 @@ namespace eosio {
return; return;
} }
if( msg.network_version != network_version) { if( msg.network_version != network_version) {
c->backwards_compatibility = is_old_version (msg.network_version);
if (network_version_match) { if (network_version_match) {
elog("Peer network version does not match expected ${nv} but got ${mnv}", elog("Peer network version does not match expected ${nv} but got ${mnv}",
("nv", network_version)("mnv", msg.network_version)); ("nv", network_version)("mnv", msg.network_version));
...@@ -2096,6 +2108,7 @@ namespace eosio { ...@@ -2096,6 +2108,7 @@ namespace eosio {
// notices of previously unknown blocks or txns, // notices of previously unknown blocks or txns,
// //
fc_dlog(logger, "got a notice_message from ${p}", ("p",c->peer_name())); fc_dlog(logger, "got a notice_message from ${p}", ("p",c->peer_name()));
c->connecting = false;
request_message req; request_message req;
bool send_req = false; bool send_req = false;
if (msg.known_trx.mode != none) { if (msg.known_trx.mode != none) {
...@@ -2867,4 +2880,32 @@ namespace eosio { ...@@ -2867,4 +2880,32 @@ namespace eosio {
if( c->peer_addr == host ) return c; if( c->peer_addr == host ) return c;
return connection_ptr(); return connection_ptr();
} }
/*
* this really should be in apputils
*/
#include <eosio/net_plugin/old_versions.hpp>
std::set<uint16_t> known_old;
std::set<uint16_t> known_new;
bool net_plugin_impl::is_old_version (uint16_t v) {
if (known_old.find (v) != known_old.end()) {
fc_ilog (logger,"version ${v} is known to be old",("v",v));
return true;
}
if (known_new.find (v) != known_new.end()) {
fc_ilog (logger,"version ${v} is known to be new",("v",v));
return false;
}
for (auto old: old_versions) {
if (v == (uint16_t)old) {
fc_ilog (logger,"adding version ${v} to the known old set",("v",v));
known_old.insert(v);
return true;
}
}
fc_ilog (logger,"adding version ${v} to the known new set",("v",v));
known_new.insert(v);
return false;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册