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:
- Returns
Uint8Array as-is
- Awaits
Promise results and processes them
- Collects chunks from
AsyncIterable and concatenates to Uint8Array
- 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
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 Uint8Arrayfns.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 returnsUint8Arraydirectly or via a Promise, but doesn't handle async iterables.Affected Code
All places where
storage.get()orblockstore.get()is called:src/oplog/oplog-store.jssrc/storage/ipfs-block.jssrc/oplog/heads.jssrc/manifest-store.jssrc/key-store.jssrc/identities/identities.jssrc/access-controllers/ipfs.jssrc/sync.jsSolution
Create a utility function
toUint8Array()that:Uint8Arrayas-isPromiseresults and processes themAsyncIterableand concatenates toUint8ArrayThen update all
storage.get()calls to useawait toUint8Array(storage.get(...)).Versions
@orbitdb/core:3.0.2blockstore-core:6.1.1+(with streaming support)libp2p:3.0.2+(commonly triggers this issue)helia:6.0.8+Related