diff --git a/config/profile.go b/config/profile.go index 068498715c5e..c73b05af27ce 100644 --- a/config/profile.go +++ b/config/profile.go @@ -204,6 +204,28 @@ fetching may be degraded. return nil }, }, + "legacy-cid-v0": { + Description: `Makes UnixFS import produce legacy CIDv0 with no raw leaves, sha2-256 and 256 KiB chunks.`, + + Transform: func(c *Config) error { + c.Import.CidVersion = *NewOptionalInteger(0) + c.Import.UnixFSRawLeaves = False + c.Import.UnixFSChunker = *NewOptionalString("size-262144") + c.Import.HashFunction = *NewOptionalString("sha2-256") + return nil + }, + }, + "test-cid-v1": { + Description: `Makes UnixFS import produce modern CIDv1 with raw leaves, sha2-256 and 1 MiB chunks.`, + + Transform: func(c *Config) error { + c.Import.CidVersion = *NewOptionalInteger(1) + c.Import.UnixFSRawLeaves = True + c.Import.UnixFSChunker = *NewOptionalString("size-1048576") + c.Import.HashFunction = *NewOptionalString("sha2-256") + return nil + }, + }, } func getAvailablePort() (port int, err error) { diff --git a/docs/changelogs/v0.29.md b/docs/changelogs/v0.29.md index b82256212a27..5ee18479230a 100644 --- a/docs/changelogs/v0.29.md +++ b/docs/changelogs/v0.29.md @@ -6,6 +6,7 @@ - [Overview](#overview) - [๐Ÿ”ฆ Highlights](#-highlights) + - [Customizing `ipfs add` defaults](#customizing-ipfs-add-defaults) - [๐Ÿ“ Changelog](#-changelog) - [๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributors](#-contributors) @@ -13,9 +14,15 @@ ### ๐Ÿ”ฆ Highlights -#### Global configuration for data ingestion +#### Customizing `ipfs add` defaults -A new configuration section, `Import`, was introduced. This section allows to override the default values of options used across several commands that do data ingestion. Read more in the [config documentation](../config.md). +This release supports overriding global data ingestion defaults used by commands like `ipfs add` via user-defined [`Import.*` configuration options](../config.md#import). +The hash function, CID version, or UnixFS raw leaves and chunker behaviors can be set once, and used as the new implicit default for `ipfs add`. + +> [!TIP] +> As a convenience, two CID [profiles](../config.md#profile) are provided: `legacy-cid-v0` and `test-cid-v1`. +> A test profile that defaults to modern CIDv1 can be applied via `ipfs config profile apply test-cid-v1`. +> We encourage users to try it and report any issues. ### ๐Ÿ“ Changelog diff --git a/docs/config.md b/docs/config.md index 450b40caaf49..130f724d5d29 100644 --- a/docs/config.md +++ b/docs/config.md @@ -270,6 +270,21 @@ documented in `ipfs config profile --help`. Use this profile with caution. +- `legacy-cid-v0` + + Makes UnixFS import (`ipfs add`) produce legacy CIDv0 with no raw leaves, sha2-256 and 256 KiB chunks. + + > [!WARNING] + > This profile is provided for legacy users and should not be used for new projects. + +- `test-cid-v1` + + Makes UnixFS import (`ipfs add`) produce modern CIDv1 with raw leaves, sha2-256 and 1 MiB chunks. + + > [!NOTE] + > This profile will become the new implicit default, provided for testing purposes. + > Follow [kubo#4143](https://github.com/ipfs/kubo/issues/4143) for more details. + ## Types This document refers to the standard JSON types (e.g., `null`, `string`, @@ -2401,7 +2416,7 @@ Type: `optionalInteger` The default UnixFS raw leaves option. Commands affected: `ipfs add`, `ipfs files write`. -Default: `false` +Default: `false` if `CidVersion=0`; `true` if `CidVersion=1` Type: `flag` @@ -2413,7 +2428,6 @@ Default: `size-262144` Type: `optionalString` - ### `Import.HashFunction` The default hash function. Commands affected: `ipfs add`, `ipfs block put`, `ipfs dag put`. diff --git a/test/cli/add_test.go b/test/cli/add_test.go index aa47f7c0b49a..ae652989ab51 100644 --- a/test/cli/add_test.go +++ b/test/cli/add_test.go @@ -95,4 +95,24 @@ func TestAdd(t *testing.T) { cidStr := node.IPFSAddStr(shortString) require.Equal(t, shortStringCidV1NoRawLeaves, cidStr) }) + + t.Run("ipfs init --profile=legacy-cid-v0 sets config that produces legacy CIDv0", func(t *testing.T) { + t.Parallel() + node := harness.NewT(t).NewNode().Init("--profile=legacy-cid-v0") + node.StartDaemon() + defer node.StopDaemon() + + cidStr := node.IPFSAddStr(shortString) + require.Equal(t, shortStringCidV0, cidStr) + }) + + t.Run("ipfs init --profile=test-cid-v1 produces modern CIDv1", func(t *testing.T) { + t.Parallel() + node := harness.NewT(t).NewNode().Init("--profile=test-cid-v1") + node.StartDaemon() + defer node.StopDaemon() + + cidStr := node.IPFSAddStr(shortString) + require.Equal(t, shortStringCidV1, cidStr) + }) }