@@ -2,10 +2,13 @@ import path from 'path';
2
2
import chalk from 'chalk' ;
3
3
import { createHash } from 'crypto' ;
4
4
import djson from 'deterministic-json' ;
5
+ import TOML from '@iarna/toml' ;
5
6
6
7
const PROVISION_PASSES = '100provisionpass' ;
7
8
const DELEGATE0_STAKE = '100000000uagstake' ;
8
9
const CHAIN_ID = 'agoric' ;
10
+
11
+ // This should be configurable.
9
12
const CHAIN_PORT = 26657 ;
10
13
11
14
const FAKE_CHAIN_DELAY =
@@ -42,6 +45,24 @@ export default async function startMain(progname, rawArgs, powers, opts) {
42
45
await fs . writeFile ( hashFile , gci ) ;
43
46
} ;
44
47
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
+
45
66
const pspawnEnv = { ...process . env } ;
46
67
const pspawn = (
47
68
cmd ,
@@ -189,13 +210,26 @@ export default async function startMain(progname, rawArgs, powers, opts) {
189
210
async function startLocalChain ( profileName , startArgs , popts ) {
190
211
const IMAGE = `agoric/agoric-sdk` ;
191
212
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
+
192
220
if ( popts . pull ) {
193
221
const status = await pspawn ( 'docker' , [ 'pull' , IMAGE ] ) ;
194
222
if ( status ) {
195
223
return status ;
196
224
}
197
225
}
198
226
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
+
199
233
let chainSpawn ;
200
234
if ( popts . sdk ) {
201
235
chainSpawn = ( args , spawnOpts = undefined ) =>
@@ -302,13 +336,14 @@ export default async function startMain(progname, rawArgs, powers, opts) {
302
336
303
337
// Complete the genesis file and launch the chain.
304
338
await finishGenesis ( genfile ) ;
339
+ await finishConfig ( `${ agServer } /config/config.toml` , portNum ) ;
305
340
return chainSpawn (
306
341
[ 'start' , '--pruning=nothing' ] ,
307
342
{
308
343
env : { ...process . env , ROLE : 'two_chain' } ,
309
344
} ,
310
345
// Accessible via either localhost or host.docker.internal
311
- [ `--publish=${ CHAIN_PORT } :${ CHAIN_PORT } ` , `--name=agoric/n0` ] ,
346
+ [ `--publish=${ portNum } :${ portNum } ` , `--name=agoric/n0` ] ,
312
347
) ;
313
348
}
314
349
@@ -322,6 +357,13 @@ export default async function startMain(progname, rawArgs, powers, opts) {
322
357
}
323
358
agServer += `-${ portNum } ` ;
324
359
360
+ if ( popts . pull ) {
361
+ const status = await pspawn ( 'docker' , [ 'pull' , IMAGE ] ) ;
362
+ if ( status ) {
363
+ return status ;
364
+ }
365
+ }
366
+
325
367
if ( popts . reset ) {
326
368
log ( chalk . green ( `removing ${ agServer } ` ) ) ;
327
369
// rm is available on all the unix-likes, so use it for speed.
0 commit comments