Coder Social home page Coder Social logo

stratum's Introduction

**!! Obsolete, not maintanied - DO NOT USE !!**
I keep this repository alive and open for study and historical purposes only.
It is no longer actively maintained (although there may be other forks that are still maintained).

Description:
============
This is implementation of Stratum protocol for server and client side
using asynchronous networking written in Python Twisted.

Homepage: http://stratum.bitcoin.cz

Contact to main developer:
==========================
Email info at bitcoin.cz
Nickname slush at bitcointalk.org forum

Installation
============

Requirements:
python 2.6 or 2.7
linux-based system (should work on Mac OS too, not tested)

Following instructions will work on Ubuntu & Debian*:

a) From GIT, for developers
git clone git://github.com/slush0/stratum.git 
sudo apt-get install python-dev
sudo python setup.py develop

b) From package, permanent install for production use
sudo apt-get install python-dev
sudo apt-get install python-setuptools
sudo easy_install stratum

*) Debian don't have a 'sudo' command, please do the installation
process as a root user.

Configuration
=============

a) Basic configuration
Copy config_default.py to config.py
Edit at least those values: HOSTNAME, BITCOIN_TRUSTED_*

b) Message signatures
For enabling message signatures, generate server's ECDSA key by
python signature.py > signing_key.pem
and fill correct values to SIGNING_KEY and SIGNING_ID (config.py)

c) Creating keys for SSL-based transports
For all SSL-based transports (HTTPS, WSS, ...) you'll need private key
and certificate file. You can use certificates from any authority or you can
generate self-signed certificates, which is helpful at least for testing.

Following script will generate self-signed SSL certificate:

#!/bin/bash
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -in server.csr -signkey server.key -out server.crt

Then you have to fill SSL_PRIVKEY and SSL_CACERT in config file with
values 'server.key' and 'server.crt'.

Startup
=======
Start devel server:
twistd -ny launcher.tac

Devel server *without* lowlevel messages of Twisted:
twistd -ny launcher.tac -l log/twistd.log
 
Running in production
=====================
TODO: Guide for running twistd as a daemon, init scripts
TODO: Loadbalancing and port redirecting using haproxy
TODO: Tunelling on 80/443 using stunnel
Any volunteer for this ^ ?

stratum's People

Contributors

admin-slush avatar ahmedbodi avatar rafaeldotjs avatar slush0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stratum's Issues

Python dev protect us from ourselves

So I cant install stratum because an 0ct 2017 commit of python disabled http in favor of https. So it complains

urllib2.HTTPError: HTTP Error 403: SSL is required

at the end of not being able to find files.
I tried adding an S to the http link in the setup.py script, but the source has no cert I guess.

PS "Let's Encrypt" is amazing and free way to add a cert to a site if you have any control over that side of this

ERROR protocol # Processing of message failed

2013-06-16 10:39:52,059 ERROR protocol # Processing of message failed
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/stratum-0.2.12-py2.7.egg/stratum/protocol.py", line 185, in dataReceived
    self.lineReceived(line, request_counter)
  File "/usr/local/lib/python2.7/dist-packages/stratum-0.2.12-py2.7.egg/stratum/protocol.py", line 216, in lineReceived
    raise custom_exceptions.ProtocolException("Cannot decode message '%s'" % line)
'rotocolException: Cannot decode message 'POST / HTTP/1.1
2013-06-16 10:39:52,187 ERROR protocol # Processing of message failed
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/stratum-0.2.12-py2.7.egg/stratum/protocol.py", line 185, in dataReceived
    self.lineReceived(line, request_counter)
  File "/usr/local/lib/python2.7/dist-packages/stratum-0.2.12-py2.7.egg/stratum/protocol.py", line 216, in lineReceived
    raise custom_exceptions.ProtocolException("Cannot decode message '%s'" % line)
'rotocolException: Cannot decode message 'POST / HTTP/1.1

Distribute too old

