Skip to content

Commit

Permalink
feat: enable comms starting ID to be configurable in comms vats
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed Feb 25, 2021
1 parent 3645430 commit 6c0b4d8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
9 changes: 7 additions & 2 deletions packages/SwingSet/src/vats/comms/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ import { makeDeliveryKit } from './delivery';

export const debugState = new WeakMap();

export function buildCommsDispatch(syscall) {
const state = makeState();
export function buildCommsDispatch(syscall, _state, _helpers, vatPowers) {
const identifierBase =
(vatPowers &&
vatPowers.vatParameters &&
vatPowers.vatParameters.identifierBase) ||
0;
const state = makeState(identifierBase);
const stateKit = makeStateKit(state);
const clistKit = makeCListKit(state, syscall, stateKit);

Expand Down
7 changes: 4 additions & 3 deletions packages/SwingSet/src/vats/comms/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ export function addRemote(state, name, transmitterID) {
name,
fromRemote,
toRemote,
nextObjectIndex: 20,
nextResolverIndex: 30,
nextPromiseIndex: 40,
nextObjectIndex: state.identifierBase + 20,
nextResolverIndex: state.identifierBase + 30,
nextPromiseIndex: state.identifierBase + 40,
transmitterID,
});
state.identifierBase += 1000;
state.names.set(name, remoteID);

// inbound messages will be directed at this exported object
Expand Down
7 changes: 4 additions & 3 deletions packages/SwingSet/src/vats/comms/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const KERNEL = 'kernel';
// record the new `p+NN` value anywhere. The counter we use for allocation
// will continue on to the next higher NN.

export function makeState() {
export function makeState(identifierBase = 0) {
const state = {
nextRemoteIndex: 1,
remotes: new Map(), // remoteNN -> { remoteID, name, fromRemote/toRemote, etc }
names: new Map(), // name -> remoteNN

// we allocate `o+NN` with this counter
nextObjectIndex: 10,
nextObjectIndex: identifierBase + 10,
remoteReceivers: new Map(), // o+NN -> remoteNN, for admin rx objects
objectTable: new Map(), // o+NN -> owning remote for non-admin objects

Expand All @@ -38,7 +38,8 @@ export function makeState() {
// decider is one of: remoteID, 'kernel', 'comms'
// once resolved, -> { resolved, resolution }
// where resolution takes the form: {rejected, data}
nextPromiseIndex: 20,
nextPromiseIndex: identifierBase + 20,
identifierBase,
};

return state; // mutable
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/test/test-comms.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { addRemote } from '../src/vats/comms/remote';
import { debugState } from '../src/vats/comms/dispatch';

test('provideRemoteForLocal', t => {
const s = makeState();
const s = makeState(0);
const stateKit = makeStateKit(s);
const fakeSyscall = {};
const clistKit = makeCListKit(s, fakeSyscall, stateKit);
Expand Down Expand Up @@ -47,7 +47,7 @@ test('transmit', t => {
// look at machine A, on which some local vat is sending messages to a
// remote 'bob' on machine B
const { syscall, sends } = mockSyscall();
const d = buildCommsDispatch(syscall, 'fakestate', 'fakehelpers');
const d = buildCommsDispatch(syscall, 'fakestate', 'fakehelpers', {});
const { state, clistKit } = debugState.get(d);
const { provideLocalForRemote, getLocalForRemote } = clistKit;
// add the remote, and an object to send at
Expand Down Expand Up @@ -96,7 +96,7 @@ test('receive', t => {
// look at machine B, which is receiving remote messages aimed at a local
// vat's object 'bob'
const { syscall, sends } = mockSyscall();
const d = buildCommsDispatch(syscall, 'fakestate', 'fakehelpers');
const d = buildCommsDispatch(syscall, 'fakestate', 'fakehelpers', {});
const { state, clistKit } = debugState.get(d);
const { provideRemoteForLocal, getRemoteForLocal } = clistKit;
// add the remote, and an object to send at
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/test/test-message-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ test.before(async t => {
a: { bundle: bundleA },
b: { bundle: bundleB },
c: { bundle: bundleC },
commsA: moreComms,
commsB: moreComms,
commsC: moreComms,
commsA: { ...moreComms, parameters: { identifierBase: 100 } },
commsB: { ...moreComms, parameters: { identifierBase: 200 } },
commsC: { ...moreComms, parameters: { identifierBase: 300 } },
vattpA: moreVatTP,
vattpB: moreVatTP,
vattpC: moreVatTP,
Expand Down

0 comments on commit 6c0b4d8

Please sign in to comment.