Permalink
Browse files

Initial commit

  • Loading branch information...
jolan committed Apr 1, 2016
0 parents commit d655cd425cfcde85b3fea3750505877fdf1634fa
Showing with 14,147 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +23 −0 LICENSE
  3. +169 −0 README.md
  4. +450 −0 config.go
  5. +19 −0 config.toml.example
  6. +9 −0 controllers/api.go
  7. +29 −0 controllers/config.go
  8. +960 −0 controllers/dcrclient.go
  9. +69 −0 controllers/log.go
  10. +642 −0 controllers/main.go
  11. +55 −0 doc.go
  12. +21 −0 helpers/auth.go
  13. +12 −0 helpers/template.go
  14. +370 −0 log.go
  15. +102 −0 models/user.go
  16. +66 −0 params.go
  17. +587 −0 public/css/bootstrap-theme.css
  18. +1 −0 public/css/bootstrap-theme.css.map
  19. +5 −0 public/css/bootstrap-theme.min.css
  20. +5,638 −0 public/css/bootstrap.css
  21. +1 −0 public/css/bootstrap.css.map
  22. +5 −0 public/css/bootstrap.min.css
  23. +15 −0 public/css/datatables.min.css
  24. +76 −0 public/css/dcrstakepool.css
  25. +641 −0 public/css/nv.d3-1.8.1.css
  26. BIN public/fonts/glyphicons-halflings-regular.eot
  27. +288 −0 public/fonts/glyphicons-halflings-regular.svg
  28. BIN public/fonts/glyphicons-halflings-regular.ttf
  29. BIN public/fonts/glyphicons-halflings-regular.woff
  30. BIN public/fonts/glyphicons-halflings-regular.woff2
  31. BIN public/images/favicon.ico
  32. BIN public/images/logo_dark.png
  33. 0 public/js/.gitkeep
  34. +2,363 −0 public/js/bootstrap.js
  35. +7 −0 public/js/bootstrap.min.js
  36. +5 −0 public/js/d3.v3.min.js
  37. +8 −0 public/js/dataTables.bootstrap-1.10.11.min.js
  38. +4 −0 public/js/html5shiv-3.7.2/html5shiv.min.js
  39. +23 −0 public/js/ie10-viewport-bug-workaround.js
  40. +5 −0 public/js/jquery-1.11.3.min.js
  41. +1 −0 public/js/jquery-1.11.3.min.map
  42. +166 −0 public/js/jquery.dataTables-1.10.11.min.js
  43. +8 −0 public/js/nv.d3-1.8.1.min.js
  44. +9 −0 public/js/parsleyjs-2.1.3/parsley.min.js
  45. +5 −0 public/js/respond-1.4.2/respond.min.js
  46. +5 −0 public/robots.txt
  47. +54 −0 sample-nginx.conf
  48. +122 −0 server.go
  49. +15 −0 system/configuration.go
  50. +35 −0 system/controller.go
  51. +124 −0 system/core.go
  52. +33 −0 system/gzip.go
  53. +135 −0 system/middleware.go
  54. 0 tmp/.gitkeep
  55. +73 −0 version.go
  56. +48 −0 views/address.html
  57. +38 −0 views/auth/signin.html
  58. +63 −0 views/auth/signup.html
  59. +29 −0 views/error.html
  60. +145 −0 views/footer.html
  61. +32 −0 views/header.html
  62. +22 −0 views/home.html
  63. +45 −0 views/main.html
  64. +75 −0 views/maintenance.html
  65. +54 −0 views/stats.html
  66. +10 −0 views/status.html
  67. +10 −0 views/stresstest.html
  68. +121 −0 views/tickets.html
@@ -0,0 +1,2 @@
config.toml
dcrstakepool
23 LICENSE
@@ -0,0 +1,23 @@
The MIT License (MIT)

Copyright (c) 2014 Pawel Szymanski (pawel@mikesz.com)
Copyright (c) HARUYAMA Seigo <hauyama@unixuser.org>
Copyright (c) 2016 The Decred developers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
169 README.md
@@ -0,0 +1,169 @@
dcrstakepool
====

dcrstakepool is a minimalist web application which provides a method for allowing users to purchase tickets and have a pool of wallet servers redeem and vote on the user's behalf.

## Requirements