The version of distribute that comes with this repo is out of date and causes problems on Ubuntu 17.04.

Installed /usr/local/lib/python2.7/dist-packages/distribute-0.6.28-py2.7.egg
Traceback (most recent call last):
  File "setup.py", line 18, in <module>
    install_requires=['twisted', 'ecdsa', 'pyopenssl', 'autobahn',]
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "build/bdist.linux-x86_64/egg/setuptools/command/install.py", line 73, in run
  File "build/bdist.linux-x86_64/egg/setuptools/command/install.py", line 101, in do_egg_install
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 358, in run

  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 578, in easy_install

  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 630, in install_item

  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 677, in process_distribution

TypeError: __init__() takes exactly 2 arguments (4 given)

Installing the latest distribute and hacking the one included helps get past the error when installing.

pip install --upgrade distribute
Successfully uninstalled distribute-0.6.28
Successfully installed distribute-0.7.3

tcp_proxy_protocol_enable problems

Failed to load application: init() got an unexpected keyword argument 'tcp_proxy_protocol_enable'

I keep hitting this same problem. I thought it was a problem with my config file but I have gone over it 100 times. Anyone else running into this? Any solutions known?

Unable to install python setup.py

As I run "sudo python setup.py develop" I get error message
"Extracting in /tmp/tmpEop01P
Now working in /tmp/tmpEop01P/distribute-0.6.28
Building a Distribute egg in /var/www/stratum.local
Traceback (most recent call last):
File "setup.py", line 220, in
scripts = scripts,
File "/usr/lib/python2.7/distutils/core.py", line 111, in setup
_setup_distribution = dist = klass(attrs)
File "/tmp/tmpEop01P/distribute-0.6.28/setuptools/dist.py", line 225, in init
_Distribution.init(self,attrs)
File "/usr/lib/python2.7/distutils/dist.py", line 287, in init
self.finalize_options()
File "/tmp/tmpEop01P/distribute-0.6.28/setuptools/dist.py", line 257, in finalize_options
ep.require(installer=self.fetch_build_egg)
File "/tmp/tmpEop01P/distribute-0.6.28/pkg_resources.py", line 2029, in require
working_set.resolve(self.dist.requires(self.extras),env,installer))
File "/tmp/tmpEop01P/distribute-0.6.28/pkg_resources.py", line 592, in resolve
raise VersionConflict(dist,req) # XXX put more info here
pkg_resources.VersionConflict: (certifi 2017.4.17 (/usr/lib/python2.7/dist-packages), Requirement.parse('certifi==1.0.1'))
/var/www/stratum.local/distribute-0.6.28-py2.7.egg
Traceback (most recent call last):
File "setup.py", line 3, in
use_setuptools()
File "/var/www/stratum.local/distribute_setup.py", line 145, in use_setuptools
return _do_download(version, download_base, to_dir, download_delay)
File "/var/www/stratum.local/distribute_setup.py", line 125, in _do_download
_build_egg(egg, tarball, to_dir)
File "/var/www/stratum.local/distribute_setup.py", line 116, in _build_egg
raise IOError('Could not build the egg.')
IOError: Could not build the egg."

ImportError: No module named server

I ran

$ pip install --user stratum

Below is the pip.log:

