mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
fix: all fast sync nodes report to peers as full nodes (#1547)
* fix: all fast sync nodes report to peers as full nodes
This commit is contained in:
parent
2ca6ecc163
commit
56ffbee7e9
4 changed files with 34 additions and 4 deletions
|
@ -189,7 +189,8 @@ impl GlobalConfig {
|
|||
file.read_to_string(&mut contents)?;
|
||||
let decoded: Result<ConfigMembers, toml::de::Error> = toml::from_str(&contents);
|
||||
match decoded {
|
||||
Ok(gc) => {
|
||||
Ok(mut gc) => {
|
||||
gc.server.validation_check();
|
||||
self.members = Some(gc);
|
||||
return Ok(self);
|
||||
}
|
||||
|
|
|
@ -54,12 +54,12 @@ impl Server {
|
|||
adapter: Arc<ChainAdapter>,
|
||||
genesis: Hash,
|
||||
stop: Arc<AtomicBool>,
|
||||
archive_mode: bool,
|
||||
_archive_mode: bool,
|
||||
block_1_hash: Option<Hash>,
|
||||
) -> Result<Server, Error> {
|
||||
// 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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -157,6 +157,32 @@ pub struct ServerConfig {
|
|||
pub stratum_mining_config: Option<StratumServerConfig>,
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue