Skip to content

Commit

Permalink
Merge pull request #66 from pipermerriam/piper/more-getting-ready-for…
Browse files Browse the repository at this point in the history
…-testnet

Piper/more getting ready for testnet
  • Loading branch information
pipermerriam committed Oct 1, 2016
2 parents c636dee + aa2c1a7 commit 215f62b
Show file tree
Hide file tree
Showing 7 changed files with 3,402 additions and 35 deletions.
9 changes: 9 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,9 @@
include LICENSE
include VERSION
include README.md
include requirements.txt

recursive-exclude * __pycache__
recursive-exclude * *.py[co]

include alarm_client/assets/v8.0.0.json
3,261 changes: 3,261 additions & 0 deletions alarm_client/assets/v0.8.0.json

Large diffs are not rendered by default.

51 changes: 45 additions & 6 deletions alarm_client/cli.py
@@ -1,3 +1,4 @@
import os
import click
import functools
import logging
Expand All @@ -19,45 +20,61 @@
)


BASE_DIR = os.path.dirname(__file__)


@click.group()
@click.option(
'--tracker-address',
'-t',
envvar='TRACKER_ADDRESS',
help='The address of the RequestTracker contract that should be used.',
)
@click.option(
'--factory-address',
'-f',
help='The address of the RequestFactory contract that should be used.',
)
@click.option(
'--payment-lib-address',
envvar='PAYMENT_LIB_ADDRESS',
help='The address of the PaymentLib contract that should be used.',
)
@click.option(
'--request-lib-address',
'-r',
envvar='REQUEST_LIB_ADDRESS',
help='The address of the RequestLib contract that should be used.',
)
@click.option(
'--log-level',
'-l',
type=int,
default=logging.INFO,
envvar='LOG_LEVEL',
help='Integer logging level - 10:DEBUG 20:INFO 30:WARNING 40:ERROR',
)
@click.option(
'--provider',
'-p',
type=click.Choice(['ipc']),
default='ipc',
envvar='PROVIDER',
help='Web3.py provider type to use to connect to the chain.',
)
@click.option(
'--ipc-path',
'-i',
# TODO: remove this
default='/Users/piper/sites/ethereum-alarm-clock/chains/local/geth.ipc',
envvar='IPC_PATH',
help='Path to the IPC socket that the IPCProvider will connect to.',
)
@click.option(
'--compiled-assets-path',
'-a',
type=click.Path(dir_okay=False),
default='./build/contracts.json',
default=os.path.join(BASE_DIR, 'assets', 'v0.8.0.json'),
envvar='COMPILED_ASSETS_PATH',
help='Path to JSON file which contains the compiled contract assets',
)
@click.pass_context
def main(ctx,
Expand Down Expand Up @@ -99,56 +116,75 @@ def main(ctx,
)


@main.command('request:create')
@main.command(
'request:create',
help="Schedule a transaction to be executed at a later time or block",
)
@click.option(
'--to-address',
'-a',
default='0x199a239ec2f7c788ce324d28be96fab34f3577f7',
help="The `toAddress` to be used",
)
@click.option(
'--call-data',
'-d',
default='this-is-test-call-data',
default='',
help="The `callData` to be used",
)
@click.option(
'--call-gas',
'-g',
default=150000,
help="The `callGas` value to be used",
)
@click.option(
'--call-value',
'-v',
default=0,
help="The `callValue` value to be used",
)
@click.option(
'--temporal-unit',
'-t',
type=click.Choice([1, 2]),
default=1,
help="The `temporalUnit` value to be used. 1:Blocks 2:Timestamp",
)
@click.option(
'--window-start',
'-w',
type=click.IntRange(min=0),
help="The `windowStart` value to be used",
)
@click.option(
'--window-size',
'-w',
type=click.IntRange(min=0),
default=255,
help="The `windowSize` value to be used",
)
@click.option(
'--endowment',
'-e',
type=click.IntRange(min=0),
help="Manually control the endowment to be sent to the contract.",
)
@click.option(
'--confirm/--no-confirm',
default=True,
help="Use --no-confirm to skip confirmation prompts.",
)
@click.option(
'--deploy-from',
'-f',
help="Sets the `from` address for the scheduling transaction. Defaults to the coinbase account if not provided.",
)
@click.option(
'--no-wait',
is_flag=True,
default=False,
help="Use --no-wait to skip waiting for the transaction to be mined",
)
@click.pass_context
def request_create(ctx,
Expand All @@ -161,7 +197,8 @@ def request_create(ctx,
window_size,
endowment,
confirm,
deploy_from):
deploy_from,
no_wait):
main_ctx = ctx.parent
config = main_ctx.config
wait = config.wait
Expand Down Expand Up @@ -253,6 +290,8 @@ def request_create(ctx,
).format(factory=factory, txn_hash=create_txn_hash)
click.echo(transaction_sent_message)

if no_wait:
return
while True:
try:
click.echo("Waiting for transaction to be mined...", nl=False)
Expand Down
23 changes: 19 additions & 4 deletions alarm_client/config.py
Expand Up @@ -48,6 +48,18 @@
# testnet
'0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303': {
'contracts': {
'tracker': '0x8e67d439713b2022cac2ff4ebca21e173ccba4a0',
'factory': '0x6005cb5aa9c4774c9f1f46ef3323c1337809cdb0',
'payment_lib': '0xad4b2a1ec5b2ca6db05152cd099ff1f620e24469',
'request_lib': '0xa941e3f9ed33fe66e0e71e1524f0508018ed7a9a',
# not used yet but here for tracking purposes.
'grove_lib': '0x1a0592f14999594357a6acc0842cf7aa2aaa17a1',
'math_lib': '0x6ef5a43c15991e0c9d888819163de26a22d06a00',
'execution_lib': '0x3336852437a0f2a81d8e3e45081b17fe6a7b5599',
'itertools': '0x4b898f3ce9cf8ee05e9e800eb97267cc6fe56a78',
'request_schedule_lib': '0x032635c4bac159d1b3b138f58e23f6a80d94717a',
'safe_send_lib': '0xccb71bdec31b8d0f21f140940616b2d09334851b',
'claim_lib': '0x1c868b2a0ecd8fd2bf2e893e18fb368d38cddd1f',
}
},
}
Expand Down Expand Up @@ -132,16 +144,19 @@ def get_logger(self, name):
logger.addHandler(file_handler)

