From e2fe21b7bab032afa4c3bb25679c5211c9982c0c Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Sat, 15 Jun 2019 09:48:57 -0600 Subject: [PATCH] Revert "wire together 'user' storage device" This reverts commit e2fd5df00a21916d6fd8c941b84837b5333ae6ea. --- Makefile | 11 ------- lib/ag-solo/chain-cosmos-sdk.js | 33 ------------------- lib/ag-solo/html/main.js | 7 ---- lib/ag-solo/start.js | 1 - lib/ag-solo/vats/bootstrap.js | 48 ++++++++++------------------ lib/ag-solo/vats/vat-demo.js | 5 ++- lib/ag-solo/vats/vat-http.js | 17 +++------- lib/ag-solo/vats/vat-provisioning.js | 4 +-- lib/launch-chain.js | 13 ++------ 9 files changed, 28 insertions(+), 111 deletions(-) diff --git a/Makefile b/Makefile index c7395393d38..64766e1432b 100644 --- a/Makefile +++ b/Makefile @@ -101,14 +101,3 @@ install-setup-client: ve3-client/bin/pip install --editable ./setup-solo run-setup-client: ve3-client/bin/ag-setup-solo - -run-chain: - rm -rf ~/.ag-chain-cosmos - lib/ag-chain-cosmos init --chain-id $(CHAIN_ID) - rm -rf t1 && bin/ag-solo init t1 - ag-chain-cosmos add-genesis-account `cat t1/ag-cosmos-helper-address` 1000agmedallion - BOOT_ADDRESS=`cat t1/ag-cosmos-helper-address` ag-chain-cosmos start - -run-client: set-local-gci-ingress - cd t1 && ../bin/ag-solo start --role=controller --role=client `cat ag-cosmos-helper-address` - diff --git a/lib/ag-solo/chain-cosmos-sdk.js b/lib/ag-solo/chain-cosmos-sdk.js index 989f3735d25..9622147eed4 100644 --- a/lib/ag-solo/chain-cosmos-sdk.js +++ b/lib/ag-solo/chain-cosmos-sdk.js @@ -15,7 +15,6 @@ export async function connectToChain( myAddr, inbound, chainID, - broadcast, ) { // Each time we read our mailbox from the chain's state, and each time we // send an outbound message to the chain, we shell out to a one-shot copy @@ -132,27 +131,6 @@ export async function connectToChain( }); } - const getStorage = path => - singletonHelper( - `getStorage${path}`, - ['query', 'swingset', 'storage', path], - ret => { - const { stdout, stderr } = ret; - process.stderr.write(stderr); - process.stdout.write(` helper said: ${stdout}`); - if (stdout.startsWith('could not find')) { - return {}; - } - try { - // Try to parse the stdout. - return JSON.parse(JSON.parse(stdout).value); - } catch (e) { - console.log(` failed to parse output:`, e); - } - return undefined; - }, - ); - const getMailbox = () => singletonHelper( 'getMailbox', @@ -167,7 +145,6 @@ export async function connectToChain( } catch (e) { console.log(` failed to parse output:`, e); } - return undefined; }, ); @@ -218,19 +195,9 @@ export async function connectToChain( // hitting the rest-server on every single block. c.lightClient.on('update', async _a => { - console.log(`fetching chain storage`); - console.log(`new block on ${GCI}, fetching mailbox`); const { outbox, ack } = await getMailbox(); await inbound(GCI, outbox, ack); - - // FIXME: Factor this differently so that the vats can register - // for storage events and send the broadcast themselves. - if (broadcast) { - console.log(`fetching canvas storage`); - const user = await getStorage('user'); - await broadcast({ type: 'updateCanvas', state: user.canvas }); - } }); function deliver(newMessages, acknum) { console.log(`delivering to chain`, GCI, newMessages, acknum); diff --git a/lib/ag-solo/html/main.js b/lib/ag-solo/html/main.js index 433be52d373..c1cae6f6539 100644 --- a/lib/ag-solo/html/main.js +++ b/lib/ag-solo/html/main.js @@ -88,13 +88,6 @@ function run() { } } - call({ type: 'getCanvasState' }).then(obj => { - console.log('got state', obj); - if (obj) { - updateCanvas(JSON.parse(obj.state)); - } - }); - function handleMessage(obj) { // we receive commands to update result boxes if (obj.type === 'updateHistory') { diff --git a/lib/ag-solo/start.js b/lib/ag-solo/start.js index 6f9ea44a59e..ba2843a3eec 100644 --- a/lib/ag-solo/start.js +++ b/lib/ag-solo/start.js @@ -123,7 +123,6 @@ export default async function start(basedir, withSES, argv) { c.myAddr, inbound, c.chainID, - broadcast, ); addDeliveryTarget(c.GCI, deliverator); } else if (c.type === 'http') { diff --git a/lib/ag-solo/vats/bootstrap.js b/lib/ag-solo/vats/bootstrap.js index 2b6d3f1991e..539c2b92b8b 100644 --- a/lib/ag-solo/vats/bootstrap.js +++ b/lib/ag-solo/vats/bootstrap.js @@ -32,40 +32,30 @@ export default function setup(syscall, state, helpers) { syscall, state, (E, D) => { + // TODO: Any wiring necessary to make the demo work. + async function startDemo(vats) { + await E(vats.demo).startup(vats.http); + return vats.demo; + } + return harden({ async bootstrap(argv, vats, devices) { console.log(`bootstrap(${argv.join(' ')}) called`); const [ROLES, bootAddress] = parseArgs(argv); console.log(`Have ROLES`, ROLES, bootAddress); - // Wiring necessary to make the demo work. - async function startDemo() { - const saver = harden({ - saveCanvas(canvasState) { - if (ROLES.client) { - return E(vats.http).updateCanvasState(canvasState); - } - if (devices.storage) { - D(devices.storage).set('canvas', canvasState); - } - }, - }); - await E(vats.demo).startup(saver); - return vats.demo; - } - D(devices.mailbox).registerInboundHandler(vats.vattp); await E(vats.vattp).registerMailboxDevice(devices.mailbox); await E(vats.comms).init(vats.vattp); + const demoRoot = await startDemo(vats); + if (ROLES.client || ROLES.controller) { // Allow http access. await E(vats.http).setCommandDevice(devices.command, ROLES); D(devices.command).registerInboundHandler(vats.http); } - const demoRoot = await startDemo(); - let chainProvisioner; if (ROLES.chain) { // 'provisioning' vat lives in the chain instances. @@ -73,10 +63,9 @@ export default function setup(syscall, state, helpers) { await E(vats.provisioning).registerHTTP(vats.http); const provisioner = harden({ - pleaseProvision(nickname, pubkey, ingress) { - ingress = ingress || 1; - console.log('Provisioning', nickname, pubkey, ingress); - return E(vats.provisioning).pleaseProvision(nickname, pubkey, ingress); + pleaseProvision(nickname, pubkey) { + console.log('Provisioning', nickname, pubkey); + return E(vats.provisioning).pleaseProvision(nickname, pubkey); }, }); @@ -85,7 +74,7 @@ export default function setup(syscall, state, helpers) { await E(vats.comms).addEgress(bootAddress, 1, provisioner); } chainProvisioner = provisioner; - } else if (GCI) { + } else if (ROLES.controller && GCI) { // Create a presence for the on-chain provisioner. chainProvisioner = await E(vats.comms).addIngress(GCI, 1); } @@ -93,8 +82,8 @@ export default function setup(syscall, state, helpers) { if (ROLES.controller) { // Allow web requests to call our provisioner. const provisioner = harden({ - pleaseProvision(nickname, pubkey, ingress) { - return E(chainProvisioner).pleaseProvision(nickname, pubkey, ingress); + pleaseProvision(nickname, pubkey) { + return E(chainProvisioner).pleaseProvision(nickname, pubkey); }, }); await E(vats.http).setProvisioner(provisioner); @@ -105,13 +94,10 @@ export default function setup(syscall, state, helpers) { await E(vats.http).setPresences({ chain: chainProvisioner }); let chainDemoRoot; - if (GCI) { - const { ingressIndex } = await E( - chainProvisioner, - ).pleaseProvision('client', bootAddress, 2); - chainDemoRoot = await E(vats.comms).addIngress(GCI, ingressIndex); - } else { + if (ROLES.chain) { chainDemoRoot = demoRoot; + } else { + chainDemoRoot = await E(vats.comms).addIngress(GCI, 1); } const bundle = await E(chainDemoRoot).getChainBundle(); await E(vats.http).setPresences(bundle); diff --git a/lib/ag-solo/vats/vat-demo.js b/lib/ag-solo/vats/vat-demo.js index d8e4da23b0b..ef6a4d5ebac 100644 --- a/lib/ag-solo/vats/vat-demo.js +++ b/lib/ag-solo/vats/vat-demo.js @@ -20,11 +20,11 @@ function build(E, log) { let sharedHandoffService; let sharedDustIssuer; - async function startup(saver) { + async function startup(http) { // define shared resources function stateChangeHandler(newState) { - return E(saver).saveCanvas(newState); + E(http).updateCanvas(newState); } const canvasSize = 10; @@ -33,7 +33,6 @@ function build(E, log) { const issuers = await E(gallery.userFacet).getIssuers(); sharedDustIssuer = issuers.dustIssuer; sharedHandoffService = makeHandoffService(); - await stateChangeHandler(await E(gallery.readFacet).getState()); } async function getChainBundle(_nickname) { diff --git a/lib/ag-solo/vats/vat-http.js b/lib/ag-solo/vats/vat-http.js index 168ad8a02a5..937238a6665 100644 --- a/lib/ag-solo/vats/vat-http.js +++ b/lib/ag-solo/vats/vat-http.js @@ -10,7 +10,6 @@ import { addReplHandler } from './repl'; function build(E, D) { let commandDevice; let provisioner; - let canvasState; const homeObjects = {}; let handler = {}; @@ -23,12 +22,6 @@ function build(E, D) { addReplHandler(handler, E, homeObjects, msg => D(commandDevice).sendBroadcast(msg), ); - handler.getCanvasState = () => { - if (!canvasState) { - return null; - } - return { type: 'updateCanvas', state: canvasState }; - }; } if (ROLES.controller) { handler.pleaseProvision = obj => { @@ -38,12 +31,6 @@ function build(E, D) { } }, - updateCanvasState(state) { - canvasState = state; - console.log(`Have canvasState`, state); - D(commandDevice).sendBroadcast({ type: 'updateCanvas', state }); - }, - setProvisioner(p) { provisioner = p; }, @@ -52,6 +39,10 @@ function build(E, D) { Object.assign(homeObjects, ps); }, + updateCanvas(canvas) { + D(commandDevice).sendBroadcast({ type: 'updateCanvas', state: canvas }); + }, + // devices.command invokes our inbound() because we passed to // registerInboundHandler() inbound(count, obj) { diff --git a/lib/ag-solo/vats/vat-provisioning.js b/lib/ag-solo/vats/vat-provisioning.js index 8d637695f5e..3aaf002f97a 100644 --- a/lib/ag-solo/vats/vat-provisioning.js +++ b/lib/ag-solo/vats/vat-provisioning.js @@ -21,7 +21,7 @@ function build(E) { http = h; } - async function pleaseProvision(nickname, pubkey, INDEX) { + async function pleaseProvision(nickname, pubkey) { const chainBundle = E(demo).getChainBundle(nickname); const fetch = harden({ getChainBundle() { @@ -30,7 +30,7 @@ function build(E) { }); // Add an egress for the pubkey. - INDEX = Number(INDEX) || 1; + const INDEX = 1; await E(comms).addEgress(pubkey, INDEX, fetch); return { ingressIndex: INDEX }; } diff --git a/lib/launch-chain.js b/lib/launch-chain.js index 1bf0ca4fbea..e5ad2fb2cdf 100644 --- a/lib/launch-chain.js +++ b/lib/launch-chain.js @@ -6,7 +6,6 @@ const { buildVatController, buildMailboxStateMap, buildMailbox, - buildStorage, getVatTPSourcePath, } = require('@agoric/swingset-vat'); @@ -18,11 +17,7 @@ async function buildSwingset(withSES, oldState, vatsDir, argv) { mbs.populateFromData(oldState.mailbox); } const mb = buildMailbox(mbs); - const st = buildStorage(oldState && oldState.user || {}); - config.devices = [ - ['mailbox', mb.srcPath, mb.endowments], - ['storage', st.srcPath, st.endowments], - ]; + config.devices = [['mailbox', mb.srcPath, mb.endowments]]; config.vatSources = new Map(); for (const fname of readdirSync(vatsDir)) { const match = fname.match(/^vat-(.*)\.js$/); @@ -47,7 +42,7 @@ async function buildSwingset(withSES, oldState, vatsDir, argv) { await controller.run(); } - return { controller, mb, mbs, st }; + return { controller, mb, mbs }; } export async function launch(vatsDir, argv) { @@ -70,7 +65,7 @@ export async function launch(vatsDir, argv) { } console.log(`buildSwingset`); - const { controller, inbound, mb, mbs, st } = await buildSwingset( + const { controller, inbound, mb, mbs } = await buildSwingset( withSES, oldState, vatsDir, @@ -81,10 +76,8 @@ export async function launch(vatsDir, argv) { // checkpoint kernel and whole-mailbox state const kernelStateData = djson.stringify(controller.getState()); const mailboxStateData = djson.stringify(mbs.exportToData()); - const userStateData = djson.stringify(st.getState()); storage.set(`kernel`, kernelStateData); storage.set(`mailbox`, mailboxStateData); - storage.set(`user`, userStateData); console.log( `checkpointed kernel state: k: ${kernelStateData.length}, m: ${mailboxStateData.length}`, );