Skip to content

Commit

Permalink
fix(cosmic-swingset): apply Far/Data as necessary (#2567)
Browse files Browse the repository at this point in the history
Annotate cosmic-swingset objects with Far or Data. We didn't try to mark everything. Instead, we marked everything we could easily find and which seemed like it was important to mark (ambiguous empty objects). Also, we changed `store` to reject empty pass-by-copy objects as keys, and we marked enough empty objects to survive that check, which ought to be enough for the immediate goal (changing `{}` to be pass-by-copy). We'll defer the other half of #2018 (requiring Far on all pass-by-reference objects) for later.

refs #2018
  • Loading branch information
warner authored Mar 11, 2021
1 parent 3c9f42a commit 92b63b6
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 38 deletions.
23 changes: 12 additions & 11 deletions packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
makeEchoConnectionHandler,
} from '@agoric/swingset-vat/src/vats/network';
import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';

// this will return { undefined } until `ag-solo set-gci-ingress`
// has been run to update gci.js
Expand All @@ -24,7 +25,7 @@ const PROVISIONER_INDEX = 1;

function makeVattpFrom(vats) {
const { vattp, comms } = vats;
return harden({
return Far('vattp', {
makeNetworkHost(allegedName, console = undefined) {
return E(vattp).makeNetworkHost(allegedName, comms, console);
},
Expand Down Expand Up @@ -205,7 +206,7 @@ export function buildRootObject(vatPowers, vatParameters) {
}),
);

return harden({
return Far('chainBundler', {
async createUserBundle(_nickname, powerFlags = []) {
// Bind to some fresh ports (unspecified name) on the IBC implementation
// and provide them for the user to have.
Expand Down Expand Up @@ -238,12 +239,12 @@ export function buildRootObject(vatPowers, vatParameters) {
pursePetname: issuerNameToRecord.get(issuerName).pursePetname,
}));

const faucet = {
const faucet = Far('faucet', {
// A method to reap the spoils of our on-chain provisioning.
async tapFaucet() {
return paymentInfo;
},
};
});

const bundle = harden({
...additionalPowers,
Expand Down Expand Up @@ -275,7 +276,7 @@ export function buildRootObject(vatPowers, vatParameters) {
);
if (bridgeMgr) {
// We have access to the bridge, and therefore IBC.
const callbacks = harden({
const callbacks = Far('callbacks', {
downcall(method, obj) {
return bridgeMgr.toBridge('dibc', {
...obj,
Expand Down Expand Up @@ -304,7 +305,7 @@ export function buildRootObject(vatPowers, vatParameters) {
// Add an echo listener on our ibc-port network.
const port = await E(vats.network).bind('/ibc-port/echo');
E(port).addListener(
harden({
Far('listener', {
async onAccept(_port, _localAddr, _remoteAddr, _listenHandler) {
return harden(makeEchoConnectionHandler());
},
Expand All @@ -314,7 +315,7 @@ export function buildRootObject(vatPowers, vatParameters) {

if (bridgeMgr) {
// Register a provisioning handler over the bridge.
const handler = harden({
const handler = Far('provisioningHandler', {
async fromBridge(_srcID, obj) {
switch (obj.type) {
case 'PLEASE_PROVISION': {
Expand Down Expand Up @@ -355,7 +356,7 @@ export function buildRootObject(vatPowers, vatParameters) {
}

// This will allow dApp developers to register in their api/deploy.js
const httpRegCallback = {
const httpRegCallback = Far('httpRegCallback', {
doneLoading(subsystems) {
return E(vats.http).doneLoading(subsystems);
},
Expand All @@ -378,7 +379,7 @@ export function buildRootObject(vatPowers, vatParameters) {
E(vats.http).setWallet(wallet),
]);
},
};
});

return allComparable(
harden({
Expand All @@ -395,7 +396,7 @@ export function buildRootObject(vatPowers, vatParameters) {
);
}

return harden({
return Far('root', {
async bootstrap(vats, devices) {
const bridgeManager =
devices.bridge && makeBridgeManager(E, D, devices.bridge);
Expand Down Expand Up @@ -494,7 +495,7 @@ export function buildRootObject(vatPowers, vatParameters) {
// Allow some hardcoded client address connections into the chain.
// This is necessary for fake-chain, which does not have Cosmos SDK
// transactions to provision its client.
const demoProvider = harden({
const demoProvider = Far('demoProvider', {
// build a chain-side bundle for a client.
async getDemoBundle(nickname) {
if (giveMeAllTheAgoricPowers) {
Expand Down
5 changes: 3 additions & 2 deletions packages/cosmic-swingset/lib/ag-solo/vats/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import makeStore from '@agoric/store';
import '@agoric/store/exported';
import { assert, details as X } from '@agoric/assert';
import { Far } from '@agoric/marshal';

/**
* @template T
Expand Down Expand Up @@ -53,7 +54,7 @@ export function makeBridgeManager(E, D, bridgeDevice) {
// No return value.
}

const bridgeHandler = harden({ inbound: bridgeInbound });
const bridgeHandler = Far('bridgeHandler', { inbound: bridgeInbound });

function callOutbound(dstID, obj) {
assert(bridgeDevice, X`bridge device not yet connected`);
Expand All @@ -70,7 +71,7 @@ export function makeBridgeManager(E, D, bridgeDevice) {
// We now manage the device.
D(bridgeDevice).registerInboundHandler(bridgeHandler);

return harden({
return Far('bridgeManager', {
toBridge(dstID, obj) {
return callOutbound(dstID, obj);
},
Expand Down
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// in its own makeHardener, etc.
import { makeCapTP } from '@agoric/captp/lib/captp';
import { E } from '@agoric/eventual-send';
import { Data } from '@agoric/marshal';

export const getCapTPHandler = (
send,
Expand All @@ -11,7 +12,7 @@ export const getCapTPHandler = (
const chans = new Map();
const doFallback = async (method, ...args) => {
if (!fallback) {
return {};
return Data({});
}
return E(fallback)[method](...args);
};
Expand Down
7 changes: 4 additions & 3 deletions packages/cosmic-swingset/lib/ag-solo/vats/ibc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import makeStore from '@agoric/store';
import { makePromiseKit } from '@agoric/promise-kit';
import { assert, details as X } from '@agoric/assert';
import { Far } from '@agoric/marshal';

import '@agoric/store/exported';
import '@agoric/swingset-vat/src/vats/network/types';
Expand Down Expand Up @@ -176,7 +177,7 @@ export function makeIBCProtocolHandler(E, rawCallIBCDevice) {
onReceive = withChannelReceiveQueue(onReceive);
}

return harden({
return Far('IBCConnectionHandler', {
async onOpen(conn, localAddr, remoteAddr, _handler) {
console.debug(
'onOpen Remote IBC Connection',
Expand Down Expand Up @@ -244,7 +245,7 @@ export function makeIBCProtocolHandler(E, rawCallIBCDevice) {
/**
* @type {ProtocolHandler}
*/
const protocol = harden({
const protocol = Far('ProtocolHandler', {
async onCreate(impl, _protocolHandler) {
console.debug('IBC onCreate');
protocolImpl = impl;
Expand Down Expand Up @@ -378,7 +379,7 @@ EOF
},
});

return harden({
return Far('IBCProtocolHandler', {
...protocol,
async fromBridge(srcID, obj) {
console.info('IBC fromBridge', srcID, obj);
Expand Down
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/lib-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { generateSparseInts } from '@agoric/sparse-ints';
import { assert, details as X, q } from '@agoric/assert';
import { Far } from '@agoric/marshal';
import makeStore from '@agoric/store';
import { models as crcmodels } from 'polycrc';

Expand Down Expand Up @@ -40,7 +41,7 @@ function makeBoard(seed = 0) {
const sparseInts = generateSparseInts(seed);

/** @type {Board} */
const board = harden({
const board = Far('Board', {
// Add if not already present
getId: value => {
if (!valToId.has(value)) {
Expand Down
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/vat-board.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Far } from '@agoric/marshal';
import { makeBoard } from './lib-board';

export function buildRootObject(_vatPowers) {
const board = makeBoard();
return harden({ getBoard: () => board });
return Far('board', { getBoard: () => board });
}
5 changes: 3 additions & 2 deletions packages/cosmic-swingset/lib/ag-solo/vats/vat-host.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (C) 2018 Agoric, under Apache License 2.0

import { Far } from '@agoric/marshal';
import { makeContractHost } from '@agoric/spawner';

export function buildRootObject(vatPowers) {
return harden({
return Far('root', {
makeHost() {
return harden(makeContractHost(vatPowers));
return makeContractHost(vatPowers);
},
});
}
9 changes: 5 additions & 4 deletions packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { makeNotifierKit } from '@agoric/notifier';
import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';
import { assert, details as X } from '@agoric/assert';
import { getReplHandler } from './repl';
import { getCapTPHandler } from './captp';
Expand Down Expand Up @@ -71,15 +72,15 @@ export function buildRootObject(vatPowers) {
urlToHandler.set(url, commandHandler);
}

return harden({
return Far('root', {
setCommandDevice(d) {
commandDevice = d;

const replHandler = getReplHandler(replObjects, send, vatPowers);
registerURLHandler(replHandler, '/private/repl');

// Assign the captp handler.
const captpHandler = harden({
const captpHandler = Far('captpHandler', {
getBootstrap(_otherSide, _meta) {
// Harden only our exported objects, and fetch them afresh each time.
return harden(exportedToCapTP);
Expand Down Expand Up @@ -113,7 +114,7 @@ export function buildRootObject(vatPowers) {
...decentralObjects, // TODO: Remove; replaced by .agoric
...privateObjects, // TODO: Remove; replaced by .local
...handyObjects,
agoric: { ...decentralObjects },
agoric: { ...decentralObjects }, // TODO: maybe needs Data()???
local: { ...privateObjects },
};

Expand Down Expand Up @@ -161,7 +162,7 @@ export function buildRootObject(vatPowers) {
try {
let channelHandle = channelIdToHandle.get(rawChannelID);
if (dispatcher === 'onOpen') {
channelHandle = harden({});
channelHandle = Far('channelHandle');
channelIdToHandle.set(rawChannelID, channelHandle);
channelHandleToId.set(channelHandle, rawChannelID);
} else if (dispatcher === 'onClose') {
Expand Down
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/vat-ibc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Far } from '@agoric/marshal';
import { E } from '@agoric/eventual-send';
import { makeIBCProtocolHandler } from './ibc';

Expand All @@ -10,7 +11,7 @@ export function buildRootObject(_vatPowers) {
);
return harden(ibcHandler);
}
return harden({
return Far('root', {
createInstance,
});
}
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/vat-mints.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Far } from '@agoric/marshal';
import { makeIssuerKit } from '@agoric/ertp';

import makeStore from '@agoric/store';
Expand All @@ -8,7 +9,7 @@ import makeStore from '@agoric/store';
export function buildRootObject(_vatPowers) {
const mintsAndMath = makeStore('issuerName');

const api = harden({
const api = Far('api', {
getAllIssuerNames: () => mintsAndMath.keys(),
getIssuer: issuerName => {
const mint = mintsAndMath.get(issuerName);
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/vat-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { E } from '@agoric/eventual-send';
import { makeRouterProtocol } from '@agoric/swingset-vat/src/vats/network/router';

export function buildRootObject(_vatPowers) {
return harden(makeRouterProtocol(E));
return makeRouterProtocol(E); // already Far('Router')
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Far } from '@agoric/marshal';
import { makePriceAuthorityRegistry } from '@agoric/zoe/tools/priceAuthorityRegistry';
import { makeFakePriceAuthority } from '@agoric/zoe/tools/fakePriceAuthority';
import { makeLocalAmountMath } from '@agoric/ertp';

export function buildRootObject(_vatPowers) {
return harden({
return Far('root', {
makePriceAuthority: makePriceAuthorityRegistry,
async makeFakePriceAuthority(options) {
const { issuerIn, issuerOut } = options;
Expand Down
5 changes: 3 additions & 2 deletions packages/cosmic-swingset/lib/ag-solo/vats/vat-provisioning.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';

// This vat contains the controller-side provisioning service. To enable local
// testing, it is loaded by both the controller and other ag-solo vat machines.
Expand All @@ -16,7 +17,7 @@ export function buildRootObject(_vatPowers) {

async function pleaseProvision(nickname, pubkey, powerFlags) {
let chainBundle;
const fetch = harden({
const fetch = Far('fetch', {
getDemoBundle() {
return chainBundle;
},
Expand All @@ -35,5 +36,5 @@ export function buildRootObject(_vatPowers) {
return { ingressIndex: INDEX };
}

return harden({ register, pleaseProvision });
return Far('root', { register, pleaseProvision });
}
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/vat-registrar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Far } from '@agoric/marshal';
import { makeRegistrar } from '@agoric/registrar';

// This vat contains the registrar for the demo.
Expand All @@ -9,5 +10,5 @@ export function buildRootObject(_vatPowers) {
return sharedRegistrar;
}

return harden({ getSharedRegistrar });
return Far('root', { getSharedRegistrar });
}
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/vat-sharing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Far } from '@agoric/marshal';
import { makeSharingService } from '@agoric/sharing-service';

// This vat contains the sharing service for the demo.
Expand All @@ -9,5 +10,5 @@ export function buildRootObject(_vatPowers) {
return sharingService;
}

return harden({ getSharingService });
return Far('root', { getSharingService });
}
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/vat-uploads.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Far } from '@agoric/marshal';
import makeScratchPad from './scratch';

// This vat contains the private upload scratch pad.
Expand All @@ -9,5 +10,5 @@ export function buildRootObject(_vatPowers) {
return uploads;
}

return harden({ getUploads });
return Far('root', { getUploads });
}
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/vat-zoe.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Far } from '@agoric/marshal';
import { makeZoe } from '@agoric/zoe';

export function buildRootObject(_vatPowers, vatParameters) {
return harden({
return Far('root', {
buildZoe: adminVat => makeZoe(adminVat, vatParameters.zcfBundleName),
});
}
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/test/test-home.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import '@agoric/install-ses';
import test from 'ava';
import bundleSource from '@agoric/bundle-source';
import { Far } from '@agoric/marshal';

import { makeFixture, E } from './captp-fixture';

Expand Down Expand Up @@ -44,7 +45,7 @@ test.serial('home.board', async t => {
`using a non-verified id throws`,
);

const myValue = {};
const myValue = Far('myValue', {});
const myId = await E(board).getId(myValue);
t.is(typeof myId, 'string', `board key is string`);

Expand Down
Loading

0 comments on commit 92b63b6

Please sign in to comment.