commit
e15f45ac95
@ -11,7 +11,6 @@ import sys
|
|||||||
import random
|
import random
|
||||||
import cStringIO
|
import cStringIO
|
||||||
from Crypto.Hash import SHA256
|
from Crypto.Hash import SHA256
|
||||||
from sha3 import sha3_256
|
|
||||||
|
|
||||||
from twisted.internet.protocol import Protocol
|
from twisted.internet.protocol import Protocol
|
||||||
from util import *
|
from util import *
|
||||||
@ -30,18 +29,12 @@ elif settings.COINDAEMON_ALGO == 'quark':
|
|||||||
elif settings.COINDAEMON_ALGO == 'max':
|
elif settings.COINDAEMON_ALGO == 'max':
|
||||||
log.debug("########################################### Loading Max Support #########################################################")
|
log.debug("########################################### Loading Max Support #########################################################")
|
||||||
import max_hash
|
import max_hash
|
||||||
|
from sha3 import sha3_256
|
||||||
elif settings.COINDAEMON_ALGO == 'keccak':
|
elif settings.COINDAEMON_ALGO == 'keccak':
|
||||||
import sha3
|
import sha3
|
||||||
else:
|
else:
|
||||||
log.debug("########################################### Loading SHA256 Support ######################################################")
|
log.debug("########################################### Loading SHA256 Support ######################################################")
|
||||||
|
|
||||||
#if settings.COINDAEMON_Reward == 'POS':
|
|
||||||
# log.debug("########################################### Loading POS Support #########################################################")
|
|
||||||
# pass
|
|
||||||
#else:
|
|
||||||
# log.debug("########################################### Loading POW Support ######################################################")
|
|
||||||
# pass
|
|
||||||
|
|
||||||
if settings.COINDAEMON_TX == 'yes':
|
if settings.COINDAEMON_TX == 'yes':
|
||||||
log.debug("########################################### Loading SHA256 Transaction Message Support #########################################################")
|
log.debug("########################################### Loading SHA256 Transaction Message Support #########################################################")
|
||||||
pass
|
pass
|
||||||
@ -162,7 +155,8 @@ class CTxOut(object):
|
|||||||
|
|
||||||
class CTransaction(object):
|
class CTransaction(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.sha3 = None
|
if settings.COINDAEMON_ALGO == 'max':
|
||||||
|
self.sha3 = None
|
||||||
if settings.COINDAEMON_Reward == 'POW':
|
if settings.COINDAEMON_Reward == 'POW':
|
||||||
self.nVersion = 1
|
self.nVersion = 1
|
||||||
if settings.COINDAEMON_TX == 'yes':
|
if settings.COINDAEMON_TX == 'yes':
|
||||||
@ -315,7 +309,6 @@ class CBlock(object):
|
|||||||
r.append(struct.pack("<I", self.nTime))
|
r.append(struct.pack("<I", self.nTime))
|
||||||
r.append(struct.pack("<I", self.nBits))
|
r.append(struct.pack("<I", self.nBits))
|
||||||
r.append(struct.pack("<I", self.nNonce))
|
r.append(struct.pack("<I", self.nNonce))
|
||||||
#self.max = uint256_from_str(max_hash.getPoWHash(''.join(r)))
|
|
||||||
self.max = uint256_from_str(sha3_256(''.join(r)).digest())
|
self.max = uint256_from_str(sha3_256(''.join(r)).digest())
|
||||||
return self.max
|
return self.max
|
||||||
elif settings.COINDAEMON_ALGO == 'keccak':
|
elif settings.COINDAEMON_ALGO == 'keccak':
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import binascii
|
|||||||
import util
|
import util
|
||||||
import StringIO
|
import StringIO
|
||||||
import settings
|
import settings
|
||||||
|
from hashlib import sha256
|
||||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||||
import ltc_scrypt
|
import ltc_scrypt
|
||||||
elif settings.COINDAEMON_ALGO == 'scrypt-jane':
|
elif settings.COINDAEMON_ALGO == 'scrypt-jane':
|
||||||
@ -11,7 +12,7 @@ elif settings.COINDAEMON_ALGO == 'quark':
|
|||||||
import quark_hash
|
import quark_hash
|
||||||
elif settings.COINDAEMON_ALGO == 'max':
|
elif settings.COINDAEMON_ALGO == 'max':
|
||||||
import max_hash
|
import max_hash
|
||||||
from hashlib import sha256
|
from sha3 import sha3_256
|
||||||
elif settings.COINDAEMON_ALGO == 'skeinhash':
|
elif settings.COINDAEMON_ALGO == 'skeinhash':
|
||||||
import skeinhash
|
import skeinhash
|
||||||
elif settings.COINDAEMON_ALGO == 'keccak':
|
elif settings.COINDAEMON_ALGO == 'keccak':
|
||||||
@ -27,9 +28,6 @@ from mining.interfaces import Interfaces
|
|||||||
from extranonce_counter import ExtranonceCounter
|
from extranonce_counter import ExtranonceCounter
|
||||||
import lib.settings as settings
|
import lib.settings as settings
|
||||||
|
|
||||||
from sha3 import sha3_256
|
|
||||||
|
|
||||||
|
|
||||||
class JobIdGenerator(object):
|
class JobIdGenerator(object):
|
||||||
'''Generate pseudo-unique job_id. It does not need to be absolutely unique,
|
'''Generate pseudo-unique job_id. It does not need to be absolutely unique,
|
||||||
because pool sends "clean_jobs" flag to clients and they should drop all previous jobs.'''
|
because pool sends "clean_jobs" flag to clients and they should drop all previous jobs.'''
|
||||||
@ -134,8 +132,7 @@ class TemplateRegistry(object):
|
|||||||
self.update_in_progress = True
|
self.update_in_progress = True
|
||||||
self.last_update = Interfaces.timestamper.time()
|
self.last_update = Interfaces.timestamper.time()
|
||||||
|
|
||||||
log.debug("calling self.bitcoin_rpc.getblocktemplate()")
|
d = self.bitcoin_rpc.getblocktemplate()
|
||||||
d = self.bitcoin_rpc.getblocktemplate()
|
|
||||||
d.addCallback(self._update_block)
|
d.addCallback(self._update_block)
|
||||||
d.addErrback(self._update_block_failed)
|
d.addErrback(self._update_block_failed)
|
||||||
|
|
||||||
@ -145,9 +142,7 @@ class TemplateRegistry(object):
|
|||||||
|
|
||||||
def _update_block(self, data):
|
def _update_block(self, data):
|
||||||
start = Interfaces.timestamper.time()
|
start = Interfaces.timestamper.time()
|
||||||
log.debug("_update_block")
|
template = self.block_template_class(Interfaces.timestamper, self.coinbaser, JobIdGenerator.get_new_id())
|
||||||
#log.info(template.fill_from_rpc(data))
|
|
||||||
template = self.block_template_class(Interfaces.timestamper, self.coinbaser, JobIdGenerator.get_new_id())
|
|
||||||
log.info(template.fill_from_rpc(data))
|
log.info(template.fill_from_rpc(data))
|
||||||
self.add_template(template,data['height'])
|
self.add_template(template,data['height'])
|
||||||
|
|
||||||
@ -163,15 +158,12 @@ 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 == 'max':
|
|
||||||
#diff1 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000
|
|
||||||
elif settings.coindaemon_algo == 'max':
|
elif settings.coindaemon_algo == 'max':
|
||||||
diff1 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000
|
diff1 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000
|
||||||
elif settings.COINDAEMON_ALGO == 'keccak':
|
elif settings.COINDAEMON_ALGO == 'keccak':
|
||||||
diff1 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000
|
diff1 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000
|
||||||
else:
|
else:
|
||||||
diff1 = 0x00000000ffff0000000000000000000000000000000000000000000000000000
|
diff1 = 0x00000000ffff0000000000000000000000000000000000000000000000000000
|
||||||
|
|
||||||
return diff1 / difficulty
|
return diff1 / difficulty
|
||||||
|
|
||||||
def get_job(self, job_id):
|
def get_job(self, job_id):
|
||||||
@ -243,9 +235,10 @@ class TemplateRegistry(object):
|
|||||||
|
|
||||||
# 1. Build coinbase
|
# 1. Build coinbase
|
||||||
coinbase_bin = job.serialize_coinbase(extranonce1_bin, extranonce2_bin)
|
coinbase_bin = job.serialize_coinbase(extranonce1_bin, extranonce2_bin)
|
||||||
#coinbase_hash = util.doublesha(coinbase_bin)
|
if settings.COINDAEMON_ALGO == 'max':
|
||||||
coinbase_hash = sha256(coinbase_bin).digest()
|
coinbase_hash = sha256(coinbase_bin).digest()
|
||||||
|
else:
|
||||||
|
coinbase_hash = util.doublesha(coinbase_bin)
|
||||||
|
|
||||||
# 2. Calculate merkle root
|
# 2. Calculate merkle root
|
||||||
merkle_root_bin = job.merkletree.withFirst(coinbase_hash)
|
merkle_root_bin = job.merkletree.withFirst(coinbase_hash)
|
||||||
@ -270,9 +263,6 @@ class TemplateRegistry(object):
|
|||||||
s = sha3.sha3_256()
|
s = sha3.sha3_256()
|
||||||
ntime1 = str(int(ntime, 16))
|
ntime1 = str(int(ntime, 16))
|
||||||
s.update(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]) + ntime1)
|
s.update(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]) + ntime1)
|
||||||
#hash_bin_temp = s.hexdigest()
|
|
||||||
#s = sha3.sha3_256()
|
|
||||||
#s.update(hash_bin_temp)
|
|
||||||
hash_bin = s.hexdigest()
|
hash_bin = s.hexdigest()
|
||||||
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) ]))
|
||||||
@ -307,24 +297,18 @@ class TemplateRegistry(object):
|
|||||||
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_Reward == 'POW':
|
|
||||||
if settings.COINDAEMON_ALGO == 'max':
|
if settings.COINDAEMON_ALGO == 'max':
|
||||||
block_hash_bin = sha3_256(''.join([ header_bin[i*4:i*4+4][::-1]
|
block_hash_bin = sha3_256(''.join([ header_bin[i*4:i*4+4][::-1]
|
||||||
for i in range(0, 20) ]) + str(int(ntime, 16))).hexdigest()
|
for i in range(0, 20) ]) + str(int(ntime, 16))).hexdigest()
|
||||||
else:
|
elif settings.COINDAEMON_ALGO == 'keccak':
|
||||||
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
|
||||||
if settings.COINDAEMON_ALGO == 'keccak':
|
|
||||||
s = sha3.SHA3256()
|
s = sha3.SHA3256()
|
||||||
ntime1 = str(int(ntime, 16))
|
ntime1 = str(int(ntime, 16))
|
||||||
s.update(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]) + ntime1)
|
s.update(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]) + ntime1)
|
||||||
#hash_bin_temp = s.hexdigest()
|
|
||||||
#s = sha3.SHA3256()
|
|
||||||
#s.update(hash_bin_temp)
|
|
||||||
block_hash_bin = s.hexdigest()
|
|
||||||
else:
|
else:
|
||||||
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
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')
|
||||||
|
if settings.COINDAEMON_ALGO != 'max':
|
||||||
|
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))
|
||||||
|
|
||||||
@ -349,11 +333,9 @@ class TemplateRegistry(object):
|
|||||||
s = sha3.sha3_256()
|
s = sha3.sha3_256()
|
||||||
ntime1 = str(int(ntime, 16))
|
ntime1 = str(int(ntime, 16))
|
||||||
s.update(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]) + ntime1)
|
s.update(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]) + ntime1)
|
||||||
#hash_bin_temp = s.hexdigest()
|
|
||||||
#s = sha3.sha3_256()
|
|
||||||
#s.update(hash_bin_temp)
|
|
||||||
block_hash_bin = s.hexdigest()
|
block_hash_bin = s.hexdigest()
|
||||||
else: 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')
|
||||||
return (header_hex, block_hash_hex, share_diff, None)
|
return (header_hex, block_hash_hex, share_diff, None)
|
||||||
else:
|
else:
|
||||||
|
|||||||
10
lib/util.py
10
lib/util.py
@ -6,10 +6,10 @@ import binascii
|
|||||||
import settings
|
import settings
|
||||||
import bitcoin_rpc
|
import bitcoin_rpc
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from sha3 import sha3_256
|
|
||||||
|
|
||||||
if settings.COINDAEMON_ALGO == 'keccak':
|
if settings.COINDAEMON_ALGO == 'keccak':
|
||||||
import sha3
|
import sha3
|
||||||
|
from sha3 import sha3_256
|
||||||
|
|
||||||
|
|
||||||
def deser_string(f):
|
def deser_string(f):
|
||||||
@ -184,10 +184,12 @@ def address_to_pubkeyhash(addr):
|
|||||||
|
|
||||||
ver = addr[0]
|
ver = addr[0]
|
||||||
cksumA = addr[-4:]
|
cksumA = addr[-4:]
|
||||||
#TODO: We should clean this up so that it works with not Keccek implementations too.
|
if settings.COINDAEMON_ALGO != 'max':
|
||||||
cksumB = sha3_256(addr[:-4]).digest()[:4]
|
cksumB = doublesha(addr[:-4])[:4]
|
||||||
|
#TODO: We should clean this up so that it works with not Keccek implementations too.
|
||||||
|
else:
|
||||||
|
cksumB = sha3_256(addr[:-4]).digest()[:4]
|
||||||
|
|
||||||
#cksumB = sha3.sha3_256(addr[:-4]).digest()[:4]
|
|
||||||
|
|
||||||
if cksumA != cksumB:
|
if cksumA != cksumB:
|
||||||
return None
|
return None
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user