Skip to content

OrbitDB incompatible with streaming blockstores (js-stores PR #358) #1244

@NiKrause

Description

@NiKrause

Issue: OrbitDB incompatible with streaming blockstores

Description

OrbitDB fails when used with blockstores that return async iterables (streams) instead of Uint8Arrays. This is due to a breaking change introduced in js-stores PR #358 , which allows blockstores to return streams.

Note: This issue commonly manifests when upgrading to libp2p v3, as libp2p v3 uses blockstores that implement the new streaming format. However, the root cause is the blockstore format change, not libp2p v3 itself.

Error

When using blockstores that return async iterables, OrbitDB throws errors like:

  • CBOR decode error: data to decode must be a Uint8Array
  • fns.shift(...) is not a function (in sync.js when using it-pipe)

Root Cause

js-stores PR #358 introduced streaming blockstores where blockstore.get() can return:

  • Uint8Array (traditional)
  • AsyncIterable<Uint8Array> (new streaming format)
  • Promise<Uint8Array | AsyncIterable<Uint8Array>>

OrbitDB currently assumes storage.get() always returns Uint8Array directly or via a Promise, but doesn't handle async iterables.

Affected Code

All places where storage.get() or blockstore.get() is called:

  • src/oplog/oplog-store.js
  • src/storage/ipfs-block.js
  • src/oplog/heads.js
  • src/manifest-store.js
  • src/key-store.js
  • src/identities/identities.js
  • src/access-controllers/ipfs.js
  • src/sync.js

Solution

Create a utility function toUint8Array() that:

  1. Returns Uint8Array as-is
  2. Awaits Promise results and processes them
  3. Collects chunks from AsyncIterable and concatenates to Uint8Array
  4. Handles other buffer-like types

Then update all storage.get() calls to use await toUint8Array(storage.get(...)).

Versions

  • @orbitdb/core: 3.0.2
  • blockstore-core: 6.1.1+ (with streaming support)
  • libp2p: 3.0.2+ (commonly triggers this issue)
  • helia: 6.0.8+

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions