From 099ce9c8f274588739ea11100eb52fb6fbd726a0 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 14 May 2024 02:10:29 +0200 Subject: [PATCH] feat: profiles for legacy-cid-v0 test-cid-v1 --- config/profile.go | 22 ++++++++++++++++++++++ docs/changelogs/v0.29.md | 11 +++++++++-- docs/config.md | 18 ++++++++++++++++-- test/cli/add_test.go | 20 ++++++++++++++++++++ 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/config/profile.go b/config/profile.go index 068498715c5..c73b05af27c 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 1e7779c27d3..632c47b15bb 100644 --- a/docs/changelogs/v0.29.md +++ b/docs/changelogs/v0.29.md @@ -7,6 +7,7 @@ - [Overview](#overview) - [๐Ÿ”ฆ Highlights](#-highlights) - [Add search functionality for pin names](#add-search-functionality-for-pin-names) + - [Customizing `ipfs add` defaults](#customizing-ipfs-add-defaults) - [๐Ÿ“ Changelog](#-changelog) - [๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributors](#-contributors) @@ -18,9 +19,15 @@ It is now possible to search for pins by name. To do so, use `ipfs pin ls --name "SomeName"`. The search is case-sensitive and will return all pins having a name which contains the exact word provided. -#### 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 450b40caaf4..130f724d5d2 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 aa47f7c0b49..ae652989ab5 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) + }) }