Skip to content

Commit

Permalink
fix: correct and simplify the bootstrap process
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Aug 23, 2020
1 parent bf1b55f commit cb95764
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 115 deletions.
15 changes: 3 additions & 12 deletions packages/cosmic-swingset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ t1-provision-one:

# Actually start the ag-solo.
t1-start-ag-solo:
cd t1/$(BASE_PORT) && ../../bin/ag-solo start --role=two_client
cd t1/$(BASE_PORT) && ../../bin/ag-solo start

# scenario3 is a single JS process without any Golang. However,
# the client and the chain within the process run two separate
Expand All @@ -131,17 +131,8 @@ scenario3-run-client: scenario3-run
# Set the fake chain here in case the delay has changed.
scenario3-run:
(cd t3 && \
../bin/ag-solo set-fake-chain --role=two_chain --delay=$(FAKE_CHAIN_DELAY) mySimGCI)
cd t3 && ../bin/ag-solo start --role=two_client

# These rules are the old scenario3. No fake delay at all.
# It's generally better to use the new scenario3.
deprecated-scenario3-setup:
rm -rf t3
bin/ag-solo init t3 --egresses=none

deprecated-scenario3-run-client:
cd t3 && ../bin/ag-solo start --role=three_client
../bin/ag-solo set-fake-chain --delay=$(FAKE_CHAIN_DELAY) mySimGCI)
cd t3 && ../bin/ag-solo start

docker-pull:
for f in '' -pserver -setup -setup-solo -solo; do \
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/bin/ag-nchainz
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ start-solos)

$SOLO set-gci-ingress --chainID="$chainid" "$gci" "$rpcport"

DEBUG=agoric $SOLO start --role=two_client
DEBUG=agoric $SOLO start
) >>nchainz/logs/$log 2>&1 &
done
sleep 2
Expand Down
6 changes: 3 additions & 3 deletions packages/cosmic-swingset/docker/ag-setup-solo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SOLO_NAME=${SOLO_NAME-agoric}
SOLO_HOME=${SOLO_HOME-$SOLO_NAME}
PORT=${PORT-8000}
HOST_PORT=${HOST_PORT-$PORT}
IMAGE=agoric/cosmic-swingset-solo
IMAGE=agoric/cosmic-swingset-solo:latest
case "$1" in
--pull)
shift
Expand All @@ -16,12 +16,12 @@ if test "$1" = shell; then
ARGS=
shift
else
set dummy --webport=$PORT --webhost=0.0.0.0 ${1+"$@"}
set dummy setup --webport=$PORT --webhost=0.0.0.0 ${1+"$@"}
shift
fi
exec docker run \
-p127.0.0.1:$HOST_PORT:$PORT \
--volume=ag-solo-state:/usr/src/app/solo \
-eAG_SOLO_BASEDIR="$SOLO_HOME" \
--rm -it $FLAGS \
"$IMAGE" setup ${1+"$@"}
"$IMAGE" ${1+"$@"}
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/lib/ag-solo/fake-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function connectToFakeChain(basedir, GCI, role, delay, inbound) {

const vatsdir = path.join(basedir, 'vats');
const argv = [
`--role=${role}`,
`--role=sim-chain`,
`--give-me-all-the-agoric-powers`,
bootAddress,
];
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/lib/ag-solo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ start
return;
}
if (!fs.existsSync(AG_SOLO_BASEDIR)) {
await solo(progname, ['init', AG_SOLO_BASEDIR, ...rawArgv.slice(1)]);
await solo(progname, ['init', AG_SOLO_BASEDIR, ...argv.slice(1)]);
}
process.chdir(AG_SOLO_BASEDIR);
await solo(progname, ['add-chain', netconfig]);
Expand Down
66 changes: 7 additions & 59 deletions packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function parseArgs(argv) {
}
});
if (!gotRoles) {
ROLE = 'three_client';
ROLE = 'client';
}

return { ROLE, giveMeAllTheAgoricPowers, hardcodedClientAddresses };
Expand Down Expand Up @@ -112,7 +112,7 @@ export function buildRootObject(vatPowers, vatParameters) {
}

