Skip to content

Commit

Permalink
feat: implement add-egress, add-delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Aug 23, 2020
1 parent 8ba1c46 commit ffd474a
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 64 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ packages/cosmic-swingset/lib/lib*.so
**/__pycache__
**/*.egg-info
**/swingset-kernel-state
**/_agstate
.vagrant
2 changes: 2 additions & 0 deletions packages/deployment/ansible/cosmos-genesis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- service: ag-chain-cosmos
- BOOTSTRAP_TOKENS: "{{ lookup('file', SETUP_HOME + '/boot-tokens.txt') }},100provisionpass"
- BOOTSTRAP_ADDRESS: "{{ lookup('file', SETUP_HOME + '/ag-pserver/data/node0/boot-address.txt') }}"
- CHAIN_NAME: "{{ lookup('file', SETUP_HOME + '/ag-chain-cosmos/chain-name.txt') }}"
- NETWORK_CONFIG_URL: https://testnet.agoric.com/network-config
- STAKER: ag-staker
- STAKER_TOKENS: 10000000000000000000000000uagstake
- STAKER_IDENTITY_FLAGS: "--website=https://testnet.agoric.com --identity=https://keybase.io/team/agoric.testnet.validators"
Expand Down
13 changes: 3 additions & 10 deletions packages/deployment/ansible/roles/cosmos-genesis/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
- name: "Create val.sh"
- name: "Create faucet-helper.sh"
delegate_to: localhost
template:
src: val.sh.j2
dest: "{{ SETUP_HOME + '/val.sh' }"
mode: '755'

- name: "Create provision.sh"
delegate_to: localhost
template:
src: provision.sh.j2
dest: "{{ SETUP_HOME + '/provision.sh' }"
src: faucet-helper.sh.j2
dest: "{{ SETUP_HOME + '/faucet-helper.sh' }}"
mode: '755'

- set_fact:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#! /bin/bash
set -e

thisdir=$(dirname -- "$0")

MAX_LINES=-1
STAKE=50000000uagstake

OP=$1
shift

NETWORK_CONFIG_URL="{{ NETWORK_CONFIG_URL }}"
nc=$(curl -s $NETWORK_CONFIG_URL)
chainName=$(echo "$nc" | jq -r .chainName)
rpcAddrs=$(echo "$nc" | jq .rpcAddrs)
numAddrs=$(echo "$rpcAddrs" | jq '. | length')

while [[ $numAddrs -gt 0 ]]; do
r=$(( $RANDOM % $numAddrs ))
selected=$(echo "$rpcAddrs" | jq -r ".[$r]")
rpcAddrs=$(echo "$rpcAddrs" | jq ".[0:$r] + .[$(( $r + 1 )):$numAddrs]")
numAddrs=$(echo "$rpcAddrs" | jq '. | length')

# echo "Checking if $selected is alive"
if [[ $(curl -s http://$selected/status | jq .result.sync_info.catching_up) == false ]]; then
case $OP in
debug)
echo "would try $selected"
;;
add-egress)
NAME=$1
ADDR=$2
exec ag-cosmos-helper --home=$thisdir/faucet \
tx swingset provision-one \
--node=tcp://$selected --chain-id=$chainName \
--yes --gas=auto --gas-adjustment=1.5 --broadcast-mode=block \
--from=faucet -- "$NAME" "$ADDR"
;;
add-delegate)
UNIQUE=yes
case "$1" in
--force | -f) UNIQUE=no; shift ;;
esac
NAME=$1
ADDR=$2

if [[ $UNIQUE != no && $MAX_LINES -ge 0 && $(wc -l $thisdir/cosmos-delegates.txt | sed -e 's/ .*//') -ge $MAX_LINES ]]; then
echo "Sorry, we've capped the number of validators at $MAX_LINES"
exit 1
fi
if [[ $UNIQUE != no ]]; then
line=$(grep -e ":$NAME$" $thisdir/cosmos-delegates.txt || true)
if [[ -n $line ]]; then
echo "$NAME has already tapped the faucet:" 1>&2
echo "$line" 1>&2
exit 1
fi
fi
if [[ $UNIQUE != no ]]; then
line=$(grep -e "^$ADDR:" $thisdir/cosmos-delegates.txt || true)
if [[ -n $line ]]; then
echo "$ADDR already received a tap:" 1>&2
echo "$line" 1>&2
exit 1
fi
fi

ag-cosmos-helper --home=$thisdir/faucet tx send faucet "$ADDR" "$STAKE"
if ag-cosmos-helper --home=$thisdir/faucet \
tx send \
--node=tcp://$selected --chain-id=$chainName \
--yes --gas=auto --gas-adjustment=1.5 --broadcast-mode=block \
-- faucet "$ADDR" "$STAKE"; then
# Record the information before exiting.
sed -i -e "/:$NAME$/d" $thisdir/cosmos-delegates.txt
echo "$ADDR:$STAKE:$NAME" >> $thisdir/cosmos-delegates.txt
exit 0
fi
;;
*)
echo 1>&2 "Unknown operation $OP"
exit 1
;;
esac
fi
done

echo 1>&2 "No active chain nodes found in: $(echo "$nc" | jq .rpcAddrs)"
exit 1

This file was deleted.

This file was deleted.

7 changes: 7 additions & 0 deletions packages/deployment/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,13 @@ ${chalk.yellow.bold(
break;
}

case 'add-egress':
case 'add-delegate': {
await inited();
await needDoRun(['./faucet-helper.sh', ...args]);
break;
}

case 'show-chain-name': {
await inited();
const chainName = await trimReadFile(`${COSMOS_DIR}/chain-name.txt`);
Expand Down

0 comments on commit ffd474a

Please sign in to comment.