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

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

上级 1a3584e3
......@@ -262,6 +262,7 @@ namespace eosio {
*/
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");
......@@ -419,6 +420,7 @@ namespace eosio {
int16_t sent_handshake_count;
bool connecting;
bool syncing;
bool backwards_compatibility;
int write_depth;
string peer_addr;
unique_ptr<boost::asio::steady_timer> response_expected;
......@@ -610,6 +612,7 @@ namespace eosio {
sent_handshake_count(0),
connecting(false),
syncing(false),
backwards_compatibility(false),
write_depth(0),
peer_addr(endpoint),
response_expected(),
......@@ -633,6 +636,7 @@ namespace eosio {
sent_handshake_count(0),
connecting(true),
syncing(false),
backwards_compatibility(false),
write_depth(0),
peer_addr(),
response_expected(),
......@@ -1317,16 +1321,21 @@ namespace eosio {
if (head < peer_lib) {
fc_dlog(logger, "sync check state 1");
// wait for receipt of a notice message before initiating sync
if (c->backwards_compatibility) {
start_sync( c, peer_lib);
}
return;
}
if (lib_num > msg.head_num ) {
fc_dlog(logger, "sync check state 2");
notice_message note;
note.known_trx.pending = lib_num;
note.known_trx.mode = last_irr_catch_up;
note.known_blocks.mode = last_irr_catch_up;
note.known_blocks.pending = head;
c->enqueue( note );
if (msg.generation > 1 || !c->backwards_compatibility) {
notice_message note;
note.known_trx.pending = lib_num;
note.known_trx.mode = last_irr_catch_up;
note.known_blocks.mode = last_irr_catch_up;
note.known_blocks.pending = head;
c->enqueue( note );
}
c->syncing = true;
return;
}
......@@ -1338,12 +1347,14 @@ namespace eosio {
}
else {
fc_dlog(logger, "sync check state 4");
notice_message note;
note.known_trx.mode = none;
note.known_blocks.mode = catch_up;
note.known_blocks.pending = head;
note.known_blocks.ids.push_back(head_id);
c->enqueue( note );
if (msg.generation > 1 || !c->backwards_compatibility) {
notice_message note;
note.known_trx.mode = none;
note.known_blocks.mode = catch_up;
note.known_blocks.pending = head;
note.known_blocks.ids.push_back(head_id);
c->enqueue( note );
}
c->syncing = true;
return;
}
......@@ -1994,6 +2005,7 @@ namespace eosio {
return;
}
if( msg.network_version != network_version) {
c->backwards_compatibility = is_old_version (msg.network_version);
if (network_version_match) {
elog("Peer network version does not match expected ${nv} but got ${mnv}",
("nv", network_version)("mnv", msg.network_version));
......@@ -2096,6 +2108,7 @@ namespace eosio {
// notices of previously unknown blocks or txns,
//
fc_dlog(logger, "got a notice_message from ${p}", ("p",c->peer_name()));
c->connecting = false;
request_message req;
bool send_req = false;
if (msg.known_trx.mode != none) {
......@@ -2867,4 +2880,32 @@ namespace eosio {
if( c->peer_addr == host ) return c;
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.
先完成此消息的编辑!
想要评论请 注册