riecoin bug fixes
This commit is contained in:
parent
77e05277e2
commit
d6729c10e1
@ -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
|
||||
|
||||
@ -252,11 +252,12 @@ class CBlock(object):
|
||||
self.hashMerkleRoot = deser_uint256(f)
|
||||
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||
self.nBits = struct.unpack("<I", f.read(4))[0]
|
||||
self.nTime = struct.unpack("<I", f.read(4))[0]
|
||||
self.nTime = struct.unpack("<II", f.read(8))[0]
|
||||
self.nNonce = struct.unpack("<IIIIIIII", f.read(32))[0]
|
||||
else:
|
||||
self.nTime = struct.unpack("<I", f.read(4))[0]
|
||||
self.nBits = struct.unpack("<I", f.read(4))[0]
|
||||
self.nNonce = struct.unpack("<I", f.read(4))[0]
|
||||
self.nNonce = struct.unpack("<I", f.read(4))[0]
|
||||
self.vtx = deser_vector(f, CTransaction)
|
||||
if settings.COINDAEMON_Reward == 'POS':
|
||||
self.signature = deser_string(f)
|
||||
@ -269,11 +270,12 @@ class CBlock(object):
|
||||
r.append(ser_uint256(self.hashMerkleRoot))
|
||||
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||
r.append(struct.pack("<I", self.nBits))
|
||||
r.append(struct.pack("<I", self.nTime))
|
||||
r.append(struct.pack("<II", self.nTime))
|
||||
r.append(struct.pack("<IIIIIIII", self.nNonce))
|
||||
else:
|
||||
r.append(struct.pack("<I", self.nTime))
|
||||
r.append(struct.pack("<I", self.nBits))
|
||||
r.append(struct.pack("<I", self.nNonce))
|
||||
r.append(struct.pack("<I", self.nNonce))
|
||||
r.append(ser_vector(self.vtx))
|
||||
if settings.COINDAEMON_Reward == 'POS':
|
||||
r.append(ser_string(self.signature))
|
||||
@ -313,7 +315,9 @@ class CBlock(object):
|
||||
r.append(ser_uint256(self.hashMerkleRoot))
|
||||
r.append(struct.pack("<I", self.nBits))
|
||||
r.append(struct.pack("<II", self.nTime))
|
||||
self.riecoin = util.riecoinPoW( util.doublesha(r), uint256_from_compact(self.nBits), self.nNonce )
|
||||
hash_bin = util.doublesha(''.join([ r[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
||||
self.riecoin = util.riecoinPoW( util.uint256_from_str(hash_bin), uint256_from_compact(self.nBits), self.nNonce )
|
||||
log.debug("riecoinPoW in Halfnode is %d" % self.riecoin)
|
||||
return self.riecoin
|
||||
else:
|
||||
def calc_sha256(self):
|
||||
|
||||
@ -150,12 +150,14 @@ class TemplateRegistry(object):
|
||||
|
||||
def diff_to_target(self, difficulty):
|
||||
'''Converts difficulty to target'''
|
||||
if settings.COINDAEMON_ALGO == 'scrypt' or 'scrypt-jane':
|
||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||
diff1 = 0x0000ffff00000000000000000000000000000000000000000000000000000000
|
||||
elif settings.COINDAEMON_ALGO == 'scrypt-jane':
|
||||
diff1 = 0x0000ffff00000000000000000000000000000000000000000000000000000000
|
||||
elif settings.COINDAEMON_ALGO == 'quark':
|
||||
diff1 = 0x000000ffff000000000000000000000000000000000000000000000000000000
|
||||
elif settings.COINDAEMON_ALGO == 'riecoin':
|
||||
return difficulty;
|
||||
return difficulty
|
||||
else:
|
||||
diff1 = 0x00000000ffff0000000000000000000000000000000000000000000000000000
|
||||
|
||||
@ -235,6 +237,9 @@ class TemplateRegistry(object):
|
||||
extranonce2_bin = binascii.unhexlify(extranonce2)
|
||||
ntime_bin = binascii.unhexlify(ntime)
|
||||
nonce_bin = binascii.unhexlify(nonce)
|
||||
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||
ntime_bin = (''.join([ ntime_bin[(1-i)*4:(1-i)*4+4] for i in range(0, 2) ]))
|
||||
nonce_bin = (''.join([ nonce_bin[(7-i)*4:(7-i)*4+4] for i in range(0, 8) ]))
|
||||
|
||||
# 1. Build coinbase
|
||||
coinbase_bin = job.serialize_coinbase(extranonce1_bin, extranonce2_bin)
|
||||
@ -259,14 +264,13 @@ class TemplateRegistry(object):
|
||||
else:
|
||||
hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
||||
|
||||
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||
# hash_bin already has doublesha
|
||||
# this is kind of an ugly hack: we use hash_int to store the number of primes
|
||||
hash_int = util.riecoinPoW( hash_bin, job.target, int(nonce, 16) )
|
||||
else:
|
||||
hash_int = util.uint256_from_str(hash_bin)
|
||||
hash_int = util.uint256_from_str(hash_bin)
|
||||
scrypt_hash_hex = "%064x" % hash_int
|
||||
|
||||
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||
# this is kind of an ugly hack: we use hash_int to store the number of primes
|
||||
hash_int = util.riecoinPoW( hash_int, job.target, int(nonce, 16) )
|
||||
|
||||
header_hex = binascii.hexlify(header_bin)
|
||||
if settings.COINDAEMON_ALGO == 'scrypt' or settings.COINDAEMON_ALGO == 'scrypt-jane':
|
||||
header_hex = header_hex+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
|
||||
@ -276,7 +280,6 @@ class TemplateRegistry(object):
|
||||
header_hex = header_hex+"00000080000000000000000080030000"
|
||||
else: pass
|
||||
|
||||
|
||||
target_user = self.diff_to_target(difficulty)
|
||||
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||
if hash_int < target_user:
|
||||
|
||||
11
lib/util.py
11
lib/util.py
@ -56,7 +56,10 @@ def uint256_from_str_be(s):
|
||||
|
||||
def uint256_from_compact(c):
|
||||
nbytes = (c >> 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
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user