From b38d8ad9277ae7c9848b0d29ac0b9b5bf7bf296f Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Mon, 21 Mar 2022 22:45:56 +0100 Subject: [PATCH] fix: lowpower config.Swarm.ConnMgr Closes #2039 --- src/daemon/config.js | 25 ++++++++++++++++++++----- test/e2e/launch.e2e.test.js | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/daemon/config.js b/src/daemon/config.js index 72ef3aaec..813cdd752 100644 --- a/src/daemon/config.js +++ b/src/daemon/config.js @@ -46,9 +46,9 @@ function applyDefaults (ipfsd) { config.Swarm = config.Swarm || {} config.Swarm.DisableNatPortMap = false config.Swarm.ConnMgr = config.Swarm.ConnMgr || {} - config.Swarm.ConnMgr.GracePeriod = '300s' - config.Swarm.ConnMgr.LowWater = 50 - config.Swarm.ConnMgr.HighWater = 300 + config.Swarm.ConnMgr.GracePeriod = '1m' + config.Swarm.ConnMgr.LowWater = 20 + config.Swarm.ConnMgr.HighWater = 40 config.Discovery = config.Discovery || {} config.Discovery.MDNS = config.Discovery.MDNS || {} @@ -76,7 +76,7 @@ function getHttpPort (addrs) { // This is the place where we execute fixes and performance tweaks for existing users. function migrateConfig (ipfsd) { // Bump revision number when new migration rule is added - const REVISION = 3 + const REVISION = 4 const REVISION_KEY = 'daemonConfigRevision' const CURRENT_REVISION = store.get(REVISION_KEY, 0) @@ -131,7 +131,22 @@ function migrateConfig (ipfsd) { } } - // TODO: update config.Swarm.ConnMgr.* + if (CURRENT_REVISION < 4) { + // lower ConnMgr https://github.com/ipfs/ipfs-desktop/issues/2039 + const { GracePeriod, LowWater, HighWater } = config.Swarm.ConnMgr + if (GracePeriod === '300s') { + config.Swarm.ConnMgr.GracePeriod = '1m' + changed = true + } + if (LowWater > 20) { + config.Swarm.ConnMgr.LowWater = 20 + changed = true + } + if (HighWater > 40) { + config.Swarm.ConnMgr.HighWater = 40 + changed = true + } + } if (changed) { try { diff --git a/test/e2e/launch.e2e.test.js b/test/e2e/launch.e2e.test.js index 27237876e..fced640e2 100644 --- a/test/e2e/launch.e2e.test.js +++ b/test/e2e/launch.e2e.test.js @@ -170,6 +170,27 @@ test.describe.serial('Application launch', async () => { ]) }) + test('applies config migration (ConnMgr)', async () => { + // create preexisting, initialized repo and config + const { repoPath, configPath, peerId: expectedId } = await makeRepository({ start: false }) + + const initConfig = fs.readJsonSync(configPath) + initConfig.Swarm.ConnMgr.GracePeriod = '300s' + initConfig.Swarm.ConnMgr.LowWater = 50 + initConfig.Swarm.ConnMgr.HighWater = 300 + fs.writeJsonSync(configPath, initConfig, { spaces: 2 }) + + const { app } = await startApp({ repoPath }) + const { peerId } = await daemonReady(app) + expect(peerId).toBe(expectedId) + + const config = fs.readJsonSync(configPath) + // ensure app has migrated config + expect(config.Swarm.ConnMgr.GracePeriod).toEqual('1m') + expect(config.Swarm.ConnMgr.LowWater).toEqual(20) + expect(config.Swarm.ConnMgr.HighWater).toEqual(40) + }) + test('starts with repository with "IPFS_PATH/api" file and no daemon running', async () => { // create "remote" repo const { ipfsd } = await makeRepository({ start: true })