------------------------------------------------------------
/usr/bin/pip-python3.2 run on Sun May 12 17:31:56 2013
Downloading/unpacking stratum

  Getting page https://pypi.python.org/simple/stratum/
  URLs to search for versions for stratum:
  * https://pypi.python.org/simple/stratum/
  Getting page http://blog.bitcoin.cz/stratum
  Could not fetch URL http://blog.bitcoin.cz/stratum (from https://pypi.python.org/simple/stratum/): HTTP Error 404: Not Found
  Will skip URL http://blog.bitcoin.cz/stratum when looking for download links for stratum
  Analyzing links from page https://pypi.python.org/simple/stratum/
    Found link https://pypi.python.org/packages/source/s/stratum/stratum-0.2.10.tar.gz#md5=047ef769135a05a21315b8161b36f35f (from https://pypi.python.org/simple/stratum/), version: 0.2.10
    Found link https://pypi.python.org/packages/source/s/stratum/stratum-0.2.11.tar.gz#md5=53dced78554ba4cdb18af4114f1bb4e4 (from https://pypi.python.org/simple/stratum/), version: 0.2.11
    Found link https://pypi.python.org/packages/source/s/stratum/stratum-0.2.12.tar.gz#md5=a685da0dce43263db08ae949568b0f54 (from https://pypi.python.org/simple/stratum/), version: 0.2.12
    Skipping link http://blog.bitcoin.cz/stratum (from https://pypi.python.org/simple/stratum/); not a file
  Using version 0.2.12 (newest of versions: 0.2.12, 0.2.11, 0.2.10)
  Downloading stratum-0.2.12.tar.gz

  Downloading from URL https://pypi.python.org/packages/source/s/stratum/stratum-0.2.12.tar.gz#md5=a685da0dce43263db08ae949568b0f54 (from https://pypi.python.org/simple/stratum/)
  Running setup.py egg_info for package stratum

    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/tmp/.private/USER/pip-build-USER/stratum/setup.py", line 8, in <module>
        from stratum import version
      File "stratum/__init__.py", line 1, in <module>
        from server import setup
    ImportError: No module named server

    Complete output from command python setup.py egg_info:

    Traceback (most recent call last):
  File "<string>", line 16, in <module>
  File "/tmp/.private/USER/pip-build-USER/stratum/setup.py", line 8, in <module>
    from stratum import version
  File "stratum/__init__.py", line 1, in <module>
    from server import setup
ImportError: No module named server

----------------------------------------

Command python setup.py egg_info failed with error code 1 in /tmp/.private/USER/pip-build-USER/stratum

Exception information:
Traceback (most recent call last):
  File "/usr/lib64/python3.2/site-packages/pip/basecommand.py", line 139, in main
    status = self.run(options, args)
  File "/usr/lib64/python3.2/site-packages/pip/commands/install.py", line 266, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib64/python3.2/site-packages/pip/req.py", line 1057, in prepare_files
    req_to_install.run_egg_info()
  File "/usr/lib64/python3.2/site-packages/pip/req.py", line 236, in run_egg_info
    command_desc='python setup.py egg_info')
  File "/usr/lib64/python3.2/site-packages/pip/util.py", line 662, in call_subprocess
    % (command_desc, proc.returncode, cwd))
pip.exceptions.InstallationError: Command python setup.py egg_info failed with error code 1 in /tmp/.private/USER/pip-build-USER/stratum

Installed /tmp/easy_install-cTLSXG/argon2_cffi-18.1.0/pycparser-2.18-py2.7.egg warning: no files found matching '*.txt' warning: no previously-included files found matching 'src/argon2/_ffi.py' warning: no previously-included files found matching '.gitmodules' warning: no previously-included files found matching 'appveyor.yml' warning: no previously-included files found matching '.readthedocs.yml' warning: no previously-included files found matching '.travis.yml' warning: no previously-included files matching '*.pyc' found under directory 'tests' no previously-included directories found matching 'docs/_build' /usr/bin/ld: cannot find -largon2 /usr/bin/ld: cannot find -largon2 collect2: error: ld returned 1 ex

I get this ๐Ÿ˜ข
Any ideea ?
Installed /tmp/easy_install-cTLSXG/argon2_cffi-18.1.0/pycparser-2.18-py2.7.egg
warning: no files found matching '.txt'
warning: no previously-included files found matching 'src/argon2/_ffi.py'
warning: no previously-included files found matching '.gitmodules'
warning: no previously-included files found matching 'appveyor.yml'
warning: no previously-included files found matching '.readthedocs.yml'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files matching '
.pyc' found under directory 'tests'
no previously-included directories found matching 'docs/_build'
/usr/bin/ld: cannot find -largon2
/usr/bin/ld: cannot find -largon2
collect2: error: ld returned 1 ex