const additionalPowers = {};
if (powerFlags.includes('agoric.vattp')) {
if (powerFlags && powerFlags.includes('agoric.vattp')) {
// Give the authority to create a new host for vattp to share objects with.
additionalPowers.vattp = makeVattpFrom(vats);
}
Expand Down Expand Up @@ -311,8 +311,7 @@ export function buildRootObject(vatPowers, vatParameters) {
// localhost, with HTML frontend. Multi-player mode.
switch (ROLE) {
// REAL VALIDATORS run this.
case 'chain':
case 'one_chain': {
case 'chain': {
// provisioning vat can ask the demo server for bundles, and can
// register client pubkeys with comms
await E(vats.provisioning).register(
Expand All @@ -325,9 +324,9 @@ export function buildRootObject(vatPowers, vatParameters) {
await registerNetworkProtocols(vats, bridgeManager);
break;
}

// ag-setup-solo runs this.
case 'client':
case 'one_client': {
case 'client': {
if (!GCI) {
throw new Error(`client must be given GCI`);
}
Expand All @@ -354,11 +353,9 @@ export function buildRootObject(vatPowers, vatParameters) {
});
break;
}
case 'two_chain': {
// scenario #2: one-node chain running on localhost, solo node on
// localhost, HTML frontend on localhost. Single-player mode.

// bootAddress holds the pubkey of localclient
// fake-chain runs this
case 'sim-chain': {
const chainBundler = await makeChainBundler(
vats,
devices.timer,
Expand Down Expand Up @@ -407,55 +404,6 @@ export function buildRootObject(vatPowers, vatParameters) {

break;
}
case 'two_client': {
if (!GCI) {
throw new Error(`client must be given GCI`);
}
await setupCommandDevice(vats.http, devices.command, {
client: true,
});
const localTimerService = await E(vats.timer).createTimerService(
devices.timer,
);
await registerNetworkProtocols(vats, bridgeManager);
await addRemote(GCI);
// addEgress(..., PROVISIONER_INDEX) is called in case two_chain
const demoProvider = E(vats.comms).addIngress(GCI, PROVISIONER_INDEX);
// Get the demo bundle from the chain-side provider
const localBundle = await createLocalBundle(vats);
await E(vats.http).setPresences(localBundle);
const bundle = await E(demoProvider).getDemoBundle('client');
await E(vats.http).setPresences(localBundle, bundle, {
localTimerService,
});
break;
}
case 'three_client': {
// scenario #3: no chain. solo node on localhost with HTML
// frontend. Limited subset of demo runs inside the solo node.

// We pretend we're on-chain.
const chainBundler = makeChainBundler(
vats,
devices.timer,
vatAdminSvc,
);
await registerNetworkProtocols(vats, bridgeManager);

// Shared Setup (virtual chain side) ///////////////////////////
await setupCommandDevice(vats.http, devices.command, {
client: true,
});
const localBundle = await createLocalBundle(vats);
await E(vats.http).setPresences(localBundle);
const bundle = await E(chainBundler).createUserBundle('localuser');

// Setup of the Local part /////////////////////////////////////
await E(vats.http).setPresences(localBundle, bundle, {
localTimerService: bundle.chainTimerService,
});
break;
}
default:
throw new Error(`ROLE was not recognized: ${ROLE}`);
}
Expand Down
6 changes: 0 additions & 6 deletions packages/cosmic-swingset/lib/ag-solo/vats/chain-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
"host": {
"sourceSpec": "vat-host.js"
},
"http": {
"sourceSpec": "vat-http.js"
},
"ibc": {
"sourceSpec": "vat-ibc.js"
},
Expand All @@ -33,9 +30,6 @@
"sharing": {
"sourceSpec": "vat-sharing.js"
},
"uploads": {
"sourceSpec": "vat-uploads.js"
},
"zoe": {
"sourceSpec": "vat-zoe.js",
"parameters": {
Expand Down
29 changes: 0 additions & 29 deletions packages/cosmic-swingset/lib/ag-solo/vats/solo-config.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,18 @@
{
"bootstrap": "bootstrap",
"bundles": {
"zcf": {
"sourceSpec": "@agoric/zoe/contractFacet"
}
},
"vats": {
"board": {
"sourceSpec": "vat-board.js"
},
"host": {
"sourceSpec": "vat-host.js"
},
"http": {
"sourceSpec": "vat-http.js"
},
"ibc": {
"sourceSpec": "vat-ibc.js"
},
"mints": {
"sourceSpec": "vat-mints.js"
},
"network": {
"sourceSpec": "vat-network.js"
},
"provisioning": {
"sourceSpec": "vat-provisioning.js"
},
"registrar": {
"sourceSpec": "vat-registrar.js"
},
"sharing": {
"sourceSpec": "vat-sharing.js"
},
"uploads": {
"sourceSpec": "vat-uploads.js"
},
"zoe": {
"sourceSpec": "vat-zoe.js",
"parameters": {
"zcfBundleName": "zcf"
}
},
"bootstrap": {
"sourceSpec": "bootstrap.js"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cosmic-swingset/lib/ag-solo/vats/vat-provisioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function buildRootObject(_vatPowers) {
vattp = v;
}

async function pleaseProvision(nickname, pubkey, powerFlags = []) {
async function pleaseProvision(nickname, pubkey, powerFlags) {
let chainBundle;
const fetch = harden({
getDemoBundle() {
Expand All @@ -32,7 +32,7 @@ export function buildRootObject(_vatPowers) {

// Do this here so that any side-effects don't happen unless
// the egress has been successfully added.
chainBundle = E(bundler).createUserBundle(nickname, powerFlags);
chainBundle = E(bundler).createUserBundle(nickname, powerFlags || []);
return { ingressIndex: INDEX };
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/lib/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const AG_COSMOS_INIT = 'AG_COSMOS_INIT';

export default async function main(progname, args, { path, env, agcc }) {
const bootAddress = env.BOOT_ADDRESS;
const role = env.ROLE || 'chain';
const role = 'chain';

const portNums = {};

Expand Down

0 comments on commit cb95764

Please sign in to comment.