Skip to content

Commit

Permalink
Revert "wire together 'user' storage device"
Browse files Browse the repository at this point in the history
This reverts commit e2fd5df.
  • Loading branch information
michaelfig committed Jun 15, 2019
1 parent e2fd5df commit e2fe21b
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 111 deletions.
11 changes: 0 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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`

33 changes: 0 additions & 33 deletions lib/ag-solo/chain-cosmos-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -167,7 +145,6 @@ export async function connectToChain(
} catch (e) {
console.log(` failed to parse output:`, e);
}
return undefined;
},
);

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions lib/ag-solo/html/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
1 change: 0 additions & 1 deletion lib/ag-solo/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
48 changes: 17 additions & 31 deletions lib/ag-solo/vats/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,40 @@ 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.
await E(vats.provisioning).register(demoRoot, vats.comms);
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);
},
});

Expand All @@ -85,16 +74,16 @@ 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);
}

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);
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions lib/ag-solo/vats/vat-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
17 changes: 4 additions & 13 deletions lib/ag-solo/vats/vat-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { addReplHandler } from './repl';
function build(E, D) {
let commandDevice;
let provisioner;
let canvasState;
const homeObjects = {};

let handler = {};
Expand All @@ -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 => {
Expand All @@ -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;
},
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/ag-solo/vats/vat-provisioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 };
}
Expand Down
13 changes: 3 additions & 10 deletions lib/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const {
buildVatController,
buildMailboxStateMap,
buildMailbox,
buildStorage,
getVatTPSourcePath,
} = require('@agoric/swingset-vat');

Expand All @@ -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$/);
Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -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}`,
);
Expand Down

0 comments on commit e2fe21b

Please sign in to comment.