| … | … | @@ -203,8 +203,16 @@ function revTime (rev) { |
| 203 | 203 | // behavioural change and be verified in place before anything is removed. |
| 204 | 204 | export async function serveMembrane (device, { corestore, swarm, did, handle, sessions = null, blobs = null, projectRepoCore = true } = {}) { |
| 205 | 205 | if (!corestore || !swarm || !did) throw new Error('serveMembrane: corestore, swarm, did required') |
| 206 | // Step markers. This function is `await`ed during a DID's boot, so anything slow here stalls the whole |
| 207 | // node — and on a phone it stalled with NO output at all, leaving "somewhere inside serveMembrane" as |
| 208 | // the entire diagnosis. Each step is cheap and local on a workstation; the point is that when one is |
| 209 | // not, the log says WHICH. Timed, because "slow" and "wedged" look identical from outside. |
| 210 | const t0 = Date.now() |
| 211 | const step = (msg) => { try { console.log(JSON.stringify({ msg: 'membrane: ' + msg, did, ms: Date.now() - t0 })) } catch {} } |
| 206 | 212 | const repo = projectRepoCore ? await new RepoStore(corestore, { name: 'membrane-repo:' + did }).ready() : null |
| 213 | step(projectRepoCore ? 'repo core ready' : 'repo core SKIPPED (virtual device)') |
| 207 | 214 | const seq = await new FirehoseSequencer(corestore.get({ name: 'membrane-firehose:' + did })).ready() |
| 215 | step('firehose sequencer ready') |
| 208 | 216 | // Project ONLY when the device's __commit__ log has advanced past what the membrane firehose already |
| 209 | 217 | // holds. WITHOUT this gate, the caller's sign loop (every signIntervalMs, ~2s) called sync() |
| 210 | 218 | // UNCONDITIONALLY, and projectRepo re-put ALL records into the APPEND-ONLY Hyperbee repo core on EVERY |
| … | … | @@ -399,6 +407,7 @@ export async function serveMembrane (device, { corestore, swarm, did, handle, se |
| 399 | 407 | // Both sides must be client:true to punch simultaneously (see peer.js:serve for the full why). |
| 400 | 408 | const dKey = swarm.join(swarm.keyPair.publicKey, { server: true, client: true }) |
| 401 | 409 | const dDid = swarm.join(discoveryTopic(did), { server: true, client: true }) |
| 410 | step('topics joined — serveMembrane returning (the announce flush is the CALLER\'s to await)') |
| 402 | 411 | return { |
| 403 | 412 | repo, seq, serverKey, repoKey, firehoseKey, sync, |
| 404 | 413 | ready: () => Promise.all([dKey.flushed(), dDid.flushed()]), |