Skip to content

Commit

Permalink
feat: use SETUP_HOME/cosmos-delegates.txt and increase defaults
Browse files Browse the repository at this point in the history
fix: search for ag-cosmos-helper in $PATH

fix: use new pip version
  • Loading branch information
michaelfig committed Apr 10, 2020
1 parent 4e0d7c5 commit 5e87ae1
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 89 deletions.
4 changes: 2 additions & 2 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 = 1000agmedallion
INITIAL_TOKENS = 10000000000000000000000000uag

# By default, make the fake chain in scenario3 produce
# "blocks" as soon as they come in.
Expand Down Expand Up @@ -69,7 +69,7 @@ scenario2-setup-nobuild:
bin/ag-solo init t1/$$port --webport=$$port; \
case $$port in \
$(BASE_PORT)) toks=$(INITIAL_TOKENS),100000000uagstake ;; \
*) toks=1agmedallion ;; \
*) toks=1000000uag ;; \
esac; \
$(AGC) add-genesis-account `cat t1/$$port/ag-cosmos-helper-address` $$toks; \
done
Expand Down
1 change: 1 addition & 0 deletions packages/cosmic-swingset/provisioning-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RUN apt-get update -y && apt-get install gcc python3 python3-venv python3-dev -y

WORKDIR /usr/src/app
RUN python3 -mvenv ve3
RUN ve3/bin/pip install --upgrade pip
RUN ve3/bin/pip install wheel
COPY . provisioning-server/
RUN ve3/bin/pip install provisioning-server/
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/provisioning-server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"console_scripts": [ "ag-pserver = ag_pserver.main:main" ],
},
include_package_data=True,
version="0.0.1",
version="0.1.0",
)

39 changes: 21 additions & 18 deletions packages/cosmic-swingset/provisioning-server/src/ag_pserver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
import sys
log.startLogging(sys.stdout)

# TODO: Don't hardcode these.
INITIAL_TOKEN = [1, 'agmedallion']

MAILBOX_URL = u"ws://relay.magic-wormhole.io:4000/v1"
#MAILBOX_URL = u"ws://10.0.2.24:4000/v1"
APPID = u"agoric.com/ag-testnet1/provisioning-tool"
Expand Down Expand Up @@ -48,6 +45,7 @@ class Options(usage.Options):
]
optParameters = [
["home", None, os.path.join(os.environ["HOME"], '.ag-pserver'), "provisioning-server's state directory"],
['initial-token', 'T', '1000uag', "initial tokens sent to the provisioned pubkey"],
]

class SendInputAndWaitProtocol(protocol.ProcessProtocol):
Expand Down Expand Up @@ -196,7 +194,7 @@ def built(response):


@defer.inlineCallbacks
def enablePubkey(reactor, opts, config, nickname, pubkey, initialToken = INITIAL_TOKEN):
def enablePubkey(reactor, opts, config, nickname, pubkey):
mobj = {
"type": "pleaseProvision",
"nickname": nickname,
Expand All @@ -207,16 +205,14 @@ def ret(server_message):
return [mobj, server_message, config]

# FIXME: Make more resilient to DOS attacks, or attempts
# to drain all our agmedallions.
if initialToken is not None:
amountToken = ''.join([str(o) for o in initialToken])
args = [
'tx', 'send', '--keyring-backend=test', config['bootstrapAddress'], pubkey, amountToken,
'--yes', '--broadcast-mode', 'block', # Don't return until committed.
]
code, output = yield agCosmosHelper(reactor, opts, config, args, 10)
if code != 0:
return ret({"ok": False, "error": 'transfer returned ' + str(code)})
# to drain all our uags.
args = [
'tx', 'send', '--keyring-backend=test', config['bootstrapAddress'], pubkey, opts['initial-token'],
'--yes', '--broadcast-mode', 'block', # Don't return until committed.
]
code, output = yield agCosmosHelper(reactor, opts, config, args, 10)
if code != 0:
return ret({"ok": False, "error": 'transfer returned ' + str(code)})

controller_url = opts["controller"]
print('contacting ' + controller_url)
Expand Down Expand Up @@ -433,10 +429,17 @@ def agCosmosHelper(reactor, opts, config, args, retries = 1):

@defer.inlineCallbacks
def doEnablePubkeys(reactor, opts, config, pkobjs):
amountToken = ''.join([str(o) for o in INITIAL_TOKEN])

txes = []
needIngress = []

# Find the token and amount.
token = opts['initial-token']
splitToken = len(token) - 1
while splitToken > 0 and token[splitToken] in string.digits:
splitToken -= 1
amount = int(token[0:splitToken])
denom = token[splitToken:]

for pkobj in pkobjs:
pubkey = pkobj['pubkey']
missing = False
Expand All @@ -448,7 +451,7 @@ def doEnablePubkeys(reactor, opts, config, pkobjs):
missing = True
for coin in output['value']['coins']:
# Check if they have some of our coins.
if coin['denom'] == INITIAL_TOKEN[1] and int(coin['amount']) >= INITIAL_TOKEN[0]:
if coin['denom'] == denom and int(coin['amount']) >= amount:
missing = False
break
elif code == 1 or code == 9:
Expand All @@ -462,7 +465,7 @@ def doEnablePubkeys(reactor, opts, config, pkobjs):
print('generating transaction for', pubkey)
# Estimate the gas, with a little bit of padding.
args = ['tx', 'send', '--keyring-backend=test', config['bootstrapAddress'], pubkey,
amountToken, '--gas=auto', '--gas-adjustment=1.05']
opts['initial-token'], '--gas=auto', '--gas-adjustment=1.05']
code, output = yield agCosmosHelper(reactor, opts, config, args, 1)
if code == 0:
txes.append(output)
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/scripts/single-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
DAEMON=${DAEMON-gaiad}
CLI=${CLI-gaiacli}
STAKE=${STAKE-10000000000stake}
coins="${STAKE},100000000000samoleans,100000agmedallion"
coins="${STAKE},100000000000samoleans,10000000000000000000000000uag"

