Skip to content

Commit

Permalink
feat(solo): fully-working ag-solo package
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Apr 25, 2021
1 parent 3525283 commit 57ea595
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 78 deletions.
2 changes: 1 addition & 1 deletion packages/solo/bin/ag-solo
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ while test $# -gt 0; do
shift
done

exec node ${nodeFlags[@]} "$thisdir/../lib/ag-solo/entrypoint.js" ${1+"$@"}
exec node ${nodeFlags[@]} "$thisdir/../src/entrypoint.cjs" ${1+"$@"}
18 changes: 18 additions & 0 deletions packages/solo/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This file can contain .js-specific Typescript compiler config.
{
"compilerOptions": {
"target": "esnext",

"noEmit": true,
/*
// The following flags are for creating .d.ts files:
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true,
*/
"downlevelIteration": true,
"strictNullChecks": true,
"moduleResolution": "node",
},
"include": ["src/**/*.js", "exported.js"],
}
86 changes: 86 additions & 0 deletions packages/solo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"name": "@agoric/solo",
"version": "0.1.0",
"description": "Agoric's Solo vat runner",
"parsers": {
"js": "mjs"
},
"bin": {
"ag-solo": "./src/entrypoint.cjs"
},
"main": "src/main.js",
"repository": "https://github.com/Agoric/agoric-sdk",
"scripts": {
"build": "exit 0",
"test": "ava",
"test:nyc": "nyc ava",
"test:xs": "exit 0",
"pretty-fix": "prettier --write '**/*.js'",
"pretty-check": "prettier --check '**/*.js'",
"lint-fix": "yarn lint:eslint --fix && yarn lint:types",
"lint-check": "yarn lint",
"lint": "yarn lint:types && yarn lint:eslint",
"lint:types": "tsc -p jsconfig.json",
"lint:eslint": "eslint '**/*.js'"
},
"keywords": [],
"author": "Agoric",
"license": "Apache-2.0",
"dependencies": {
"@agoric/assert": "^0.2.8",
"@agoric/captp": "^1.7.9",
"@agoric/cosmic-swingset": "^0.29.3",
"@agoric/dapp-svelte-wallet": "^0.9.3",
"@agoric/eventual-send": "^0.13.10",
"@agoric/import-bundle": "^0.2.10",
"@agoric/install-metering-and-ses": "^0.2.9",
"@agoric/marshal": "^0.4.7",
"@agoric/notifier": "^0.3.10",
"@agoric/promise-kit": "^0.2.9",
"@agoric/spawner": "^0.4.10",
"@agoric/store": "^0.4.10",
"@agoric/swing-store-lmdb": "^0.4.8",
"@agoric/swing-store-simple": "^0.3.6",
"@agoric/swingset-vat": "^0.16.3",
"@agoric/vats": "^0.1.0",
"anylogger": "^0.21.0",
"deterministic-json": "^1.0.5",
"esm": "^3.2.25",
"express": "^4.17.1",
"minimist": "^1.2.0",
"morgan": "^1.9.1",
"node-fetch": "^2.6.0",
"node-lmdb": "^0.9.4",
"temp": "^0.9.1",
"ws": "^7.2.0"
},
"devDependencies": {
"@agoric/bundle-source": "^1.3.3",
"ava": "^3.12.1",
"nyc": "^15.1.0"
},
"eslintConfig": {
"extends": [
"@agoric"
]
},
"prettier": {
"trailingComma": "all",
"singleQuote": true
},
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=11.0"
},
"ava": {
"files": [
"test/**/test-*.js"
],
"require": [
"esm"
],
"timeout": "20m"
}
}
10 changes: 5 additions & 5 deletions packages/solo/solo-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"bootstrap": "bootstrap",
"vats": {
"spawner": {
"sourceSpec": "vat-spawner.js"
"sourceSpec": "./src/vat-spawner.js"
},
"http": {
"sourceSpec": "vat-http.js"
"sourceSpec": "./src/vat-http.js"
},
"network": {
"sourceSpec": "vat-network.js"
"sourceSpec": "@agoric/vats/src/vat-network.js"
},
"uploads": {
"sourceSpec": "vat-uploads.js"
"sourceSpec": "./src/vat-uploads.js"
},
"bootstrap": {
"sourceSpec": "bootstrap.js"
"sourceSpec": "@agoric/vats/src/bootstrap.js"
}
}
}
2 changes: 1 addition & 1 deletion packages/solo/src/chain-cosmos-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { makeNotifierKit } from '@agoric/notifier';
import { makePromiseKit } from '@agoric/promise-kit';

import { assert, details as X } from '@agoric/assert';
import { makeBatchedDeliver } from './batched-deliver';
import { makeBatchedDeliver } from '@agoric/vats/src/batched-deliver';

const log = anylogger('chain-cosmos-sdk');

