Skip to content

Commit

Permalink
fix: remove genesis bootstrap config; use just add-genesis-account
Browse files Browse the repository at this point in the history
We also just use `tx bank send` to send coins instead of special
provision-one handling.
  • Loading branch information
michaelfig committed May 28, 2021
1 parent c7cba64 commit fdc1255
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 85 deletions.
18 changes: 2 additions & 16 deletions packages/agoric-cli/lib/chain-config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import djson from 'deterministic-json';
import TOML from '@iarna/toml';

export const CENTRAL_DENOM = 'urun';
export const MINT_DENOM = 'ubld';
export const STAKING_DENOM = 'ubld';
export const STAKING_MAX_VALIDATORS = 150;

export const DEFAULT_BOOTSTRAP_VALUE = 50000n * 10n ** 6n;
export const DEFAULT_DONATION_VALUE = 5n * 10n ** 6n;

export const GOV_DEPOSIT_COINS = [{ amount: '1000000', denom: MINT_DENOM }];

// Can't beat the speed of light, we need 600ms round trip time for the other
Expand Down Expand Up @@ -96,13 +94,7 @@ export function finishTendermintConfig({
}

// Rewrite/import the genesis.json.
export function finishCosmosGenesis({
genesisJson,
exportedGenesisJson,
bootstrapAddress,
bootstrapValue,
donationValue,
}) {
export function finishCosmosGenesis({ genesisJson, exportedGenesisJson }) {
const genesis = JSON.parse(genesisJson);
const exported = exportedGenesisJson ? JSON.parse(exportedGenesisJson) : {};

Expand Down Expand Up @@ -133,12 +125,6 @@ export function finishCosmosGenesis({
genesis.app_state.mint.params.inflation_rate_change = '0.0';
genesis.app_state.mint.params.inflation_min = '0.0';

genesis.app_state.vpurse.bootstrap_address = bootstrapAddress;
genesis.app_state.vpurse.bootstrap_value = `${bootstrapValue ||
DEFAULT_BOOTSTRAP_VALUE}`;
genesis.app_state.vpurse.donation_value = `${donationValue ||
DEFAULT_DONATION_VALUE}`;

// Set the denomination for different modules.
genesis.app_state.mint.params.mint_denom = MINT_DENOM;
genesis.app_state.crisis.constant_fee.denom = MINT_DENOM;
Expand Down
29 changes: 1 addition & 28 deletions packages/agoric-cli/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* global __dirname process */
import { Command } from 'commander';

import { assert, details as X, quote as q } from '@agoric/assert';
import { Nat } from '@agoric/nat';
import { assert, details as X } from '@agoric/assert';
import cosmosMain from './cosmos';
import deployMain from './deploy';
import initMain from './init';
Expand Down Expand Up @@ -33,15 +32,6 @@ const main = async (progname, rawArgs, powers) => {
return true;
}

const makeParseNatValue = flag => value => {
try {
const bi = BigInt(value);
return Nat(bi);
} catch (e) {
assert.fail(X`${q(flag)} must be a natural number, not ${value}; ${e}`);
}
};

function subMain(fn, args, options) {
return fn(progname, args, powers, options).then(
// This seems to be the only way to propagate the exit code.
Expand Down Expand Up @@ -121,23 +111,6 @@ const main = async (progname, rawArgs, powers) => {
program
.command('set-defaults <program> <config-dir>')
.description('update the configuration files for <program> in <config-dir>')
.option(
'--bootstrap-address <bech32>',
'the chain address which should receive urun',
'',
)
.option(
'--bootstrap-value <number>',
'the amount of urun to give to bootstrap-address',
makeParseNatValue('bootstrap-value'),
0n,
)
.option(
'--donation-value <number>',
'the amount of urun to transfer from bootsrtap-address to each client',
makeParseNatValue('donation-value'),
0n,
)
.option(
'--export-metrics',
'open ports to export Prometheus metrics',
Expand Down
15 changes: 0 additions & 15 deletions packages/agoric-cli/lib/set-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ export default async function setDefaultsMain(progname, rawArgs, powers, opts) {
X`<prog> must currently be 'ag-chain-cosmos'`,
);

const { bootstrapAddress, bootstrapValue, donationValue } = opts;

console.log(bootstrapAddress, bootstrapValue, donationValue);
assert(
bootstrapAddress || !bootstrapValue,
X`must set bootstrap-address if bootstrap-value is set`,
);
assert(
bootstrapAddress || !donationValue,
X`must set bootstrap-address if donation-value is set`,
);

const { exportMetrics } = opts;

let appFile;
Expand Down Expand Up @@ -94,9 +82,6 @@ export default async function setDefaultsMain(progname, rawArgs, powers, opts) {
const newGenesisJson = finishCosmosGenesis({
genesisJson,
exportedGenesisJson,
bootstrapAddress,
bootstrapValue,
donationValue,
});

await create(genesisFile, newGenesisJson);
Expand Down
68 changes: 49 additions & 19 deletions packages/agoric-cli/lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import chalk from 'chalk';
import { createHash } from 'crypto';

import {
CENTRAL_DENOM,
STAKING_DENOM,
finishTendermintConfig,
finishCosmosGenesis,
Expand All @@ -12,8 +13,9 @@ import {

import { makePspawn } from './helpers';

const PROVISION_COINS = `100000000${STAKING_DENOM},100provisionpass,100sendpacketpass`;
const PROVISION_COINS = `100000000${STAKING_DENOM},50000000000${CENTRAL_DENOM},100provisionpass,100sendpacketpass`;
const DELEGATE0_COINS = `50000000${STAKING_DENOM}`;
const SOLO_COINS = `13000000${STAKING_DENOM},5000000${CENTRAL_DENOM}`;
const CHAIN_ID = 'agoric';

const FAKE_CHAIN_DELAY =
Expand All @@ -39,7 +41,12 @@ export default async function startMain(progname, rawArgs, powers, opts) {
const SDK_IMAGE = `agoric/agoric-sdk:${opts.dockerTag}`;
const SOLO_IMAGE = `agoric/cosmic-swingset-solo:${opts.dockerTag}`;

const pspawnEnv = { ...process.env };
const pspawnEnv = {
...process.env,
// TODO: We'd love to --expose-gc in this environment variable,
// but Node.js rejects it.
// NODE_OPTIONS: `${process.env.NODE_OPTIONS || ''} --expose-gc`,
};
const pspawn = makePspawn({ env: pspawnEnv, spawn, log, chalk });

let keysSpawn;
Expand Down Expand Up @@ -344,7 +351,10 @@ export default async function startMain(progname, rawArgs, powers, opts) {
return chainSpawn(
[...debugOpts, 'start'],
{
env: { ...pspawnEnv, ROLE: 'two_chain' },
env: {
...pspawnEnv,
ROLE: 'two_chain',
},
},
// Accessible via either localhost or host.docker.internal
[`--publish=127.0.0.1:${portNum}:${portNum}`, `--name=agoric-n0`],
Expand Down Expand Up @@ -468,9 +478,8 @@ export default async function startMain(progname, rawArgs, powers, opts) {
`--node=tcp://${rpcAddr}`,
]);
if (exitStatus) {
// We need to provision our address.
const capret = capture(
keysSpawn,
const provCmds = [
// We need to provision our address.
[
'tx',
'swingset',
Expand All @@ -487,20 +496,41 @@ export default async function startMain(progname, rawArgs, powers, opts) {
soloAddr,
...provisionPowers,
],
true,
);
// eslint-disable-next-line no-await-in-loop
exitStatus = await capret[0];
if (!exitStatus) {
const json = capret[1].replace(/^gas estimate: \d+$/m, '');
try {
const ret = JSON.parse(json);
if (ret.code !== 0) {
exitStatus = 2;
// Then send it some coins.
[
'tx',
'bank',
'send',
'--keyring-backend=test',
'--gas=auto',
'--gas-adjustment=1.2',
'--broadcast-mode=block',
'--yes',
`--chain-id=${CHAIN_ID}`,
`--node=tcp://${rpcAddr}`,
'provision',
soloAddr,
SOLO_COINS,
],
];
for (const cmd of provCmds) {
const capret = capture(keysSpawn, cmd, true);
// eslint-disable-next-line no-await-in-loop
exitStatus = await capret[0];
if (!exitStatus) {
const json = capret[1].replace(/^gas estimate: \d+$/m, '');
try {
const ret = JSON.parse(json);
if (ret.code !== 0) {
exitStatus = 2;
}
} catch (e) {
console.error(`Cannot parse JSON:`, e, json);
exitStatus = 99;
}
} catch (e) {
console.error(`Cannot parse JSON:`, e, json);
exitStatus = 99;
}
if (exitStatus) {
break;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions packages/cosmic-swingset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ scenario2-setup-nobuild:
# Create the bootstrap account.
$(AGCH) --home=t1/bootstrap keys add bootstrap --keyring-backend=test
$(AGCH) --home=t1/bootstrap keys show -a bootstrap --keyring-backend=test > t1/bootstrap-address
$(AGCH) --home=t1/n0 add-genesis-account `cat t1/bootstrap-address` 1000000000000000ubld,100provisionpass,100sendpacketpass
$(AGCH) --home=t1/n0 add-genesis-account `cat t1/bootstrap-address` 1000000000000000ubld,50000000000urun,100provisionpass,100sendpacketpass
# Create the (singleton) chain node.
$(AGCH) --home=t1/n0 --keyring-dir=t1/bootstrap gentx --keyring-backend=test bootstrap 73000000ubld --chain-id=$(CHAIN_ID)
$(AGCH) --home=t1/n0 collect-gentxs
$(AGCH) --home=t1/n0 validate-genesis
../agoric-cli/bin/agoric set-defaults --export-metrics --bootstrap-address=`cat t1/bootstrap-address` ag-chain-cosmos t1/n0/config
../agoric-cli/bin/agoric set-defaults --export-metrics ag-chain-cosmos t1/n0/config
# Set the chain address in all the ag-solos.
jq '. + { genesis_time: "$(GENESIS_TIME)", initial_height: "$(INITIAL_HEIGHT)" }' t1/n0/config/genesis.json > t1/n0/config/genesis2.json
mv t1/n0/config/genesis2.json t1/n0/config/genesis.json
Expand All @@ -87,8 +87,8 @@ scenario2-reset-client:
scenario2-run-client: t1-provision-one-with-powers t1-start-ag-solo

# Provision the ag-solo from an provisionpass-holding address (idempotent).
AGORIC_POWERS = agoric.bankManager,agoric.agoricNamesAdmin,agoric.pegasusConnections,agoric.priceAuthorityAdmin,agoric.treasuryCreator,agoric.vattp
SOLO_COINS = 13000000ubld
AGORIC_POWERS = agoric.ALL_THE_POWERS
SOLO_COINS = 13000000ubld,5000000urun
COSMOS_RPC_HOST = localhost
COSMOS_RPC_PORT = 26657
wait-for-cosmos:
Expand All @@ -106,7 +106,7 @@ t1-provision-one-with-powers: wait-for-cosmos
$(AGCH) --home=t1/bootstrap query swingset egress $$addr --chain-id=$(CHAIN_ID) || \
{ $(AGCH) --home=t1/bootstrap tx bank send --keyring-backend=test --from=bootstrap \
--gas=auto --gas-adjustment=1.2 --broadcast-mode=block --yes --chain-id=$(CHAIN_ID) \
bootstrap $$addr $(SOLO_COINS); \
bootstrap $$addr $(SOLO_COINS) && \
$(AGCH) --home=t1/bootstrap tx swingset provision-one --keyring-backend=test --from=bootstrap \
--gas=auto --gas-adjustment=1.2 --broadcast-mode=block --yes --chain-id=$(CHAIN_ID) \
t1/$(BASE_PORT) $$addr $(AGORIC_POWERS) | tee /dev/stderr | grep -q '"code":0'; }
Expand All @@ -116,7 +116,7 @@ t1-provision-one: wait-for-cosmos
$(AGCH) --home=t1/bootstrap query swingset egress $$addr --chain-id=$(CHAIN_ID) || \
{ $(AGCH) --home=t1/bootstrap tx bank send --keyring-backend=test --from=bootstrap \
--gas=auto --gas-adjustment=1.2 --broadcast-mode=block --yes --chain-id=$(CHAIN_ID) \
bootstrap $$addr $(SOLO_COINS); \
bootstrap $$addr $(SOLO_COINS) && \
$(AGCH) --home=t1/bootstrap tx swingset provision-one --keyring-backend=test --from=bootstrap \
--gas=auto --gas-adjustment=1.2 --broadcast-mode=block --yes --chain-id=$(CHAIN_ID) \
t1/$(BASE_PORT) $$addr | tee /dev/stderr | grep -q '"code":0'; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FAUCET_HOME=$thisdir/../faucet

MAX_LINES=-1
DELEGATE_COINS=62000000ubld,93000000urun
SOLO_COINS=5000000urun

OP=$1
shift
Expand Down Expand Up @@ -38,11 +39,20 @@ while [[ ${#rpcAddrs[@]} -gt 0 ]]; do
add-egress)
NAME=$1
ADDR=$2
exec ag-cosmos-helper --home=$FAUCET_HOME \
if ag-cosmos-helper query swingset egress "$ADDR" --chain-id=$chainName; then
# Already provisioned.
exit 1
fi
ag-cosmos-helper --home=$FAUCET_HOME \
tx swingset provision-one \
--node=tcp://$selected --chain-id=$chainName --keyring-backend=test \
--yes --broadcast-mode=block \
--from=faucet -- "$NAME" "$ADDR"
exec ag-cosmos-helper --home=$FAUCET_HOME \
tx bank send \
--node=tcp://$selected --chain-id=$chainName --keyring-backend=test \
--yes --gas=auto --gas-adjustment=1.2 --broadcast-mode=block \
-- faucet "$ADDR" "$SOLO_COINS"
;;
add-delegate)
UNIQUE=yes
Expand Down

0 comments on commit fdc1255

Please sign in to comment.