From 56ffbee7e94e18a29eb6dc76d9615bc87bf6d1eb Mon Sep 17 00:00:00 2001 From: Gary Yu Date: Thu, 20 Sep 2018 07:09:39 +0800 Subject: [PATCH] fix: all fast sync nodes report to peers as full nodes (#1547) * fix: all fast sync nodes report to peers as full nodes --- config/src/config.rs | 3 ++- p2p/src/serv.rs | 4 ++-- p2p/src/types.rs | 5 ++++- servers/src/common/types.rs | 26 ++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/config/src/config.rs b/config/src/config.rs index cbe084090..9b81e4d2f 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -189,7 +189,8 @@ impl GlobalConfig { file.read_to_string(&mut contents)?; let decoded: Result = toml::from_str(&contents); match decoded { - Ok(gc) => { + Ok(mut gc) => { + gc.server.validation_check(); self.members = Some(gc); return Ok(self); } diff --git a/p2p/src/serv.rs b/p2p/src/serv.rs index 899c63248..8474e00d8 100644 --- a/p2p/src/serv.rs +++ b/p2p/src/serv.rs @@ -54,12 +54,12 @@ impl Server { adapter: Arc, genesis: Hash, stop: Arc, - archive_mode: bool, + _archive_mode: bool, block_1_hash: Option, ) -> Result { // In the case of an archive node, check that we do have the first block. // In case of first sync we do not perform this check. - if archive_mode && adapter.total_height() > 0 { + if capab.contains(Capabilities::FULL_HIST) && adapter.total_height() > 0 { // Check that we have block 1 match block_1_hash { Some(hash) => match adapter.get_block(hash) { diff --git a/p2p/src/types.rs b/p2p/src/types.rs index 8d46a7b19..a22b67e7f 100644 --- a/p2p/src/types.rs +++ b/p2p/src/types.rs @@ -128,7 +128,7 @@ impl Default for P2PConfig { P2PConfig { host: ipaddr, port: 13414, - capabilities: Capabilities::FULL_NODE, + capabilities: Capabilities::FAST_SYNC_NODE, seeding_type: Seeding::default(), seeds: None, peers_allow: None, @@ -202,6 +202,9 @@ bitflags! { /// Can provide a list of healthy peers const PEER_LIST = 0b00000100; + const FAST_SYNC_NODE = Capabilities::TXHASHSET_HIST.bits + | Capabilities::PEER_LIST.bits; + const FULL_NODE = Capabilities::FULL_HIST.bits | Capabilities::TXHASHSET_HIST.bits | Capabilities::PEER_LIST.bits; diff --git a/servers/src/common/types.rs b/servers/src/common/types.rs index 982f608c9..4c545615b 100644 --- a/servers/src/common/types.rs +++ b/servers/src/common/types.rs @@ -157,6 +157,32 @@ pub struct ServerConfig { pub stratum_mining_config: Option, } +impl ServerConfig { + /// Configuration items validation check + pub fn validation_check(&mut self) { + // check [server.p2p_config.capabilities] with 'archive_mode' in [server] + if let Some(archive) = self.archive_mode { + // note: slog not available before config loaded, only print here. + if archive != self + .p2p_config + .capabilities + .contains(p2p::Capabilities::FULL_HIST) + { + // if conflict, 'archive_mode' win + self.p2p_config + .capabilities + .toggle(p2p::Capabilities::FULL_HIST); + println!( + "ServerConfig - capabilities conflict with archive_mode: {}, force to: {:?}", + archive, self.p2p_config.capabilities, + ); // note: slog not available before config loaded, only print here. + } + } + + // todo: other checks if needed + } +} + impl Default for ServerConfig { fn default() -> ServerConfig { ServerConfig {