@@ -5,6 +5,7 @@ import { createHash } from 'crypto';
5
5
import chalk from 'chalk' ;
6
6
import parseArgs from 'minimist' ;
7
7
import { assert , details as X } from '@agoric/assert' ;
8
+ import { dirname , basename } from 'path' ;
8
9
import { doInit } from './init' ;
9
10
import { shellMetaRegexp , shellEscape } from './run' ;
10
11
import { streamFromString } from './files' ;
@@ -200,6 +201,7 @@ show-config display the client connection parameters
200
201
default : {
201
202
'boot-tokens' : DEFAULT_BOOT_TOKENS ,
202
203
} ,
204
+ string : [ 'bump' , 'import-from' , 'genesis' ] ,
203
205
stopEarly : true ,
204
206
} ,
205
207
) ;
@@ -246,7 +248,7 @@ show-config display the client connection parameters
246
248
case undefined : {
247
249
await wr . createFile ( 'boot-tokens.txt' , bootTokens ) ;
248
250
const bootOpts = [ ] ;
249
- for ( const propagate of [ 'bump' , 'import-from' ] ) {
251
+ for ( const propagate of [ 'bump' , 'import-from' , 'genesis' ] ) {
250
252
const val = subOpts [ propagate ] ;
251
253
if ( val !== undefined ) {
252
254
bootOpts . push ( `--${ propagate } =${ val } ` ) ;
@@ -309,7 +311,7 @@ show-config display the client connection parameters
309
311
await inited ( ) ;
310
312
// eslint-disable-next-line no-unused-vars
311
313
const { _ : subArgs , ...subOpts } = parseArgs ( args . slice ( 1 ) , {
312
- string : [ 'bump' , 'import-from' ] ,
314
+ string : [ 'bump' , 'import-from' , 'genesis' ] ,
313
315
stopEarly : true ,
314
316
} ) ;
315
317
@@ -339,9 +341,18 @@ show-config display the client connection parameters
339
341
await guardFile ( `chain-version.txt` , makeFile => makeFile ( '1' ) ) ;
340
342
341
343
// Assign the chain name.
342
- const networkName = await trimReadFile ( 'network.txt' ) ;
343
- const chainVersion = await trimReadFile ( 'chain-version.txt' ) ;
344
- const chainName = `${ networkName } -${ chainVersion } ` ;
344
+ let chainName ;
345
+ let genJSON ;
346
+ if ( subOpts . genesis ) {
347
+ // Fetch the specified genesis, don't generate it.
348
+ genJSON = await trimReadFile ( subOpts . genesis ) ;
349
+ const genesis = JSON . parse ( genJSON ) ;
350
+ chainName = genesis . chain_id ;
351
+ } else {
352
+ const networkName = await trimReadFile ( 'network.txt' ) ;
353
+ const chainVersion = await trimReadFile ( 'chain-version.txt' ) ;
354
+ chainName = `${ networkName } -${ chainVersion } ` ;
355
+ }
345
356
const currentChainName = await trimReadFile (
346
357
`${ COSMOS_DIR } /chain-name.txt` ,
347
358
) . catch ( _ => undefined ) ;
@@ -363,14 +374,25 @@ show-config display the client connection parameters
363
374
await guardFile ( `${ COSMOS_DIR } /prepare.stamp` , ( ) =>
364
375
needReMain ( [ 'play' , 'prepare-cosmos' ] ) ,
365
376
) ;
366
- await guardFile ( `${ COSMOS_DIR } /genesis.stamp` , ( ) =>
367
- needReMain ( [ 'play' , 'cosmos-genesis' ] ) ,
368
- ) ;
377
+
378
+ // If the canonical genesis exists, use it.
379
+ await guardFile ( `${ COSMOS_DIR } /genesis.stamp` , async ( ) => {
380
+ await wr . mkdir ( `${ COSMOS_DIR } /data` , { recursive : true } ) ;
381
+ if ( genJSON ) {
382
+ await wr . createFile ( `${ COSMOS_DIR } /data/genesis.json` , genJSON ) ;
383
+ } else {
384
+ await guardFile ( `${ COSMOS_DIR } /data/genesis.json` , async ( ) => {
385
+ await needReMain ( [ 'play' , 'cosmos-genesis' ] ) ;
386
+ // Don't overwrite the data/genesis.json.
387
+ return true ;
388
+ } ) ;
389
+ }
390
+ } ) ;
369
391
370
392
await guardFile ( `${ COSMOS_DIR } /set-defaults.stamp` , async ( ) => {
371
393
await needReMain ( [ 'play' , 'cosmos-clone-config' ] ) ;
372
394
373
- const agoricCli = rd . resolve ( __dirname , `../agoric-cli/bin/agoric` ) ;
395
+ const agoricCli = rd . resolve ( __dirname , `../../ agoric-cli/bin/agoric` ) ;
374
396
375
397
// Apply the Agoric set-defaults to all the .dst dirs.
376
398
const files = await rd . readdir ( `${ COSMOS_DIR } /data` ) ;
@@ -397,13 +419,19 @@ show-config display the client connection parameters
397
419
...importFlags ,
398
420
`${ COSMOS_DIR } /data/${ dst } ` ,
399
421
] ) ;
400
- if ( i === 0 ) {
401
- // Make a canonical copy of the genesis.json.
402
- const data = await rd . readFile (
403
- `${ COSMOS_DIR } /data/${ dst } /genesis.json` ,
404
- ) ;
405
- await wr . createFile ( `${ COSMOS_DIR } /data/genesis.json` , data ) ;
422
+ if ( i !== 0 ) {
423
+ return ;
406
424
}
425
+ await guardFile (
426
+ `${ COSMOS_DIR } /data/genesis.json` ,
427
+ async makeGenesis => {
428
+ // Make a canonical copy of the genesis.json if there isn't one.
429
+ const data = await rd . readFile (
430
+ `${ COSMOS_DIR } /data/${ dst } /genesis.json` ,
431
+ ) ;
432
+ await makeGenesis ( data ) ;
433
+ } ,
434
+ ) ;
407
435
} ) ,
408
436
) ;
409
437
} ) ;
@@ -862,6 +890,10 @@ ${name}:
862
890
if ( ! addRole [ role ] ) {
863
891
addRole [ role ] = makeGroup ( role , 4 ) ;
864
892
}
893
+ const keyFile = rd . resolve (
894
+ dirname ( SSH_PRIVATE_KEY_FILE ) ,
895
+ `${ provider } -${ basename ( SSH_PRIVATE_KEY_FILE ) } ` ,
896
+ ) ;
865
897
for ( let instance = 0 ; instance < ips . length ; instance += 1 ) {
866
898
const ip = ips [ instance ] ;
867
899
const node = `${ role } ${ offset + instance } ` ;
@@ -877,7 +909,7 @@ ${name}:
877
909
${ node } :${ roleParams }
878
910
ansible_host: ${ ip }
879
911
ansible_ssh_user: root
880
- ansible_ssh_private_key_file: '${ SSH_PRIVATE_KEY_FILE } '
912
+ ansible_ssh_private_key_file: '${ keyFile } '
881
913
ansible_python_interpreter: /usr/bin/python` ;
882
914
addProvider ( host ) ;
883
915
0 commit comments