Skip to content

Commit

Permalink
feat: provision without Python
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Aug 21, 2020
1 parent 5b156d4 commit 1fdc1d3
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 17 deletions.
16 changes: 9 additions & 7 deletions packages/cosmic-swingset/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
REPOSITORY = agoric/cosmic-swingset
CHAIN_ID = agoric
INITIAL_TOKENS = 10000000000000000000000000uag
INITIAL_TOKENS = 1000000000000uag

# By default, make the fake chain in scenario3 produce
# "blocks" as soon as they come in.
Expand Down Expand Up @@ -46,13 +46,15 @@ include Makefile.ledger
all: build-cosmos install

scenario0-setup:
rm -rf ~/.ag-chain-cosmos
python3 -mvenv ve3
ve3/bin/pip install setup-solo/
mkdir -p t9
rm -rf t9/$(BASE_PORT)
bin/ag-solo init t9/$(BASE_PORT) --webport=$(BASE_PORT)

scenario0-run-client:
AG_SOLO_BASEDIR=t9 ve3/bin/ag-setup-solo --webhost=127.0.0.1:$(BASE_PORT)
scenario0-run:
(cd t9/$(BASE_PORT) && ../../bin/ag-solo add-chain)
(cd t9/$(BASE_PORT) && ../../bin/ag-solo start)

scenario0-run-client: scenario0-run
scenario0-run-chain:
@echo 'No local chain needs to run in scenario0'

Expand All @@ -63,7 +65,7 @@ scenario1-run-chain:
AG_SETUP_COSMOS_HOME=t8 setup/ag-setup-cosmos bootstrap

scenario1-run-client:
AG_SOLO_BASEDIR=t7 ve3/bin/ag-setup-solo --webhost=127.0.0.1:$(BASE_PORT)
AG_SOLO_BASEDIR=t9 ve3/bin/ag-setup-solo --webhost=127.0.0.1:$(BASE_PORT)

AGC = ./bin/ag-chain-cosmos
AGCH = ag-cosmos-helper
Expand Down
53 changes: 53 additions & 0 deletions packages/cosmic-swingset/lib/ag-solo/add-chain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import fetch from 'node-fetch';
import path from 'path';
import fs from 'fs';

import setGCIIngress from './set-gci-ingress';

const DEFAULT_CHAIN_CONFIG = 'https://testnet.agoric.com/network-config';

/**
* @param {string} basedir
* @param {string=} chainConfig
* @param {boolean} [force=false]
*/
async function addChain(basedir, chainConfig, force = false) {
let actualConfig = chainConfig;
const cache = path.join(basedir, 'add-chain-default.txt');
if (actualConfig === undefined) {
if (fs.existsSync(cache)) {
actualConfig = fs.readFileSync(cache, 'utf-8');
} else {
actualConfig = DEFAULT_CHAIN_CONFIG;
}
}

console.log('downloading netconfig from', actualConfig);
const r = await fetch(actualConfig);
const netconf = await r.json();
if (!netconf.gci) {
throw Error(`${actualConfig} does not contain a "gci" entry`);
}

const connFile = path.join(basedir, 'connections.json');
const conns = JSON.parse(fs.readFileSync(connFile));
for (const conn of conns) {
if (conn.GCI === netconf.gci) {
if (!force) {
console.log(`Already have an entry for ${conn.GCI}; not replacing`);
return 0;
}
}
}

console.log('Setting chain parameters');
setGCIIngress(basedir, netconf.gci, netconf.rpcAddrs, netconf.chainName);

if (chainConfig === undefined) {
console.log('Writing', actualConfig, 'to', cache);
fs.writeFileSync(cache, actualConfig);
}
return 0;
}

export default addChain;
47 changes: 47 additions & 0 deletions packages/cosmic-swingset/lib/ag-solo/chain-cosmos-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ import anylogger from 'anylogger';
const log = anylogger('chain-cosmos-sdk');

const HELPER = 'ag-cosmos-helper';
const SUPPORT_ADDRESS =
'@agoric.support#testnet on Keybase (https://keybase.io)';

const adviseProvision = myAddr =>
`\
Send:
!faucet provision ${myAddr}
to ${SUPPORT_ADDRESS}`;

const MAX_BUFFER_SIZE = 10 * 1024 * 1024;

Expand Down Expand Up @@ -299,6 +311,41 @@ export async function connectToChain(
});
});