CHAINID=$1
GENACCT=$2
Expand Down
1 change: 1 addition & 0 deletions packages/cosmic-swingset/setup-solo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RUN apt-get update -y && apt-get install gcc python3 python3-venv python3-dev -y

WORKDIR /usr/src/app
RUN python3 -mvenv ve3
RUN ve3/bin/pip install --upgrade pip
RUN ve3/bin/pip install wheel
COPY . setup-solo/
RUN ve3/bin/pip install setup-solo/
Expand Down
5 changes: 2 additions & 3 deletions packages/cosmic-swingset/setup-solo/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
packages=["ag_setup_solo"],
install_requires=[
"magic-wormhole",
"treq",
"twisted[tls]",
],
entry_points={
"console_scripts": [ "ag-setup-solo = ag_setup_solo.main:main" ],
},
version="0.0.1",
version="0.1.0",
)

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from twisted.internet import endpoints, defer
from twisted.python import usage
import wormhole
import treq
import json
import os.path
import shutil
Expand Down
2 changes: 1 addition & 1 deletion packages/deployment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN curl https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform
RUN echo 'deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main' >> /etc/apt/sources.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 && \
apt-get update -y && \
apt-get install -y ansible rsync curl sudo gnupg2 && \
apt-get install -y ansible rsync curl sudo gnupg2 jq python-jmespath && \
apt-get clean -y

# Copy journalbeat for logging support
Expand Down
2 changes: 2 additions & 0 deletions packages/deployment/Dockerfile.sdk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ COPY --from=cosmic-swingset-go /usr/src/app/lib/ packages/cosmic-swingset/lib/
COPY --from=cosmic-swingset-go /go/bin/ag-cosmos-helper /usr/local/bin/
RUN ln -s agoric-sdk/packages/cosmic-swingset ../app

# Install some conveniences.
RUN apt-get update && apt-get install -y vim jq less && apt-get clean -y
RUN yarn install

# Need to build the Node.js node extension that uses our above Golang shared library.
Expand Down
1 change: 1 addition & 0 deletions packages/deployment/ansible/cosmos-genesis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- BOOTSTRAP_ADDRESS: "{{ lookup('file', SETUP_HOME + '/ag-pserver/data/node0/boot-address.txt') }}"
- STAKER: ag-staker
- STAKER_TOKENS: 10000000000000000000000000uagstake
- STAKER_IDENTITY_FLAGS: "--website=https://testnet.agoric.com --identity=https://keybase.io/team/agoric.testnet.validators"
- STAKER_AMOUNT: 50000000uagstake
- STAKER_NODE: node0
roles:
Expand Down
12 changes: 0 additions & 12 deletions packages/deployment/ansible/cosmos-validators.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
---

- hosts: "{{ STAKER_NODE }}"
user: root
gather_facts: no
vars:
- service: ag-chain-cosmos
- CHAIN_NAME: "{{ lookup('file', SETUP_HOME + '/' + service + '/chain-name.txt') }}"
- STAKER: ag-staker
- STAKER_NODE: node0
- STAKER_AMOUNT: 50000000uagstake
roles:
- cosmos-delegates

- hosts: "{{ service }}"
user: root
#any_errors_fatal: true
Expand Down
16 changes: 0 additions & 16 deletions packages/deployment/ansible/roles/cosmos-delegates/tasks/main.yml

