From 8b89b50225a4f5abdc247b2f89845f47fb4b138c Mon Sep 17 00:00:00 2001 From: Christophe Diederichs Date: Wed, 27 Nov 2024 16:57:27 +0000 Subject: [PATCH] wakeup add is now async because of user data api --- lib/wakeup.js | 8 ++++---- lib/writer.js | 2 +- package.json | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/wakeup.js b/lib/wakeup.js index b3cd3d66..626a1780 100644 --- a/lib/wakeup.js +++ b/lib/wakeup.js @@ -1,5 +1,6 @@ const b4a = require('b4a') const c = require('compact-encoding') +const safetyCatch = require('safety-catch') const ReadyResource = require('ready-resource') const WakeupEntry = { @@ -143,18 +144,17 @@ module.exports = class AutoWakeup extends ReadyResource { add (core) { if (core.writable || !core.opened) return // no need to track local cores... - return this._add(core) + return this._add(core).catch(safetyCatch) } remove (core) { return this._remove(core) } - _add (core) { - const userData = core.header.userData // unsafe but sync so much less race-condition-ey + async _add (core) { let referrer = null - for (const { key, value } of userData) { + for await (const { key, value } of core.getUserData()) { if (key === 'referrer') referrer = value else if (key === 'autobase/view') return false } diff --git a/lib/writer.js b/lib/writer.js index 035885a8..2a426f61 100644 --- a/lib/writer.js +++ b/lib/writer.js @@ -79,7 +79,7 @@ module.exports = class Writer extends ReadyResource { this.recover = autoRecover(this.core) // add it again incase it wasn't readied before, only needed if this is the first time we set the referrer... - this.base._wakeup.add(this.core.core) + await this.base._wakeup.add(this.core.core) } // in case we are in the middle of a migration we might need to old sigs to reach threshold on the new cores diff --git a/package.json b/package.json index 3c8e6a7b..00b06258 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "core-coupler": "^1.0.0", "debounceify": "^1.0.0", "hyperbee": "^2.15.0", - "hypercore": "github:holepunchto/hypercore#rocksdb-memory-view", + "hypercore": "github:holepunchto/hypercore#rocksdb-user-data", "hypercore-crypto": "^3.4.0", "hypercore-id-encoding": "^1.2.0", "mutexify": "^1.4.0", @@ -50,7 +50,7 @@ "devDependencies": { "autobase-test-helpers": "^2.0.1", "brittle": "^3.1.1", - "corestore": "github:holepunchto/corestore#v7-memory-view", + "corestore": "github:holepunchto/corestore#v7", "rache": "^1.0.0", "random-access-memory": "^6.2.0", "same-data": "^1.0.0",