Skip to content

Commit

Permalink
feat(cosmic-swingset): xs-worker option in ag-solo, chain
Browse files Browse the repository at this point in the history
 - ag-solo --defaultManagerType option
 - default to env.WORKER_TYPE in initBasedir()
  • Loading branch information
dckc committed Mar 30, 2021
1 parent 973b403 commit cbf8e56
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ t1-start-ag-solo:
#
# If you still want the client/chain separation without delay,
# then run: make scenario3-setup FAKE_CHAIN_DELAY=0
VATWORKER=local
scenario3-setup:
rm -rf t3
bin/ag-solo init t3 --egresses=fake --webport=$(BASE_PORT)
bin/ag-solo init t3 --egresses=fake --webport=$(BASE_PORT) --defaultManagerType=$(VATWORKER)
@echo 'Execute `make scenario3-run` to run the client and simulated chain'

# This runs both the client and the fake chain.
Expand Down
10 changes: 8 additions & 2 deletions packages/cosmic-swingset/lib/ag-solo/init-basedir.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global __dirname Buffer */
/* global __dirname Buffer process */
import fs from 'fs';
import path from 'path';
import { execFileSync } from 'child_process';
Expand All @@ -18,8 +18,14 @@ export default function initBasedir(
egresses,
opts = {},
) {
const { wallet = DEFAULT_WALLET, ...options } = opts;
const { env = process.environment } = opts;
const {
wallet = DEFAULT_WALLET,
defaultManagerType = env.WORKER_TYPE || 'local',
...options
} = opts;
options.wallet = wallet;
options.defaultManagerType = defaultManagerType;

const here = __dirname;
// We either need a basedir with an initialised key, or no basedir.
Expand Down
1 change: 1 addition & 0 deletions packages/cosmic-swingset/lib/ag-solo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ start
webport: '8000',
webhost: '127.0.0.1',
egresses: DEFAULT_EGRESSES,
defaultManagerType: process.env.WORKER_TYPE || 'local',
},
});
const webport = Number(subOpts.webport);
Expand Down
11 changes: 9 additions & 2 deletions packages/cosmic-swingset/lib/ag-solo/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ async function buildSwingset(
vatsDir,
argv,
broadcast,
defaultManagerType,
) {
const initialMailboxState = JSON.parse(fs.readFileSync(mailboxStateFile));

Expand Down Expand Up @@ -143,6 +144,9 @@ async function buildSwingset(
const { storage, commit } = openSwingStore(kernelStateDBDir);

if (!swingsetIsInitialized(storage)) {
if (defaultManagerType && !config.defaultManagerType) {
config.defaultManagerType = defaultManagerType;
}
await initializeSwingset(config, argv, storage);
}
const controller = await makeSwingsetController(storage, deviceEndowments);
Expand Down Expand Up @@ -277,6 +281,10 @@ export default async function start(basedir, argv) {
}
}

const { wallet, defaultManagerType } = JSON.parse(
fs.readFileSync('options.json', 'utf-8'),
);

const vatsDir = path.join(basedir, 'vats');
const stateDBDir = path.join(basedir, 'swingset-kernel-state');
const d = await buildSwingset(
Expand All @@ -285,6 +293,7 @@ export default async function start(basedir, argv) {
vatsDir,
argv,
broadcast,
defaultManagerType,
);

const {
Expand All @@ -298,8 +307,6 @@ export default async function start(basedir, argv) {
// Remove wallet traces.
await unlink('html/wallet').catch(_ => {});

const { wallet } = JSON.parse(fs.readFileSync('options.json', 'utf-8'));

// Symlink the wallet.
const pjs = require.resolve(`${wallet}/package.json`);
const {
Expand Down

0 comments on commit cbf8e56

Please sign in to comment.