Skip to content

Commit

Permalink
fix(vats): move vat-ibc/vat-network from config to network-proposal.js
Browse files Browse the repository at this point in the history
Previously, certain configurations included vat-ibc and vat-network
code as part of bootstrap.

These two vats are not properly upgradable, and are not used in our
initial launch configuration. To minimize risk, we don't want unused
code running on-chain, however we have development and test
configurations which *do* need IBC support, so we don't want to delete
this code entirely.

This commit removes ibc/network from `config.bundles`, and instead
creates "proposals" for them (just like we do for Pegasus and the
Inter protocol). You can run `agoric run
packages/vats/scripts/init-network.js` to create both a set of bundles
for installation, and a proposal file to submit in a transaction. Once
executed, this will cause the target chain to create vat-network and
vat-ibc, and to wire them up just as if they were included at
bootstrap time.

closes #7044
  • Loading branch information
warner committed May 5, 2023
1 parent 1cacac8 commit 382f7ad
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 170 deletions.
1 change: 1 addition & 0 deletions packages/cosmic-swingset/economy-template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
"@agoric/vats/scripts/init-core.js",
"@agoric/vats/scripts/init-network.js",
{
"module": "@agoric/inter-protocol/scripts/init-core.js",
"entrypoint": "defaultProposalBuilder",
Expand Down
6 changes: 0 additions & 6 deletions packages/vats/decentral-core-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,9 @@
"bridge": {
"sourceSpec": "@agoric/vats/src/vat-bridge.js"
},
"ibc": {
"sourceSpec": "@agoric/vats/src/vat-ibc.js"
},
"mints": {
"sourceSpec": "@agoric/vats/src/vat-mints.js"
},
"network": {
"sourceSpec": "@agoric/vats/src/vat-network.js"
},
"priceAuthority": {
"sourceSpec": "@agoric/vats/src/vat-priceAuthority.js"
},
Expand Down
7 changes: 1 addition & 6 deletions packages/vats/decentral-demo-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"snapshotInterval": 1000,
"coreProposals": [
"@agoric/vats/scripts/init-core.js",
"@agoric/vats/scripts/init-network.js",
{
"module": "@agoric/inter-protocol/scripts/init-core.js",
"entrypoint": "defaultProposalBuilder",
Expand Down Expand Up @@ -126,12 +127,6 @@
"board": {
"sourceSpec": "@agoric/vats/src/vat-board.js"
},
"ibc": {
"sourceSpec": "@agoric/vats/src/vat-ibc.js"
},
"network": {
"sourceSpec": "@agoric/vats/src/vat-network.js"
},
"priceAuthority": {
"sourceSpec": "@agoric/vats/src/vat-priceAuthority.js"
},
Expand Down
7 changes: 1 addition & 6 deletions packages/vats/decentral-devnet-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"defaultReapInterval": 1000,
"coreProposals": [
"@agoric/vats/scripts/init-core.js",
"@agoric/vats/scripts/init-network.js",
{
"module": "@agoric/inter-protocol/scripts/init-core.js",
"entrypoint": "defaultProposalBuilder",
Expand Down Expand Up @@ -175,18 +176,12 @@
"centralSupply": {
"sourceSpec": "@agoric/vats/src/centralSupply.js"
},
"ibc": {
"sourceSpec": "@agoric/vats/src/vat-ibc.js"
},
"mintHolder": {
"sourceSpec": "@agoric/vats/src/mintHolder.js"
},
"mints": {
"sourceSpec": "@agoric/vats/src/vat-mints.js"
},
"network": {
"sourceSpec": "@agoric/vats/src/vat-network.js"
},
"priceAuthority": {
"sourceSpec": "@agoric/vats/src/vat-priceAuthority.js"
},
Expand Down
6 changes: 0 additions & 6 deletions packages/vats/decentral-test-vaults-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,9 @@
"centralSupply": {
"sourceSpec": "@agoric/vats/src/centralSupply.js"
},
"ibc": {
"sourceSpec": "@agoric/vats/src/vat-ibc.js"
},
"mintHolder": {
"sourceSpec": "@agoric/vats/src/mintHolder.js"
},
"network": {
"sourceSpec": "@agoric/vats/src/vat-network.js"
},
"priceAuthority": {
"sourceSpec": "@agoric/vats/src/vat-priceAuthority.js"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/vats/demo-proposals.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
"@agoric/inter-protocol/scripts/init-core.js",
"@agoric/pegasus/scripts/init-core.js"
"@agoric/pegasus/scripts/init-core.js",
"@agoric/vats/scripts/init-network.js"
]
18 changes: 18 additions & 0 deletions packages/vats/scripts/init-network.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { makeHelpers } from '@agoric/deploy-script-support';

export const defaultProposalBuilder = async ({ publishRef, install }) =>
harden({
sourceSpec: '../src/proposals/network-proposal.js',
getManifestCall: [
'getManifestForNetwork',
{
networkRef: publishRef(install('../src/vat-network.js')),
ibcRef: publishRef(install('../src/vat-ibc.js')),
},
],
});

export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('gov-network', defaultProposalBuilder);
};
144 changes: 0 additions & 144 deletions packages/vats/src/core/chain-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import {
makeSubscriptionKit,
observeIteration,
} from '@agoric/notifier';
import {
makeLoopbackProtocolHandler,
makeEchoConnectionHandler,
makeNonceMaker,
} from '@agoric/swingset-vat/src/vats/network/index.js';
import { importBundle } from '@endo/import-bundle';
import { allValues, BridgeId as BRIDGE_ID } from '@agoric/internal';
import * as STORAGE_PATH from '@agoric/internal/src/chain-storage-paths.js';
Expand All @@ -25,9 +20,6 @@ import { PowerFlags } from '../walletFlags.js';
const { Fail } = assert;
const { keys } = Object;

const NUM_IBC_PORTS_PER_CLIENT = 3;
const INTERCHAIN_ACCOUNT_CONTROLLER_PORT_PREFIX = 'icacontroller-';

/**
* This registers the code triggered by `agd tx gov submit-proposal
* swingset-core-eval permit.json code.js`. It is the "big hammer" governance
Expand Down Expand Up @@ -470,130 +462,6 @@ export const connectChainFaucet = async ({ consume: { client } }) => {
};
harden(connectChainFaucet);

/**
* @param {SoloVats | NetVats} vats
* @param {ERef<import('../types.js').ScopedBridgeManager>} [dibcBridgeManager]
*/
export const registerNetworkProtocols = async (vats, dibcBridgeManager) => {
const ps = [];
// Every vat has a loopback device.
ps.push(
E(vats.network).registerProtocolHandler(
['/local'],
makeLoopbackProtocolHandler(),
),
);
if (dibcBridgeManager) {
assert('ibc' in vats);
// We have access to the bridge, and therefore IBC.
const callbacks = Far('callbacks', {
downcall(method, obj) {
return E(dibcBridgeManager).toBridge({
...obj,
type: 'IBC_METHOD',
method,
});
},
});
ps.push(
E(vats.ibc)
.createInstance(callbacks)
.then(ibcHandler =>
E(dibcBridgeManager)
.initHandler(ibcHandler)
.then(() =>
E(vats.network).registerProtocolHandler(
['/ibc-port', '/ibc-hop'],
ibcHandler,
),
),
),
);
} else {
const loHandler = makeLoopbackProtocolHandler(
makeNonceMaker('ibc-channel/channel-'),
);
ps.push(E(vats.network).registerProtocolHandler(['/ibc-port'], loHandler));
}
await Promise.all(ps);

// Add an echo listener on our ibc-port network (whether real or virtual).
const echoPort = await E(vats.network).bind('/ibc-port/echo');

return E(echoPort).addListener(
Far('listener', {
async onAccept(_port, _localAddr, _remoteAddr, _listenHandler) {
return harden(makeEchoConnectionHandler());
},
async onListen(port, _listenHandler) {
console.debug(`listening on echo port: ${port}`);
},
}),
);
};

/**
* @param { BootstrapPowers & {
* consume: { loadCriticalVat: VatLoader<any> }
* produce: { networkVat: Producer<any> }
* }} powers
*
* // TODO: why doesn't overloading VatLoader work???
* @typedef { ((name: 'network') => NetworkVat) &
* ((name: 'ibc') => IBCVat) } VatLoader2
*
* @typedef {{ network: ERef<NetworkVat>, ibc: ERef<IBCVat>, provisioning: ERef<ProvisioningVat | undefined>}} NetVats
*/
export const setupNetworkProtocols = async ({
consume: {
client,
loadCriticalVat,
bridgeManager: bridgeManagerP,
provisioning,
},
produce: { networkVat },
}) => {
/** @type { NetVats } */
const vats = {
network: E(loadCriticalVat)('network'),
ibc: E(loadCriticalVat)('ibc'),
provisioning,
};
// don't proceed if loadCriticalVat fails
await Promise.all(Object.values(vats));

networkVat.reset();
networkVat.resolve(vats.network);
const bridgeManager = await bridgeManagerP;
const dibcBridgeManager =
bridgeManager && E(bridgeManager).register(BRIDGE_ID.DIBC);

// The Interchain Account (ICA) Controller must be bound to a port that starts
// with 'icacontroller', so we provide one such port to each client.
let lastICAPort = 0;
const makePorts = async () => {
// Bind to some fresh ports (either unspecified name or `icacontroller-*`)
// on the IBC implementation and provide them for the user to have.
const ibcportP = [];
for (let i = 0; i < NUM_IBC_PORTS_PER_CLIENT; i += 1) {
let bindAddr = '/ibc-port/';
if (i === NUM_IBC_PORTS_PER_CLIENT - 1) {
lastICAPort += 1;
bindAddr += `${INTERCHAIN_ACCOUNT_CONTROLLER_PORT_PREFIX}${lastICAPort}`;
}
const port = E(vats.network).bind(bindAddr);
ibcportP.push(port);
}
return Promise.all(ibcportP);
};

// Note: before we add the pegasus transfer port,
// we need to finish registering handlers for
// ibc-port etc.
await registerNetworkProtocols(vats, dibcBridgeManager);
return E(client).assignBundle([_a => ({ ibcport: makePorts() })]);
};

/** @type {import('./lib-boot').BootstrapManifest} */
export const SHARED_CHAIN_BOOTSTRAP_MANIFEST = {
...BASIC_BOOTSTRAP_PERMITS,
Expand Down Expand Up @@ -670,18 +538,6 @@ export const SHARED_CHAIN_BOOTSTRAP_MANIFEST = {
clientCreator: true,
},
},
[setupNetworkProtocols.name]: {
consume: {
client: true,
loadCriticalVat: true,
bridgeManager: 'bridge',
zoe: 'zoe',
provisioning: 'provisioning',
},
produce: {
networkVat: 'network',
},
},
};
harden(SHARED_CHAIN_BOOTSTRAP_MANIFEST);

Expand Down
2 changes: 1 addition & 1 deletion packages/vats/src/core/client-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { E, Far } from '@endo/far';
import { makePluginManager } from '@agoric/swingset-vat/src/vats/plugin-manager.js';
import { observeNotifier } from '@agoric/notifier';
import { deeplyFulfilledObject } from '@agoric/internal';
import { registerNetworkProtocols } from './chain-behaviors.js';
import { registerNetworkProtocols } from '../proposals/network-proposal.js';
import { makeVatsFromBundles } from './basic-behaviors.js';

const { Fail } = assert;
Expand Down
Loading

0 comments on commit 382f7ad

Please sign in to comment.