diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e569f67 --- /dev/null +++ b/.gitmodules @@ -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 diff --git a/externals/litecoin_scrypt b/externals/litecoin_scrypt new file mode 160000 index 0000000..967f2ef --- /dev/null +++ b/externals/litecoin_scrypt @@ -0,0 +1 @@ +Subproject commit 967f2ef35b17e3630bc42ba3fc1313b70ee446ab diff --git a/externals/stratum b/externals/stratum new file mode 160000 index 0000000..8ba1b5f --- /dev/null +++ b/externals/stratum @@ -0,0 +1 @@ +Subproject commit 8ba1b5fd8a802b981f31dace4cf920cfb4a3907c diff --git a/externals/stratum-mining-proxy b/externals/stratum-mining-proxy new file mode 160000 index 0000000..9b893fa --- /dev/null +++ b/externals/stratum-mining-proxy @@ -0,0 +1 @@ +Subproject commit 9b893fab15df318670cd137636df758dfcffa005 diff --git a/lib/bitcoin_rpc.py b/lib/bitcoin_rpc.py index 63be393..3d65ea1 100644 --- a/lib/bitcoin_rpc.py +++ b/lib/bitcoin_rpc.py @@ -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: diff --git a/lib/config_default.py b/lib/config_default.py index e156491..5f96e58 100755 --- a/lib/config_default.py +++ b/lib/config_default.py @@ -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 '' | sha256sum | cut -f1 -d' ' " # for calculating SHA256 of your preferred password diff --git a/lib/halfnode.py b/lib/halfnode.py index d64b4f8..576ea8b 100644 --- a/lib/halfnode.py +++ b/lib/halfnode.py @@ -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 - self.scrypt = None + if settings.COINDAEMON_ALGO == 'scrypt': + self.scrypt = None + else: pass def deserialize(self, f): self.nVersion = struct.unpack(" target: - if self.scrypt > target: - return False + if settings.COINDAEMON_ALGO == 'scrypt': + if self.scrypt > target: + return false + else: + if self.sha256 > target: + return False hashes = [] for tx in self.vtx: tx.sha256 = None diff --git a/lib/template_registry.py b/lib/template_registry.py index 434939a..34f6d7c 100644 --- a/lib/template_registry.py +++ b/lib/template_registry.py @@ -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,9 +142,10 @@ class TemplateRegistry(object): def diff_to_target(self, difficulty): '''Converts difficulty to target''' - #diff1 = 0x00000000ffff0000000000000000000000000000000000000000000000000000 - diff1 = 0x0000ffff00000000000000000000000000000000000000000000000000000000 - return diff1 / difficulty + if settings.COINDAEMON_ALGO == 'scrypt': + diff1 = 0x0000ffff00000000000000000000000000000000000000000000000000000000 + else: diff1 = 0x00000000ffff0000000000000000000000000000000000000000000000000000 + return diff1 / difficulty def get_job(self, job_id): '''For given job_id returns BlockTemplate instance or None''' @@ -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 - hash_bin = ltc_scrypt.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ])) + 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) - header_hex = header_hex+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000" - + 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 \ @@ -245,16 +251,16 @@ class TemplateRegistry(object): 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: - # Yay! It is block candidate! + # Yay! It is block candidate! 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) 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') - # 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)) if not job.is_valid():