Skip to content

Instantly share code, notes, and snippets.

@mathfarmer
Last active August 29, 2015 14:08
Show Gist options
  • Save mathfarmer/d70b11fc1061c9a99981 to your computer and use it in GitHub Desktop.
Save mathfarmer/d70b11fc1061c9a99981 to your computer and use it in GitHub Desktop.
SimpleCoin: The Missing Setup Guide

SimpleCoin: The Missing Setup Guide

The following should get you a running SimpleCoin pool that generates valid merge-mined blocks and pays them out to users. The setup is based on a relatively stock Xubuntu 14.04 distribution, and assumes bash as the shell.

While the guide below includes a lot of the data from the README files, it does not include all of it, so make sure to read each README file in addition to this guide.

Install Prerequisites

Installing python2.7 and virtualenv

Install python2.7 and a package and environment setup system:

sudo apt-get install git python2.7-dev
sudo apt-get install python-setuptools 
sudo easy_install pip
sudo pip install --upgrade pip virtualenv virtualenvwrapper

The following should be invoked before running any of the commands to setup, install, or run the pool.

# Python virtualenv support
export WORKON_HOME=$HOME/Envs
source /usr/local/bin/virtualenvwrapper.sh

Installing the needed packages for PowerPool and SimpleCoin:

PowerPool should only need rabbitmq and redis, SimpleCoin needs all of the following:

apt-get install redis-server postgresql-contrib-9.3 postgresql-9.3 postgresql-server-dev-9.3 
# to install rabbitmq as well
apt-get install rabbitmq-server
# add the ppa that includes latest version of nodejs. Ubuntu repos are really out of date
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get install nodejs npm

Check to see if node is installed in /usr/bin/node or if it is in /usr/bin/nodejs. If the latter:

ln -s /usr/bin/nodejs /usr/bin/node

Install PowerPool

cd to wherever you want to install, then:

# Setup the virtualenv:
mkvirtualenv powerpool
# Install powerpool from github:
git clone https://github.com/simplecrypto/powerpool.git
cd powerpool
# Install all [most] of powerpools dependencies
pip install -r requirements.txt
# install the rest of powerpool's dependencies:
pip install redis
pip install celery
# Install powerpool
pip install -e .
# Install the hashing algorithm modules for the coins you are going to support
#pip install vtc_scrypt  # for scryptn support
#pip install drk_hash  # for x11 support
pip install ltc_scrypt  # for scrypt support
#pip install git+https://github.com/BlueDragon747/Blakecoin_Python_POW_Module.git@e3fb2a5d4ea5486f52f9568ffda132bb69ed8772#egg=blake_hash

Configure your config.yml file. Some changes that you will need to make in order to get things running properly:

# This is only really needed for SimpleMulti
RR:
    type: powerpool.reporters.RedisReporter
    redis:
        db: 15
    # Configures special users which will get all the pool shares reported to
    # them
    pool_report_configs:
        - worker_format_string: "{chain}"
          user: "pool"
        - worker_format_string: "{currency}"
          user: "pool_currency"
          report_merge: True
        - worker_format_string: "{algo}"
          user: "pool_algo"
    # **** ADD THIS ****
    attrs:
        # Name to report in the pool stats graph. This can be different per stratum if desired.
        # You have to include this key (or disable redis reporting) or PowerPool will fail.
        chain: "USA east"
CR:
    type: powerpool.reporters.CeleryReporter
    # **** ADD THIS ****
    # Configures special users which will get all the pool shares reported to
    # them
    pool_report_configs:
        - worker_format_string: "{chain}"
          user: "pool"
        # I don't think you really need the two below for SimpleCoin, but whatever.
        - worker_format_string: "{currency}"
          user: "pool_currency"
          report_merge: True
        - worker_format_string: "{algo}"
          user: "pool_algo"
    attrs:
        # Name to report in the pool stats graph. This can be different per stratum if desired.
        # You have to include this key or PowerPool will fail.
        chain: "USA east"

