MinerGain Forum

Full Version: creating a stratum server
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So there are some coins that can still be solo mined.  Here are instructions from https://bitcointalk.org/index.php?topic=162788.0 - re-posted here in case they disappear...

This is use at your own risk. I'm not a expert. I don't have asic miner so I cant test it on real btc, works on testnet though and gives shares to gpu miner fine and testnet coins fine.
So I am not responsible if you lose your real coins.

Re the major pools.
They seem to be good people and the amount of work they do and investment over the years including writing the software below, should be worth the 1 to 3 percent they ask. But in the name of diversity..

You can do this in virtual box to give it a try out first.

So you have yourself a ubuntu 12.10 32bit (see a post further down on what changes are needed for 64bit) linux server install and you want to setup a pool server for solo mining on it.

I have added a part for ubuntu 12.04 32bit its in blue.

I normally do this from windows box using putty to ssh into the ubuntu box.
Things you need

Make sure your login is in the sudoers list (this will be automatic if you installed from dvd and created your login name with the installer).

Then at the command prompt first thing we are going to do is update and upgrade the system to the latest packages
with all the sudos you have to put your login password in when it asks for it.
with the apt-get installs hit y and enter whenever it asks you.
Code:
sudo apt-get update

once its complete

Code:
sudo apt-get upgrade

now to install bitcoind

make sure git is installed first

Code:
sudo apt-get install git

now make directory under you home one called like so

Code:
mkdir git

change the directory you just made

Code:
cd git

get the source for bitcoind instructions to build it are also here

Code:
git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin
git checkout v0.8.6

Install the build dependencies
Code:
sudo apt-get install build-essential
sudo apt-get install libssl-dev
sudo apt-get install libboost-all-dev
sudo apt-get install libminiupnpc-dev

wget https://launchpad.net/~bitcoin/+archive/bitcoin/+files/libdb4.8_4.8.30-quantal2_i386.deb
wget https://launchpad.net/~bitcoin/+archive/bitcoin/+files/libdb4.8-dev_4.8.30-quantal2_i386.deb
wget https://launchpad.net/~bitcoin/+archive/bitcoin/+files/libdb4.8%2B%2B_4.8.30-quantal2_i386.deb
wget https://launchpad.net/~bitcoin/+archive/bitcoin/+files/libdb4.8%2B%2B-dev_4.8.30-quantal2_i386.deb

sudo dpkg -i libdb4.8_4.8.30-quantal2_i386.deb
sudo dpkg -i libdb4.8-dev_4.8.30-quantal2_i386.deb
sudo dpkg -i libdb4.8++_4.8.30-quantal2_i386.deb
sudo dpkg -i libdb4.8++-dev_4.8.30-quantal2_i386.deb

*********************
[color=blue][font=Verdana]This is the libdb4.8 packages for only fo ubuntu 12.04  dont use these if you are using ubuntu 12.10

