Per-order terminal reorg linkage
This commit is contained in:
@@ -334,6 +334,14 @@ export class PostgresCustody {
|
||||
await this.update(c, 'orders', o); await this.update(c, 'listings', l);
|
||||
await c.query('INSERT INTO wk_custody.custody_meta VALUES($1,$2)', [`sale-rehearsal-terminal:${o.id}`,
|
||||
JSON.stringify({ version: 1, binding: replay.binding, stateRoot: replay.stateRoot, input: replay.input })]);
|
||||
await c.query('INSERT INTO wk_custody.custody_meta(key,value) VALUES($1,$2)',
|
||||
[`sale-rehearsal-terminal-index:${o.id}`, JSON.stringify({ version: 1,
|
||||
terminalTransactionId: replay.terminalTransactionId ?? null, stateRoot: replay.stateRoot })]);
|
||||
if (replay.terminalTransactionId) {
|
||||
await c.query('INSERT INTO wk_custody.custody_meta(key,value) VALUES($1,$2)',
|
||||
[`sale-rehearsal-tx:${replay.terminalTransactionId}`,
|
||||
JSON.stringify({ version: 1, orderId: o.id, stateRoot: replay.stateRoot })]);
|
||||
}
|
||||
await auditOrder(c, o.id);
|
||||
}
|
||||
return { order: o, action: replay.decision.action, reservationDigest: replay.reservationDigest, stateRoot: replay.stateRoot };
|
||||
@@ -345,7 +353,17 @@ export class PostgresCustody {
|
||||
return this.transaction(true, async c => {
|
||||
check(!this.diagnostics().mutationHold, 'Custody reconciliation hold');
|
||||
check(!(await c.query("SELECT 1 FROM wk_custody.custody_meta WHERE key='integrity_incident_v1'")).rowCount, 'Custody integrity incident unresolved');
|
||||
try { return await ingestCanonicalPage(c, page); }
|
||||
try {
|
||||
const result = await ingestCanonicalPage(c, page);
|
||||
for (const event of result.appendedEvents) {
|
||||
if (event.type !== 'disconnect') continue;
|
||||
for (const txid of event.transactionIds) {
|
||||
const terminal = await c.query('SELECT value FROM wk_custody.custody_meta WHERE key=$1', [`sale-rehearsal-tx:${txid}`]);
|
||||
if (terminal.rowCount) throw new CustodyIntegrityError('posted-sale-terminal-disconnected');
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof CanonicalInboxError) throw new CustodyIntegrityError(`canonical-inbox-${error.code}`);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user