mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +01:00
common: support opt_shutdown_anysegwit checks (EXPERIMENTAL_FEATURES).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -5,6 +5,7 @@ from shutil import copyfile
|
||||
from utils import (
|
||||
only_one, sync_blockheight, wait_for, DEVELOPER, TIMEOUT,
|
||||
account_balance, first_channel_id, basic_fee, TEST_NETWORK,
|
||||
EXPERIMENTAL_FEATURES,
|
||||
)
|
||||
|
||||
import os
|
||||
@@ -2609,3 +2610,80 @@ def test_invalid_upfront_shutdown_script(node_factory, bitcoind, executor):
|
||||
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
|
||||
with pytest.raises(RpcError, match=r'Unacceptable upfront_shutdown_script'):
|
||||
l1.fundchannel(l2, 1000000, False)
|
||||
|
||||
|
||||
@unittest.skipIf(not DEVELOPER, "needs to set upfront_shutdown_script")
|
||||
@pytest.mark.slow_test
|
||||
def test_segwit_shutdown_script(node_factory, bitcoind, executor):
|
||||
"""
|
||||
Try a range of future segwit versions as shutdown scripts. We create many nodes, so this is quite slow under valgrind
|
||||
"""
|
||||
l1 = node_factory.get_node(allow_warning=True)
|
||||
|
||||
# BOLT-4e329271a358ee52bf43ddbd96776943c5d74508 #2:
|
||||
# 5. if (and only if) `option_shutdown_anysegwit` is negotiated:
|
||||
# * `OP_1` through `OP_16` inclusive, followed by a single push of 2 to 40 bytes
|
||||
# (witness program versions 1 through 16)
|
||||
valid = ['51020000', '5128' + '00' * 0x28,
|
||||
'52020000', '5228' + '00' * 0x28,
|
||||
'53020000', '5328' + '00' * 0x28,
|
||||
'54020000', '5428' + '00' * 0x28,
|
||||
'55020000', '5528' + '00' * 0x28,
|
||||
'56020000', '5628' + '00' * 0x28,
|
||||
'57020000', '5728' + '00' * 0x28,
|
||||
'58020000', '5828' + '00' * 0x28,
|
||||
'59020000', '5928' + '00' * 0x28,
|
||||
'5A020000', '5A28' + '00' * 0x28,
|
||||
'5B020000', '5B28' + '00' * 0x28,
|
||||
'5C020000', '5C28' + '00' * 0x28,
|
||||
'5D020000', '5D28' + '00' * 0x28,
|
||||
'5E020000', '5E28' + '00' * 0x28,
|
||||
'5F020000', '5F28' + '00' * 0x28,
|
||||
'60020000', '6028' + '00' * 0x28]
|
||||
invalid = ['50020000', # Not OP_1-OP_16
|
||||
'61020000', # Not OP_1-OP_16
|
||||
'5102000000', # Extra bytes
|
||||
'510100', # Too short
|
||||
'5129' + '00' * 0x29] # Too long
|
||||
|
||||
if EXPERIMENTAL_FEATURES:
|
||||
xsuccess = valid
|
||||
xfail = invalid
|
||||
else:
|
||||
xsuccess = []
|
||||
xfail = valid + invalid
|
||||
|
||||
# More efficient to create them all up-front.
|
||||
nodes = node_factory.get_nodes(len(xfail) + len(xsuccess))
|
||||
|
||||
# Give it one UTXO to spend for each node.
|
||||
addresses = {}
|
||||
for n in nodes:
|
||||
addresses[l1.rpc.newaddr()['bech32']] = (10**6 + 100000) / 10**8
|
||||
bitcoind.rpc.sendmany("", addresses)
|
||||
bitcoind.generate_block(1)
|
||||
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == len(addresses))
|
||||
|
||||
# FIXME: Since we don't support other non-v0 encodings, we need a protocol
|
||||
# test for this (we're actually testing our upfront check, not the real
|
||||
# shutdown one!),
|
||||
for script in xsuccess:
|
||||
# Insist on upfront script we're not going to match.
|
||||
l1.stop()
|
||||
l1.daemon.env["DEV_OPENINGD_UPFRONT_SHUTDOWN_SCRIPT"] = script
|
||||
l1.start()
|
||||
|
||||
l2 = nodes.pop()
|
||||
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
|
||||
l1.rpc.fundchannel(l2.info['id'], 10**6)
|
||||
|
||||
for script in xfail:
|
||||
# Insist on upfront script we're not going to match.
|
||||
l1.stop()
|
||||
l1.daemon.env["DEV_OPENINGD_UPFRONT_SHUTDOWN_SCRIPT"] = script
|
||||
l1.start()
|
||||
|
||||
l2 = nodes.pop()
|
||||
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
|
||||
with pytest.raises(RpcError, match=r'Unacceptable upfront_shutdown_script'):
|
||||
l1.rpc.fundchannel(l2.info['id'], 10**6)
|
||||
|
||||
Reference in New Issue
Block a user