ipfs / helia

An implementation of IPFS in JavaScript
https://helia.io
Other
904 stars 95 forks source link

Restoring pinned data from BlockstoreIDB #172

Open pat721 opened 1 year ago

pat721 commented 1 year ago

Hey everyone,

I'm having issues restoring the stored data using BlockstoreIDB. When creating my node I'm initializing the Blockstore like so:

  let localSafedBlockstore = window.localStorage.getItem("blockstore");

  if (!localSafedBlockstore) {
    localSafedBlockstore = "blockstore-" + window.crypto.randomUUID();
    window.localStorage.setItem("blockstore", localSafedBlockstore);
  }

  const blockstore = new IDBBlockstore(localSafedBlockstore);
  await blockstore.open();

When I look into the IndexedDB in my Browser, everything is created as expected using helia.pins.add(cid). However, when i restart my node, the contents of IDB is not pinned again so others nodes do not know about it. Do I have to repin the data again when restarting the node? Or do I have to intialize the blockstore in a special way when restarting the node?

EDIT: I tried to repin the data when restarting the node but it doesn't change anything.

        for await (const item of helia.blockstore.getAll()) {
          const cid = await fs.addBytes(item.block);
          helia.pins.add(cid);
        }
whizzzkid commented 1 year ago

Thanks for submitting this issue @pat721, can you please share a repo/gist of the complete setup? It would be easier to repro and work with.

I tried to recreate this: https://codesandbox.io/p/sandbox/helia-script-tag-forked-qh4zrr?file=%2Fsrc%2Findex.js%3A151%2C13

And indexedDB creates the entry:

Image

And then tried starting the helia node with the IDBBlockstore and didn't see the pinned content show up.

I feel this is a bug, where helia should populate and publish pins when init with a persistent blockstore.

CC: @achingbrain

pat721 commented 1 year ago

@whizzzkid Thanks for your response. I quickly hacked together an example for recreating the issue https://github.com/pat721/Helia-Test. It uses IDBBlockstore for pinning the content. I was not able to verify yet if this issue with repopulating the pins only occurs on IDBBlockstore or also on the other store implementations.