Expand Down
2 changes: 1 addition & 1 deletion packages/solo/src/entrypoint.cjs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ esmRequire('@agoric/install-metering-and-ses');
const process = require('process');

// Configure logs.
esmRequire('../anylogger-agoric.js');
esmRequire('@agoric/cosmic-swingset/src/anylogger-agoric.js');
const solo = esmRequire('./main.js').default;

solo(process.argv[1], process.argv.splice(2)).then(
Expand Down
33 changes: 2 additions & 31 deletions packages/solo/src/init-basedir.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,15 @@ export default function initBasedir(
path.join(basedir, 'connections.json'),
`${JSON.stringify(connections)}\n`,
);
const srcHtmldir = path.join(here, 'html');
const dstHtmldir = path.join(basedir, 'html');
fs.mkdirSync(dstHtmldir);
fs.readdirSync(srcHtmldir)
.filter(name => name.match(/^[^.]/))
.forEach(name => {
fs.copyFileSync(path.join(srcHtmldir, name), path.join(dstHtmldir, name));
});

// Save the configuration options.
fs.writeFileSync(path.join(basedir, 'options.json'), JSON.stringify(options));

// Save our version codes.
const pj = 'package.json';
fs.copyFileSync(path.join(`${here}/../..`, pj), path.join(dstHtmldir, pj));
fs.copyFileSync(path.join(`${here}/..`, pj), path.join(dstHtmldir, pj));
const gr = 'git-revision.txt';
try {
fs.copyFileSync(path.join(`${here}/..`, gr), path.join(dstHtmldir, gr));
Expand All @@ -71,29 +65,6 @@ export default function initBasedir(
fs.writeFileSync(path.join(dstHtmldir, gr), revision);
}

const srcVatdir = subdir
? path.join(here, 'vats', subdir)
: path.join(here, 'vats');
const dstVatdir = path.join(basedir, 'vats');
fs.mkdirSync(dstVatdir);
fs.readdirSync(srcVatdir)
.filter(name => name.match(/\.(js|json)$/))
.forEach(name => {
fs.copyFileSync(path.join(srcVatdir, name), path.join(dstVatdir, name));
});

// Enable our node_modules to be found.
let dots = '';
let nm = path.resolve(here, dots, 'node_modules');
while (
!nm.startsWith('/node_modules/') &&
!fs.existsSync(path.join(nm, '@agoric'))
) {
dots += '../';
nm = path.resolve(here, dots, 'node_modules');
}
fs.symlinkSync(nm, path.join(basedir, 'node_modules'), 'junction');

// cosmos-sdk keypair
if (egresses.includes('cosmos')) {
const agchServerDir = path.join(basedir, 'ag-cosmos-helper-statedir');
Expand Down Expand Up @@ -144,7 +115,7 @@ export default function initBasedir(

// this marker file is how we recognize ag-solo basedirs
fs.copyFileSync(
path.join(here, 'solo-README-to-install.md'),
path.join(here, '..', 'solo-README-to-install.md'),
path.join(basedir, 'solo-README.md'),
);

Expand Down
2 changes: 1 addition & 1 deletion packages/solo/src/reset-state.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import fs from 'fs';

import { getBestSwingStore } from '../check-lmdb';
import { getBestSwingStore } from '@agoric/swing-store-lmdb/check-lmdb';

export default async function resetState(basedir) {
const mailboxStateFile = path.resolve(
Expand Down
6 changes: 0 additions & 6 deletions packages/solo/src/set-fake-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,4 @@ export default function setFakeChain(basedir, GCI, fakeDelay) {
connections.push(...conns),
);
fs.writeFileSync(fn, `${JSON.stringify(connections, undefined, 2)}\n`);

const gciFileContents = `\
export const GCI = ${JSON.stringify(GCI)};
`;
const bfn = path.join(basedir, 'vats', 'gci.js');
fs.writeFileSync(bfn, gciFileContents);
}
17 changes: 5 additions & 12 deletions packages/solo/src/start.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global require process setTimeout */
/* global __dirname require process setTimeout */
import fs from 'fs';
import path from 'path';
import temp from 'temp';
Expand All @@ -13,7 +13,6 @@ import anylogger from 'anylogger';

import { assert, details as X } from '@agoric/assert';
import {
loadBasedir,
loadSwingsetConfigFile,
buildCommand,
swingsetIsInitialized,
Expand All @@ -24,14 +23,14 @@ import {
buildPlugin,
buildTimer,
} from '@agoric/swingset-vat';
import { getBestSwingStore } from '../check-lmdb';
import { getBestSwingStore } from '@agoric/swing-store-lmdb/check-lmdb';
import { connectToFakeChain } from '@agoric/cosmic-swingset/src/sim-chain';
import { makeWithQueue } from '@agoric/vats/src/queue';

import { deliver, addDeliveryTarget } from './outbound';
import { makeHTTPListener } from './web';
import { makeWithQueue } from './vats/queue';

import { connectToChain } from './chain-cosmos-sdk';
import { connectToFakeChain } from './fake-chain';

const log = anylogger('start');

Expand Down Expand Up @@ -78,7 +77,6 @@ async function atomicReplaceFile(filename, contents) {
async function buildSwingset(
kernelStateDBDir,
mailboxStateFile,
vatsDir,
argv,
broadcast,
defaultManagerType,
Expand Down Expand Up @@ -114,10 +112,7 @@ async function buildSwingset(

const plugin = buildPlugin(pluginDir, pluginRequire, queueThunkForKernel);

let config = loadSwingsetConfigFile(`${vatsDir}/solo-config.json`);
if (config === null) {
config = loadBasedir(vatsDir);
}
const config = loadSwingsetConfigFile(`${__dirname}/../solo-config.json`);
config.devices = {
mailbox: {
sourceSpec: mb.srcPath,
Expand Down Expand Up @@ -285,7 +280,6 @@ export default async function start(basedir, argv) {
fs.readFileSync('options.json', 'utf-8'),
);

const vatsDir = path.join(basedir, 'vats');
const stateDBDir = path.join(basedir, 'swingset-kernel-state');

// FIXME: Replace this functionality with per-connection bootstrap code.
Expand All @@ -304,7 +298,6 @@ export default async function start(basedir, argv) {
const d = await buildSwingset(
stateDBDir,
mailboxStateFile,
vatsDir,
{ ...getLegacyGCI(), ...argv },
broadcast,
defaultManagerType,
Expand Down
2 changes: 1 addition & 1 deletion packages/solo/src/vat-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 { getReplHandler } from '@agoric/vats/src/repl';
import { getCapTPHandler } from './captp';

// This vat contains the HTTP request handler.
Expand Down
3 changes: 2 additions & 1 deletion packages/solo/src/web.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global require setTimeout clearTimeout setInterval clearInterval */
/* global __dirname require setTimeout clearTimeout setInterval clearInterval */
// Start a network service
import path from 'path';
import http from 'http';
Expand Down Expand Up @@ -89,6 +89,7 @@ export async function makeHTTPListener(basedir, port, host, rawInboundCommand) {
const htmldir = path.join(basedir, 'html');
log(`Serving static files from ${htmldir}`);
app.use(express.static(htmldir));
app.use(express.static(`${__dirname}/../public`));

// The rules for validation:
//
Expand Down
20 changes: 8 additions & 12 deletions packages/solo/test/captp-fixture.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global __dirname process setTimeout */
/* global process setTimeout */
import { spawn } from 'child_process';
import WebSocket from 'ws';
import { makeCapTP, E } from '@agoric/captp';

import { getAccessToken } from '../lib/ag-solo/access-token';
import { getAccessToken } from '../src/access-token';

const PORT = 7999;

Expand All @@ -18,16 +18,12 @@ export async function makeFixture(noisy = false) {
const stdio = noisy
? ['ignore', 'inherit', 'inherit']
: ['ignore', 'pipe', 'pipe'];
const cp = spawn(
'make',
['scenario3-setup', 'scenario3-run', `BASE_PORT=${PORT}`],
{
cwd: `${__dirname}/..`,
env: { ...process.env, PORT },
stdio,
detached: true,
},
);
// TODO: Remove dependency on cosmic-swingset.
const cp = spawn('./startsolo.sh', {
env: { ...process.env, PORT },
stdio,
detached: true,
});

if (!noisy) {
cp.stdout.on('data', chunk => (buf += chunk.toString('utf-8')));
Expand Down
13 changes: 8 additions & 5 deletions packages/solo/test/startsolo.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#! /bin/sh
set -e
PORT=${PORT-8000}
rm -rf t3
../bin/ag-solo init t3 --egresses=fake --webport=$PORT --defaultManagerType=local
cd t3
../../bin/ag-solo set-fake-chain --delay=0 mySimGCI
exec ../../bin/ag-solo start
AG_SOLO=$(cd ../src && pwd)/entrypoint.cjs

TDIR="${TMPDIR-/tmp}/startsolo.$$"
trap 'rm -rf "$TDIR"' EXIT
"$AG_SOLO" init "$TDIR" --egresses=fake --webport=$PORT --defaultManagerType=local
cd "$TDIR"
"$AG_SOLO" set-fake-chain --delay=0 mySimGCI
exec "$AG_SOLO" start
2 changes: 1 addition & 1 deletion packages/solo/test/test-home.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import test from 'ava';

import bundleSource from '@agoric/bundle-source';
import { Far } from '@agoric/marshal';
import { CENTRAL_ISSUER_NAME } from '@agoric/vats/src/issuers';

import { makeFixture, E } from './captp-fixture';
import { CENTRAL_ISSUER_NAME } from '../lib/ag-solo/vats/issuers';

// This runs before all the tests.
let home;
Expand Down

0 comments on commit 57ea595

Please sign in to comment.