Rejected and Job not found in cgminer

After 10 - 12 min of mining i get Rejected and job not found error. What it can be? Any ideas?
I googled this problem and saw, that many had this problem but cant see solution. One sulution was found, but it is not working for me. It was about 120 sec for new block sumbit.
PREVHASH_REFRESH_INTERVAL = 120

Max recursion depth exceeded

When I try to install this, using either sudo python setup.py develop or sudo python setup.py develop, I get a max recursion depth exceeded error. Anything you suggest? I've tried adding sys.setrecursionlimit(5000) to the beginnings of various files (after the import calls, of course), but I'm still hitting the limit. I'm thinking it might be an issue of RAM, as I don't have much, but that seems like a pretty weird issue for me to be having. It'd be pretty odd for a python module installation to use more than a few megabytes of RAM, right?

I'm trying to install using Python 2.7.6 on Ubuntu 14.04.

Edit: This is still technically an issue, but it isn't in any way urgent, as I was able to get the proxy running on my VPS via Wine. It doesn't work with Mono, but it does with Wine.

JSON-RPC 2.0 compatibility

Why is this "based" on JSON-RPC 2.0 but does some changes to the protocol and renders all existing implementations useless: https://en.wikipedia.org/wiki/JSON-RPC#Implementations

It's like pushing everyone in to the face who wants to use it and saying "No, don't use an existing JSON-RPC implementation. No, build your own..."
Yeah, im referring to the "jsonrpc": "2.0" parameter.

That's the specs from the year 2010: http://jsonrpc.org/historical/json-rpc-2-0.html
The first stratum commit is dated at 19/Dec/2011. So the specs were changed without obvious reasons (at least not for me).

Feature Request: stratum_listener.get_transactions

I'm noticing that clients are requesting stratum_listener.get_transactions.

Everytime I see the following on my client:

  • Pool 0 is sending mismatched block contents to us (0 is not 512-1023)

I see the following on the server's log:

  • 2015-03-20 20:50:14,567 WARNING proxy stratum_listener.get_transactions # mining.get_transactions isn't supported by proxy

Thanks

Ping?

Can you ping a stratum server?
Easily with a command line expression or with a small tool?

Add new method "mining.ping"

When using multiple pools, it would be useful to add a new ping method for the stratum protocol. So the worker does not need to wait until the timeout or the TCP connection lost event. It can send pings periodically, wait some seconds for the reply and if not change to the second pool.

Client: {"params": [], "id": 4, "method": "ping"}

Server: {"error": null, "id": 4, "result": true}

If the pool is sending new jobs often (every few seconds) this method is not needed, but in case the pool is sending jobs or changing difficulty not so often (depends on the coin, the block generation time, etc.), then this method might increase the performance of many workers by not spending time waiting for a pool timeout.

Python 3 support

Would be nice if Stratum would support Python 3. The 2to3 tool seems to work fine on the sources - the only catch is that the dependencies are not yet all converted (at least ecdsa fails).

twistd.log

