Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(swingset): check promise resolution table during comms.inbound #1405

Merged
merged 3 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion packages/SwingSet/src/vats/comms/inbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@ import {
markPromiseAsResolved,
} from './state';

function getInboundFor(state, remoteID, remoteTarget) {
const target = getInbound(state, remoteID, remoteTarget);
// That might point to o-NN or a promise. Check if the promise was resolved
// already.
if (state.promiseTable.has(target)) {
const p = state.promiseTable.get(target);
if (p.state === 'unresolved') {
return target;
}
if (p.state === 'resolved') {
if (p.resolution.type === 'object') {
return p.resolution.slot;
}
if (p.resolution.type === 'data') {
throw Error(`todo: error for fulfilledToData`);
}
if (p.resolution.type === 'reject') {
throw Error(`todo: error for rejected`);
}
throw Error(`unknown res type ${p.resolution.type}`);
}
throw Error(`unknown p.state ${p.state}`);
}
return target;
}

export function deliverFromRemote(syscall, state, remoteID, message) {
const command = message.split(':', 1)[0];

Expand All @@ -21,7 +47,7 @@ export function deliverFromRemote(syscall, state, remoteID, message) {
.split(':')
.slice(1);
// slots: [$target, $method, $result, $slots..]
const target = getInbound(state, remoteID, slots[0]);
const target = getInboundFor(state, remoteID, slots[0]);
const method = slots[1];
const result = slots[2]; // 'rp-NN' or empty string
const msgSlots = slots.slice(3).map(s => mapInbound(state, remoteID, s));
Expand Down
22 changes: 22 additions & 0 deletions packages/SwingSet/test/message-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { E } from '@agoric/eventual-send';
import { makePromiseKit } from '@agoric/promise-kit';
import { ignore } from './util';

// Exercise a set of increasingly complex object-capability message patterns,
// for testing.
Expand Down Expand Up @@ -516,6 +517,27 @@ export function buildPatterns(log) {
];
test('a72');

// Exercise bug #1400. We set up two messages:
// pipe1 = bob~.one()
// pipe1~.two()
// but their handling must meet two ordering constraints:
// 1: left-comms transmits two() before learning about pipe1 resolving
// 2: right-comms receives two() *after* learning about pipe1 resolving
// to achieve this, we changed loopbox() to deliver one message at a time
{
objA.a73 = async () => {
const pipe1 = E(b.bob).b73_one();
const p2 = E(pipe1).two();
ignore(p2);
};
objB.b73_one = () =>
harden({
two: () => log('two'),
});
}
out.a73 = ['two'];
test('a73');

return harden({
setA,
setB,
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/test-message-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function runVatsInComms(t, enablePipelining, name) {
config.vats.leftvattp = { sourcePath: vatTPSourcePath };
config.vats.rightvattp = { sourcePath: vatTPSourcePath };
const { passOneMessage, loopboxSrcPath, loopboxEndowments } = buildLoopbox(
'immediate',
'queued',
);
config.devices = [['loopbox', loopboxSrcPath, loopboxEndowments]];
const c = await buildVatController(config, [name]);
Expand Down
7 changes: 7 additions & 0 deletions packages/SwingSet/test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ export function buildDispatch(onDispatchCallback = undefined) {

return { log, dispatch };
}

export function ignore(p) {
p.then(
() => 0,
() => 0,
);
}