Skip to content

Commit a1e815b

Browse files
committed
fix: tweak the config.toml for local-chain
1 parent 15165b4 commit a1e815b

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

packages/agoric-cli/lib/start.js

+43-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import path from 'path';
22
import chalk from 'chalk';
33
import { createHash } from 'crypto';
44
import djson from 'deterministic-json';
5+
import TOML from '@iarna/toml';
56

67
const PROVISION_PASSES = '100provisionpass';
78
const DELEGATE0_STAKE = '100000000uagstake';
89
const CHAIN_ID = 'agoric';
10+
11+
// This should be configurable.
912
const CHAIN_PORT = 26657;
1013

1114
const FAKE_CHAIN_DELAY =
@@ -42,6 +45,24 @@ export default async function startMain(progname, rawArgs, powers, opts) {
4245
await fs.writeFile(hashFile, gci);
4346
};
4447

48+
const finishConfig = async (configfile, portNum) => {
49+
// Fix up the server.toml file.
50+
log('finishing', configfile);
51+
const configtoml = await fs.readFile(configfile, 'utf-8');
52+
const config = TOML.parse(configtoml);
53+
54+
const rpcPort = Number(portNum);
55+
config.proxy_app = `kvstore`;
56+
config.rpc.laddr = `tcp://127.0.0.1:${rpcPort}`;
57+
config.p2p.laddr = `tcp://0.0.0.0:${rpcPort - 1}`;
58+
59+
// Make blocks run faster than normal.
60+
config.consensus.timeout_propose = '2s';
61+
config.consensus.timeout_commit = '2s';
62+
63+
await fs.writeFile(configfile, TOML.stringify(config));
64+
};
65+
4566
const pspawnEnv = { ...process.env };
4667
const pspawn = (
4768
cmd,
@@ -189,13 +210,26 @@ export default async function startMain(progname, rawArgs, powers, opts) {
189210
async function startLocalChain(profileName, startArgs, popts) {
190211
const IMAGE = `agoric/agoric-sdk`;
191212

213+
const portNum = startArgs[0] === undefined ? CHAIN_PORT : startArgs[0];
214+
if (`${portNum}` !== `${Number(portNum)}`) {
215+
log.error(`Argument to local-chain must be a port number`);
216+
return 1;
217+
}
218+
agServer += `-${portNum}`;
219+
192220
if (popts.pull) {
193221
const status = await pspawn('docker', ['pull', IMAGE]);
194222
if (status) {
195223
return status;
196224
}
197225
}
198226

227+
if (popts.reset) {
228+
log(chalk.green(`removing ${agServer}`));
229+
// rm is available on all the unix-likes, so use it for speed.
230+
await pspawn('rm', ['-rf', agServer]);
231+
}
232+
199233
let chainSpawn;
200234
if (popts.sdk) {
201235
chainSpawn = (args, spawnOpts = undefined) =>
@@ -302,13 +336,14 @@ export default async function startMain(progname, rawArgs, powers, opts) {
302336

303337
// Complete the genesis file and launch the chain.
304338
await finishGenesis(genfile);
339+
await finishConfig(`${agServer}/config/config.toml`, portNum);
305340
return chainSpawn(
306341
['start', '--pruning=nothing'],
307342
{
308343
env: { ...process.env, ROLE: 'two_chain' },
309344
},
310345
// Accessible via either localhost or host.docker.internal
311-
[`--publish=${CHAIN_PORT}:${CHAIN_PORT}`, `--name=agoric/n0`],
346+
[`--publish=${portNum}:${portNum}`, `--name=agoric/n0`],
312347
);
313348
}
314349

@@ -322,6 +357,13 @@ export default async function startMain(progname, rawArgs, powers, opts) {
322357
}
323358
agServer += `-${portNum}`;
324359

360+
if (popts.pull) {
361+
const status = await pspawn('docker', ['pull', IMAGE]);
362+
if (status) {
363+
return status;
364+
}
365+
}
366+
325367
if (popts.reset) {
326368
log(chalk.green(`removing ${agServer}`));
327369
// rm is available on all the unix-likes, so use it for speed.

packages/agoric-cli/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@agoric/evaluate": "^2.2.6",
2828
"@agoric/eventual-send": "^0.9.2",
2929
"@agoric/produce-promise": "^0.1.2",
30+
"@iarna/toml": "^2.2.3",
3031
"anylogger": "^0.21.0",
3132
"builtin-modules": "^3.1.0",
3233
"chalk": "^2.4.2",

0 commit comments

Comments
 (0)