-
Notifications
You must be signed in to change notification settings - Fork 47
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
refactor: remove invalid string2code mappings #137
Conversation
Codec table was missing dag-json and it had invalid code for dag-cbor. It also had invalid string representation of dag-pb -- it was using 'protobuf' which is a totally different code. I fixed those bugs, and added generic variants for Protobuf, JSON and CBOR, so go-cid finally match the source of truth at https://github.com/multiformats/multicodec/blob/master/table.csv
2022-03-24 conversation:
|
People should use https://github.com/multiformats/go-multicodec instead.
I went with Approach B (Remove mappings). |
Based on multiformats/go-multicodec#65 (comment) I wrote migration guide (will include it in release notes). This is now ready to merge as soon I get some reviews. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM with the understanding that we're okay with the breaking change. An alternative would be to have go-cid import the new go-multicodec, filling the global map at init time - it would avoid breaking users, but longer term it's a worse approach.
If you're breaking users, have you thought about removing the constants and pointing users towards go-multicodec directly? It might be a bit too much in terms of breakage, but if we're already replacing the from/to string APIs, replacing the constants as well would seem consistent.
@mvdan the reason to break users with the maps but not the constants is because the maps are wrong. The most egregious issue is that
Why would you choose to break users when you could just not at trivial cost? We could add Deprecated markers pointing people at go-multicodec though.
With some basic searching:
So breaking the maps seems to cause much less trouble for people than also breaking the constants. |
ACK, I hadn't caught the detail about the bad map entries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. While generally, it'd be nice to see some PRs in the downstream breakages (e.g. go-ipfs) to see how this plays out I suspect it's fine here to merge. This repo doesn't get too many changes so it's fair to assume we won't make more before we deal with the breakages in go-ipfs and related repos and we can figure this out later.
Whether you want to tag now, before we have PRs resolving the breakages in the few effected projects is your call.
note to self: before I merge this, I'll test this in go-ipfs, see how painful refactor is etc |
The mappings in go-cid were maintained by hand and are invalid. More details in ipfs/go-cid#137 This is switching to go-multicodec which has correct mappings that are generated, not written by hand.
|
The mappings in go-cid were maintained by hand and are invalid. More details in ipfs/go-cid#137 This is switching to go-multicodec which has correct mappings that are generated, not written by hand. Co-authored-by: Daniel Martí <mvdan@mvdan.cc>
2022-03-31 conversation: the work isn't blocked, but it won't get merged and released until the libp2p resource manager work for ipfs. |
This is unblocked and ok to merge:
TLDR: if you've found this PR because you need to map CODE to STRING or STRING TO CODE, see usage https://github.com/multiformats/go-multicodec#usage |
Suggested version: Changes in diff --git a/go.mod b/go.mod
index e307ff9..6e3b580 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,17 @@ require (
github.com/multiformats/go-multibase v0.0.3
github.com/multiformats/go-multihash v0.0.15
github.com/multiformats/go-varint v0.0.6
+)
+
+require (
+ github.com/klauspost/cpuid/v2 v2.0.4 // indirect
+ github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
+ github.com/minio/sha256-simd v1.0.0 // indirect
+ github.com/mr-tron/base58 v1.2.0 // indirect
+ github.com/multiformats/go-base32 v0.0.3 // indirect
+ github.com/multiformats/go-base36 v0.1.0 // indirect
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf // indirect
+ golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 // indirect
)
-go 1.15
+go 1.17
|
The mappings in go-cid were maintained by hand and are invalid. More details in ipfs/go-cid#137 This is switching to go-multicodec which has correct mappings that are generated, not written by hand. Co-authored-by: Daniel Martí <mvdan@mvdan.cc>
Problem: string2codec maps are a mess
The current state is not sustainable, string mappings are invalid or missing, and we don't have correct ones for core IPLD formats like
dag-pb
,dag-json
anddag-cbor
🙈Solution: cleanup
Problem 2: cleanup may introduce silent bugs into people's codebases
da55247 demonstrates the map changes we would have to do to restore sanity: fixes mapping, and adds IPLD formats along with non-dag generic variants for Protobuf, JSON and CBOR, so go-cid finally match the source of truth.
This approach would change the meaning of code
0x70
and0x71
and stringscbor
andprotobuf
:protobuf
string now correctly points at code0x50
(was0x70
, which isdag-pb
)0x70
code is mapped todag-pb
(wasprotobuf
before)cbor
string now correctly points at code0x51
(was0x71
, which isdag-cbor
)0x71
code is now mapped todag-cbor
(wascbor
before)Pretty risky – people dont read release notes, this could cause silent errors in people's software.
Also, we have proper code2string mappings in go-multicodec (generated, and not written by hand)
Solution
Remove invalid/redundant string2code mappings from go-ipfs, point ecosystem at using go-multicodec directly.
BREAKING CHANGE
Implemented Approach B: Remove invalid mappings entirely 💚
I applied this in 6ca2617
We already have go-multicodec which is generated from the source of truth.
We remove hardcoded maps, then people will be forced to refactor their code to use go-multicodec (multiformats/go-multicodec#65) – forcing people to refactor makes it less likely they will just blindly bump the dependency without reading release notes.
Refactor guide
Converting code to string and vice versa will no longer be done with go-cid, go-multicodec should be used instead
Old way (go-cid)
New way (go-multicodec)