Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lowpower config in Swarm.ConnMgr #2055

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/daemon/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions test/e2e/launch.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down