From 758ee5bbe207ec877751d75ce54dfaaad3d3a9a4 Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Fri, 20 Oct 2023 19:57:19 +1100 Subject: [PATCH] [ENG-1332] Fix regression causing P2P to be disabled by default (#1641) lol, lmao, rofl --- core/src/node/config.rs | 18 ++++++++++++++++-- crates/p2p/src/manager.rs | 5 ----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/core/src/node/config.rs b/core/src/node/config.rs index 6b7401282..2da94aa45 100644 --- a/core/src/node/config.rs +++ b/core/src/node/config.rs @@ -42,7 +42,7 @@ pub struct NodeConfig { #[async_trait::async_trait] impl Migrate for NodeConfig { - const CURRENT_VERSION: u32 = 0; + const CURRENT_VERSION: u32 = 1; type Ctx = (); @@ -67,11 +67,25 @@ impl Migrate for NodeConfig { async fn migrate( from_version: u32, - _config: &mut Map, + config: &mut Map, _ctx: &Self::Ctx, ) -> Result<(), MigratorError> { match from_version { 0 => Ok(()), + 1 => { + // All where never hooked up to the UI + config.remove("p2p_email"); + config.remove("p2p_img_url"); + config.remove("p2p_port"); + + // In a recent PR I screwed up Serde `default` so P2P was disabled by default, prior it was always enabled. + // Given the config for it is behind a feature flag (so no one would have changed it) this fixes the default. + if let Some(Value::Object(obj)) = config.get_mut("p2p") { + obj.insert("enabled".into(), Value::Bool(true)); + } + + Ok(()) + } v => unreachable!("Missing migration for library version {}", v), } } diff --git a/crates/p2p/src/manager.rs b/crates/p2p/src/manager.rs index 5596fe139..16a39e4fa 100644 --- a/crates/p2p/src/manager.rs +++ b/crates/p2p/src/manager.rs @@ -203,17 +203,12 @@ pub enum ManagerError { #[derive(Debug, Clone, Serialize, Deserialize, Type)] pub struct ManagerConfig { // Enable or disable the P2P layer - #[serde(default, skip_serializing_if = "is_true")] pub enabled: bool, // `None` will chose a random free port on startup #[serde(default, skip_serializing_if = "Option::is_none")] pub port: Option, } -fn is_true(b: &bool) -> bool { - *b -} - impl Default for ManagerConfig { fn default() -> Self { Self {