Stratum stats are available on port 3855, with stats specific to each module (top-level key) defined in the config.yml available at the corresponding path (e.g. the redis stats would be at http://127.0.0.1:3855/RR). You thus might want to rename 'TEST_STRAT' to something else, like 'stratum'. SimpleMulti uses this to get some of its data from PowerPool, so it is important that the names match between the two configurations there, but it is not important when only running SimpleCoin.

You'll also need to add a valid address for the primary coin to the StratumServer config via the 'donate_key' key. Failure to do so will cause shares with invalid usernames to be credited to 'donate' in the DB, which will break payouts.

You can disable redis reporting by commenting out (or deleting) the RR and DR sections, and changing the 'reporter' key in the StratumServer section to 'CR'. It doesn't seem to be needed for SimpleCoin, only SimpleMulti (which in turn does not seem to need the celery reporter).

PowerPool should now be installed.

Run PowerPool

Run the following to start the stratum server:

workon powerpool
pp config.yml

Note that the 'mkvirtualenv powerpool' command above implicitly performs a 'workon powerpool' command at the end of its action, so that command is not needed if you start PowerPool in the same bash session as you used when installing. It will be required before any subsequent session, however, and should be part of any startup script.

Install SimpleCoin

cd to wherever you want to install, then:

# make a new virtual enviroment for simpledoge
mkvirtualenv simplecoin
# clone the source code repo
git clone https://github.com/simplecrypto/simplecoin.git
cd simplecoin
pip install -e .
# install all python dependencies
pip install -r requirements.txt
pip install -r dev-requirements.txt
# install nodejs dependencies for grunt
## setup grunt binary globally
sudo npm install -g grunt-cli
## setup all the grunt libs local to the project
npm install

At this point, you should set up your config.yml:

  • When setting 'mon_address' in 'monitor_addrs', append /05 to the end of the URL (e.g. http://127.0.0.1/3855/05). This is how you access the PowerPool legacy reporting option (the latest versions of PowerPool have been updated for SimpleMulti; SimpleCoin needs the older reports).
  • You must have a payout_fee percentage set (even if 0.0) for each coin, or else payouts will break.
  • You must enter a donate_address for each coin, or else payouts will break.
  • You should probably enter a catchall_address for each coin, or payouts will probably break at some point. This address seems to only be used as the address in the sample config on the home page. Not setting it should not cause payouts to break. Actual invalid addresses end up paying out to the donate_address instead.

Next, initialize the database:

# creates a new user with password testing, creates the database, enabled
# contrib extensions
./util/reset_db.sh
# creates the database schema for simpledoge, requires config.yml to be present
python manage.py init_db

Run SimpleCoin

There are four processes that need to be run:

  1. The main website
  2. The celery worker to talk to the stratum process
  3. The scheduler, which runs the background processes (like confirming blocks, populating network info, pool info, etc.)
  4. The payout code

All of the processes need to be in the simplecoin virtualenv to run correctly, so similar to the PowerPool instructions, make sure that 'workon simplecoin' has been run before any of the commands below are executed:

Run the main website

grunt watch

Note that stopping grunt will not shut down the webserver; that requires killing gunicorn

Run the celery worker

python simplecoin/celery_entry.py -l INFO

Run the background process

python simplecoin/scheduler.py

Run the payouts

These commands execute a single payout run, and so need to be triggered periodically (presumably by a cron job). If the payout run encounters an error that stops it from completing a payout, it will lock the offending transactions in the DB and write them out to a file. You can call 'sc_rpc reset_trans_file FILE_NAME' to unlock them and have the pool try to process them agagin in the next payout run. The directory where these files go is set by the -d option (LOCKED_TRANS_FILE_DIR below).

Note that the sc_rpc command itself is included in the bin folder of the simplecoin virtualenv. It will be in the $PATH when that environment has been activated.

# Run the payout for the primary coin:
sc_rpc -l INFO proc_trans -d LOCKED_TRANS_FILE_DIR >> payout.log
# Run the payout for each merged coin (specified by symbol, e.g. DOGE, SYS, ULTC):
sc_rpc -l INFO proc_trans -d LOCKED_TRANS_FILE_DIR -m DOGE >> payout-doge.log
sc_rpc -l INFO proc_trans -d LOCKED_TRANS_FILE_DIR -m SYS >> payout-sys.log
sc_rpc -l INFO proc_trans -d LOCKED_TRANS_FILE_DIR -m ULTC >> payout-ultc.log
# Check to make sure that the transactions have been confirmed (default is 6 confirmations):
sc_rpc -l INFO confirm_trans >> confirm.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment