Skip to content

Commit

Permalink
fix: Recipient-side resolved promise retirement
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed May 18, 2020
1 parent 7461007 commit dc0aec9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/SwingSet/src/kernel/liveSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,14 @@ function build(syscall, _state, makeRoot, forVatID) {
};
}

function retirePromiseID(promiseID) {
lsdebug(`Retiring ${forVatID}:${promiseID}`);
importedPromisesByPromiseID.delete(promiseID);
const p = slotToVal.get(promiseID);
valToSlot.delete(p);
slotToVal.delete(promiseID);
}

function notifyFulfillToData(promiseID, data) {
insistCapData(data);
lsdebug(
Expand All @@ -463,6 +471,7 @@ function build(syscall, _state, makeRoot, forVatID) {
const pRec = importedPromisesByPromiseID.get(promiseID);
const val = m.unserialize(data);
pRec.resolve(val);
retirePromiseID(promiseID);
}

function notifyFulfillToPresence(promiseID, slot) {
Expand All @@ -478,6 +487,7 @@ function build(syscall, _state, makeRoot, forVatID) {
// val is either a local pass-by-presence object, or a Presence (which
// points at some remote pass-by-presence object).
pRec.resolve(val);
retirePromiseID(promiseID);
}

// TODO: when we add notifyForward, guard against cycles
Expand All @@ -495,6 +505,7 @@ function build(syscall, _state, makeRoot, forVatID) {
const pRec = importedPromisesByPromiseID.get(promiseID);
const val = m.unserialize(data);
pRec.reject(val);
retirePromiseID(promiseID);
}

// here we finally invoke the vat code, and get back the root object
Expand Down
15 changes: 15 additions & 0 deletions packages/SwingSet/src/kernel/state/vatKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ export function makeVatKeeper(
return storage.get(kernelKey);
}

/**
* Remove an entry from the vat's c-list.
*
* @param kernelSlot The kernel slot being removed
* @param vatSlot The vat slot being removed
*/
function deleteCListEntry(kernelSlot, vatSlot) {
const kernelKey = `${vatID}.c.${kernelSlot}`;
const vatKey = `${vatID}.c.${vatSlot}`;
kdebug(`Delete mapping ${kernelKey}<=>${vatKey}`);
storage.delete(kernelKey);
storage.delete(vatKey);
}

/**
* Generator function to return the vat's transcript, one entry at a time.
*/
Expand Down Expand Up @@ -198,6 +212,7 @@ export function makeVatKeeper(
return harden({
mapVatSlotToKernelSlot,
mapKernelSlotToVatSlot,
deleteCListEntry,
getTranscript,
addToTranscript,
vatStats,
Expand Down
3 changes: 3 additions & 0 deletions packages/SwingSet/src/kernel/vatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export default function makeVatManager(
['notifyFulfillToPresence', vpid, slot],
`vat[${vatID}].promise[${vpid}] fulfillToPresence failed`,
);
vatKeeper.deleteCListEntry(kpid, vpid);
} else if (kp.state === 'redirected') {
throw new Error('not implemented yet');
} else if (kp.state === 'fulfilledToData') {
Expand All @@ -386,6 +387,7 @@ export default function makeVatManager(
['notifyFulfillToData', vpid, vatData],
`vat[${vatID}].promise[${vpid}] fulfillToData failed`,
);
vatKeeper.deleteCListEntry(kpid, vpid);
} else if (kp.state === 'rejected') {
const vpid = mapKernelSlotToVatSlot(kpid);
const vatData = harden({
Expand All @@ -396,6 +398,7 @@ export default function makeVatManager(
['notifyReject', vpid, vatData],
`vat[${vatID}].promise[${vpid}] reject failed`,
);
vatKeeper.deleteCListEntry(kpid, vpid);
} else {
throw new Error(`unknown kernelPromise state '${kp.state}'`);
}
Expand Down

0 comments on commit dc0aec9

Please sign in to comment.