File size: 1,478 Bytes
d739b1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 | // 승인 grant에 원본이 보존된 마지막 유령 행 하나만 현재 writer transaction에서 제외할 수 있다.
// 설명 문서: docs/specs/batch-loop-ghost.md v1.1.0, docs/specs/batch-loop-first.md v1.0.0
const{hash}=require('../services/bong-browser-resolution'),{same}=require('./batch-recovery-record'),ghost=require('../services/batch-loop-ghost');
function verifyRemoval(db,runId,grantId,verify){
const c=db.getBatchCheckpoint(runId),g=Object.values(c?.recoveries||{}).at(-1),d=g?.loopState,row=db.getBatchRun(runId),{usage:_,...raw}=row||{};
const first=require('../services/batch-loop-first');
if(!c||c.revocations||!g||g.id!==grantId||c.revision!==g.checkpointRevision+1||!['unstarted_iteration','unstarted_first_iteration'].includes(d?.reconciliation?.kind)||!same(raw,{...g.originalRun,status:'paused',error_message:null,completed_at:null})||typeof verify!=='function')ghost.fail();
const actual={run:db.getLoopRun(d.originalRun.run_id),iterations:db.getLoopIterations(d.originalRun.run_id)},event=first.source(c,d);require('../services/batch-recovery-proof').prefixes({checkpoint:c,usage:db.getRuntimeUsage(runId)});if(first.isFirst(d))first.validate(c,g);else ghost.validate(d.reconciliation,event);
if(hash(actual)!==d.rowsHash||actual.iterations.at(-1)?.id!==d.reconciliation.ghostId||hash(actual.iterations.at(-1))!==d.reconciliation.ghostHash||verify(g)!==true)ghost.fail();
return d.reconciliation.ghostId;
}
module.exports={verifyRemoval};
|