[ENG-1332] Fix regression causing P2P to be disabled by default (#1641)

lol, lmao, rofl
This commit is contained in:
Oscar Beaumont
2023-10-20 19:57:19 +11:00
committed by GitHub
parent 51d99cdb3a
commit 758ee5bbe2
2 changed files with 16 additions and 7 deletions

View File

@@ -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<String, Value>,
config: &mut Map<String, Value>,
_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),
}
}

View File

@@ -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<u16>,
}
fn is_true(b: &bool) -> bool {
*b
}
impl Default for ManagerConfig {
fn default() -> Self {
Self {