mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
c67f1f92a8
Don’t send the funding spend to onchaind if we detect it in inflights (aka. a splice). While we already prevented onchaind_funding_spent from being called directly, the call to wallet_channeltxs_add meant onchaind_funding_spent would be called *anyway* on restart. This is now fixed. Additionally there was a potential for a race problem depending on the firing order of the channel depth and and funding spent events. Instead of requiring these events fire in a specific order, we make a special “memory only” inflight object to prevent the race regardless of firing order. Changelog-Fixed: Splice: bugfix for restart related race condition interacting with adversarial close detection.
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from fixtures import * # noqa: F401,F403
|
|
from utils import TEST_NETWORK
|
|
import pytest
|
|
import unittest
|
|
import time
|
|
|
|
|
|
@pytest.mark.openchannel('v1')
|
|
@pytest.mark.openchannel('v2')
|
|
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
|
|
def test_splice(node_factory, bitcoind):
|
|
l1, l2 = node_factory.line_graph(2, fundamount=1000000, wait_for_announce=True, opts={'experimental-splicing': None})
|
|
|
|
chan_id = l1.get_channel_id(l2)
|
|
|
|
# add extra sats to pay fee
|
|
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'])
|
|
|
|
l2.daemon.wait_for_log(r'CHANNELD_NORMAL to CHANNELD_AWAITING_SPLICE')
|
|
l1.daemon.wait_for_log(r'CHANNELD_NORMAL to CHANNELD_AWAITING_SPLICE')
|
|
|
|
mempool = bitcoind.rpc.getrawmempool(True)
|
|
assert len(list(mempool.keys())) == 1
|
|
assert result['txid'] in list(mempool.keys())
|
|
|
|
bitcoind.generate_block(6, wait_for_mempool=1)
|
|
|
|
l2.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
|
|
l1.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
|
|
|
|
inv = l2.rpc.invoice(10**2, '3', 'no_3')
|
|
l1.rpc.pay(inv['bolt11'])
|
|
|
|
# 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
|