@@ -9,83 +9,77 @@ export const BLOCK_CADENCE_S = 2;
9
9
export const ORIG_BLOCK_CADENCE_S = 5 ;
10
10
export const ORIG_SIGNED_BLOCKS_WINDOW = 100 ;
11
11
12
- // Rewrite the config.toml and genesis.json.
13
- export function finishCosmosConfigs ( {
14
- genesisJson,
12
+ // Rewrite the config.toml.
13
+ export function finishCosmosConfig ( {
15
14
configToml,
16
- exportedGenesisJson,
17
15
portNum = '26657' ,
18
16
persistentPeers = '' ,
19
17
} ) {
20
18
const rpcPort = Number ( portNum ) ;
21
- const ret = { } ;
22
-
23
- if ( genesisJson ) {
24
- const genesis = JSON . parse ( genesisJson ) ;
25
- const exported = exportedGenesisJson ? JSON . parse ( exportedGenesisJson ) : { } ;
26
-
27
- genesis . app_state . staking . params . bond_denom = STAKING_DENOM ;
28
-
29
- // We scale this parameter according to our own block cadence, so
30
- // that we tolerate the same downtime as the old genesis.
31
- genesis . app_state . slashing . params . signed_blocks_window = `${ Math . ceil (
32
- ( ORIG_BLOCK_CADENCE_S * ORIG_SIGNED_BLOCKS_WINDOW ) / BLOCK_CADENCE_S ,
33
- ) } `;
34
-
35
- // Zero inflation, for now.
36
- genesis . app_state . mint . minter . inflation = '0.0' ;
37
- genesis . app_state . mint . params . inflation_rate_change = '0.0' ;
38
- genesis . app_state . mint . params . inflation_min = '0.0' ;
39
-
40
- // Set the denomination for different modules.
41
- genesis . app_state . mint . params . mint_denom = MINT_DENOM ;
42
- genesis . app_state . crisis . constant_fee . denom = MINT_DENOM ;
43
- genesis . app_state . gov . deposit_params . min_deposit = GOV_DEPOSIT_COINS ;
44
-
45
- // Reduce the cost of a transaction.
46
- genesis . app_state . auth . params . tx_size_cost_per_byte = '1' ;
47
-
48
- // We upgrade from export data.
49
- const { app_state : exportedAppState = { } } = exported ;
50
- for ( const state of Object . keys ( exportedAppState ) ) {
51
- genesis . app_state [ state ] = exportedAppState [ state ] ;
52
- }
53
-
54
- // Remove IBC and capability state.
55
- // TODO: This needs much more support to preserve contract state
56
- // between exports in order to be able to carry forward IBC conns.
57
- delete genesis . app_state . capability ;
58
- delete genesis . app_state . ibc ;
59
-
60
- // Use the same consensus_params.
61
- if ( 'consensus_params' in exported ) {
62
- genesis . consensus_params = exported . consensus_params ;
63
- }
64
-
65
- // This is necessary until https://github.com/cosmos/cosmos-sdk/issues/6446 is closed.
66
- genesis . consensus_params . block . time_iota_ms = '1000' ;
67
- ret . newGenesisJson = djson . stringify ( genesis ) ;
68
- }
69
19
70
- if ( configToml ) {
71
- // Adjust the config.toml.
72
- const config = TOML . parse ( configToml ) ;
73
- config . proxy_app = 'kvstore' ;
20
+ // Adjust the config.toml.
21
+ const config = TOML . parse ( configToml ) ;
22
+ config . proxy_app = 'kvstore' ;
23
+
24
+ // Enforce our inter-block delays for this node.
25
+ config . consensus . timeout_commit = `${ BLOCK_CADENCE_S } s` ;
26
+
27
+ // Update addresses in the config.
28
+ config . p2p . laddr = `tcp://0.0.0.0:${ rpcPort - 1 } ` ;
29
+ config . p2p . persistent_peers = persistentPeers ;
30
+ config . rpc . laddr = `tcp://127.0.0.1:${ rpcPort } ` ;
31
+
32
+ // Needed for IBC.
33
+ config . tx_index . index_all_keys = true ;
34
+
35
+ // Stringify the new config.toml.
36
+ return TOML . stringify ( config ) ;
37
+ }
38
+
39
+ // Rewrite/import the genesis.json.
40
+ export function finishCosmosGenesis ( { genesisJson, exportedGenesisJson } ) {
41
+ const genesis = JSON . parse ( genesisJson ) ;
42
+ const exported = exportedGenesisJson ? JSON . parse ( exportedGenesisJson ) : { } ;
43
+
44
+ genesis . app_state . staking . params . bond_denom = STAKING_DENOM ;
45
+
46
+ // We scale this parameter according to our own block cadence, so
47
+ // that we tolerate the same downtime as the old genesis.
48
+ genesis . app_state . slashing . params . signed_blocks_window = `${ Math . ceil (
49
+ ( ORIG_BLOCK_CADENCE_S * ORIG_SIGNED_BLOCKS_WINDOW ) / BLOCK_CADENCE_S ,
50
+ ) } `;
74
51
75
- // Enforce our inter-block delays for this node.
76
- config . consensus . timeout_commit = `${ BLOCK_CADENCE_S } s` ;
52
+ // Zero inflation, for now.
53
+ genesis . app_state . mint . minter . inflation = '0.0' ;
54
+ genesis . app_state . mint . params . inflation_rate_change = '0.0' ;
55
+ genesis . app_state . mint . params . inflation_min = '0.0' ;
77
56
78
- // Update addresses in the config.
79
- config . p2p . laddr = `tcp://0.0.0.0:${ rpcPort - 1 } ` ;
80
- config . p2p . persistent_peers = persistentPeers ;
81
- config . rpc . laddr = `tcp://127.0.0.1:${ rpcPort } ` ;
57
+ // Set the denomination for different modules.
58
+ genesis . app_state . mint . params . mint_denom = MINT_DENOM ;
59
+ genesis . app_state . crisis . constant_fee . denom = MINT_DENOM ;
60
+ genesis . app_state . gov . deposit_params . min_deposit = GOV_DEPOSIT_COINS ;
61
+
62
+ // Reduce the cost of a transaction.
63
+ genesis . app_state . auth . params . tx_size_cost_per_byte = '1' ;
64
+
65
+ // We upgrade from export data.
66
+ const { app_state : exportedAppState = { } } = exported ;
67
+ for ( const state of Object . keys ( exportedAppState ) ) {
68
+ genesis . app_state [ state ] = exportedAppState [ state ] ;
69
+ }
82
70
83
- // Needed for IBC.
84
- config . tx_index . index_all_keys = true ;
71
+ // Remove IBC and capability state.
72
+ // TODO: This needs much more support to preserve contract state
73
+ // between exports in order to be able to carry forward IBC conns.
74
+ delete genesis . app_state . capability ;
75
+ delete genesis . app_state . ibc ;
85
76
86
- // Stringify the new config.toml.
87
- ret . newConfigToml = TOML . stringify ( config ) ;
77
+ // Use the same consensus_params.
78
+ if ( 'consensus_params' in exported ) {
79
+ genesis . consensus_params = exported . consensus_params ;
88
80
}
89
81
90
- return ret ;
82
+ // This is necessary until https://github.com/cosmos/cosmos-sdk/issues/6446 is closed.
83
+ genesis . consensus_params . block . time_iota_ms = '1000' ;
84
+ return djson . stringify ( genesis ) ;
91
85
}
0 commit comments