Skip to content

Commit

Permalink
fix(swingset): add dummy dispatch.dropExports to liveslots
Browse files Browse the repository at this point in the history
The new `dropExports()` doesn't do anything yet, but at least test that it
can be called directly in liveslots. It should be reachable through all vat
worker types, but I won't be able to test that until we have a kernel
mechanism to provoke it.

closes #2653
  • Loading branch information
warner committed Mar 16, 2021
1 parent c3e81e1 commit a470720
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/SwingSet/docs/vat-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The `Delivery` object is a hardened Array of data (Objects, Arrays, and Strings,

* `['message', targetSlot, msg]`
* `['notify', resolutions]`
* `['dropExports', vrefs]`

In the `message` form, `targetSlot` is a object/promise reference (a string like `o+13` or `p-24`), which identifies the object or promise to which the message is being sent. This target can be a promise if the message is being pipelined to the result of some earlier message.

Expand Down
9 changes: 8 additions & 1 deletion packages/SwingSet/src/kernel/liveSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,13 @@ function build(
}
}

function dropExports(vrefs) {
assert(Array.isArray(vrefs));
vrefs.map(vref => insistVatType('object', vref));
vrefs.map(vref => assert(parseVatSlot(vref).allocatedByVat));
console.log(`-- liveslots ignoring dropExports`);
}

// TODO: when we add notifyForward, guard against cycles

function exitVat(completion) {
Expand Down Expand Up @@ -674,7 +681,7 @@ function build(
slotToVal.set(rootSlot, rootObject);
}

const dispatch = harden({ deliver, notify });
const dispatch = harden({ deliver, notify, dropExports });
return harden({ vatGlobals, setBuildRootObject, dispatch, m });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ function doNotify(resolutions) {
return doProcess(['notify', resolutions], errmsg);
}

function doDropExports(vrefs) {
const errmsg = `vat.doDropExport failed`;
return doProcess(['dropExports', vrefs], errmsg);
}

parentPort.on('message', ([type, ...margs]) => {
workerLog(`received`, type);
if (type === 'start') {
Expand Down Expand Up @@ -143,6 +148,8 @@ parentPort.on('message', ([type, ...margs]) => {
doMessage(...dargs).then(res => sendUplink(['deliverDone', ...res]));
} else if (dtype === 'notify') {
doNotify(...dargs).then(res => sendUplink(['deliverDone', ...res]));
} else if (dtype === 'dropExports') {
doDropExports(...dargs).then(res => sendUplink(['deliverDone', ...res]));
} else {
assert.fail(X`bad delivery type ${dtype}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ function doNotify(resolutions) {
return doProcess(['notify', resolutions], errmsg);
}

function doDropExports(vrefs) {
const errmsg = `vat.doDropExport failed`;
return doProcess(['dropExports', vrefs], errmsg);
}

const toParent = arrayEncoderStream();
toParent
.pipe(netstringEncoderStream())
Expand Down Expand Up @@ -163,6 +168,8 @@ fromParent.on('data', ([type, ...margs]) => {
doMessage(...dargs).then(res => sendUplink(['deliverDone', ...res]));
} else if (dtype === 'notify') {
doNotify(...dargs).then(res => sendUplink(['deliverDone', ...res]));
} else if (dtype === 'dropExports') {
doDropExports(...dargs).then(res => sendUplink(['deliverDone', ...res]));
} else {
assert.fail(X`bad delivery type ${dtype}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ function makeWorker(port) {
return doProcess(['notify', resolutions], errmsg);
}

/** @type { (rs: unknown) => Promise<Tagged> } */
function doDropExports(vrefs) {
const errmsg = `vat.dropExports failed`;
return doProcess(['dropExports', vrefs], errmsg);
}

/**
* TODO: consider other methods per SES VirtualConsole.
* See https://github.com/Agoric/agoric-sdk/issues/2146
Expand Down Expand Up @@ -277,6 +283,8 @@ function makeWorker(port) {
return doMessage(dargs[0], dargs[1]);
case 'notify':
return doNotify(dargs[0]);
case 'dropExports':
return doDropExports(dargs[0]);
default:
assert.fail(X`bad delivery type ${dtype}`);
}
Expand Down
49 changes: 46 additions & 3 deletions packages/SwingSet/test/test-liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ function capargs(args, slots = []) {
return capdata(JSON.stringify(args), slots);
}

function caponeslot(slot) {
return capargs([{ '@qclass': 'slot', index: 0 }], [slot]);
function capdataOneSlot(slot) {
return capargs({ '@qclass': 'slot', iface: 'Alleged: export', index: 0 }, [
slot,
]);
}

function capargsOneSlot(slot) {
return capargs(
[{ '@qclass': 'slot', iface: 'Alleged: export', index: 0 }],
[slot],
);
}

function oneResolution(promiseID, rejected, data) {
Expand Down Expand Up @@ -639,7 +648,7 @@ test('disavow', async t => {
const import1 = 'o-1';

// root~.one(import1) // sendOnly
dispatch.deliver(rootA, 'one', caponeslot(import1), undefined);
dispatch.deliver(rootA, 'one', capargsOneSlot(import1), undefined);
await waitUntilQuiescent();
t.deepEqual(log.shift(), { type: 'dropImports', slots: [import1] });
t.deepEqual(log.shift(), 'disavowed pres1');
Expand Down Expand Up @@ -672,3 +681,37 @@ test('disavow', async t => {
t.deepEqual(log.shift(), 'tried to send to disavowed');
t.deepEqual(log, []);
});

test('dropExports', async t => {
const { log, syscall } = buildSyscall();

function build(_vatPowers) {
const ex1 = Far('export', {});
const root = Far('root', {
one() {
return ex1;
},
});
return root;
}
const dispatch = makeDispatch(syscall, build, true);
t.deepEqual(log, []);
const rootA = 'o+0';

// rp1 = root~.one()
// ex1 = await rp1
const rp1 = 'p-1';
dispatch.deliver(rootA, 'one', capargs([]), rp1);
await waitUntilQuiescent();
const l1 = log.shift();
const ex1 = l1.resolutions[0][2].slots[0];
t.deepEqual(l1, {
type: 'resolve',
resolutions: [[rp1, false, capdataOneSlot(ex1)]],
});
t.deepEqual(log, []);

// now tell the vat to drop that export
dispatch.dropExports([ex1]);
// for now, all that we care about is that liveslots doesn't crash
});

0 comments on commit a470720

Please sign in to comment.