jtoomim / p2pool

Peer-to-peer Bitcoin mining pool
https://github.com/jtoomim/p2pool/
GNU General Public License v3.0
38 stars 46 forks source link

exceptions.KeyError: 'version-rolling.min-bit-count' #41

Closed arruah closed 5 years ago

arruah commented 5 years ago

Some times I get this error on the debug log 2019-10-18 00:14:20.862869 >>>Authorize: 1CVaiBEx8t8Qiq5CK1Tu63BBuByU9qjFMf+119808 from 192.162.65.242 Squelched JSON error: Traceback (most recent call last): File "/usr/local/lib/pypy2.7/dist-packages/Twisted-17.9.0-py2.7-linux-x86_64.egg/twisted/protocols/basic.py", line 454, in dataReceived self.lineReceived(line) File "/home/kamren/p2pool/p2pool/util/jsonrpc.py", line 164, in lineReceived _handle(line, self, response_handler=self._matcher.got_response).addCallback(lambda line2: self.sendLine(line2) if line2 is not None else None) File "/usr/local/lib/pypy2.7/dist-packages/Twisted-17.9.0-py2.7-linux-x86_64.egg/twisted/internet/defer.py", line 1532, in unwindGenerator return _inlineCallbacks(None, gen, Deferred()) File "/usr/local/lib/pypy2.7/dist-packages/Twisted-17.9.0-py2.7-linux-x86_64.egg/twisted/internet/defer.py", line 1386, in _inlineCallbacks result = g.send(result) --- <exception caught here> --- File "/home/kamren/p2pool/p2pool/util/jsonrpc.py", line 85, in _handle result = yield method_meth(*list(preargs) + list(params)) File "/home/kamren/p2pool/p2pool/bitcoin/stratum.py", line 48, in rpc_configure minbitcount = extensionParameters['version-rolling.min-bit-count'] exceptions.KeyError: 'version-rolling.min-bit-count'

jtoomim commented 5 years ago

It looks like you might have a miner on your network (at address 192.162.65.242) that is sending malformed stratum requests -- specifically, sending requests with the version-rolling extension enabled (which is used for AsicBoost) but without specifying the min-bit-count argument (which is required by the spec). P2pool doesn't actually need or use the min-bit-count argument, so one workaround could be to comment out the following line in p2pool/bitcoin/stratum.py:

        minbitcount = extensionParameters['version-rolling.min-bit-count']

change to:

        #minbitcount = extensionParameters['version-rolling.min-bit-count']

That's probably line 58, but if you're not using the same branch/version that I am, it might be a different line number.

The "correct" way to solve this problem would be to complain to the manufacturer of that miner. But the correct solution is probably not the easiest solution.

What miner type is that?

jtoomim commented 5 years ago

I did some packet sniffing from a Braiins OS miner client, and I found Braiins sends this mining.configure message to p2pool:

{"id": 32, "method": "mining.configure", "params": [["version-rolling"], {"version-rolling.bit-count": 2, "version-rolling.mask": "ffffffff"}]}

This is an incorrectly formatted message, according to the version-rolling extension spec (https://github.com/slushpool/stratumprotocol/blob/master/stratum-extensions.mediawiki). The spec requires a parameter called version-rolling.min-bit-count, but Braiins is providing version-rolling.bit-count (no min-). P2pool doesn't actually do anything with this parameter except parse it, but the absence of the required parameter is causing a parsing error and a closing of the stratum connection.

It should be pretty easy to implement a workaround in p2pool's code for this.

jtoomim commented 5 years ago

Fixed by https://github.com/jtoomim/p2pool/commit/335369c748afd868750df2af55f41b8e40482cdf.