Skip to content
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

feat: make blockstore identity-hash compatible #297

Merged
merged 4 commits into from
Apr 14, 2021

Conversation

hannahhoward
Copy link
Contributor

@hannahhoward hannahhoward commented Apr 7, 2021

Goals

Make the blockstore properly return blocks for "identity" CIDs (CID's where the multihash algorithm is "identity", meaning the contents of the hash are the actual data for the block, and there is no other data associated with the CID).

Implementation

  • Separate out typing for the blockstore interface
  • Implement idstore based on https://github.com/ipfs/go-ipfs-blockstore/blob/master/idstore.go - this leaves the original blockstore implementation unchanged but adds a composable layer applied on top to add compatibility with identity hashes (served as the same blockstore interface)
  • add idstore in construction of repo.blocks
  • fix minor compatibility issues with just-safe-get and just-safe-set by fixing to patch release for now

For discussion

I based implementation for delete and put operations on the go versions, which essentially treats a put or delete for an identity hash as a no-op. However, the golang version does not return the block itself for puts, and I wasn't sure whether I should be doing that. For now, I've made it so the identity block is included in the results of puts.

Since I extracted Blockstore typings to an interface, to save writing them twice for blockstore and idstore and insure they both return the exact same types, I removed the JSDoc comments on blockstore. I wasn't sure though if that affects what shows up in JSDocs. (I did put the type on the return value for createBaseStore)

fix ipfs/js-ipfs#3289

@achingbrain achingbrain changed the title Make blockstore identity-hash compatible feat: make blockstore identity-hash compatible Apr 7, 2021
package.json Outdated
"it-map": "^1.0.2",
"it-pushable": "^1.4.0",
"just-safe-get": "^2.0.0",
"just-safe-set": "^2.1.0",
"just-safe-get": "~2.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the error that meant this needed to change from ^ to ~?

src/idstore.js Outdated
* @param {Blockstore} blockstore
*/
module.exports = (blockstore) => {
return createIdStore(blockstore)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just export the createIdStore function?

@achingbrain
Copy link
Member

Nice work, thanks for submitting this.

To land this could you please open a PR against js-ipfs that depends on this PR as a gh dep and add tests for identity CIDs to the interface-ipfs-core suite? At least for dag.get and block.get but anywhere these code paths will be executed.
This will make sure it's tested against core, over http and that it behaves in the same way as go-IPFS (over http).

There's an overview of how to run the tests here: https://github.com/ipfs/js-ipfs/blob/master/docs/DEVELOPMENT.md#run-tests

reset dependencies and make corrections, respond to PR comments
@hannahhoward
Copy link
Contributor Author

@achingbrain I've responded to PR comments and reset the dependencies, resolving the breaking change in the latest just-safe-get / just-safe-set by fixing our calls to match the newly added types. A PR with tests to js-ipfs is incoming.

@hannahhoward
Copy link
Contributor Author

PR for js-ipfs to demonstrate fix: ipfs/js-ipfs#3616

do not use concrete type for block in the interface definition
@achingbrain achingbrain merged commit bbcdb12 into ipfs:master Apr 14, 2021
achingbrain added a commit to ipfs/js-ipfs that referenced this pull request Apr 28, 2021
- Adds support for identity hashes in ipfs-repo blockstore
- Add core interface tests for block.get and dag.get when fetching identity hashes

Refs: ipfs/js-ipfs-repo#297
Closes:  #3289

Co-authored-by: Alex Potsides <alex@achingbrain.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Support identity CIDs
2 participants