Closed vmx closed 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.
@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.
What is the purpose of
Block.create()
? Isn't that the same as: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?