Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Removing Block.create()? #15

Closed
vmx opened this issue Apr 30, 2019 · 2 comments
Closed

Removing Block.create()? #15

vmx opened this issue Apr 30, 2019 · 2 comments

Comments

@vmx
Copy link
Member

vmx commented Apr 30, 2019

What is the purpose of Block.create()? Isn't that the same as:

Block.decoder(binary, cid.codec, multihash.decode(cid.multihashhash).name)

I think we should always calculate the hash. I see no reason why we should use the supplied CID directly (this feature was intentionally removed from the current API). Creating a block with a not matching CID should be made a hard as possible?

@mikeal
Copy link
Contributor

mikeal commented May 1, 2019

Calculating the hash is expensive so we don’t do it until/unless it is necessary. If you’re pulling the block as a key/value pair out of a storage system you trust you don’t actually want to spend unnecessary cycles calculating the hash. That’s why the validate() function exists, and that’s why the validate function always passes if we haven’t created a CID yet, because we know the hash we create when we eventually encode the data will be correct.

@vmx
Copy link
Member Author

vmx commented May 2, 2019

@mikeal I was too deep into IPLD things, without seeing the full picture. It forgot about the case when you get it from some storage and have the data separate from the CID and just want to combine it.

I'm still not fully convinced we need it, but convinced enough for now to keep and revisit in case it turns out we don't need it.

@vmx vmx closed this as completed May 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants