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
fix!: replace dag walkers with generic CID extraction from blocks #447
base: main
Are you sure you want to change the base?
Conversation
Replace the codec-specific `.dagWalkers` property with a generic dag walker internally that uses the `Block` interface from the `multicodecs` module. - Removes the `.dagWalkers` property from the Helia interface - Adds `getCodec` and `getHasher` to retrieve codecs and hashers by code - Adds `loadCodec` and `loadHasher` options to allow sync or async loading of extra codecs/hashes in addition to staticlly configured ones in the `codecs`/`hashers` keys BREAKING CHANGE: the `.dagWalkers` property has been removed
I think the pinning benchmarks should be re-run with this PR before merging. The This could potentially be more expensive than deserializing a block, collecting |
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.
a few things that could be changed, not sure if the networked-storage accepting an additional arg was done explicitly for some reason though
|
||
await withBlock(cid, block) | ||
const block = createUnsafe({ bytes, cid, codec }) |
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.
what's the implication of using createUnsafe
? I'm not sure I understand how this change affects things. And https://github.com/multiformats/js-multiformats/blob/5e2159a5126f15f2e16032b29a8bb5e31e619160/src/block.ts#L197 doesn't have much information
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.
We need a Block
instance to call .links()
on it.
createUnsafe
doesn't verify that the block hash matches the block data, which is a (potentially) expensive operation, it just creates the block.
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.
For the sake of verified-fetch, where do we verify the block hash matches the data after the changes in this PR?
|
||
await addChildren(subChild, name, level + 1, index + i, depth - 1, children, dag, codec, blocks) | ||
links.push( | ||
await createAndPutBlock(dagCbor.code, dagCbor.encode(child), blocks) |
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.
I know this is just a test fixture, but do we want to remove the ability to use any codec?
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.
The problem is creating a layered DAG depends on the codec - different codecs will implement this in different ways.
Previously we were only ever using one codec so it was a bit misleading.
9bb948d
to
c31f5e1
Compare
Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
Replace the codec-specific
.dagWalkers
property with a generic dag walker internally that uses theBlock
interface from themulticodecs
module..dagWalkers
property from the Helia interfacegetCodec
andgetHasher
to retrieve codecs and hashers by codeloadCodec
andloadHasher
options to allow sync or async loading of extra codecs/hashes in addition to staticlly configured ones in thecodecs
/hashers
keysBREAKING CHANGE: the
.dagWalkers
property has been removedChange checklist