From d6729c10e1f9b8ad6bd794b40959f6ae470b55d7 Mon Sep 17 00:00:00 2001 From: gatra Date: Thu, 13 Mar 2014 23:29:04 -0300 Subject: [PATCH] riecoin bug fixes --- lib/block_template.py | 3 ++- lib/halfnode.py | 14 +++++++++----- lib/template_registry.py | 21 ++++++++++++--------- lib/util.py | 11 +++++++---- mining/service.py | 2 +- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/block_template.py b/lib/block_template.py index 686baf0..d27b93f 100644 --- a/lib/block_template.py +++ b/lib/block_template.py @@ -68,7 +68,8 @@ class BlockTemplate(halfnode.CBlock): self.height = data['height'] self.nVersion = data['version'] self.hashPrevBlock = int(data['previousblockhash'], 16) - self.nBits = int(data['bits'], 8) + self.nBits = int(data['bits'], 16) + self.hashMerkleRoot = 0 self.nTime = 0 self.nNonce = 0 diff --git a/lib/halfnode.py b/lib/halfnode.py index 51b1420..a0394c1 100644 --- a/lib/halfnode.py +++ b/lib/halfnode.py @@ -252,11 +252,12 @@ class CBlock(object): self.hashMerkleRoot = deser_uint256(f) if settings.COINDAEMON_ALGO == 'riecoin': self.nBits = struct.unpack("> 24) & 0xFF - v = (c & 0xFFFFFFL) << (8 * (nbytes - 3)) + if nbytes <= 3: + v = (c & 0xFFFFFFL) >> (8 * (3 - nbytes)) + else: + v = (c & 0xFFFFFFL) << (8 * (nbytes - 3)) return v def deser_vector(f, c): @@ -217,12 +220,12 @@ def isPrime( n ): return True return False -def riecoinPoW( hash_bin, diff, nNonce ): +def riecoinPoW( hash_int, diff, nNonce ): base = 1 << 8 for i in range(256): base = base << 1 - base = base | (hash_bin & 1) - hash_bin = hash_bin >> 1 + base = base | (hash_int & 1) + hash_int = hash_int >> 1 trailingZeros = diff - 1 - 8 - 256 if trailingZeros < 16 or trailingZeros > 20000: return 0 diff --git a/mining/service.py b/mining/service.py index 6cb2efb..fd8a2d7 100644 --- a/mining/service.py +++ b/mining/service.py @@ -87,7 +87,7 @@ class MiningService(GenericService): else: session['difficulty'] = settings.POOL_TARGET # worker_log = (valid, invalid, is_banned, diff, is_ext_diff, timestamp) - Interfaces.worker_manager.worker_log['authorized'][worker_name] = (0, 0, False, session['difficulty'], is_ext_diff, Interfaces.timestamper.time()) + Interfaces.worker_manager.worker_log['authorized'][worker_name] = (0, 0, False, session['difficulty'], is_ext_diff, Interfaces.timestamper.time()) return True else: ip = self.connection_ref()._get_ip()