From 8a0e67512a25e476f9dcab3dd08e7e80d2c79ecc Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 22 Apr 2022 09:45:18 +0000 Subject: [PATCH 1/2] Handle Litecoin MWEB rules --- p2pool/bitcoin/helper.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/p2pool/bitcoin/helper.py b/p2pool/bitcoin/helper.py index 6255d1e5a..bf39ad24f 100644 --- a/p2pool/bitcoin/helper.py +++ b/p2pool/bitcoin/helper.py @@ -16,6 +16,9 @@ def check(bitcoind, net, args): raise deferral.RetrySilentlyException() version_check_result = net.VERSION_CHECK((yield bitcoind.rpc_getnetworkinfo())['version']) + blockchaininfo = yield bitcoind.rpc_getblockchaininfo() + global softforkrules + softforkrules = ['segwit','mweb'] if 'mweb' in blockchaininfo['softforks'] else ['segwit'] if version_check_result == True: version_check_result = None # deprecated if version_check_result == False: version_check_result = 'Coin daemon too old! Upgrade!' # deprecated if version_check_result is not None: @@ -51,7 +54,7 @@ def check(bitcoind, net, args): def getwork(bitcoind, use_getblocktemplate=False, txidcache={}, feecache={}, feefifo=[], known_txs={}): def go(): if use_getblocktemplate: - return bitcoind.rpc_getblocktemplate(dict(mode='template', rules=['segwit'])) + return bitcoind.rpc_getblocktemplate(dict(mode='template', rules=softforkrules)) else: return bitcoind.rpc_getmemorypool() try: @@ -137,6 +140,7 @@ def go(): last_update=time.time(), use_getblocktemplate=use_getblocktemplate, latency=end - start, + mweb="01" + work['mweb'] if 'mweb' in work else '', )) @deferral.retry('Error submitting primary block: (will retry)', 10, 10) @@ -153,7 +157,7 @@ def submit_block_rpc(block, ignore_failure, bitcoind, bitcoind_work, net): segwit_activated = len(segwit_rules - set(bitcoind_work.value['rules'])) < len(segwit_rules) if bitcoind_work.value['use_getblocktemplate']: try: - result = yield bitcoind.rpc_submitblock((bitcoin_data.block_type if segwit_activated else bitcoin_data.stripped_block_type).pack(block).encode('hex')) + result = yield bitcoind.rpc_submitblock((bitcoin_data.block_type if segwit_activated else bitcoin_data.stripped_block_type).pack(block).encode('hex') + bitcoind_work.value['mweb']) except jsonrpc.Error_for_code(-32601): # Method not found, for older litecoin versions result = yield bitcoind.rpc_getblocktemplate(dict(mode='submit', data=bitcoin_data.block_type.pack(block).encode('hex'))) success = result is None From 17fda1e825a832b331935483932a6fae9b5aee39 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 23 Apr 2022 13:23:00 +0000 Subject: [PATCH 2/2] Handle Litecoin MWEB rules --- p2pool/bitcoin/helper.py | 9 +++------ p2pool/bitcoin/networks/litecoin_testnet.py | 1 + p2pool/main.py | 2 +- p2pool/networks/litecoin.py | 2 +- p2pool/networks/litecoin_testnet.py | 2 +- p2pool/node.py | 4 ++-- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/p2pool/bitcoin/helper.py b/p2pool/bitcoin/helper.py index bf39ad24f..a20cdafe8 100644 --- a/p2pool/bitcoin/helper.py +++ b/p2pool/bitcoin/helper.py @@ -16,9 +16,6 @@ def check(bitcoind, net, args): raise deferral.RetrySilentlyException() version_check_result = net.VERSION_CHECK((yield bitcoind.rpc_getnetworkinfo())['version']) - blockchaininfo = yield bitcoind.rpc_getblockchaininfo() - global softforkrules - softforkrules = ['segwit','mweb'] if 'mweb' in blockchaininfo['softforks'] else ['segwit'] if version_check_result == True: version_check_result = None # deprecated if version_check_result == False: version_check_result = 'Coin daemon too old! Upgrade!' # deprecated if version_check_result is not None: @@ -51,10 +48,10 @@ def check(bitcoind, net, args): @deferral.retry('Error getting work from bitcoind:', 3) @defer.inlineCallbacks -def getwork(bitcoind, use_getblocktemplate=False, txidcache={}, feecache={}, feefifo=[], known_txs={}): +def getwork(bitcoind, net, use_getblocktemplate=False, txidcache={}, feecache={}, feefifo=[], known_txs={}): def go(): if use_getblocktemplate: - return bitcoind.rpc_getblocktemplate(dict(mode='template', rules=softforkrules)) + return bitcoind.rpc_getblocktemplate(dict(mode='template', rules=['segwit','mweb'] if 'mweb' in getattr(net, 'SOFTFORKS_REQUIRED', set()) else ['segwit'])) else: return bitcoind.rpc_getmemorypool() try: @@ -140,7 +137,7 @@ def go(): last_update=time.time(), use_getblocktemplate=use_getblocktemplate, latency=end - start, - mweb="01" + work['mweb'] if 'mweb' in work else '', + mweb='01' + work['mweb'] if 'mweb' in work else '', )) @deferral.retry('Error submitting primary block: (will retry)', 10, 10) diff --git a/p2pool/bitcoin/networks/litecoin_testnet.py b/p2pool/bitcoin/networks/litecoin_testnet.py index f231aaf5b..d7452516a 100644 --- a/p2pool/bitcoin/networks/litecoin_testnet.py +++ b/p2pool/bitcoin/networks/litecoin_testnet.py @@ -28,3 +28,4 @@ SANE_TARGET_RANGE = (1<<128-1, 1<<240-1) DUMB_SCRYPT_DIFF = 2**16 DUST_THRESHOLD = 1e8 +SOFTFORKS_REQUIRED = set(['bip65', 'csv', 'segwit', 'mweb']) diff --git a/p2pool/main.py b/p2pool/main.py index 1ff006096..a2485e383 100644 --- a/p2pool/main.py +++ b/p2pool/main.py @@ -104,7 +104,7 @@ def long(): print '''Testing bitcoind RPC connection to '%s' with username '%s'...''' % (url, args.bitcoind_rpc_username) bitcoind = jsonrpc.HTTPProxy(url, dict(Authorization='Basic ' + base64.b64encode(args.bitcoind_rpc_username + ':' + args.bitcoind_rpc_password)), timeout=30) yield helper.check(bitcoind, net, args) - temp_work = yield helper.getwork(bitcoind) + temp_work = yield helper.getwork(bitcoind, net) bitcoind_getinfo_var = variable.Variable(None) @defer.inlineCallbacks diff --git a/p2pool/networks/litecoin.py b/p2pool/networks/litecoin.py index 783a7da5a..ef7e734e1 100644 --- a/p2pool/networks/litecoin.py +++ b/p2pool/networks/litecoin.py @@ -29,7 +29,7 @@ ANNOUNCE_CHANNEL = '#p2pool-ltc' VERSION_CHECK = lambda v: None if 100400 <= v else 'Litecoin version too old. Upgrade to 0.10.4 or newer!' VERSION_WARNING = lambda v: None -SOFTFORKS_REQUIRED = set(['bip65', 'csv', 'segwit']) +SOFTFORKS_REQUIRED = set(['bip65', 'csv', 'segwit', 'taproot', 'mweb']) MINIMUM_PROTOCOL_VERSION = 3301 SEGWIT_ACTIVATION_VERSION = 17 BLOCK_MAX_SIZE = 1000000 diff --git a/p2pool/networks/litecoin_testnet.py b/p2pool/networks/litecoin_testnet.py index e494b1000..6153c8369 100644 --- a/p2pool/networks/litecoin_testnet.py +++ b/p2pool/networks/litecoin_testnet.py @@ -16,7 +16,7 @@ BOOTSTRAP_ADDRS = 'forre.st'.split(' ') ANNOUNCE_CHANNEL = '#p2pool-alt' VERSION_CHECK = lambda v: True -SOFTFORKS_REQUIRED = set(['bip65', 'csv', 'segwit']) +SOFTFORKS_REQUIRED = set(['bip65', 'csv', 'segwit', 'taproot', 'mweb']) MINIMUM_PROTOCOL_VERSION = 3301 SEGWIT_ACTIVATION_VERSION = 17 BLOCK_MAX_SIZE = 1000000 diff --git a/p2pool/node.py b/p2pool/node.py index c47dd98fc..8820aa291 100644 --- a/p2pool/node.py +++ b/p2pool/node.py @@ -204,14 +204,14 @@ def start(self): # BITCOIND WORK - self.bitcoind_work = variable.Variable((yield helper.getwork(self.bitcoind))) + self.bitcoind_work = variable.Variable((yield helper.getwork(self.bitcoind, self.net))) @defer.inlineCallbacks def work_poller(): while stop_signal.times == 0: flag = self.factory.new_block.get_deferred() try: - self.bitcoind_work.set((yield helper.getwork(self.bitcoind, self.bitcoind_work.value['use_getblocktemplate'], self.txidcache, self.feecache, self.feefifo, self.known_txs_var.value))) + self.bitcoind_work.set((yield helper.getwork(self.bitcoind, self.net, self.bitcoind_work.value['use_getblocktemplate'], self.txidcache, self.feecache, self.feefifo, self.known_txs_var.value))) self.check_and_purge_txs() except: log.err()