// Validate that our chain egress exists.
await retryRpcAddr(async rpcAddr => {
const args = ['query', 'swingset', 'egress', myAddr];
const fullArgs = [
...args,
`--chain-id=${chainID}`,
'--output=json',
`--node=tcp://${rpcAddr}`,
`--home=${helperDir}`,
];
// log(HELPER, ...fullArgs);
const r = await new Promise(resolve => {
execFile(HELPER, fullArgs, (error, stdout, stderr) => {
resolve({ error, stdout, stderr });
});
});

if (r.stderr.includes('not found: unknown request')) {
console.error(`\
=============
${chainID} chain does not yet know of address ${myAddr}${adviseProvision(
myAddr,
)}
=============
`);
return undefined;
} else if (r.error) {
console.error(`Error running`, HELPER, ...args);
console.error(r.stderr);
return undefined;
}

return r;
});

// We need one subscription-type thing
// to tell us that a new block exists, then we can use a different
// query-type tool to retrieve the outbox, but we want to know that the
Expand Down
10 changes: 10 additions & 0 deletions packages/cosmic-swingset/lib/ag-solo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { assert } from '@agoric/assert';
import anylogger from 'anylogger';

// Start a network service
import addChain from './add-chain';
import initBasedir from './init-basedir';
import resetState from './reset-state';
import setGCIIngress from './set-gci-ingress';
Expand Down Expand Up @@ -87,6 +88,15 @@ start
// );
break;
}
case 'add-chain': {
const basedir = insistIsBasedir();
const { _: subArgs, ...subOpts } = parseArgs(argv.slice(1), {
boolean: ['reset'],
});
const [chainConfig] = subArgs;
await addChain(basedir, chainConfig, subOpts.reset);
break;
}
case 'set-gci-ingress': {
const basedir = insistIsBasedir();
const { _: subArgs, ...subOpts } = parseArgs(argv.slice(1), {});
Expand Down
6 changes: 3 additions & 3 deletions packages/cosmic-swingset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint-check": "yarn lint",
"lint": "yarn lint:types && eslint '**/*.js'",
"lint:types": "tsc -p jsconfig.json"
},
},
"keywords": [],
"author": "Agoric",
"license": "Apache-2.0",
Expand All @@ -24,6 +24,7 @@
"@agoric/babel-parser": "^7.6.4",
"@agoric/bundle-source": "^1.1.6",
"@agoric/captp": "^1.3.3",
"@agoric/dapp-svelte-wallet": "^0.1.0",
"@agoric/ertp": "^0.6.0",
"@agoric/eventual-send": "^0.9.3",
"@agoric/import-bundle": "^0.0.8",
Expand All @@ -43,12 +44,11 @@
"@agoric/swingset-vat": "^0.6.0",
"@agoric/tendermint": "^4.1.3",
"@agoric/transform-eventual-send": "^1.3.1",
"@agoric/dapp-svelte-wallet": "^0.1.0",
"@agoric/weak-store": "^0.0.8",
"@agoric/zoe": "^0.7.0",
"agoric": "^0.7.0",
"@babel/generator": "^7.6.4",
"@iarna/toml": "^2.2.3",
"agoric": "^0.7.0",
"anylogger": "^0.21.0",
"bindings": "^1.2.1",
"chalk": "^2.4.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,13 @@
- "/home/{{ service }}/.{{ service }}/config/gentx"
- "/home/{{ service }}/validator-txes.txt"

- name: "Add bootstrap coins to {{ service }}"
become: yes
become_user: "{{ service }}"
shell: "{{ service }} add-genesis-account {{ BOOTSTRAP_ADDRESS }} {{ BOOTSTRAP_TOKENS }}"
ignore_errors: true

- name: "Add faucet coins to {{ service }}"
become: yes
become_user: "{{ service }}"
shell: "\
{{ service }} add-genesis-account \
$(ag-cosmos-helper keys show --keyring-backend=test faucet -a) \
{{ STAKER_TOKENS }}"
{{ STAKER_TOKENS }},{{ BOOTSTRAP_TOKENS }}"
ignore_errors: true

- name: "Add {{ STAKER_AMOUNT }} coins to {{ STAKER }}-{{ STAKER_NODE }}"
Expand Down

0 comments on commit 1fdc1d3

Please sign in to comment.