From 4486ba28a7f526f5c7ee17feccca43a821827bfc Mon Sep 17 00:00:00 2001 From: Dusty Daemon Date: Tue, 15 Aug 2023 16:56:26 -0400 Subject: [PATCH] splice: Agressive restart testing during splices Test node restarts in lots of phases of splice. Changelog-None --- lightningd/channel.c | 7 +- tests/test_splicing.py | 146 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 5 deletions(-) diff --git a/lightningd/channel.c b/lightningd/channel.c index 60d1c19cd48e..8b9ab96be974 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -137,7 +137,6 @@ new_inflight(struct channel *channel, s64 splice_amnt, bool i_am_initiator) { - struct wally_psbt *last_tx_psbt_clone; struct channel_inflight *inflight = tal(channel, struct channel_inflight); struct funding_info *funding @@ -156,10 +155,8 @@ new_inflight(struct channel *channel, /* Make a 'clone' of this tx */ inflight->last_tx = NULL; - if (last_tx) { - last_tx_psbt_clone = clone_psbt(inflight, last_tx->psbt); - inflight->last_tx = bitcoin_tx_with_psbt(inflight, last_tx_psbt_clone); - } + if (last_tx) + inflight->last_tx = clone_bitcoin_tx(inflight, last_tx); inflight->last_sig = last_sig; inflight->tx_broadcast = false; diff --git a/tests/test_splicing.py b/tests/test_splicing.py index 959e4d4dc614..de977860d116 100644 --- a/tests/test_splicing.py +++ b/tests/test_splicing.py @@ -39,3 +39,149 @@ def test_splice(node_factory, bitcoind): # Check that the splice doesn't generate a unilateral close transaction time.sleep(5) assert l1.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0 + + +def make_pending_splice(node_factory): + l1, l2 = node_factory.line_graph(2, fundamount=1000000, wait_for_announce=True, opts={'experimental-splicing': None, 'may_reconnect': True}) + + chan_id = l1.get_channel_id(l2) + + funds_result = l1.rpc.fundpsbt("109000sat", "slow", 166, excess_as_change=True) + + result = l1.rpc.splice_init(chan_id, 100000, funds_result['psbt']) + result = l1.rpc.splice_update(chan_id, result['psbt']) + result = l1.rpc.signpsbt(result['psbt']) + result = l1.rpc.splice_signed(chan_id, result['signed_psbt']) + + return [l1, l2] + + +def wait_for_await(l1, l2): + l2.daemon.wait_for_log(r'CHANNELD_NORMAL to CHANNELD_AWAITING_SPLICE') + l1.daemon.wait_for_log(r'CHANNELD_NORMAL to CHANNELD_AWAITING_SPLICE') + + +def wait_for_confirm(l1, l2): + l2.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL') + l1.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL') + + +def confirm(bitcoind): + bitcoind.generate_block(6, wait_for_mempool=1) + + +def confirm_and_wait(l1, l2, bitcoind): + confirm(bitcoind) + wait_for_confirm(l1, l2) + + +def wait_for_await_and_finish(l1, l2, bitcoind): + wait_for_await(l1, l2) + confirm_and_wait(l1, l2, bitcoind) + + +def confirm_funding_not_spent(nodes): + for node in nodes: + assert not node.daemon.is_in_log("Funding transaction spent") + assert node.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0 + + +@pytest.mark.openchannel('v1') +@pytest.mark.openchannel('v2') +@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need') +def test_splice_restart(node_factory, bitcoind): + nodes = [] + + l1, l2 = make_pending_splice(node_factory) + l2.restart() + wait_for_await_and_finish(l1, l2, bitcoind) + nodes.append(l1) + nodes.append(l2) + + l1, l2 = make_pending_splice(node_factory) + l1.restart() + # failing here "bad commit sig" + wait_for_await_and_finish(l1, l2, bitcoind) + nodes.append(l1) + nodes.append(l2) + + l1, l2 = make_pending_splice(node_factory) + l1.restart() + l2.restart() + wait_for_await_and_finish(l1, l2, bitcoind) + nodes.append(l1) + nodes.append(l2) + + l1, l2 = make_pending_splice(node_factory) + wait_for_await(l1, l2) + l1.restart() + confirm_and_wait(l1, l2, bitcoind) + nodes.append(l1) + nodes.append(l2) + + l1, l2 = make_pending_splice(node_factory) + wait_for_await(l1, l2) + l2.restart() + confirm_and_wait(l1, l2, bitcoind) + nodes.append(l1) + nodes.append(l2) + + l1, l2 = make_pending_splice(node_factory) + wait_for_await(l1, l2) + l1.restart() + l2.restart() + confirm_and_wait(l1, l2, bitcoind) + nodes.append(l1) + nodes.append(l2) + + l1, l2 = make_pending_splice(node_factory) + wait_for_await(l1, l2) + confirm(bitcoind) + l1.restart() + wait_for_confirm(l1, l2) + nodes.append(l1) + nodes.append(l2) + + l1, l2 = make_pending_splice(node_factory) + wait_for_await(l1, l2) + confirm(bitcoind) + l2.restart() + wait_for_confirm(l1, l2) + nodes.append(l1) + nodes.append(l2) + + l1, l2 = make_pending_splice(node_factory) + wait_for_await(l1, l2) + confirm(bitcoind) + l1.restart() + l2.restart() + wait_for_confirm(l1, l2) + nodes.append(l1) + nodes.append(l2) + + l1, l2 = make_pending_splice(node_factory) + wait_for_await(l1, l2) + confirm(bitcoind) + wait_for_await_and_finish(l1, l2, bitcoind) + l1.restart() + nodes.append(l1) + nodes.append(l2) + + l1, l2 = make_pending_splice(node_factory) + wait_for_await(l1, l2) + confirm(bitcoind) + wait_for_await_and_finish(l1, l2, bitcoind) + l2.restart() + nodes.append(l1) + nodes.append(l2) + + l1, l2 = make_pending_splice(node_factory) + wait_for_await(l1, l2) + confirm(bitcoind) + wait_for_await_and_finish(l1, l2, bitcoind) + l1.restart() + l2.restart() + nodes.append(l1) + nodes.append(l2) + + confirm_funding_not_spent(nodes)