commit
ed65b627b5
9
.gitmodules
vendored
Normal file
9
.gitmodules
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
[submodule "externals/stratum-mining-proxy"]
|
||||
path = externals/stratum-mining-proxy
|
||||
url = https://github.com/generalfault/stratum-mining-proxy
|
||||
[submodule "externals/litecoin_scrypt"]
|
||||
path = externals/litecoin_scrypt
|
||||
url = https://github.com/Tydus/litecoin_scrypt.git
|
||||
[submodule "externals/stratum"]
|
||||
path = externals/stratum
|
||||
url = https://github.com/slush0/stratum.git
|
||||
1
externals/litecoin_scrypt
vendored
Submodule
1
externals/litecoin_scrypt
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 967f2ef35b17e3630bc42ba3fc1313b70ee446ab
|
||||
1
externals/stratum
vendored
Submodule
1
externals/stratum
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 8ba1b5fd8a802b981f31dace4cf920cfb4a3907c
|
||||
1
externals/stratum-mining-proxy
vendored
Submodule
1
externals/stratum-mining-proxy
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 9b893fab15df318670cd137636df758dfcffa005
|
||||
@ -43,12 +43,14 @@ class BitcoinRPC(object):
|
||||
def submitblock(self, block_hex, block_hash_hex):
|
||||
# Try submitblock if that fails, go to getblocktemplate
|
||||
try:
|
||||
print("Submitting Block with Submit Block ")
|
||||
resp = (yield self._call('submitblock', [block_hex,]))
|
||||
except Exception:
|
||||
try:
|
||||
print("Submit Block call failed, trying GetBlockTemplate")
|
||||
resp = (yield self._call('getblocktemplate', [{'mode': 'submit', 'data': block_hex}]))
|
||||
except Exception as e:
|
||||
log.exception("Problem Submitting block %s" % str(e))
|
||||
log.exception("Both SubmitBlock and GetBlockTemplate failed. Problem Submitting block %s" % str(e))
|
||||
raise
|
||||
|
||||
if json.loads(resp)['result'] == None:
|
||||
|
||||
@ -111,6 +111,12 @@ COINDAEMON_TRUSTED_PORT = 8332 # RPC port
|
||||
COINDAEMON_TRUSTED_USER = 'stratum'
|
||||
COINDAEMON_TRUSTED_PASSWORD = '***somepassword***'
|
||||
|
||||
# Coin Algorithm is the option used to determine the algortithm used by stratum
|
||||
# This currently only works with POW SHA256 and Scrypt Coins
|
||||
# The available options are scrypt and sha256d.
|
||||
# If the option does not meet either of these criteria stratum defaults to scrypt
|
||||
COINDAEMON_ALGO = 'scrypt'
|
||||
|
||||
# ******************** OTHER CORE SETTINGS *********************
|
||||
# Use "echo -n '<yourpassword>' | sha256sum | cut -f1 -d' ' "
|
||||
# for calculating SHA256 of your preferred password
|
||||
|
||||
@ -15,7 +15,14 @@ from Crypto.Hash import SHA256
|
||||
from twisted.internet.protocol import Protocol
|
||||
from util import *
|
||||
|
||||
import ltc_scrypt
|
||||
import settings
|
||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||
print("########################################### Loading LTC Scrypt Module #########################################################")
|
||||
import ltc_scrypt
|
||||
else:
|
||||
print("########################################### NOT Loading LTC Scrypt Module ######################################################")
|
||||
pass
|
||||
|
||||
import lib.logger
|
||||
log = lib.logger.get_logger('halfnode')
|
||||
|
||||
@ -174,7 +181,9 @@ class CBlock(object):
|
||||
self.nNonce = 0
|
||||
self.vtx = []
|
||||
self.sha256 = None
|
||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||
self.scrypt = None
|
||||
else: pass
|
||||
def deserialize(self, f):
|
||||
self.nVersion = struct.unpack("<i", f.read(4))[0]
|
||||
self.hashPrevBlock = deser_uint256(f)
|
||||
@ -193,6 +202,20 @@ class CBlock(object):
|
||||
r.append(struct.pack("<I", self.nNonce))
|
||||
r.append(ser_vector(self.vtx))
|
||||
return ''.join(r)
|
||||
|
||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||
def calc_scrypt(self):
|
||||
if self.scrypt 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.nTime))
|
||||
r.append(struct.pack("<I", self.nBits))
|
||||
r.append(struct.pack("<I", self.nNonce))
|
||||
self.scrypt = uint256_from_str(ltc_scrypt.getPoWHash(''.join(r)))
|
||||
return self.scrypt
|
||||
else:
|
||||
def calc_sha256(self):
|
||||
if self.sha256 is None:
|
||||
r = []
|
||||
@ -205,24 +228,18 @@ class CBlock(object):
|
||||
self.sha256 = uint256_from_str(SHA256.new(SHA256.new(''.join(r)).digest()).digest())
|
||||
return self.sha256
|
||||
|
||||
def calc_scrypt(self):
|
||||
if self.scrypt 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.nTime))
|
||||
r.append(struct.pack("<I", self.nBits))
|
||||
r.append(struct.pack("<I", self.nNonce))
|
||||
self.scrypt = uint256_from_str(ltc_scrypt.getPoWHash(''.join(r)))
|
||||
return self.scrypt
|
||||
|
||||
def is_valid(self):
|
||||
#self.calc_sha256()
|
||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||
self.calc_scrypt()
|
||||
else:
|
||||
self.calc_sha256()
|
||||
target = uint256_from_compact(self.nBits)
|
||||
#if self.sha256 > target:
|
||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||
if self.scrypt > target:
|
||||
return false
|
||||
else:
|
||||
if self.sha256 > target:
|
||||
return False
|
||||
hashes = []
|
||||
for tx in self.vtx:
|
||||
|
||||
@ -2,8 +2,10 @@ import weakref
|
||||
import binascii
|
||||
import util
|
||||
import StringIO
|
||||
import ltc_scrypt
|
||||
|
||||
import settings
|
||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||
import ltc_scrypt
|
||||
else: pass
|
||||
from twisted.internet import defer
|
||||
from lib.exceptions import SubmitException
|
||||
|
||||
@ -140,8 +142,9 @@ class TemplateRegistry(object):
|
||||
|
||||
def diff_to_target(self, difficulty):
|
||||
'''Converts difficulty to target'''
|
||||
#diff1 = 0x00000000ffff0000000000000000000000000000000000000000000000000000
|
||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||
diff1 = 0x0000ffff00000000000000000000000000000000000000000000000000000000
|
||||
else: diff1 = 0x00000000ffff0000000000000000000000000000000000000000000000000000
|
||||
return diff1 / difficulty
|
||||
|
||||
def get_job(self, job_id):
|
||||
@ -223,12 +226,15 @@ class TemplateRegistry(object):
|
||||
header_bin = job.serialize_header(merkle_root_int, ntime_bin, nonce_bin)
|
||||
|
||||
# 4. Reverse header and compare it with target of the user
|
||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||
hash_bin = ltc_scrypt.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
|
||||
else: 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)
|
||||
scrypt_hash_hex = "%064x" % hash_int
|
||||
header_hex = binascii.hexlify(header_bin)
|
||||
if settings.COINDAEMON_ALGO == 'scrypt':
|
||||
header_hex = header_hex+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
|
||||
|
||||
else: pass
|
||||
|
||||
target_user = self.diff_to_target(difficulty)
|
||||
if hash_int > target_user and \
|
||||
|
||||
Loading…
Reference in New Issue
Block a user