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

feat: default MFS to CIDv1 #2527

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
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
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 })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to this, should also set Import.* in config to apply CIDv1 to files imported via context menu in Windows Explorer's right-click context menu (which uses ipfs add).

See thoughts in ipfs/kubo#4143 (comment) – my current thinking is that we want to avoid breaking existing users, and in next verison of Kubo we will explicitly save defaults in Import on repo creation.

IPFS Desktop could follow this philosophy (or just wait for Kubo) – initialize new users with CIDv1 and store that in Import.*, and for old users who have Import.CidVersion=0 or unset give them context menu for switching to CIDv1, which would switch + set Import.CidVersion=1 and other values.

This way we won't break anyone, but still be able to move forward.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd much rather just pull in settings directly from kubo and have things work there if we can

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we need a fix in Kubo. It should respect Import.* especially Import.CidVersion when a new MFS root is created. (TODO: fill issue once im at PC)

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
Loading