Skip to content

Commit

Permalink
fix: adjust agoric-cli genesis and config.toml params
Browse files Browse the repository at this point in the history
Use json-merge-patch to make updates declarative.
  • Loading branch information
michaelfig committed Jun 30, 2020
1 parent 605183b commit 41614a6
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 38 deletions.
71 changes: 71 additions & 0 deletions packages/agoric-cli/lib/chain-params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
export const MINT_DENOM = 'uag';
export const STAKING_DENOM = 'uagstake';
export const GOV_DEPOSIT_COINS = [{ amount: '10000000', denom: MINT_DENOM }];

// A JSON Merge Patch for an exported genesis.json.
export const genesisMergePatch = {
app_state: {
staking: {
params: {
bond_denom: STAKING_DENOM,
},
},
mint: {
// Zero inflation, for now.
minter: {
inflation: '0.0',
},
params: {
inflation_rate_change: '0.0',
inflation_min: '0.0',
mint_denom: MINT_DENOM,
},
},
crisis: {
constant_fee: {
denom: MINT_DENOM,
},
},
gov: {
deposit_params: {
min_deposit: GOV_DEPOSIT_COINS,
},
},
auth: {
params: {
tx_size_cost_per_byte: '1',
},
},

// Remove IBC and capability state.
// TODO: This needs much more support to preserve contract state
// between exports in order to be able to carry forward IBC conns.
capability: null,
ibc: null,
},
consensus_params: {
block: {
// This is necessary until https://github.com/cosmos/cosmos-sdk/issues/6446 is closed.
time_iota_ms: '1000',
},
},
};

// The JSON merge patch for the config.toml.
export function makeConfigMergePatch(portNum) {
const rpcPort = Number(portNum);
const configMergePatch = {
proxy_app: 'kvstore',
consensus: {
// Make blocks run faster than normal.
timeout_commit: '2s',
},
p2p: {
laddr: `tcp://0.0.0.0:${rpcPort - 1}`,
},
rpc: {
laddr: `tcp://127.0.0.1:${rpcPort}`,
},
};
return configMergePatch;
}
48 changes: 12 additions & 36 deletions packages/agoric-cli/lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import path from 'path';
import chalk from 'chalk';
import { createHash } from 'crypto';
import djson from 'deterministic-json';
import jsonmergepatch from 'json-merge-patch';
import TOML from '@iarna/toml';

const MINT_DENOM = 'uag';
const STAKING_DENOM = 'uagstake';
const GOV_DEPOSIT_COINS = [{ amount: '10000000', denom: MINT_DENOM }];
import {
MINT_DENOM,
STAKING_DENOM,
genesisMergePatch,
makeConfigMergePatch,
} from './chain-params';

const PROVISION_COINS = `100000000${STAKING_DENOM},100000000${MINT_DENOM},100provisionpass,100sendpacketpass`;
const DELEGATE0_COINS = `50000000${STAKING_DENOM}`;
Expand All @@ -30,32 +34,9 @@ export default async function startMain(progname, rawArgs, powers, opts) {
const genjson = await fs.readFile(genfile, 'utf-8');
const genesis = JSON.parse(genjson);

// Use our own denominations.
genesis.app_state.staking.params.bond_denom = STAKING_DENOM;
genesis.app_state.mint.params.mint_denom = MINT_DENOM;
genesis.app_state.crisis.constant_fee.denom = MINT_DENOM;
genesis.app_state.gov.deposit_params.min_deposit = GOV_DEPOSIT_COINS;
const finishedGenesis = jsonmergepatch.apply(genesis, genesisMergePatch);

// Tweak the parameters we need.
genesis.app_state.auth.params.tx_size_cost_per_byte = '1';

// Zero inflation, for now.
genesis.app_state.mint.minter.inflation = '0.0';
genesis.app_state.mint.params.inflation_rate_change = '0.0';
genesis.app_state.mint.params.inflation_min = '0.0';

// Remove IBC and capability state.
// TODO: This needs much more support to preserve contract state
// between exports in order to be able to carry forward IBC conns.
delete genesis.app_state.capability;
delete genesis.app_state.ibc;

// genesis.validators[0].address = '4688325E1761CAC253216A789DC895947C08F8EE'

// This is necessary until https://github.com/cosmos/cosmos-sdk/issues/6446 is closed.
genesis.consensus_params.block.time_iota_ms = '1000';

const ds = djson.stringify(genesis);
const ds = djson.stringify(finishedGenesis);
await fs.writeFile(genfile, ds);

// Calculate the GCI and save to disk.
Expand All @@ -73,15 +54,10 @@ export default async function startMain(progname, rawArgs, powers, opts) {
const configtoml = await fs.readFile(configfile, 'utf-8');
const config = TOML.parse(configtoml);

const rpcPort = Number(portNum);
config.proxy_app = `kvstore`;
config.rpc.laddr = `tcp://127.0.0.1:${rpcPort}`;
config.p2p.laddr = `tcp://0.0.0.0:${rpcPort - 1}`;

// Make blocks run faster than normal.
config.consensus.timeout_commit = '2s';
const configMergePatch = makeConfigMergePatch(portNum);
const finishedConfig = jsonmergepatch.apply(config, configMergePatch);

await fs.writeFile(configfile, TOML.stringify(config));
await fs.writeFile(configfile, TOML.stringify(finishedConfig));
};

const pspawnEnv = { ...process.env };
Expand Down
1 change: 1 addition & 0 deletions packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"commander": "^5.0.0",
"deterministic-json": "^1.0.5",
"esm": "^3.2.25",
"json-merge-patch": "^1.0.0",
"ws": "^7.2.0"
},
"keywords": [],
Expand Down
Loading

0 comments on commit 41614a6

Please sign in to comment.