From 5870a247518e1bbad9ae68cde4b843713588d8df Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 21 Jun 2023 23:36:47 -0600 Subject: [PATCH 1/2] feat: :arrow_up: Upgrade to cid-v1 --- src/daemon/config.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/daemon/config.js b/src/daemon/config.js index 43efe53f1..21b168226 100644 --- a/src/daemon/config.js +++ b/src/daemon/config.js @@ -150,7 +150,7 @@ const getGatewayPort = (config) => getHttpPort(config.Addresses.Gateway) */ function migrateConfig (ipfsd) { // Bump revision number when new migration rule is added - const REVISION = 5 + const REVISION = 6 const REVISION_KEY = 'daemonConfigRevision' const CURRENT_REVISION = store.get(REVISION_KEY, 0) @@ -231,6 +231,10 @@ function migrateConfig (ipfsd) { } } + if (CURRENT_REVISION < 6) { + ipfsd.api.files.chcid('/', { cidVersion: 1 }) + } + if (changed) { try { writeConfigFile(ipfsd, config) From 0d9b53a5fdbde95ba27f864532d52a102580efe0 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:24:25 -0600 Subject: [PATCH 2/2] fix: enable cidv1 for future versions --- src/common/store.js | 10 ++++++++++ src/daemon/config.js | 6 +----- src/enable-cid-v1.js | 27 +++++++++++++++++++++++++++ src/index.js | 4 +++- 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 src/enable-cid-v1.js diff --git a/src/common/store.js b/src/common/store.js index 94fd523ae..63740cf4b 100644 --- a/src/common/store.js +++ b/src/common/store.js @@ -72,6 +72,16 @@ const migrations = { flags = flags.filter(f => f !== dhtClientFlag) store.set('ipfsConfig.flags', flags) } + }, + '>=0.39.1': store => { + fileLogger.info('Running migration: >=0.39.1') + logger.info('[store]: Migrating to use CID version 1 for files') + const useCIDv1 = store.get('ipfsConfig.useCIDv1', null) + if (useCIDv1 === null) { + // if it's null, it's not set to true or false, so we set it to the new default + store.safeSet('ipfsConfig.useCIDv1', true) + } + // otherwise, it's already set to true or false, so we don't need to do anything } } diff --git a/src/daemon/config.js b/src/daemon/config.js index 21b168226..43efe53f1 100644 --- a/src/daemon/config.js +++ b/src/daemon/config.js @@ -150,7 +150,7 @@ const getGatewayPort = (config) => getHttpPort(config.Addresses.Gateway) */ function migrateConfig (ipfsd) { // Bump revision number when new migration rule is added - const REVISION = 6 + const REVISION = 5 const REVISION_KEY = 'daemonConfigRevision' const CURRENT_REVISION = store.get(REVISION_KEY, 0) @@ -231,10 +231,6 @@ function migrateConfig (ipfsd) { } } - if (CURRENT_REVISION < 6) { - ipfsd.api.files.chcid('/', { cidVersion: 1 }) - } - if (changed) { try { writeConfigFile(ipfsd, config) diff --git a/src/enable-cid-v1.js b/src/enable-cid-v1.js new file mode 100644 index 000000000..09fbb09ff --- /dev/null +++ b/src/enable-cid-v1.js @@ -0,0 +1,27 @@ +const store = require('./common/store') +const getCtx = require('./context') +const logger = require('./common/logger') + +module.exports = async function () { + const shouldUseCIDv1 = store.get('ipfsConfig.useCIDv1', true) + + if (shouldUseCIDv1) { + logger.info('[enable-cid-v1]: Attempting to enable CID version 1 for files') + const ctx = getCtx() + const getIpfsd = await ctx.getProp('getIpfsd') + /** @type {import('ipfsd-ctl').Controller|null} */ + const ipfsd = await getIpfsd() + if (!ipfsd) { + logger.error('[enable-cid-v1]: Could not get IPFS daemon controller') + return + } + logger.info('[enable-cid-v1]: Enabling CID version 1 for files') + try { + // @ts-expect-error - ipfsd.api is not typed properly + await ipfsd.api.files.chcid('/', { cidVersion: 1 }) + logger.info('[enable-cid-v1]: CID version 1 enabled for files') + } catch (e) { + logger.error('[enable-cid-v1]: Failed to enable CID version 1 for files', e) + } + } +} diff --git a/src/index.js b/src/index.js index 461fe7d71..5afc08df7 100644 --- a/src/index.js +++ b/src/index.js @@ -34,6 +34,7 @@ const setupSecondInstance = require('./second-instance') const { analyticsKeys } = require('./analytics/keys') const handleError = require('./handleError') const createSplashScreen = require('./splash/create-splash-screen') +const enableCIDv1 = require('./enable-cid-v1') // Hide Dock if (app.dock) app.dock.hide() @@ -82,7 +83,8 @@ async function run () { setupNamesysPubsub(), setupSecondInstance(), // Setup global shortcuts - setupTakeScreenshot() + setupTakeScreenshot(), + enableCIDv1() ]) const submitAppReady = () => { logger.addAnalyticsEvent({ withAnalytics: analyticsKeys.APP_READY, dur: getSecondsSinceAppStart() })