Skip to content

Commit

Permalink
feat: profiles for legacy-cid-v0 test-cid-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed May 14, 2024
1 parent cc2ccd0 commit 564b7ac
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
22 changes: 22 additions & 0 deletions config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions docs/changelogs/v0.29.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,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 iadd` 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 test it and report any issues.
### 📝 Changelog

Expand Down
18 changes: 16 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down Expand Up @@ -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`

Expand All @@ -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`.
Expand Down
20 changes: 20 additions & 0 deletions test/cli/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit 564b7ac

Please sign in to comment.