if is_rollbar_available():
import rollbar
from rollbar.logger import RollbarHandler
has_rollbar_handler = any(
isinstance(handler, RollbarHandler)
for handler in logger.handlers
)
if not has_rollbar_handler:
rb_handler = RollbarHandler(
os.environ['ROLLBAR_SECRET'],
os.environ['ROLLBAR_ENVIRONMENT'],
)
rb_secret = os.environ['ROLLBAR_SECRET']
rb_environment = os.environ['ROLLBAR_ENVIRONMENT']
if not rollbar._initialized:
rollbar.init(rb_secret, rb_environment)

rb_handler = RollbarHandler()
rb_handler.setLevel(self.log_level)
logger.addHandler(rb_handler)
return logger
Expand Down
4 changes: 4 additions & 0 deletions contracts/RequestFactory.sol
Expand Up @@ -140,3 +140,7 @@ contract RequestFactory is RequestFactoryInterface {
return requests[_address];
}
}


contract TestnetRequestFactory is RequestFactory(0x8e67d439713b2022cac2ff4ebca21e173ccba4a0) {
}
4 changes: 4 additions & 0 deletions contracts/RequestTracker.sol
Expand Up @@ -5,6 +5,10 @@ import {MathLib} from "contracts/MathLib.sol";


contract RequestTracker {
/*
* testnet: 0x8e67d439713b2022cac2ff4ebca21e173ccba4a0
* mainnet: n/a
*/
using GroveLib for GroveLib.Index;
using MathLib for uint;

Expand Down
85 changes: 60 additions & 25 deletions docs/cli.rst
Expand Up @@ -68,7 +68,18 @@ Setting up an
Rollbar Integration
-------------------

TODO
Monitoring these sorts of things can be difficult. I am a big fan of the
`rollbar`_ service which provides what I feel is a very solid monitoring and
log management solution.

To enable rollbar logging with the ``eth_alarm`` client you'll need to do the
following.

1. Install the python rollbar package.
* ``$ pip install rollbar``
2. Run ``eth_alarm`` with the following environment variables set.
* ``ROLLBAR_SECRET`` set to the *server side* token that rollbar provides.
* ``ROLLBAR_ENVIRONMENT`` set to a string such as `'production'` or `'ec2-instance-abcdefg'``.
Running a server
Expand Down Expand Up @@ -96,7 +107,7 @@ steps should get an EC2 instance provisioned with the scheduler running.
* ``sudo apt-get update --fix-missing``
* ``sudo apt-get install -y supervisor``
* ``sudo apt-get install -y python3-dev python build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev python-virtualenv``
* ``sudo apt-get install -y python3-dev python build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev python-virtualenv libffi-dev``

3. Mount the extra volume
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -152,6 +163,7 @@ Install the Alarm client.
* ``pip install setuptools --upgrade``
* ``pip install ethereum-alarm-clock-client``


6. Configure Supervisord
^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -162,24 +174,28 @@ If you are using Go-Ethereum put the following in ``/etc/supervisord/conf.d/geth
.. code-block:: shell
[program:geth]
command=geth --datadir /data/ethereum --unlock 0 --password /home/ubuntu/geth_password --rpc --fast
command=geth --datadir /data/ethereum --unlock 0 --password /home/ubuntu/scheduler_password --fast
user=ubuntu
stdout_logfile=/var/log/supervisor/geth-stdout.log
stderr_logfile=/var/log/supervisor/geth-stderr.log
autorestart=true
autostart=false
If you are using Go-Ethereum put the following in ``/etc/supervisord/conf.d/parity.conf``

.. code-block:: shell
[program:parity]
command=parity TODO
command=parity --db-path /data/ethereum --unlock <your-account-address> --password /home/ubuntu/scheduler_password
user=ubuntu
stdout_logfile=/var/log/supervisor/geth-stdout.log
stderr_logfile=/var/log/supervisor/geth-stderr.log
stdout_logfile=/var/log/supervisor/parity-stdout.log
stderr_logfile=/var/log/supervisor/parity-stderr.log
autorestart=true
autostart=false
Put the following in ``/etc/supervisord/conf.d/scheduler-v8.conf``
If you are using Go-Ethereum put the following in ``/etc/supervisord/conf.d/scheduler-v8.conf``

.. code-block:: shell
Expand All @@ -194,19 +210,37 @@ Put the following in ``/etc/supervisord/conf.d/scheduler-v8.conf``
autostart=false
7. Generate geth account
^^^^^^^^^^^^^^^^^^^^^^^^
If you are using Parity put the following in ``/etc/supervisord/conf.d/scheduler-v8.conf``

Use the following command to generate an account. The ``--datadir`` argument
is important, otherwise the generated account won't be found by our geth
process being run by supervisord.
.. code-block:: shell
[program:scheduler-v8]
user=ubuntu
command=/home/ubuntu/alarm-0.8.0/env/bin/eth_alarm --ipc-path /home/ubuntu/.parity/jsonrpc.ipc client:run
directory=/home/ubuntu/alarm-0.8.0/
environment=PATH="/home/ubuntu/alarm-0.8.0/env/bin"
stdout_logfile=/var/log/supervisor/scheduler-v8-stdout.log
stderr_logfile=/var/log/supervisor/scheduler-v8-stderr.log
autorestart=true
autostart=false
7. Generate an account
^^^^^^^^^^^^^^^^^^^^^^

For Go-Ethereum

* ``$ geth --datadir /data/ethereum account new``

Place the password for that account in ``/home/ubuntu/geth_password``.
For parity

* ``$ parity account new``

You will also need to send this account a few ether. Twice the maximum
transaction cost should be sufficient.
Place the password for that account in ``/home/ubuntu/scheduler_password``.

You will also need to send this account a few ether. A few times the maximum
transaction cost should be sufficient as this account should always trend
upwards as it executes requests and receives payment for them.

8. Turn it on
^^^^^^^^^^^^^
Expand All @@ -215,25 +249,19 @@ Reload supervisord so that it finds the two new config files.

* ``sudo supervisord reload``

You'll want to wait for ``geth`` to fully sync with the network before you
start the ``scheduler-v6`` process.
You'll want to wait for Go-Ethereum or Parity to fully sync with the network
before you start the ``scheduler-v8`` process.

9. Monitoring
^^^^^^^^^^^^^

You can monitor these two processes with ``tail``
You can monitor these processes with ``tail``

* ``tail -f /var/log/supervisor/geth*.log``
* ``tail -f /var/log/supervisor/parity*.log``
* ``tail -f /var/log/supervisor/scheduler-v6*.log``



.. _Ethereum Alarm Clock Client: https://github.com/pipermerriam/ethereum-alarm-client
.. _pip: https://pip.pypa.io/en/stable/
.. _issue 1: https://github.com/pipermerriam/ethereum-alarm-client/issues/1
.. _AWS Documentation: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html


10. Cron
^^^^^^^^

Expand All @@ -244,3 +272,10 @@ system clock up to date. I've had issues with my servers *drifting*.
.. code-block:: shell
0 0 * * * /usr/sbin/ntpdate ntp.ubuntu.com
.. _Ethereum Alarm Clock Client: https://github.com/pipermerriam/ethereum-alarm-client
.. _pip: https://pip.pypa.io/en/stable/
.. _rollbar: https://rollbar.com/
.. _AWS Documentation: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

0 comments on commit 215f62b

Please sign in to comment.