This commit is contained in:
Raven Scott
2026-05-27 19:47:06 -04:00
parent c8334a8d63
commit 54cbee254d
4 changed files with 84 additions and 65 deletions
+3 -10
View File
@@ -4,7 +4,7 @@ const { logDebug, logError, logInfo, logWarn } = require('../infrastructure/logg
const { trackDomainEvent, trackConsensusEvent } = require('../maintenance/metrics');
const { validateConfig } = require('../infrastructure/config');
const { secondsToMs, getPersistentPublicKey } = require('../infrastructure/utils');
const { dnsPassAdd, dnsPassRemove, dnsPassGet, whenDnsPassIdle } = require('./dns-pass-queue');
const { dnsPassAdd, dnsPassRemove, dnsPassGet, listAllEntries } = require('./dns-pass-queue');
// Get consensus configuration
let consensusConfig = null;
@@ -93,16 +93,9 @@ async function getAllEntries(pass = state.dnsPass, useCache = true) {
return entriesCache || [];
}
const entries = [];
let entries = [];
try {
await whenDnsPassIdle();
const stream = pass.list();
for await (const entry of stream) {
entries.push({
key: entry.key.toString('utf8'),
value: entry.value.toString('utf8')
});
}
entries = await listAllEntries(pass);
// Update cache
entriesCache = entries;
entriesCacheTimestamp = now;
+26 -7
View File
@@ -1,13 +1,13 @@
/**
* Serializes Autopass / Autobase operations on the master corestore.
* Concurrent createInvite, list(), add(), and remove() calls cause
* Serializes all Autopass / Autobase operations on the master corestore.
* Concurrent list(), createInvite(), add(), and remove() cause
* "Atomic state must flush to parent" on Hypercore 11.
*/
let chain = Promise.resolve();
function enqueueDnsPass(operation) {
const run = chain.then(() => operation());
const run = chain.then(() => Promise.resolve().then(operation));
chain = run.then(
() => {},
() => {}
@@ -15,7 +15,7 @@ function enqueueDnsPass(operation) {
return run;
}
/** Wait until queued dnsPass work finishes (for reads). */
/** @deprecated Use enqueueDnsPass; kept for compatibility */
function whenDnsPassIdle() {
return chain;
}
@@ -33,8 +33,26 @@ async function dnsPassRemove(pass, key) {
}
async function dnsPassGet(pass, key) {
await whenDnsPassIdle();
return pass.get(key);
return enqueueDnsPass(() => pass.get(key));
}
/**
* List all Autopass records (serialized with other dnsPass ops).
* @param {object} pass - Autopass instance
* @returns {Promise<Array<{key: string, value: string}>>}
*/
async function listAllEntries(pass) {
return enqueueDnsPass(async () => {
const entries = [];
const stream = pass.list();
for await (const entry of stream) {
entries.push({
key: entry.key.toString('utf8'),
value: entry.value.toString('utf8')
});
}
return entries;
});
}
module.exports = {
@@ -43,5 +61,6 @@ module.exports = {
createInvite,
dnsPassAdd,
dnsPassRemove,
dnsPassGet
dnsPassGet,
listAllEntries
};