OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git-v3 / scripts / inspect-store.mjs

76 lines · javascript ref:
#!/usr/bin/env node
/**
 * Read-only inspect: open the corrupt-20260421 store, find the identity
 * autobase root core (key f10b54d2bb59...), report its length.
 *
 * If length >> 1, the corrupt store has the pre-corruption history that
 * stortron cached, confirming the fork hypothesis and pointing at the
 * fix (restore-from-aside).
 */
import Corestore from 'corestore'
import b4a from 'b4a'

const STORE = process.argv[2] || '/home/fleeky/pgv3-storage/store.corrupt-20260421'
const ROOT_HEX = 'f10b54d2bb59896559d3d4f8' // prefix of identity autobase root from earlier RPC

async function main () {
  console.log('opening', STORE, '(read-only)')
  const store = new Corestore(STORE, { readonly: true })
  await store.ready()
  console.log('store opened')

  // We don't have the full key, only first 24 chars. Need to enumerate
  // cores or use the namespace pattern. The identity autobase root
  // is from pear-git.js: corestore.namespace('identity'), so we can try
  // opening by namespace + name 'local' or via the bootstrap key.

  // Approach: open by full key. The hex prefix is f10b54d2bb59896559d3d4f8
  // — we need the FULL 64-char key. Get it from the running tabertron
  // daemon via dump-mirror-writers (already have it as identity-key).
  // For now, list all opened cores in the store after touching the
  // identity namespace.
  const ns = store.namespace('identity')
  const local = ns.get({ name: 'local' })
  await local.ready()
  console.log('identity namespace local core:')
  console.log('  key:', b4a.toString(local.key, 'hex'))
  console.log('  length:', local.length)
  console.log('  writable:', local.writable)
  console.log('  fork:', local.fork)
  await local.close()

  // Also try opening the bootstrap-key core (tabertron's hyperident pubkey)
  const HYPERIDENT_PUBKEY = 'b74708cb1fda118ff3e218d32f12ad4404509365d48910448c8a0e675d063c17'
  const root = store.get({ key: b4a.from(HYPERIDENT_PUBKEY, 'hex') })
  await root.ready()
  console.log('hyperident root core (by pubkey):')
  console.log('  key:', b4a.toString(root.key, 'hex'))
  console.log('  length:', root.length)
  console.log('  writable:', root.writable)
  console.log('  fork:', root.fork)
  await root.close()

  // List ALL cores in this corestore
  console.log('--- listing all cores ---')
  let count = 0
  try {
    for await (const c of store.list()) {
      const core = store.get({ key: c.key })
      await core.ready()
      console.log('  key=' + b4a.toString(c.key,'hex').slice(0,16) + ' length=' + core.length + ' fork=' + core.fork)
      await core.close()
      if (++count >= 30) { console.log('  (truncated at 30)'); break }
    }
  } catch (err) {
    console.log('  list err:', err.message)
  }
  console.log('  (total cores listed: ' + count + ')')

  await store.close()
}

main().catch(err => {
  console.error('error:', err.message)
  process.exit(1)
})