Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Litecoin MWEB rules #59

Merged
merged 2 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions p2pool/bitcoin/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,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=['segwit']))
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:
Expand Down Expand Up @@ -137,6 +137,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)
Expand All @@ -153,7 +154,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
Expand Down
1 change: 1 addition & 0 deletions p2pool/bitcoin/networks/litecoin_testnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
2 changes: 1 addition & 1 deletion p2pool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion p2pool/networks/litecoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion p2pool/networks/litecoin_testnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions p2pool/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down