2014-01-06 17:26:58+0800 [-] Log opened.
2014-01-06 17:26:58+0800 [-] twistd 11.1.0 (/usr/bin/python 2.7.3) starting up.
2014-01-06 17:26:58+0800 [-] reactor class: twisted.internet.epollreactor.EPollReactor.
2014-01-06 17:26:58+0800 [HTTPPageGetter,client] 2014-01-06 17:26:58,371 DEBUG stats # Logging initialized
2014-01-06 17:26:58+0800 [HTTPPageGetter,client] 2014-01-06 17:26:58,374 DEBUG protocol # Logging initialized
2014-01-06 17:26:58+0800 [HTTPPageGetter,client] 2014-01-06 17:26:58,375 DEBUG socket_transport # Logging initialized
2014-01-06 17:26:58+0800 [HTTPPageGetter,client] 2014-01-06 17:26:58,375 DEBUG http_transport # Logging initialized
2014-01-06 17:26:58+0800 [HTTPPageGetter,client] Unhandled error in Deferred:
2014-01-06 17:26:58+0800 [HTTPPageGetter,client] Unhandled Error
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1039, in _inlineCallbacks
result = g.send(result)
File "/root/stratum-mining/mining/init.py", line 112, in setup
on_startup.callback(True)
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 362, in callback
self._startRunCallbacks(result)
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 458, in _startRunCallbacks
self._runCallbacks()
--- ---
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 545, in _runCallbacks
current.result = callback(current.result, _args, *_kw)
File "/root/stratum-mining/stratum/stratum/server.py", line 46, in setup_finalize
import websocket_transport
File "/root/stratum-mining/stratum/stratum/websocket_transport.py", line 1, in
from autobahn.websocket import WebSocketServerProtocol, WebSocketServerFactory
exceptions.ImportError: cannot import name WebSocketServerProtocol

SRV Record

Hi,

First i'll start by saying I don't have any personal experience with python, other then compiling/running it,
I want to create a SRV record for stratum, But it seems like certain libraries or code needs to be added/changed in the server application ?

I know its a bit ancient, But here is a reference;
http://stackoverflow.com/questions/1189253/how-do-i-resolve-an-srv-record-in-python
http://www.dnspython.org/examples.html
http://twistedmatrix.com/trac/browser/trunk/twisted/names
http://twistedmatrix.com/pipermail/twisted-python/2002-December/002487.html

Does stratum already have a SRV record? Have i missed something?

Any assistance would be appreciated.

protocol.py - lineReceived() causes connection resets for stratum-mining

Looks like cgminer sometimes sends through data that cannot be loaded by the json library. This ends up throwing an error at line 185 in protocol.py and the connection is closed.

Can there be some type of setting to trap this error in stratum? Or is there another way to catch the error before it ends up closing the connection?

Method 'subscribe' not found for service 'mining'

JSON-RPC call failed: [
-3,
"Method 'subscribe' not found for service 'mining'",
"Traceback: : Method 'subscribe' not found for service 'mining'\n/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.py:626:_doReadOrWrite\n/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py:203:doRead\n/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py:209:_dataReceived\n/root/stratum-mining-litecoin/stratum/protocol.py:192:dataReceived\n--- ---\n/root/stratum-mining-litecoin/stratum/protocol.py:238:lineReceived\n/root/stratum-mining-litecoin/stratum/services.py:14:_handle_event\n/root/stratum-mining-litecoin/stratum/services.py:76:call\n"
]

Could you please help me in this.
I am getting error when call run the following command
./minerd --url=stratum+tcp://127.0.0.1:3332 --userpass=kiradfsdn.kiran:kiran

Develop a stratum client library

Is there an independent stratum client library in whatever programming language?

I mean of course a library I can use for arbitrary purposes, not a full-fledged client like Electrum that simply uses Stratum server.

If Electrum uses Stratum can a separate client library be extracted from it?

Subscribe() takes exactly 1 argument (2 given)

I get this error on several different setups of Stratum in various miners every time a user joins the pool:

2013-04-10 07:20:16,353 ERROR protocol # [Failure instance: Traceback: <type 'exceptions.TypeError'>: subscribe() takes exactly 1 argument (2 given)
/opt/stratum/stratum/stratum/protocol.py:192:dataReceived
/opt/stratum/stratum/stratum/protocol.py:238:lineReceived
/opt/stratum/stratum/stratum/services.py:13:_handle_event
/opt/stratum/stratum/stratum/services.py:81:call
--- ---
/usr/lib/python2.7/dist-packages/twisted/internet/defer.py:134:maybeDeferred
/opt/stratum/stratum/stratum/services.py:78:_run
]
None

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.