orbitdb / orbitdb

Peer-to-Peer Databases for the Decentralized Web

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with GETTING_STARTED.md LevelBlockstore

Arav-Chheda opened this issue · comments

On the following page: https://github.com/orbitdb/orbitdb/blob/main/docs/GETTING_STARTED.md
the code in the Replicating a database section seems to have an issue (Though I will admit I am very new to this, so I may be making a mistake or be misunderstanding something) The code has the following line:
const blockstore = new LevelBlockstore('./ipfs')
However, this results in a code: 'LEVEL_DATABASE_NOT_OPEN' error due to the fact they are trying to access the db concurrently. It seems that by giving each peer its own Levelblock store directory, the issue is resolved. For example, this was taken from another piece of sample code:
const id = process.argv.length > 2 ? 2 : 1
const blockstore = new LevelBlockstore('./ipfs/${id}')
Replacing the old line with these two new lines seems to resolve the issue. Again, I may be overlooking something on my end that is causing the original bug, but as far as I can tell, each peer should have its own LevelBlockstore directory.

Yes you are correct. Each peer should have its own blockstore otherwise they would be opening the same blockstore.

The Getting Started example should probably be something like:

  const randDir = (Math.random() + 1).toString(36).substring(2)

  const blockstore = new LevelBlockstore('./${randDir}/ipfs')

  const libp2p = await createLibp2p(Libp2pOptions)
  const ipfs = await createHelia({ libp2p, blockstore })

  const orbitdb = await createOrbitDB({ ipfs, directory: `./${randDir}/orbitdb` })

Thanks for pointing out the issue. I'll make an update as soon as time permits.