- [Go](http://golang.org) 1.5.3 or newer.
- MySQL
- Nginx or other web server to proxy to dcrstakepool

## Installation

#### Linux/BSD/MacOSX/POSIX - Build from Source

- Install Go according to the installation instructions here:
http://golang.org/doc/install

- Ensure Go was installed properly and is a supported version:

```bash
$ go version
$ go env GOROOT GOPATH
```

NOTE: The `GOROOT` and `GOPATH` above must not be the same path. It is
recommended that `GOPATH` is set to a directory in your home directory such as
`~/goprojects` to avoid write permission issues.

- Run the following command to obtain dcrstakepool, all dependencies, and install it:

```bash
$ go get -u github.com/decred/dcrstakepool-private/...
```

- dcrstakepool (and utilities) will now be installed in either ```$GOROOT/bin``` or
```$GOPATH/bin``` depending on your configuration. If you did not already
add the bin directory to your system path during Go installation, we
recommend you do so now.
## Setup
#### Pre-requisites
These instructions assume you are familiar with dcrd/dcrwallet.
- Create basic dcrd/dcrwallet/dcrctl config files with usernames, passwords, rpclisten, and network set appropriately within them or run example commands with additional flags as necessary
- Build/install dcrd and dcrwallet from latest master
- Run dcrd instances and let them fully sync
#### dcrwallet
- Create the wallets. All wallets should have the same seed. **Backup the seed for disaster recovery!**
```bash
$ dcrwallet --create
```

- Start dcrwallet with debug on (this prints the position of the address index which is useful if getnewaddress fails and the wallets get de-synced)

```bash
$ dcrwallet -d debug
```

- Unlock the wallet

```bash
$ dcrctl --wallet walletpassphrase pass 0
```

#### MySQL

- Install, configure, and start MySQL

- Add stakepool user and create the stakepool database

```bash
$ mysql -uroot -ppassword
MySQL> CREATE USER 'stakepool'@'localhost' IDENTIFIED BY 'password';
MySQL> GRANT ALL PRIVILEGES ON *.* TO '%' WITH GRANT OPTION;
MySQL> FLUSH PRIVILEGES;
MySQL> CREATE DATABASE stakepool;
```

#### Nginx/web server

- Adapt sample-nginx.conf or setup a different web server in a proxy configuration

#### dcrstakepool

- Register a recaptcha key for your domain at https://www.google.com/recaptcha/admin

- Generate a secret for cookie authentication

```bash
$ openssl rand -hex 32
```

- add wallet server information to controllers/config.go

- Create the .dcrstakepool directory and copy dcrwallet certs to it
```bash
$ mkdir ~/.dcrstakepool
$ cd ~/.dcrstakepool
$ scp walletserver1:~/.dcrwallet/rpc.cert wallet1.cert
$ scp walletserver2:~/.dcrwallet/rpc.cert wallet2.cert
$ scp walletserver3:~/.dcrwallet/rpc.cert wallet3.cert
```

- add recaptcha secret to controllers/main.go and recaptcha sitekey to views/auth/signup.html or disable captcha if you don't want it

- copy sample config and edit appropriately
```bash
$ cp -p config.toml.sample config.toml
```

- Run dcrstakepool

## Operations

- dcrstakepool will connect to the database or error out if it cannot do so

- dcrstakepool will create the stakepool.Users table automatically if it doesn't exist

- dcrstakepool attempts to connect to all of the wallet servers on startup and or error out if it cannot do so

- dcrstakepool takes a user's pubkey, validates it, calls getnewaddress on all the wallet servers, then createmultisig, and finally importscript. If any of these RPCs fail or returns inconsistent results, the RPC client built-in to dcrstakepool will shut down and will not operate until it has been restarted. Wallets should be verified to be in sync before restarting.

## Backups, monitoring, security considerations

- MySQL should be backed up often and regularly (probably at least hourly). Backups should be transferred off-site. If using binary backups, do a test restore. For .sql files, verify visually.

- A monitoring system with alerting should be pointed at dcrstakepool and tested/verified to be operating properly. There is a hidden /status page which throws 500 if the RPC client is shutdown. If your monitoring system supports it, add additional points of verification such as: checking that the /stats page loads and has expected information in it, create a test account and setup automated login testing, etc.

- Wallets should never be used for anything else (they should always have a balance of 0)

## Disaster Recovery

**Always keep at least one wallet voting while performing maintenance / restoration!**

- In the case of a total failure of a wallet server:
* Restore the failed wallet(s) from seed
* getnewaddress until it matches the index of the other wallets
* Import scripts for all users
```bash
for s in `mysql -ustakepool -ppassword -Dstakepool -se 'SELECT Multisigscript FROM Users WHERE LENGTH(Multisigscript) != 0'`;
do dcrctl --wallet importscript "$s";
done
```

- If servers get desynced but are otherwise running okay, call getnewaddress/listscripts/importscript until they're re-synced. See doc.go for some example shell commands.

## TODO

- vendor goji
- fix flags conflict between goji/dcrstakepool
- finish unified config file

## Issue Tracker

The [integrated github issue tracker](https://github.com/decred/dcrstakepool-private/issues)
is used for this project.

## License

dcrstakepool is licensed under the [copyfree](http://copyfree.org) ISC License.
Oops, something went wrong.

0 comments on commit d655cd4

Please sign in to comment.