Skip to content

Commit 92b63b6

Browse files
authored
fix(cosmic-swingset): apply Far/Data as necessary (#2567)
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
1 parent 3c9f42a commit 92b63b6

19 files changed

+56
-38
lines changed

packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
makeEchoConnectionHandler,
66
} from '@agoric/swingset-vat/src/vats/network';
77
import { E } from '@agoric/eventual-send';
8+
import { Far } from '@agoric/marshal';
89

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

2526
function makeVattpFrom(vats) {
2627
const { vattp, comms } = vats;
27-
return harden({
28+
return Far('vattp', {
2829
makeNetworkHost(allegedName, console = undefined) {
2930
return E(vattp).makeNetworkHost(allegedName, comms, console);
3031
},
@@ -205,7 +206,7 @@ export function buildRootObject(vatPowers, vatParameters) {
205206
}),
206207
);
207208

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

241-
const faucet = {
242+
const faucet = Far('faucet', {
242243
// A method to reap the spoils of our on-chain provisioning.
243244
async tapFaucet() {
244245
return paymentInfo;
245246
},
246-
};
247+
});
247248

248249
const bundle = harden({
249250
...additionalPowers,
@@ -275,7 +276,7 @@ export function buildRootObject(vatPowers, vatParameters) {
275276
);
276277
if (bridgeMgr) {
277278
// We have access to the bridge, and therefore IBC.
278-
const callbacks = harden({
279+
const callbacks = Far('callbacks', {
279280
downcall(method, obj) {
280281
return bridgeMgr.toBridge('dibc', {
281282
...obj,
@@ -304,7 +305,7 @@ export function buildRootObject(vatPowers, vatParameters) {
304305
// Add an echo listener on our ibc-port network.
305306
const port = await E(vats.network).bind('/ibc-port/echo');
306307
E(port).addListener(
307-
harden({
308+
Far('listener', {
308309
async onAccept(_port, _localAddr, _remoteAddr, _listenHandler) {
309310
return harden(makeEchoConnectionHandler());
310311
},
@@ -314,7 +315,7 @@ export function buildRootObject(vatPowers, vatParameters) {
314315

315316
if (bridgeMgr) {
316317
// Register a provisioning handler over the bridge.
317-
const handler = harden({
318+
const handler = Far('provisioningHandler', {
318319
async fromBridge(_srcID, obj) {
319320
switch (obj.type) {
320321
case 'PLEASE_PROVISION': {
@@ -355,7 +356,7 @@ export function buildRootObject(vatPowers, vatParameters) {
355356
}
356357

357358
// This will allow dApp developers to register in their api/deploy.js
358-
const httpRegCallback = {
359+
const httpRegCallback = Far('httpRegCallback', {
359360
doneLoading(subsystems) {
360361
return E(vats.http).doneLoading(subsystems);
361362
},
@@ -378,7 +379,7 @@ export function buildRootObject(vatPowers, vatParameters) {
378379
E(vats.http).setWallet(wallet),
379380
]);
380381
},
381-
};
382+
});
382383

383384
return allComparable(
384385
harden({
@@ -395,7 +396,7 @@ export function buildRootObject(vatPowers, vatParameters) {
395396
);
396397
}
397398

398-
return harden({
399+
return Far('root', {
399400
async bootstrap(vats, devices) {
400401
const bridgeManager =
401402
devices.bridge && makeBridgeManager(E, D, devices.bridge);
@@ -494,7 +495,7 @@ export function buildRootObject(vatPowers, vatParameters) {
494495
// Allow some hardcoded client address connections into the chain.
495496
// This is necessary for fake-chain, which does not have Cosmos SDK
496497
// transactions to provision its client.
497-
const demoProvider = harden({
498+
const demoProvider = Far('demoProvider', {
498499
// build a chain-side bundle for a client.
499500
async getDemoBundle(nickname) {
500501
if (giveMeAllTheAgoricPowers) {

packages/cosmic-swingset/lib/ag-solo/vats/bridge.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import makeStore from '@agoric/store';
44
import '@agoric/store/exported';
55
import { assert, details as X } from '@agoric/assert';
6+
import { Far } from '@agoric/marshal';
67

78
/**
89
* @template T
@@ -53,7 +54,7 @@ export function makeBridgeManager(E, D, bridgeDevice) {
5354
// No return value.
5455
}
5556

56-
const bridgeHandler = harden({ inbound: bridgeInbound });
57+
const bridgeHandler = Far('bridgeHandler', { inbound: bridgeInbound });
5758

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

73-
return harden({
74+
return Far('bridgeManager', {
7475
toBridge(dstID, obj) {
7576
return callOutbound(dstID, obj);
7677
},

packages/cosmic-swingset/lib/ag-solo/vats/captp.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// in its own makeHardener, etc.
33
import { makeCapTP } from '@agoric/captp/lib/captp';
44
import { E } from '@agoric/eventual-send';
5+
import { Data } from '@agoric/marshal';
56

67
export const getCapTPHandler = (
78
send,
@@ -11,7 +12,7 @@ export const getCapTPHandler = (
1112
const chans = new Map();
1213
const doFallback = async (method, ...args) => {
1314
if (!fallback) {
14-
return {};
15+
return Data({});
1516
}
1617
return E(fallback)[method](...args);
1718
};

packages/cosmic-swingset/lib/ag-solo/vats/ibc.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import makeStore from '@agoric/store';
99
import { makePromiseKit } from '@agoric/promise-kit';
1010
import { assert, details as X } from '@agoric/assert';
11+
import { Far } from '@agoric/marshal';
1112

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

179-
return harden({
180+
return Far('IBCConnectionHandler', {
180181
async onOpen(conn, localAddr, remoteAddr, _handler) {
181182
console.debug(
182183
'onOpen Remote IBC Connection',
@@ -244,7 +245,7 @@ export function makeIBCProtocolHandler(E, rawCallIBCDevice) {
244245
/**
245246
* @type {ProtocolHandler}
246247
*/
247-
const protocol = harden({
248+
const protocol = Far('ProtocolHandler', {
248249
async onCreate(impl, _protocolHandler) {
249250
console.debug('IBC onCreate');
250251
protocolImpl = impl;
@@ -378,7 +379,7 @@ EOF
378379
},
379380
});
380381

381-
return harden({
382+
return Far('IBCProtocolHandler', {
382383
...protocol,
383384
async fromBridge(srcID, obj) {
384385
console.info('IBC fromBridge', srcID, obj);

packages/cosmic-swingset/lib/ag-solo/vats/lib-board.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { generateSparseInts } from '@agoric/sparse-ints';
44
import { assert, details as X, q } from '@agoric/assert';
5+
import { Far } from '@agoric/marshal';
56
import makeStore from '@agoric/store';
67
import { models as crcmodels } from 'polycrc';
78

@@ -40,7 +41,7 @@ function makeBoard(seed = 0) {
4041
const sparseInts = generateSparseInts(seed);
4142

4243
/** @type {Board} */
43-
const board = harden({
44+
const board = Far('Board', {
4445
// Add if not already present
4546
getId: value => {
4647
if (!valToId.has(value)) {
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { Far } from '@agoric/marshal';
12
import { makeBoard } from './lib-board';
23

34
export function buildRootObject(_vatPowers) {
45
const board = makeBoard();
5-
return harden({ getBoard: () => board });
6+
return Far('board', { getBoard: () => board });
67
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Copyright (C) 2018 Agoric, under Apache License 2.0
22

3+
import { Far } from '@agoric/marshal';
34
import { makeContractHost } from '@agoric/spawner';
45

56
export function buildRootObject(vatPowers) {
6-
return harden({
7+
return Far('root', {
78
makeHost() {
8-
return harden(makeContractHost(vatPowers));
9+
return makeContractHost(vatPowers);
910
},
1011
});
1112
}

packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { makeNotifierKit } from '@agoric/notifier';
22
import { E } from '@agoric/eventual-send';
3+
import { Far } from '@agoric/marshal';
34
import { assert, details as X } from '@agoric/assert';
45
import { getReplHandler } from './repl';
56
import { getCapTPHandler } from './captp';
@@ -71,15 +72,15 @@ export function buildRootObject(vatPowers) {
7172
urlToHandler.set(url, commandHandler);
7273
}
7374

74-
return harden({
75+
return Far('root', {
7576
setCommandDevice(d) {
7677
commandDevice = d;
7778

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

8182
// Assign the captp handler.
82-
const captpHandler = harden({
83+
const captpHandler = Far('captpHandler', {
8384
getBootstrap(_otherSide, _meta) {
8485
// Harden only our exported objects, and fetch them afresh each time.
8586
return harden(exportedToCapTP);
@@ -113,7 +114,7 @@ export function buildRootObject(vatPowers) {
113114
...decentralObjects, // TODO: Remove; replaced by .agoric
114115
...privateObjects, // TODO: Remove; replaced by .local
115116
...handyObjects,
116-
agoric: { ...decentralObjects },
117+
agoric: { ...decentralObjects }, // TODO: maybe needs Data()???
117118
local: { ...privateObjects },
118119
};
119120

@@ -161,7 +162,7 @@ export function buildRootObject(vatPowers) {
161162
try {
162163
let channelHandle = channelIdToHandle.get(rawChannelID);
163164
if (dispatcher === 'onOpen') {
164-
channelHandle = harden({});
165+
channelHandle = Far('channelHandle');
165166
channelIdToHandle.set(rawChannelID, channelHandle);
166167
channelHandleToId.set(channelHandle, rawChannelID);
167168
} else if (dispatcher === 'onClose') {

packages/cosmic-swingset/lib/ag-solo/vats/vat-ibc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Far } from '@agoric/marshal';
12
import { E } from '@agoric/eventual-send';
23
import { makeIBCProtocolHandler } from './ibc';
34

@@ -10,7 +11,7 @@ export function buildRootObject(_vatPowers) {
1011
);
1112
return harden(ibcHandler);
1213
}
13-
return harden({
14+
return Far('root', {
1415
createInstance,
1516
});
1617
}

packages/cosmic-swingset/lib/ag-solo/vats/vat-mints.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Far } from '@agoric/marshal';
12
import { makeIssuerKit } from '@agoric/ertp';
23

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

11-
const api = harden({
12+
const api = Far('api', {
1213
getAllIssuerNames: () => mintsAndMath.keys(),
1314
getIssuer: issuerName => {
1415
const mint = mintsAndMath.get(issuerName);

packages/cosmic-swingset/lib/ag-solo/vats/vat-network.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { E } from '@agoric/eventual-send';
33
import { makeRouterProtocol } from '@agoric/swingset-vat/src/vats/network/router';
44

55
export function buildRootObject(_vatPowers) {
6-
return harden(makeRouterProtocol(E));
6+
return makeRouterProtocol(E); // already Far('Router')
77
}

packages/cosmic-swingset/lib/ag-solo/vats/vat-priceAuthority.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { Far } from '@agoric/marshal';
12
import { makePriceAuthorityRegistry } from '@agoric/zoe/tools/priceAuthorityRegistry';
23
import { makeFakePriceAuthority } from '@agoric/zoe/tools/fakePriceAuthority';
34
import { makeLocalAmountMath } from '@agoric/ertp';
45

56
export function buildRootObject(_vatPowers) {
6-
return harden({
7+
return Far('root', {
78
makePriceAuthority: makePriceAuthorityRegistry,
89
async makeFakePriceAuthority(options) {
910
const { issuerIn, issuerOut } = options;

packages/cosmic-swingset/lib/ag-solo/vats/vat-provisioning.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { E } from '@agoric/eventual-send';
2+
import { Far } from '@agoric/marshal';
23

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

1718
async function pleaseProvision(nickname, pubkey, powerFlags) {
1819
let chainBundle;
19-
const fetch = harden({
20+
const fetch = Far('fetch', {
2021
getDemoBundle() {
2122
return chainBundle;
2223
},
@@ -35,5 +36,5 @@ export function buildRootObject(_vatPowers) {
3536
return { ingressIndex: INDEX };
3637
}
3738

38-
return harden({ register, pleaseProvision });
39+
return Far('root', { register, pleaseProvision });
3940
}

packages/cosmic-swingset/lib/ag-solo/vats/vat-registrar.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Far } from '@agoric/marshal';
12
import { makeRegistrar } from '@agoric/registrar';
23

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

12-
return harden({ getSharedRegistrar });
13+
return Far('root', { getSharedRegistrar });
1314
}

packages/cosmic-swingset/lib/ag-solo/vats/vat-sharing.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Far } from '@agoric/marshal';
12
import { makeSharingService } from '@agoric/sharing-service';
23

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

12-
return harden({ getSharingService });
13+
return Far('root', { getSharingService });
1314
}

packages/cosmic-swingset/lib/ag-solo/vats/vat-uploads.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Far } from '@agoric/marshal';
12
import makeScratchPad from './scratch';
23

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

12-
return harden({ getUploads });
13+
return Far('root', { getUploads });
1314
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { Far } from '@agoric/marshal';
12
import { makeZoe } from '@agoric/zoe';
23

34
export function buildRootObject(_vatPowers, vatParameters) {
4-
return harden({
5+
return Far('root', {
56
buildZoe: adminVat => makeZoe(adminVat, vatParameters.zcfBundleName),
67
});
78
}

packages/cosmic-swingset/test/test-home.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import '@agoric/install-ses';
33
import test from 'ava';
44
import bundleSource from '@agoric/bundle-source';
5+
import { Far } from '@agoric/marshal';
56

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

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

47-
const myValue = {};
48+
const myValue = Far('myValue', {});
4849
const myId = await E(board).getId(myValue);
4950
t.is(typeof myId, 'string', `board key is string`);
5051

0 commit comments

Comments
 (0)