OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-proto-peer / bin / resync-did.js

40 lines · javascript ref:
// resync-did — mark a hosted DID for a FRESH-CORESTORE re-join on the next daemon boot.
//
// The heal for a POISONED StateBase autobase local writer: the daemon crash-loops with a native
// SIGABRT in autobase's ApplyState._appendLocalNodes (it re-encodes a malformed on-disk local node
// every boot during drain). A fresh NAMESPACE does not help — autobase's local writer key is derived
// from the Corestore primaryKey (shared across .namespace()), so it re-derives the SAME poisoned writer.
// Only a fresh CORESTORE sheds it (pgv3 #4 / force-resync-participation.test.js).
//
//   bare bin/resync-did.js <did> [--storage <path>]
//
// This BUMPS the DID's gen in <storage>/statebase-resync/index.json. On the next boot bootMultiDevice
// opens that DID's StateBase from a fresh side Corestore (<storage>/statebase-resync/<did16>-r<gen>) — a
// clean local writer that replicates the group's healthy state as a read-only replica, then re-admits
// via the tick loop's ensureAdmitted doorbell (a current indexer addWriters the fresh local key). The
// overlay/membrane/control-keypair stay on the shared store, so the bridge sees no change. Nothing is
// deleted — the old poisoned cores remain on disk.
//
// A poisoned base cannot be live-closed (it aborts on apply), so this is a persisted directive, not a
// live RPC: after running it, RESTART the daemon (`pgh app restart hyper-proto-peer`) to apply.

import '../lib/bare-globals.js'
import { loadConfig } from '../lib/config.js'
import { resyncDid, readResyncIndex } from '../lib/device-node.js'

const argv = globalThis.Bare.argv.slice(2)
const did = argv.find((a) => a.startsWith('did:'))
const sIdx = argv.indexOf('--storage')
const storage = sIdx >= 0 ? argv[sIdx + 1] : loadConfig().storage

if (!did) {
  console.error('usage: bare bin/resync-did.js <did> [--storage <path>]')
  console.error('hosted DIDs currently flagged for resync:', JSON.stringify(readResyncIndex(storage)))
  globalThis.Bare.exit(1)
}

const { gen, sidePath } = resyncDid(storage, did)
console.log(JSON.stringify({ msg: 'resync-did: DID flagged for fresh-corestore re-join on next boot', did, gen, sidePath, storage }))
console.log('RESTART the daemon to apply:  pgh app restart hyper-proto-peer')
globalThis.Bare.exit(0)