wget [url=https://launchpad.net/ubuntu/+source/db4.8/4.8.30-11ubuntu1/+build/3392254/+files/libdb4.8-dev_4.8.30-11ubuntu1_i386.deb]https://launchpad.net/ubuntu/+source/db4.8/4.8.30-11ubuntu1/+build/3392254/+files/libdb4.8-dev_4.8.30-11ubuntu1_i386.deb[/url]
wget [url=https://launchpad.net/ubuntu/+source/db4.8/4.8.30-11ubuntu1/+build/3392254/+files/libdb4.8_4.8.30-11ubuntu1_i386.deb]https://launchpad.net/ubuntu/+source/db4.8/4.8.30-11ubuntu1/+build/3392254/+files/libdb4.8_4.8.30-11ubuntu1_i386.deb[/url]
wget [url=https://launchpad.net/~bitcoin/+archive/bitcoin/+files/libdb4.8%2B%2B_4.8.30-10precise1_i386.deb]https://launchpad.net/~bitcoin/+archive/bitcoin/+files/libdb4.8%2B%2B_4.8.30-10precise1_i386.deb[/url]
wget [url=https://launchpad.net/~bitcoin/+archive/bitcoin/+files/libdb4.8%2B%2B-dev_4.8.30-10precise1_i386.deb]https://launchpad.net/~bitcoin/+archive/bitcoin/+files/libdb4.8%2B%2B-dev_4.8.30-10precise1_i386.deb[/url][/font][/color]

sudo dpkg -i libdb4.8_4.8.30-11ubuntu1_i386.deb
sudo dpkg -i libdb4.8-dev_4.8.30-11ubuntu1_i386.deb
sudo dpkg -i libdb4.8++_4.8.30--10-precise1_i386.deb
sudo dpkg -i libdb4.8++-dev_4.8.30-10precise1_i386.deb
*********************

then to build

Code:
cd src/
make -f makefile.unix

once its finished building without errors, copy it into /usr/local/bin
Code:
sudo cp ./bitcoind /usr/local/bin/


then run it by typing
Code:
bitcoind
it will output

Code:
Error: To use bitcoind, you must set a rpcpassword in the configuration file:
/home/yourusername/.bitcoin/bitcoin.conf
It is recommended you use the following random password:
rpcuser=bitcoinrpc
rpcpassword=EjkjenJHJhhfdkwemkjmnkk37883njn37hfdkjn38n
(you do not need to remember this password)
The username and password MUST NOT be the same.
If the file does not exist, create it with owner-readable-only file permissions.
cut and past the rpcuser and rpcpassword lines to a temporary text file and save it for later.


now create the bitcoin.conf file
Code:
cd
cd .bitcoin

open up bitcoin.conf in a text editor like pico
Code:
pico bitcoin.conf

add the lines and cut and paste the two lines from above that you saved from above from the temporary text file into the bitcoin.conf

Code:
server=1
rpcport=8332
rpctimeout=30

so it should look like this once finsihed


Code:
server=1
rpcport=8332
rpctimeout=30
rpcuser=bitcoinrpc
rpcpassword=EjkjenJHJhhfdkwemkjmnkk37883njn37hfdkjn38n

Code:
then press cntrl x
hit y to save
hit enter to save it to bitcoin.conf

then change the permissions on bitcoin.conf to user only read permissions

Code:
chmod go-rwx bitcoin.conf

now start bitcoind  on the testnet

Code:
bitcoind -testnet -daemon

it should show


Code:
Bitcoin server starting
hit enter again to get back to shell prompt

after a couple of minutes on the command line type
Code:
bitcoind getinfo

you get something similar to

Code:
blah@ks3098647:~$ bitcoind getinfo
{
    "version" : 80000,
    "protocolversion" : 70001,
    "walletversion" : 60000,
    "balance" : 0.00000000,
    "blocks" : 32935,
    "timeoffset" : -5,
    "connections" : 17,
    "proxy" : "",
    "difficulty" : 11.90472507,
    "testnet" : True,
    "keypoololdest" : 1364506205,
    "keypoolsize" : 101,
    "paytxfee" : 0.00000000,
    "errors" : ""
}

it will take about 10 to 20 minutes to download the testnet coin chain.

Now onto the pool server which is at https://github.com/generalfault/stratum-...er/INSTALL

Code:
cd
cd git
git clone https://github.com/slush0/stratum.git
git clone https://github.com/generalfault/stratum-mining.git

sudo apt-get install python-dev
sudo apt-get install python-setuptools
sudo apt-get install python-crypto
sudo easy_install -U distribute
sudo easy_install stratum
sudo easy_install simplejson

cd stratum-mining/conf
cp config_sample.py config.py

now get the testnet wallet address from bitcoind

Code:
bitcoind getaccountaddress ""

copy this adddress to the clipboard

now edit the config.py file by

Code:
pico config.py

edit the line that says central wallet

delete the text between the ' '

then past you key from the clipboard in between the ' '

so it should look like this

Code:
CENTRAL_WALLET = 'mv9mpc6xLEZNYpXJtodRrfjbyF3kbbr7CL'   # local bitcoin address where money goes

this has to be correct as this is where your coins that you mine go not so bad for the testnet ones we do first, very bad if you get it wrong and you mine real btc.

The BITCOIN_TRUSTED_USER = 'bitcoinrpc' should be the same as in the trusted user you saved to a text file ealier if you lost it its the same on as in the bitcoin.conf file.

The BITCOIN_TRUSTED_PASSWORD = 'some password'  line should be edited to become BITCOIN_TRUSTED_PASSWORD = ''  then paste your trusted password from the temporary text file from earlier if you lost it its the same on as in the bitcoin.conf file.

it should look something like this

Code:
BITCOIN_TRUSTED_PASSWORD = 'BRqw9gB78hcm6qSZ7DHvuTPWxCPVHzE9BY9gkFTddBNH'

Code:
cntrl x and hit y to save then enter to save to that file name

then

Code:
cd ..

start the server by running this on the command line

Code:
twistd -ny launcher.tac -l -

the output should be like this

Code:
2013-03-31 00:04:32,584 INFO mining # Connecting to bitcoind...
2013-03-31 00:04:32+0100 [-] Log opened.
2013-03-31 00:04:32+0100 [-] twistd 12.3.0 (/usr/bin/python 2.7.3) starting up.
2013-03-31 00:04:32+0100 [-] reactor class: twisted.internet.epollreactor.EPollReactor.
2013-03-31 00:04:33,353 INFO mining # Connected to bitcoind - Ready to GO!
2013-03-31 00:04:33,372 INFO coinbaser # Coinbase address 'yourwalletkeyhere' is valid
2013-03-31 00:04:33,375 INFO mining # MINING SERVICE IS READY
2013-03-31 00:04:33+0100 [HTTPPageGetter,client] Loading of signing key 'None' failed, protocol messages cannot be signed.
2013-03-31 00:04:33+0100 [HTTPPageGetter,client] Cannot initiate SSL context, are SSL_PRIVKEY or SSL_CACERT missing?
2013-03-31 00:04:33+0100 [HTTPPageGetter,client] This will skip all SSL-based transports.
2013-03-31 00:04:33+0100 [HTTPPageGetter,client] SocketTransportFactory starting on 3333
2013-03-31 00:04:33+0100 [HTTPPageGetter,client] Starting factory <stratum.socket_transport.SocketTransportFactory instance at 0x8c94cec>
2013-03-31 00:04:33+0100 [HTTPPageGetter,client] Site starting on 8889
2013-03-31 00:04:33+0100 [HTTPPageGetter,client] Starting factory <lib.basic_stats.Site instance at 0x8ce8b2c>
2013-03-31 00:04:34,107 INFO template_registry # New template for 00000000000000e272aaab8803cb27f73563f3accd373f6cc838be7e10d886ae
2013-03-31 00:04:34,108 INFO subscription # BROADCASTED to 0 connections in 0.000 sec
2013-03-31 00:04:34,108 INFO template_registry # Update finished, 0.256 sec, 297 txes

you should be able to point your miner at

http://YOURHOSTNAMEORIPADDRESS:3333

eg cgminer -o yourhostnameORIPADRESS:3333 -u guest -p guest

(the guest can bereplaced by any username/password you want)

you should see it connect and be given work

Once your miner has mined some blocks check the transactions are showing in the wallet by running this

Code:
bitcoind listtransactions

it should show the incoming blocks you have mined (the testnet balamce wont show in getinfo till they are confirmed 120 times)

Now to setup blocknofity so bitcoind will tell the pool software when a new block is deteced instead of having the pool server poll bitciond every 5 seconds.

there is script to generate the hash of the password to put in the pool servers config.py generate it by using the command below replace somepassword with the password you wish to use.

Code:
./scripts/generateAdminHash.sh somepassword

it should outsomething like this
Code:
blah@ks3098644:~/git/stratum-mining$ ./scripts/generateAdminHash.sh somepassword1
37bc885f08c043f1cb9852956e01ca0d07ba664a5eee14fc417408c01aae063d

copy the hash(the long sequence of letters and numbers) and past it into the config.py file

by editing via
Code:
pico ./conf/config.py

then find the

Code:
ADMIN_PASSWORD_SHA256 = none
line in the config.py file and change that line to

Code:
ADMIN_PASSWORD_SHA256 = 'youhashhere'

so using the hash i made above I  should end up with something like this below, the hash you paste in must be surround by these ' '


Code:
ADMIN_PASSWORD_SHA256 = '37bc885f08c043f1cb9852956e01ca0d07ba664a5eee14fc417408c01aae063d'
save it by hitting cntrl x then y then enter
now to test it

restart the pool server or run it again if you stopped it before

to start it again run

Code:
twistd -ny launcher.tac -l -

at a new command prompt

Code:
./scripts/blocknotify.sh --password somepassword1 --host localhost --port 3333

if its working it should display something like below (the amount of time it takes to notify will change each time)

blocknotify: done in 0.012 sec

now to add blocknotify to bitcoind
stop the bitcoin server by

Code:
bitcoind stop

wait for it to stop then type in the following line replace yourusername with your username you log into ubuntu with and replace somepassword1 with the password you used to create the admin hash before.

Code:
bitcoind -blocknotify="/home/yourusername/git/stratum-mining/scripts/blocknotify.sh --password somepassword1 --host localhost --port 3333" -testnet -daemon

if it starts up check the output from the pool server for and if you see the blocknotify notifications coming in then edit config.py with

Code:
pico ./conf/config.py

and find the line below

PREVHASH_REFRESH_INTERVAL =

edit it to the same as the line below


Code:
PREVHASH_REFRESH_INTERVAL = 60
save it by hitting cntrl x then y then enter
restart the pool again switch to the command prompt that has the pool running  and hit control c which will stop the server.

Then enter to start it again run
Code:
twistd -ny launcher.tac -l -

it should run and it should show when new blocks are found.

If all is working we can change over to the real btc network

first stop the pool server using cntrl c on the command prompt with its output.

Then stop bitcoind with
Code:
bitcoind stop

If you dont want to wait the 8 to 24 hours to download the real bitcoin chain

You can get a bootstrap chain  bootstrap file which is on  source forge and can  downloaded via a torrent file which you can download and then upload to the ubuntu server and put it in the .bitcoin directory under your home directory before you start bitcoind.

Information here http://sourceforge.net/projects/bitcoin/...lockchain/

link to the torrent file below

http://downloads.sourceforge.net/project...at.torrent

If your downloading it all or using bootstrap file

start bitcoind replace yourusername with your username you log into ubuntu with and replace somepassword1 with the password you used to create the admin hash before.
Code:
bitcoind -blocknotify="/home/yourusername/git/stratum-mining/scripts/blocknotify.sh --password somepassword1 --host localhost --port 3333" -daemon
*notice the -testnet flag has been removed from the line above

wait for it sync up to the current blocks. (It MUST be synced before you can mine on the pool)

On the command line you can check the current blocks by

Code:
bitcoind getblockcount

you can check the current blocks on the normall bitcoind-qt client by hovering over the green check mark it will pop up the current block. When these two numbers are the same or very close then your wallet on bitcoind is synced up.

Now we have to edit config.py to put a real Bitcoin address in there so you get your coins when you mine them!

on the command line
Code:
cd
cd git/stratum-mining/
pico conf/config.py
find the line
CENTRAL_WALLET = 'mv9mpc6xLEZNYpXJtodRrfjbyF3kbbr7CL'   # local bitcoin address where money goes

replace the wallet address with a real one generated from whatever wallet software you use.

It should look something like this

CENTRAL_WALLET = '1jxc4KgRXCkn2JD7QjmgMrDKqM2yQtPAp'   # local bitcoin address where money goes

(DO NOT USE THE WALLET ADDRESS IN THE ABOVE LINE)

The address MUST have the ' ' chars around it like above.

If this line is not correct you will lose your coins!
(The pool will warn you if its not a valid address, but a vaild one can still be a wrong address i.e not one you own)


further down in the config.py file find this line ALLOW_NONLOCAL_WALLET = True                            # Allow valid, but NON-Local wallet's

change ALLOW_NONLOCAL_WALLET = False
to


Code:
ALLOW_NONLOCAL_WALLET = True
save it by hitting cntrl x then y then enter
start the pool by typing on the command line

Code:
twistd -ny launcher.tac -l -

The pool server will tell you if bitcoind is not synced when you start it as well.

does it show the btc wallet address is valid?
does it show that bitcoin is synced?

if so cntrl c

then started the server again using


Code:
twistd -ny launcher.tac -l - &

(On headless servers, You can use screen to run the server in so you can reattach back to screen and see the output of the server. just type screen on the command

line and it will load up to a new command prompt, start the server as usual. when you done before you disconnect or close your ssh session do a cntrl d  which will detach screen. When you login next and want to look at the pool server output type screen -r on the command line.)
Mine away [Image: smiley.gif]

You can set the config.py to its unwriteable (can be changed by root or your user login) on the command prompt type

Code:
cd
cd git/stratum-mining/conf
chmod a-w config.py
If you find a block it and the wallet address you used is in a bitcoin-qt client it will notify you and show up under the label immature until it has been confirmed 120 times.

You can check some basic server stats at(this works when you are mining testnet as well).

http://yourserveripaddress:8889/

For asic miners you might need to increase the threads in this line in config.py

THREAD_POOL_SIZE = 30

give this a try

THREAD_POOL_SIZE = 150

I don't own a asic miner so I cannot try it out, some of pool owners might be able to give recommendations.

If the machine is rebooted for some reason you will have to start bitcoind and the pool server again. This can be automated if you want.
The blocknotify I assume can be moved from the command line into the bitcoin.conf file.
Eg add this to bitcoin.conf replacing the bits you need.
Code:
blocknotify=/home/yourusername/git/stratum-mining/scripts/blocknotify.sh --password somepassword1 --host localhost --port 3333

then just running bitcoind  like this


Code:
bitcoind -daemon

Cheers and good luck with your mining.

edit: fixed a cut and paste [Image: smiley.gif]
edit:6/4 Removed quotes on line to put in bitcoin.conf
edit:9/4 Changed git repository, and changing to current stable version 0.8.1
edit:9/6 Added part for ubuntu 12.04 also changed bitcoin version to 0.8.2
Tips: 1MivVoqttGDpqK8qZzJcfQdkwUG91bGC7G