Skip to content

Commit

Permalink
fix: enable cidv1 for future versions
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Nov 7, 2024
1 parent 97b8622 commit 0d9b53a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/common/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/daemon/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -231,10 +231,6 @@ function migrateConfig (ipfsd) {
}
}

if (CURRENT_REVISION < 6) {
ipfsd.api.files.chcid('/', { cidVersion: 1 })
}

if (changed) {
try {
writeConfigFile(ipfsd, config)
Expand Down
27 changes: 27 additions & 0 deletions src/enable-cid-v1.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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() })
Expand Down

0 comments on commit 0d9b53a

Please sign in to comment.