ipld / js-ipld-stack

EXPERIMENTAL: Next JS IPLD authoring stack
7 stars 3 forks source link

Removing `Block.create()`? #15

Closed vmx closed 5 years ago

vmx commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

@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.