Integrate with the new go-ipld-format decoder framework#14
Integrate with the new go-ipld-format decoder framework#14whyrusleeping merged 3 commits intoipfs:masterfrom
Conversation
3388947 to
4b04798
Compare
(and update dependencies)
Also, pre-compute the CID. We're probably going to need it anyways. The alternatives are: 1. Compute it every time we need it (slow). 2. Cache it when we first compute it (requires synchronization for thread safety).
4b04798 to
e0e7215
Compare
|
Ah, this breaks our tests that assert cbor values get normalized to their canonical values when you decode a block from them. @Stebalien what do you think? |
|
Here is a test case that reproduces this https://gist.github.com/magik6k/5b1b30087914ebaf0ccc7d0cb91c2d67 Based on https://github.com/ipfs/go-ipfs/blob/master/test/sharness/t0053-dag.sh#L115 |
|
IMO, it's more important to avoid changing the CID than to normalize. I'd remove the tests (but I'm probably missing prior discussion on this topic). |
|
We can either normalize, or throw an error. Otherwise we can have two objects that are equivalent by value comparison, but have different 'hashes', which is an issue. |
|
My primary concern is that However, looking back at this commit, I believe the problem is that However, once something has a CID, I think we either need to keep it as-is or throw an error. I'm all for strict validation that fails early but I'm worried that if we always re-encode before generating the CID, we'll never be able to upgrade our CBOR library (also, efficiency). As an aside, IMO, all comparison of blocks/nodes should compare CIDs and only CIDs. |
Agreed with this, i think any place where we take in raw data (not a block) should do normalization validation. |
Although remember, we may be taking in raw data through a user interface where the user will want us to normalize, not validate (e.g., JSON). Your comment on IRC about having a strict mode versus a non-strict mode is on-point. |
Also, pre-compute the CID. We're probably going to need it anyways. The alternatives are: