riecoin support
This commit is contained in:
parent
88a1499685
commit
05d3f1789a
19
README.md
19
README.md
@ -1,6 +1,6 @@
|
|||||||
[ ](https://www.codeship.io/projects/12274)
|
[ ](https://www.codeship.io/projects/12274)
|
||||||
#Status
|
#Status
|
||||||
This project is now in what i'd consider v1 stage as such i dont believe there is much to add to stratum. so as of now this code is in bug fix stage only and should be considered unmaintained.
|
Riecoin support just implemented, needs testing.
|
||||||
|
|
||||||
#Description
|
#Description
|
||||||
Stratum-mining is a pooled mining protocol. It is a replacement for *getwork* based pooling servers by allowing clients to generate work. The stratum protocol is described [here](http://mining.bitcoin.cz/stratum-mining) in full detail.
|
Stratum-mining is a pooled mining protocol. It is a replacement for *getwork* based pooling servers by allowing clients to generate work. The stratum protocol is described [here](http://mining.bitcoin.cz/stratum-mining) in full detail.
|
||||||
@ -28,15 +28,7 @@ The goal is to make a reliable stratum mining server for a wide range of coins u
|
|||||||
* Transaction Messaging Support
|
* Transaction Messaging Support
|
||||||
|
|
||||||
#Donations
|
#Donations
|
||||||
* BTC: 18Xg4qP6RUvpeajanKPt5PDvvcqvU2pP6d
|
Please see riecoin.org
|
||||||
* BTE: 8UJLskr8eDYATvYzmaCBw3vbRmeNweT3rW
|
|
||||||
* DGC: DSBb5KmGWYKMJjxk3rETtvpk9sPqgCCYAw
|
|
||||||
* LTC: Lg4kXMqPsmMHrGr81LLe8oHpbsMiWiuMSB
|
|
||||||
* WDC: WeVFgZQsKSKXGak7NJPp9SrcUexghzTPGJ
|
|
||||||
* Doge: DLtBRYtNCzfiZfcpUeEr8KPvy5k1aR7jca
|
|
||||||
* SRC: sMP2wHN5H2ik7FQDPjhSzFZUWux75BYZGe
|
|
||||||
* ARG: AQvXPWVqGzcpH2j2XSRG7X5R9nA3y9D9aQ
|
|
||||||
* Cryptsy Trade Key: ec13d183e304326ebd41258d6ae7188e303866fe
|
|
||||||
|
|
||||||
|
|
||||||
#Requirements
|
#Requirements
|
||||||
@ -70,8 +62,8 @@ Other coins have been known to work with this implementation. I have tested with
|
|||||||
The installation of this *stratum-mining* can be found in the Repo Wiki.
|
The installation of this *stratum-mining* can be found in the Repo Wiki.
|
||||||
|
|
||||||
#Contact
|
#Contact
|
||||||
I am available in the #MPOS, #crypto-expert, #digitalcoin, and #worldcoin channels on freenode.
|
See riecoin.org
|
||||||
Although i am willing to provide support through IRC please file issues on the repo.
|
Please file issues on the repo.
|
||||||
Issues as a direct result of stratum will be helped with as much as possible
|
Issues as a direct result of stratum will be helped with as much as possible
|
||||||
However issues related to a coin daemon's setup and other non stratum issues,
|
However issues related to a coin daemon's setup and other non stratum issues,
|
||||||
Please research and attempt to debug first.
|
Please research and attempt to debug first.
|
||||||
@ -81,7 +73,8 @@ Please research and attempt to debug first.
|
|||||||
* Original version by Slush0 and ArtForz (original stratum code)
|
* Original version by Slush0 and ArtForz (original stratum code)
|
||||||
* More Features added by GeneralFault, Wadee Womersley, Viperaus, TheSeven and Moopless
|
* More Features added by GeneralFault, Wadee Womersley, Viperaus, TheSeven and Moopless
|
||||||
* Multi Algo, Vardiff, DB and MPOS support done by Ahmed_Bodi, penner42 and Obigal
|
* Multi Algo, Vardiff, DB and MPOS support done by Ahmed_Bodi, penner42 and Obigal
|
||||||
|
* Riecoin support by gatra
|
||||||
|
|
||||||
#License
|
#License
|
||||||
This software is provides AS-IS without any warranties of any kind. Please use at your own risk.
|
This software is provided AS-IS without any warranties of any kind. Please use at your own risk.
|
||||||
|
|
||||||
|
|||||||
@ -12,17 +12,17 @@ You NEED to set the parameters in BASIC SETTINGS
|
|||||||
CENTRAL_WALLET = 'set_valid_addresss_in_config!' # Local coin address where money goes
|
CENTRAL_WALLET = 'set_valid_addresss_in_config!' # Local coin address where money goes
|
||||||
|
|
||||||
COINDAEMON_TRUSTED_HOST = 'localhost'
|
COINDAEMON_TRUSTED_HOST = 'localhost'
|
||||||
COINDAEMON_TRUSTED_PORT = 8332
|
COINDAEMON_TRUSTED_PORT = 28332
|
||||||
COINDAEMON_TRUSTED_USER = 'user'
|
COINDAEMON_TRUSTED_USER = 'user'
|
||||||
COINDAEMON_TRUSTED_PASSWORD = 'somepassword'
|
COINDAEMON_TRUSTED_PASSWORD = 'somepassword'
|
||||||
|
|
||||||
# Coin algorithm is the option used to determine the algorithm used by stratum
|
# Coin algorithm is the option used to determine the algorithm used by stratum
|
||||||
# This currently works with POW and POS coins
|
# This currently works with POW and POS coins
|
||||||
# The available options are:
|
# The available options are:
|
||||||
# scrypt, sha256d, scrypt-jane, skeinhash, and quark
|
# scrypt, sha256d, scrypt-jane, skeinhash, quark and riecoin
|
||||||
# If the option does not meet either of these criteria stratum defaults to scrypt
|
# If the option does not meet either of these criteria stratum defaults to scrypt
|
||||||
# For Coins which support TX Messages please enter yes in the TX selection
|
# For Coins which support TX Messages please enter yes in the TX selection
|
||||||
COINDAEMON_ALGO = 'scrypt'
|
COINDAEMON_ALGO = 'riecoin'
|
||||||
COINDAEMON_TX = 'no'
|
COINDAEMON_TX = 'no'
|
||||||
|
|
||||||
# ******************** BASIC SETTINGS ***************
|
# ******************** BASIC SETTINGS ***************
|
||||||
@ -30,12 +30,12 @@ COINDAEMON_TX = 'no'
|
|||||||
# You can have up to 99
|
# You can have up to 99
|
||||||
|
|
||||||
#COINDAEMON_TRUSTED_HOST_1 = 'localhost'
|
#COINDAEMON_TRUSTED_HOST_1 = 'localhost'
|
||||||
#COINDAEMON_TRUSTED_PORT_1 = 8332
|
#COINDAEMON_TRUSTED_PORT_1 = 28332
|
||||||
#COINDAEMON_TRUSTED_USER_1 = 'user'
|
#COINDAEMON_TRUSTED_USER_1 = 'user'
|
||||||
#COINDAEMON_TRUSTED_PASSWORD_1 = 'somepassword'
|
#COINDAEMON_TRUSTED_PASSWORD_1 = 'somepassword'
|
||||||
|
|
||||||
#COINDAEMON_TRUSTED_HOST_2 = 'localhost'
|
#COINDAEMON_TRUSTED_HOST_2 = 'localhost'
|
||||||
#COINDAEMON_TRUSTED_PORT_2 = 8332
|
#COINDAEMON_TRUSTED_PORT_2 = 28332
|
||||||
#COINDAEMON_TRUSTED_USER_2 = 'user'
|
#COINDAEMON_TRUSTED_USER_2 = 'user'
|
||||||
#COINDAEMON_TRUSTED_PASSWORD_2 = 'somepassword'
|
#COINDAEMON_TRUSTED_PASSWORD_2 = 'somepassword'
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ VDIFF_X2_TYPE = True # Powers of 2 e.g. 2,4,8,16,32,64,128,256,512,10
|
|||||||
VDIFF_FLOAT = False # Use float difficulty
|
VDIFF_FLOAT = False # Use float difficulty
|
||||||
|
|
||||||
# Pool Target (Base Difficulty)
|
# Pool Target (Base Difficulty)
|
||||||
POOL_TARGET = 32 # Pool-wide difficulty target int >= 1
|
POOL_TARGET = 4 # Pool-wide difficulty target int >= 1
|
||||||
|
|
||||||
# Variable Difficulty Enable
|
# Variable Difficulty Enable
|
||||||
VARIABLE_DIFF = True # Master variable difficulty enable
|
VARIABLE_DIFF = True # Master variable difficulty enable
|
||||||
|
|||||||
@ -139,8 +139,12 @@ class BlockTemplate(halfnode.CBlock):
|
|||||||
r = struct.pack(">i", self.nVersion)
|
r = struct.pack(">i", self.nVersion)
|
||||||
r += self.prevhash_bin
|
r += self.prevhash_bin
|
||||||
r += util.ser_uint256_be(merkle_root_int)
|
r += util.ser_uint256_be(merkle_root_int)
|
||||||
r += ntime_bin
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
r += struct.pack(">I", self.nBits)
|
r += struct.pack(">I", self.nBits)
|
||||||
|
r += ntime_bin
|
||||||
|
else:
|
||||||
|
r += ntime_bin
|
||||||
|
r += struct.pack(">I", self.nBits)
|
||||||
r += nonce_bin
|
r += nonce_bin
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|||||||
@ -109,7 +109,7 @@ COINDAEMON_TRUSTED_PASSWORD = '***somepassword***'
|
|||||||
# Until AutoReward Selecting Code has been implemented the below options are us$
|
# Until AutoReward Selecting Code has been implemented the below options are us$
|
||||||
# For Reward type there is POW and POS. please ensure you choose the currect ty$
|
# For Reward type there is POW and POS. please ensure you choose the currect ty$
|
||||||
# For SHA256 PoS Coins which support TX Messages please enter yes in the TX sel$
|
# For SHA256 PoS Coins which support TX Messages please enter yes in the TX sel$
|
||||||
COINDAEMON_ALGO = 'scrypt'
|
COINDAEMON_ALGO = 'riecoin'
|
||||||
COINDAEMON_Reward = 'POW'
|
COINDAEMON_Reward = 'POW'
|
||||||
COINDAEMON_SHA256_TX = 'yes'
|
COINDAEMON_SHA256_TX = 'yes'
|
||||||
|
|
||||||
|
|||||||
@ -239,6 +239,8 @@ class CBlock(object):
|
|||||||
self.scrypt = None
|
self.scrypt = None
|
||||||
elif settings.COINDAEMON_ALGO == 'quark':
|
elif settings.COINDAEMON_ALGO == 'quark':
|
||||||
self.quark = None
|
self.quark = None
|
||||||
|
elif settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
|
self.riecoin = None
|
||||||
else: pass
|
else: pass
|
||||||
if settings.COINDAEMON_Reward == 'POS':
|
if settings.COINDAEMON_Reward == 'POS':
|
||||||
self.signature = b""
|
self.signature = b""
|
||||||
@ -248,8 +250,12 @@ class CBlock(object):
|
|||||||
self.nVersion = struct.unpack("<i", f.read(4))[0]
|
self.nVersion = struct.unpack("<i", f.read(4))[0]
|
||||||
self.hashPrevBlock = deser_uint256(f)
|
self.hashPrevBlock = deser_uint256(f)
|
||||||
self.hashMerkleRoot = deser_uint256(f)
|
self.hashMerkleRoot = deser_uint256(f)
|
||||||
self.nTime = struct.unpack("<I", f.read(4))[0]
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
self.nBits = struct.unpack("<I", f.read(4))[0]
|
self.nBits = struct.unpack("<I", f.read(4))[0]
|
||||||
|
self.nTime = struct.unpack("<I", f.read(4))[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)
|
self.vtx = deser_vector(f, CTransaction)
|
||||||
if settings.COINDAEMON_Reward == 'POS':
|
if settings.COINDAEMON_Reward == 'POS':
|
||||||
@ -261,8 +267,12 @@ class CBlock(object):
|
|||||||
r.append(struct.pack("<i", self.nVersion))
|
r.append(struct.pack("<i", self.nVersion))
|
||||||
r.append(ser_uint256(self.hashPrevBlock))
|
r.append(ser_uint256(self.hashPrevBlock))
|
||||||
r.append(ser_uint256(self.hashMerkleRoot))
|
r.append(ser_uint256(self.hashMerkleRoot))
|
||||||
r.append(struct.pack("<I", self.nTime))
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
r.append(struct.pack("<I", self.nBits))
|
r.append(struct.pack("<I", self.nBits))
|
||||||
|
r.append(struct.pack("<I", self.nTime))
|
||||||
|
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))
|
r.append(ser_vector(self.vtx))
|
||||||
if settings.COINDAEMON_Reward == 'POS':
|
if settings.COINDAEMON_Reward == 'POS':
|
||||||
@ -294,6 +304,17 @@ class CBlock(object):
|
|||||||
r.append(struct.pack("<I", self.nNonce))
|
r.append(struct.pack("<I", self.nNonce))
|
||||||
self.quark = uint256_from_str(quark_hash.getPoWHash(''.join(r)))
|
self.quark = uint256_from_str(quark_hash.getPoWHash(''.join(r)))
|
||||||
return self.quark
|
return self.quark
|
||||||
|
elif settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
|
def calc_riecoin(self):
|
||||||
|
if self.riecoin is None:
|
||||||
|
r = []
|
||||||
|
r.append(struct.pack("<i", self.nVersion))
|
||||||
|
r.append(ser_uint256(self.hashPrevBlock))
|
||||||
|
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 )
|
||||||
|
return self.riecoin
|
||||||
else:
|
else:
|
||||||
def calc_sha256(self):
|
def calc_sha256(self):
|
||||||
if self.sha256 is None:
|
if self.sha256 is None:
|
||||||
@ -309,6 +330,8 @@ class CBlock(object):
|
|||||||
|
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
|
self.calc_riecoin()
|
||||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||||
self.calc_scrypt()
|
self.calc_scrypt()
|
||||||
elif settings.COINDAEMON_ALGO == 'quark':
|
elif settings.COINDAEMON_ALGO == 'quark':
|
||||||
@ -316,8 +339,14 @@ class CBlock(object):
|
|||||||
else:
|
else:
|
||||||
self.calc_sha256()
|
self.calc_sha256()
|
||||||
|
|
||||||
target = uint256_from_compact(self.nBits)
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
|
target = settings.POOL_TARGET
|
||||||
|
else
|
||||||
|
target = uint256_from_compact(self.nBits)
|
||||||
|
|
||||||
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
|
if self.riecoin < target:
|
||||||
|
return False
|
||||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||||
if self.scrypt > target:
|
if self.scrypt > target:
|
||||||
return False
|
return False
|
||||||
|
|||||||
@ -154,6 +154,8 @@ class TemplateRegistry(object):
|
|||||||
diff1 = 0x0000ffff00000000000000000000000000000000000000000000000000000000
|
diff1 = 0x0000ffff00000000000000000000000000000000000000000000000000000000
|
||||||
elif settings.COINDAEMON_ALGO == 'quark':
|
elif settings.COINDAEMON_ALGO == 'quark':
|
||||||
diff1 = 0x000000ffff000000000000000000000000000000000000000000000000000000
|
diff1 = 0x000000ffff000000000000000000000000000000000000000000000000000000
|
||||||
|
elif settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
|
return difficulty;
|
||||||
else:
|
else:
|
||||||
diff1 = 0x00000000ffff0000000000000000000000000000000000000000000000000000
|
diff1 = 0x00000000ffff0000000000000000000000000000000000000000000000000000
|
||||||
|
|
||||||
@ -202,15 +204,23 @@ class TemplateRegistry(object):
|
|||||||
raise SubmitException("Job '%s' not found" % job_id)
|
raise SubmitException("Job '%s' not found" % job_id)
|
||||||
|
|
||||||
# Check if ntime looks correct
|
# Check if ntime looks correct
|
||||||
if len(ntime) != 8:
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
raise SubmitException("Incorrect size of ntime. Expected 8 chars")
|
if len(ntime) != 16:
|
||||||
|
raise SubmitException("Incorrect size of ntime. Expected 16 chars")
|
||||||
|
else:
|
||||||
|
if len(ntime) != 8:
|
||||||
|
raise SubmitException("Incorrect size of ntime. Expected 8 chars")
|
||||||
|
|
||||||
if not job.check_ntime(int(ntime, 16)):
|
if not job.check_ntime(int(ntime, 16)):
|
||||||
raise SubmitException("Ntime out of range")
|
raise SubmitException("Ntime out of range")
|
||||||
|
|
||||||
# Check nonce
|
# Check nonce
|
||||||
if len(nonce) != 8:
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
raise SubmitException("Incorrect size of nonce. Expected 8 chars")
|
if len(nonce) != 64:
|
||||||
|
raise SubmitException("Incorrect size of nonce. Expected 64 chars")
|
||||||
|
else:
|
||||||
|
if len(nonce) != 8:
|
||||||
|
raise SubmitException("Incorrect size of nonce. Expected 8 chars")
|
||||||
|
|
||||||
# Check for duplicated submit
|
# Check for duplicated submit
|
||||||
if not job.register_submit(extranonce1_bin, extranonce2, ntime, nonce):
|
if not job.register_submit(extranonce1_bin, extranonce2, ntime, nonce):
|
||||||
@ -238,7 +248,7 @@ class TemplateRegistry(object):
|
|||||||
header_bin = job.serialize_header(merkle_root_int, ntime_bin, nonce_bin)
|
header_bin = job.serialize_header(merkle_root_int, ntime_bin, nonce_bin)
|
||||||
|
|
||||||
# 4. Reverse header and compare it with target of the user
|
# 4. Reverse header and compare it with target of the user
|
||||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
elif settings.COINDAEMON_ALGO == 'scrypt':
|
||||||
hash_bin = ltc_scrypt.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
hash_bin = ltc_scrypt.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
||||||
elif settings.COINDAEMON_ALGO == 'scrypt-jane':
|
elif settings.COINDAEMON_ALGO == 'scrypt-jane':
|
||||||
hash_bin = yac_scrypt.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]), int(ntime, 16))
|
hash_bin = yac_scrypt.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]), int(ntime, 16))
|
||||||
@ -249,39 +259,59 @@ class TemplateRegistry(object):
|
|||||||
else:
|
else:
|
||||||
hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
||||||
|
|
||||||
hash_int = util.uint256_from_str(hash_bin)
|
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)
|
||||||
scrypt_hash_hex = "%064x" % hash_int
|
scrypt_hash_hex = "%064x" % hash_int
|
||||||
|
|
||||||
header_hex = binascii.hexlify(header_bin)
|
header_hex = binascii.hexlify(header_bin)
|
||||||
if settings.COINDAEMON_ALGO == 'scrypt' or settings.COINDAEMON_ALGO == 'scrypt-jane':
|
if settings.COINDAEMON_ALGO == 'scrypt' or settings.COINDAEMON_ALGO == 'scrypt-jane':
|
||||||
header_hex = header_hex+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
|
header_hex = header_hex+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
|
||||||
elif settings.COINDAEMON_ALGO == 'quark':
|
elif settings.COINDAEMON_ALGO == 'quark':
|
||||||
header_hex = header_hex+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
|
header_hex = header_hex+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
|
||||||
|
elif settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
|
header_hex = header_hex+"00000080000000000000000080030000"
|
||||||
else: pass
|
else: pass
|
||||||
|
|
||||||
target_user = self.diff_to_target(difficulty)
|
|
||||||
if hash_int > target_user:
|
|
||||||
raise SubmitException("Share is above target")
|
|
||||||
|
|
||||||
# Mostly for debugging purposes
|
target_user = self.diff_to_target(difficulty)
|
||||||
target_info = self.diff_to_target(100000)
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
if hash_int <= target_info:
|
if hash_int < target_user:
|
||||||
log.info("Yay, share with diff above 100000")
|
raise SubmitException("Share does not meet target")
|
||||||
|
else:
|
||||||
|
if hash_int > target_user:
|
||||||
|
raise SubmitException("Share is above target")
|
||||||
|
# Mostly for debugging purposes
|
||||||
|
target_info = self.diff_to_target(100000)
|
||||||
|
if hash_int <= target_info:
|
||||||
|
log.info("Yay, share with diff above 100000")
|
||||||
|
|
||||||
# Algebra tells us the diff_to_target is the same as hash_to_diff
|
# Algebra tells us the diff_to_target is the same as hash_to_diff
|
||||||
share_diff = int(self.diff_to_target(hash_int))
|
share_diff = int(self.diff_to_target(hash_int))
|
||||||
|
|
||||||
# 5. Compare hash with target of the network
|
# 5. Compare hash with target of the network
|
||||||
if hash_int <= job.target:
|
isBlockCandidate = False
|
||||||
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
|
if hash_int == 6
|
||||||
|
isBlockCandidate = True
|
||||||
|
else:
|
||||||
|
if hash_int <= job.target:
|
||||||
|
isBlockCandidate = True
|
||||||
|
|
||||||
|
if isBlockCandidate == True:
|
||||||
# Yay! It is block candidate!
|
# Yay! It is block candidate!
|
||||||
log.info("We found a block candidate! %s" % scrypt_hash_hex)
|
log.info("We found a block candidate! %s" % scrypt_hash_hex)
|
||||||
|
|
||||||
# Reverse the header and get the potential block hash (for scrypt only)
|
# Reverse the header and get the potential block hash (for scrypt only)
|
||||||
#if settings.COINDAEMON_ALGO == 'scrypt' or settings.COINDAEMON_ALGO == 'sha256d':
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
# if settings.COINDAEMON_Reward == 'POW':
|
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 28) ]))
|
||||||
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
else:
|
||||||
|
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
||||||
block_hash_hex = block_hash_bin[::-1].encode('hex_codec')
|
block_hash_hex = block_hash_bin[::-1].encode('hex_codec')
|
||||||
#else: block_hash_hex = hash_bin[::-1].encode('hex_codec')
|
|
||||||
#else: block_hash_hex = hash_bin[::-1].encode('hex_codec')
|
|
||||||
# 6. Finalize and serialize block object
|
# 6. Finalize and serialize block object
|
||||||
job.finalize(merkle_root_int, extranonce1_bin, extranonce2_bin, int(ntime, 16), int(nonce, 16))
|
job.finalize(merkle_root_int, extranonce1_bin, extranonce2_bin, int(ntime, 16), int(nonce, 16))
|
||||||
|
|
||||||
@ -302,7 +332,10 @@ class TemplateRegistry(object):
|
|||||||
|
|
||||||
if settings.SOLUTION_BLOCK_HASH:
|
if settings.SOLUTION_BLOCK_HASH:
|
||||||
# Reverse the header and get the potential block hash (for scrypt only) only do this if we want to send in the block hash to the shares table
|
# Reverse the header and get the potential block hash (for scrypt only) only do this if we want to send in the block hash to the shares table
|
||||||
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
if settings.COINDAEMON_ALGO == 'riecoin':
|
||||||
|
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 28) ]))
|
||||||
|
else:
|
||||||
|
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
||||||
block_hash_hex = block_hash_bin[::-1].encode('hex_codec')
|
block_hash_hex = block_hash_bin[::-1].encode('hex_codec')
|
||||||
return (header_hex, block_hash_hex, share_diff, None)
|
return (header_hex, block_hash_hex, share_diff, None)
|
||||||
else:
|
else:
|
||||||
|
|||||||
50
lib/util.py
50
lib/util.py
@ -211,6 +211,56 @@ def ser_number(n):
|
|||||||
s.append(n)
|
s.append(n)
|
||||||
return bytes(s)
|
return bytes(s)
|
||||||
|
|
||||||
|
|
||||||
|
def isPrime( n )
|
||||||
|
if pow( 2, n-1, n ) == 1:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def riecoinPoW( hash_bin, diff, nNonce )
|
||||||
|
base = 1 << 8
|
||||||
|
for i in range(256)
|
||||||
|
base = base << 1
|
||||||
|
base = base | (hash_bin & 1)
|
||||||
|
hash_bin = hash_bin >> 1
|
||||||
|
trailingZeros = diff - 1 - 8 - 256
|
||||||
|
if trailingZeros < 16 or trailingZeros > 20000
|
||||||
|
return 0
|
||||||
|
base = base << trailingZeros
|
||||||
|
|
||||||
|
base += nNonce
|
||||||
|
primes = 0
|
||||||
|
|
||||||
|
if (base % 210) != 97:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if !isPrime( base ):
|
||||||
|
return primes
|
||||||
|
primes++
|
||||||
|
|
||||||
|
base += 4
|
||||||
|
if !isPrime( base ):
|
||||||
|
return primes
|
||||||
|
primes++
|
||||||
|
|
||||||
|
base += 2
|
||||||
|
if isPrime( base ):
|
||||||
|
primes++
|
||||||
|
|
||||||
|
base += 4
|
||||||
|
if !isPrime( base ):
|
||||||
|
primes++
|
||||||
|
|
||||||
|
base += 2
|
||||||
|
if !isPrime( base ):
|
||||||
|
primes++
|
||||||
|
|
||||||
|
base += 4
|
||||||
|
if !isPrime( base ):
|
||||||
|
primes++
|
||||||
|
|
||||||
|
return primes
|
||||||
|
|
||||||
#if settings.COINDAEMON_Reward == 'POW':
|
#if settings.COINDAEMON_Reward == 'POW':
|
||||||
def script_to_address(addr):
|
def script_to_address(addr):
|
||||||
d = address_to_pubkeyhash(addr)
|
d = address_to_pubkeyhash(addr)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user