Hi Guys,
I've been trying to use orbit-db without success (angular 5 project), not sure why, but persistency is not working and db is not triggering replicateX events.
Here is my code:
import * as IPFS from 'ipfs';
import * as OrbitDB from 'orbit-db';
...
const ipfsOptions = {
start: true,
repo: './test',
EXPERIMENTAL: {
pubsub: true
},
config: {
Addresses: {
Swarm: [
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
]
},
}
};
...
this.ipfs = new IPFS(ipfsOptions);
this.ipfs.on('error', (e) => console.error('IPFS - error', e) );
this.ipfs.on('ready', async () => {
this.orbitdb = new OrbitDB(this.ipfs, './test');
// console.log('orbit - public key', this.orbitdb.key.getPublic('hex') );
const dbConfig = {
replicate: true,
create: true,
sync: true,
localOnly: false,
// type: 'keyvalue',
// Give write access to ourselves
// admin: [this.orbitdb.key.getPublic('hex')],
write: ['*'],
};
this.db = await this.orbitdb.keyvalue('test.user', dbConfig);
/* /////////////////////////////////////////////////// */
// Listen for updates from peers
this.db.events.on('ready', (res) => {
console.log('db ready', res);
console.log('orbitdb - keyvalue', this.db.address.toString(), this.db.get('user'), this.db.get('state') );
this.orbitObserver.next( { dbLoaded: true } );
});
this.db.events.on('synced', (res) => {
console.log('db synced', res);
});
this.db.events.on('load.progress', (address, hash, entry, progress, total) => {
console.log('db - load.progress', progress, total);
});
this.db.events.on('replicated', (address) => {
console.log( 'db - replicated - state', this.db.get('state'), address );
});
this.db.events.on('replicate', (address) => console.log('db - replicate', address ) );
this.db.events.on('replicate.progress', (address) => console.log('db - replicate progress', address) );
this.db.events.on('write', (res) => {
const userValue = this.db.get('user');
const tmpValue = this.db.get('state');
console.log('db write', res, userValue, tmpValue);
});
await this.db.load();
});
The events triggering are ready and write, but the db is always empty after reload the page.
Any help, please?
Thanks, E
Just came back and updated my npm dependencied, and that's what I'm experiencing too.
I can write to a db, and read the values I wrote to it. But if I reload the page and load the db again, all the values are gone.
Current dependencies are:
"orbit-db": "^0.19.3",
"ipfs": "^0.27.7",
Thanks for reporting the issue @eusthace! And welcome back @cristiano-belloni!
This sound weird and should work as expected. Can either of you share the full project where this is happening so that I could take a look? This happens in the browser, right?
Could you run the browser examples and see if you're able to reproduce the problem with that?
I'll still check browser examples but here's a repo with a repro of the problem – although I think I might be doing something wrong.
https://github.com/thiagodelgado111/orbitdb-persistency-reproduce
Looking at the browser example, using docstore
If you create a db and let it write an entry, after a reload, when you open that, it lists no entries.
I guess it has something to do with caching / level.js?
Thank you everyone for looking into this! ❤️I found the bug 👍😄
It is indeed the case in the browsers that the persisted db doesn't load. This was due to an early return in the local cache module (due to API differences between browser leveldb and nodejs leveldb). The good news is, the db does get persisted (as expected), it just wasn't loaded correctly.
This will be fixed with https://github.com/orbitdb/orbit-db/pull/316 and once it's in, I'll publish a new version to npm. Will post here when it's published.
Published to npm as 0.19.4.
Let us know, and re-open the issue, if you're still experiencing problems!
Most helpful comment
Thank you everyone for looking into this! ❤️I found the bug 👍😄
It is indeed the case in the browsers that the persisted db doesn't load. This was due to an early return in the local cache module (due to API differences between browser leveldb and nodejs leveldb). The good news is, the db does get persisted (as expected), it just wasn't loaded correctly.
This will be fixed with https://github.com/orbitdb/orbit-db/pull/316 and once it's in, I'll publish a new version to npm. Will post here when it's published.