This file was deleted.

65 changes: 55 additions & 10 deletions packages/deployment/ansible/roles/cosmos-genesis/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,91 @@
- name: "Add bootstrap coins to {{ service }}"
- name: "Check faucet exists"
become: yes
become_user: "{{ service }}"
shell: "{{ service }} add-genesis-account {{ BOOTSTRAP_ADDRESS }} {{ BOOTSTRAP_TOKENS }}"
shell: "ag-cosmos-helper keys show --keyring-backend=test faucet"
ignore_errors: true
register: faucet_exists

- name: "Check {{ STAKER }}-* exists"
- name: "Create faucet account for {{ service }}"
become: yes
become_user: "{{ service }}"
shell: "ag-cosmos-helper keys add --keyring-backend=test faucet"
when: faucet_exists.rc != 0

- name: "Check {{ STAKER }}-{{ STAKER_NODE }} exists"
become: yes
become_user: "{{ service }}"
shell: "ag-cosmos-helper keys show --keyring-backend=test {{ STAKER }}-{{ STAKER_NODE }}"
ignore_errors: true
register: staker_exists

- name: "Create staking account for {{ service }}"
- name: "Create {{ STAKER_NODE }} account for {{ service }}"
become: yes
become_user: "{{ service }}"
shell: "ag-cosmos-helper keys add --keyring-backend=test {{ STAKER }}-{{ STAKER_NODE }}"
when: staker_exists.rc != 0

- name: "Add staking coins to {{ service }}"
- name: "Remove transaction directories"
become: yes
become_user: "{{ service }}"
file:
state: absent
path: "{{ item }}"
with_items:
- "/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 {{ STAKER }}-{{ STAKER_NODE }} -a) \
$(ag-cosmos-helper keys show --keyring-backend=test faucet -a) \
{{ STAKER_TOKENS }}"
ignore_errors: true

- name: "Create {{ gentx }}"
- name: "Add {{ STAKER_AMOUNT }} coins to {{ STAKER }}-{{ STAKER_NODE }}"
become: yes
become_user: "{{ service }}"
shell: "{{ service }} add-genesis-account \
$(ag-cosmos-helper keys show --keyring-backend=test {{ STAKER }}-{{ STAKER_NODE }} -a) \
{{ STAKER_AMOUNT }}"
ignore_errors: true

- set_fact:
delegates: "{{ lookup('file', SETUP_HOME + '/cosmos-delegates.txt', errors='ignore') }}"

- name: "Transfer stake to delegates"
become_user: "{{ service }}"
become: true
shell: "\
{{ service }} add-genesis-account \
{{ item | regex_replace('^([^:]*):([^:]*).*$', '\\1 \\2') }}"
with_items:
- "{{ delegates.splitlines() }}"
when: delegates

- name: "Create transaction directory"
become: yes
become_user: "{{ service }}"
file:
state: directory
path: "{{ gentx }}"
path: "{{ item }}"
mode: 0700
vars:
gentx: "/home/{{ service }}/.{{ service }}/config/gentx"
with_items:
- "/home/{{ service }}/.{{ service }}/config/gentx"

- name: "Create first validator gentx"
become: yes
become_user: "{{ service }}"
shell: "\
{{ service }} gentx --keyring-backend=test --amount={{ STAKER_AMOUNT }} \
{{ STAKER_IDENTITY_FLAGS }}
--name={{ STAKER }}-{{ STAKER_NODE }} --output-document={{ json }}"
vars:
json: "/home/{{ service }}/.{{ service }}/config/gentx/{{ STAKER_NODE }}.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
become: true
delegate_to: "{{ STAKER_NODE }}"
shell: "\
ag-cosmos-helper tx send --keyring-backend=test {{ STAKER }}-{{ STAKER_NODE }} \
ag-cosmos-helper tx send --keyring-backend=test \
faucet \
$(ag-cosmos-helper keys show --keyring-backend=test {{ staker }} -a) \
{{ STAKER_AMOUNT }} --yes --broadcast-mode=block --chain-id={{ CHAIN_NAME }}"
{{ STAKER_AMOUNT }} \
--chain-id={{ CHAIN_NAME }} --broadcast-mode=block --yes"
vars:
staker: "{{ STAKER }}-{{ inventory_hostname }}"
when: inventory_hostname != STAKER_NODE

- name: "Create validator for {{ STAKER }}-*"
- name: "Create validators for {{ STAKER }}-*"
become_user: "{{ service }}"
become: true
delegate_to: "{{ STAKER_NODE }}"
Expand Down
Loading

0 comments on commit 5e87ae1

Please sign in to comment.