mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
onchaind: use lightningd for spending our unilateral "to us" output.
This follows the same pattern as the "spend htlc tx" in fact. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
07413c20b9
commit
9d5dfa7bdd
5 changed files with 124 additions and 108 deletions
|
@ -614,14 +614,6 @@ static void set_htlc_success_fee(struct bitcoin_tx *tx,
|
||||||
tal_hex(tmpctx, wscript));
|
tal_hex(tmpctx, wscript));
|
||||||
}
|
}
|
||||||
|
|
||||||
static u8 *delayed_payment_to_us(const tal_t *ctx,
|
|
||||||
struct bitcoin_tx *tx,
|
|
||||||
const u8 *wscript)
|
|
||||||
{
|
|
||||||
return towire_hsmd_sign_delayed_payment_to_us(ctx, commit_num,
|
|
||||||
tx, wscript);
|
|
||||||
}
|
|
||||||
|
|
||||||
static u8 *remote_htlc_to_us(const tal_t *ctx,
|
static u8 *remote_htlc_to_us(const tal_t *ctx,
|
||||||
struct bitcoin_tx *tx,
|
struct bitcoin_tx *tx,
|
||||||
const u8 *wscript)
|
const u8 *wscript)
|
||||||
|
@ -2739,9 +2731,8 @@ static void our_unilateral_to_us(struct tracked_output ***outs,
|
||||||
const u8 *local_scriptpubkey,
|
const u8 *local_scriptpubkey,
|
||||||
const u8 *local_wscript)
|
const u8 *local_wscript)
|
||||||
{
|
{
|
||||||
struct bitcoin_tx *to_us;
|
|
||||||
struct tracked_output *out;
|
struct tracked_output *out;
|
||||||
enum tx_type tx_type = OUR_DELAYED_RETURN_TO_WALLET;
|
const u8 *msg;
|
||||||
|
|
||||||
/* BOLT #5:
|
/* BOLT #5:
|
||||||
*
|
*
|
||||||
|
@ -2760,26 +2751,21 @@ static void our_unilateral_to_us(struct tracked_output ***outs,
|
||||||
amt,
|
amt,
|
||||||
DELAYED_OUTPUT_TO_US,
|
DELAYED_OUTPUT_TO_US,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
/* BOLT #3:
|
|
||||||
*
|
msg = towire_onchaind_spend_to_us(NULL,
|
||||||
* The output is spent by an input with
|
outpoint, amt,
|
||||||
* `nSequence` field set to `to_self_delay` (which can
|
rel_blockheight(out, to_self_delay[LOCAL]),
|
||||||
* only be valid after that duration has passed) and
|
commit_num,
|
||||||
* witness:
|
local_wscript);
|
||||||
*
|
|
||||||
* <local_delayedsig> <>
|
|
||||||
*/
|
|
||||||
to_us = tx_to_us(out, delayed_payment_to_us, out,
|
|
||||||
sequence, 0, NULL, 0,
|
|
||||||
local_wscript, &tx_type,
|
|
||||||
delayed_to_us_feerate);
|
|
||||||
|
|
||||||
/* BOLT #5:
|
/* BOLT #5:
|
||||||
*
|
*
|
||||||
* Note: if the output is spent (as recommended), the
|
* Note: if the output is spent (as recommended), the
|
||||||
* output is *resolved* by the spending transaction
|
* output is *resolved* by the spending transaction
|
||||||
*/
|
*/
|
||||||
propose_resolution(out, to_us, sequence, tx_type);
|
propose_resolution_to_master(out, take(msg),
|
||||||
|
rel_blockheight(out, to_self_delay[LOCAL]),
|
||||||
|
OUR_DELAYED_RETURN_TO_WALLET);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_our_unilateral(const struct tx_parts *tx,
|
static void handle_our_unilateral(const struct tx_parts *tx,
|
||||||
|
|
|
@ -44,10 +44,11 @@ def test_bookkeeping_closing_trimmed_htlcs(node_factory, bitcoind, executor):
|
||||||
l1.daemon.wait_for_log(' to ONCHAIN')
|
l1.daemon.wait_for_log(' to ONCHAIN')
|
||||||
l2.daemon.wait_for_log(' to ONCHAIN')
|
l2.daemon.wait_for_log(' to ONCHAIN')
|
||||||
|
|
||||||
bitcoind.generate_block(5)
|
((_, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
sync_blockheight(bitcoind, [l1])
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
l1.daemon.wait_for_log('Broadcasting OUR_DELAYED_RETURN_TO_WALLET')
|
assert blocks == 4
|
||||||
bitcoind.generate_block(20, wait_for_mempool=1)
|
bitcoind.generate_block(4)
|
||||||
|
bitcoind.generate_block(20, wait_for_mempool=txid)
|
||||||
sync_blockheight(bitcoind, [l1])
|
sync_blockheight(bitcoind, [l1])
|
||||||
l1.daemon.wait_for_log(r'All outputs resolved.*')
|
l1.daemon.wait_for_log(r'All outputs resolved.*')
|
||||||
|
|
||||||
|
@ -87,12 +88,15 @@ def test_bookkeeping_closing_subsat_htlcs(node_factory, bitcoind, chainparams):
|
||||||
|
|
||||||
l2.stop()
|
l2.stop()
|
||||||
l1.rpc.close(l2.info['id'], 1)
|
l1.rpc.close(l2.info['id'], 1)
|
||||||
bitcoind.generate_block(5, wait_for_mempool=1)
|
bitcoind.generate_block(1, wait_for_mempool=1)
|
||||||
|
|
||||||
|
((_, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
|
bitcoind.generate_block(4)
|
||||||
|
|
||||||
l2.start()
|
l2.start()
|
||||||
sync_blockheight(bitcoind, [l1])
|
bitcoind.generate_block(80, wait_for_mempool=txid)
|
||||||
l1.daemon.wait_for_log('Broadcasting OUR_DELAYED_RETURN_TO_WALLET')
|
|
||||||
bitcoind.generate_block(80)
|
|
||||||
|
|
||||||
sync_blockheight(bitcoind, [l1, l2])
|
sync_blockheight(bitcoind, [l1, l2])
|
||||||
evs = l1.rpc.bkpr_listaccountevents()['events']
|
evs = l1.rpc.bkpr_listaccountevents()['events']
|
||||||
|
|
|
@ -1297,14 +1297,18 @@ def test_penalty_htlc_tx_fulfill(node_factory, bitcoind, chainparams):
|
||||||
# l2 moves on for closed l3
|
# l2 moves on for closed l3
|
||||||
bitcoind.generate_block(1)
|
bitcoind.generate_block(1)
|
||||||
l2.daemon.wait_for_log('to ONCHAIN')
|
l2.daemon.wait_for_log('to ONCHAIN')
|
||||||
l2.daemon.wait_for_logs(['Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET .* after 5 blocks',
|
needle = l2.daemon.logsearch_start
|
||||||
'Propose handling OUR_UNILATERAL/THEIR_HTLC by OUR_HTLC_SUCCESS_TX .* after 0 blocks'])
|
l2.daemon.wait_for_log('Propose handling OUR_UNILATERAL/THEIR_HTLC by OUR_HTLC_SUCCESS_TX .* after 0 blocks')
|
||||||
|
|
||||||
l2.wait_for_onchaind_broadcast('OUR_HTLC_SUCCESS_TX',
|
l2.wait_for_onchaind_broadcast('OUR_HTLC_SUCCESS_TX',
|
||||||
'OUR_UNILATERAL/THEIR_HTLC')
|
'OUR_UNILATERAL/THEIR_HTLC')
|
||||||
|
l2.daemon.logsearch_start = needle
|
||||||
|
|
||||||
|
((_, _, blocks),) = l2.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
|
|
||||||
bitcoind.generate_block(1)
|
bitcoind.generate_block(1)
|
||||||
((_, txid, blocks),) = l2.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
((_, _, blocks),) = l2.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
'OUR_HTLC_SUCCESS_TX/DELAYED_OUTPUT_TO_US')
|
'OUR_HTLC_SUCCESS_TX/DELAYED_OUTPUT_TO_US')
|
||||||
assert blocks == 4
|
assert blocks == 4
|
||||||
|
|
||||||
|
@ -1492,7 +1496,6 @@ def test_penalty_htlc_tx_timeout(node_factory, bitcoind, chainparams):
|
||||||
bitcoind.generate_block(1, wait_for_mempool=1)
|
bitcoind.generate_block(1, wait_for_mempool=1)
|
||||||
l2.daemon.wait_for_log('to ONCHAIN')
|
l2.daemon.wait_for_log('to ONCHAIN')
|
||||||
l2.daemon.wait_for_logs(['Propose handling OUR_UNILATERAL/OUR_HTLC by OUR_HTLC_TIMEOUT_TX .* after 16 blocks',
|
l2.daemon.wait_for_logs(['Propose handling OUR_UNILATERAL/OUR_HTLC by OUR_HTLC_TIMEOUT_TX .* after 16 blocks',
|
||||||
'Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET .* after 5 blocks',
|
|
||||||
'Propose handling OUR_UNILATERAL/THEIR_HTLC by OUR_HTLC_SUCCESS_TX .* after 0 blocks'])
|
'Propose handling OUR_UNILATERAL/THEIR_HTLC by OUR_HTLC_SUCCESS_TX .* after 0 blocks'])
|
||||||
|
|
||||||
l2.wait_for_onchaind_broadcast('OUR_HTLC_SUCCESS_TX',
|
l2.wait_for_onchaind_broadcast('OUR_HTLC_SUCCESS_TX',
|
||||||
|
@ -1865,13 +1868,15 @@ def test_onchain_first_commit(node_factory, bitcoind):
|
||||||
l1.daemon.wait_for_log(' to ONCHAIN')
|
l1.daemon.wait_for_log(' to ONCHAIN')
|
||||||
l2.daemon.wait_for_log(' to ONCHAIN')
|
l2.daemon.wait_for_log(' to ONCHAIN')
|
||||||
|
|
||||||
# 10 later, l1 should collect its to-self payment.
|
((_, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
bitcoind.generate_block(10)
|
|
||||||
l1.wait_for_onchaind_broadcast('OUR_DELAYED_RETURN_TO_WALLET',
|
|
||||||
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 9
|
||||||
|
|
||||||
|
# 10 later, l1 should collect its to-self payment.
|
||||||
|
bitcoind.generate_block(9)
|
||||||
|
|
||||||
# 94 later, l2 is done.
|
# 94 later, l2 is done.
|
||||||
bitcoind.generate_block(94)
|
bitcoind.generate_block(94, wait_for_mempool=txid)
|
||||||
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
||||||
|
|
||||||
# Now, 100 blocks and l1 should be done.
|
# Now, 100 blocks and l1 should be done.
|
||||||
|
@ -1897,13 +1902,15 @@ def test_onchain_unwatch(node_factory, bitcoind):
|
||||||
l1.daemon.wait_for_log(' to ONCHAIN')
|
l1.daemon.wait_for_log(' to ONCHAIN')
|
||||||
l2.daemon.wait_for_log(' to ONCHAIN')
|
l2.daemon.wait_for_log(' to ONCHAIN')
|
||||||
|
|
||||||
# 10 later, l1 should collect its to-self payment.
|
((_, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
bitcoind.generate_block(10)
|
|
||||||
l1.wait_for_onchaind_broadcast('OUR_DELAYED_RETURN_TO_WALLET',
|
|
||||||
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
|
|
||||||
|
# 5 later, l1 should collect its to-self payment.
|
||||||
|
bitcoind.generate_block(4)
|
||||||
|
|
||||||
# First time it sees it, onchaind cares.
|
# First time it sees it, onchaind cares.
|
||||||
bitcoind.generate_block(1)
|
bitcoind.generate_block(1, wait_for_mempool=txid)
|
||||||
l1.daemon.wait_for_log('Resolved OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by our proposal '
|
l1.daemon.wait_for_log('Resolved OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by our proposal '
|
||||||
'OUR_DELAYED_RETURN_TO_WALLET')
|
'OUR_DELAYED_RETURN_TO_WALLET')
|
||||||
|
|
||||||
|
@ -1978,10 +1985,11 @@ def test_onchaind_replay(node_factory, bitcoind):
|
||||||
assert l1.daemon.is_in_log(r'Restarting onchaind for channel')
|
assert l1.daemon.is_in_log(r'Restarting onchaind for channel')
|
||||||
|
|
||||||
# l1 should still notice that the funding was spent and that we should react to it
|
# l1 should still notice that the funding was spent and that we should react to it
|
||||||
l1.daemon.wait_for_log("Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET")
|
((_, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
sync_blockheight(bitcoind, [l1])
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
bitcoind.generate_block(10)
|
assert blocks == 200
|
||||||
sync_blockheight(bitcoind, [l1])
|
bitcoind.generate_block(200)
|
||||||
|
bitcoind.generate_block(1, wait_for_mempool=txid)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.developer("needs DEVELOPER=1")
|
@pytest.mark.developer("needs DEVELOPER=1")
|
||||||
|
@ -2033,13 +2041,15 @@ def test_onchain_dust_out(node_factory, bitcoind, executor):
|
||||||
with pytest.raises(RpcError, match=r'WIRE_UNKNOWN_NEXT_PEER'):
|
with pytest.raises(RpcError, match=r'WIRE_UNKNOWN_NEXT_PEER'):
|
||||||
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
|
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
|
||||||
|
|
||||||
# 6 later, l1 should collect its to-self payment.
|
((_, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
bitcoind.generate_block(6)
|
|
||||||
l1.wait_for_onchaind_broadcast('OUR_DELAYED_RETURN_TO_WALLET',
|
|
||||||
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
|
|
||||||
|
# 4 later, l1 should collect its to-self payment.
|
||||||
|
bitcoind.generate_block(4)
|
||||||
|
|
||||||
# 94 later, l2 is done.
|
# 94 later, l2 is done.
|
||||||
bitcoind.generate_block(94)
|
bitcoind.generate_block(94, wait_for_mempool=txid)
|
||||||
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
||||||
|
|
||||||
# Restart l1, it should not crash!
|
# Restart l1, it should not crash!
|
||||||
|
@ -2103,31 +2113,36 @@ def test_onchain_timeout(node_factory, bitcoind, executor):
|
||||||
l2.daemon.wait_for_log(' to ONCHAIN')
|
l2.daemon.wait_for_log(' to ONCHAIN')
|
||||||
|
|
||||||
# Wait for timeout.
|
# Wait for timeout.
|
||||||
l1.daemon.wait_for_logs(['Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET .* after 5 blocks',
|
needle = l1.daemon.logsearch_start
|
||||||
'Propose handling OUR_UNILATERAL/OUR_HTLC by OUR_HTLC_TIMEOUT_TX .* after 6 blocks'])
|
l1.daemon.wait_for_log('Propose handling OUR_UNILATERAL/OUR_HTLC by OUR_HTLC_TIMEOUT_TX .* after 6 blocks')
|
||||||
|
|
||||||
|
# Could happen any order.
|
||||||
|
l1.daemon.logsearch_start = needle
|
||||||
|
((_, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
|
|
||||||
bitcoind.generate_block(4)
|
bitcoind.generate_block(4)
|
||||||
|
|
||||||
l1.wait_for_onchaind_broadcast('OUR_DELAYED_RETURN_TO_WALLET',
|
bitcoind.generate_block(1, wait_for_mempool=txid)
|
||||||
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
|
||||||
|
|
||||||
bitcoind.generate_block(1)
|
|
||||||
l1.wait_for_onchaind_broadcast('OUR_HTLC_TIMEOUT_TX',
|
l1.wait_for_onchaind_broadcast('OUR_HTLC_TIMEOUT_TX',
|
||||||
'OUR_UNILATERAL/OUR_HTLC')
|
'OUR_UNILATERAL/OUR_HTLC')
|
||||||
|
|
||||||
bitcoind.generate_block(1, wait_for_mempool=1)
|
bitcoind.generate_block(1, wait_for_mempool=1)
|
||||||
((rawtx, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
# After the first block it saw htlc_timeout_tx and planned this:
|
||||||
|
((_, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
'OUR_HTLC_TIMEOUT_TX/DELAYED_OUTPUT_TO_US')
|
'OUR_HTLC_TIMEOUT_TX/DELAYED_OUTPUT_TO_US')
|
||||||
assert blocks == 4
|
assert blocks == 4
|
||||||
|
|
||||||
# We use 3 blocks for "reasonable depth"
|
# We use 3 blocks for "reasonable depth"
|
||||||
bitcoind.generate_block(3)
|
bitcoind.generate_block(2)
|
||||||
|
|
||||||
# It should fail.
|
# It should fail.
|
||||||
with pytest.raises(RpcError, match=r'WIRE_PERMANENT_CHANNEL_FAILURE: timed out'):
|
with pytest.raises(RpcError, match=r'WIRE_PERMANENT_CHANNEL_FAILURE: timed out'):
|
||||||
payfuture.result(TIMEOUT)
|
payfuture.result(TIMEOUT)
|
||||||
|
|
||||||
# 1 later, l1 spends HTLC (depth = 5 blocks).
|
bitcoind.generate_block(2)
|
||||||
bitcoind.generate_block(1)
|
|
||||||
|
|
||||||
|
# l1 spends HTLC (depth = 5 blocks).
|
||||||
# 89 later, l2 is done.
|
# 89 later, l2 is done.
|
||||||
bitcoind.generate_block(89, wait_for_mempool=txid)
|
bitcoind.generate_block(89, wait_for_mempool=txid)
|
||||||
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
||||||
|
@ -2227,12 +2242,17 @@ def test_onchain_middleman_simple(node_factory, bitcoind):
|
||||||
l1.daemon.wait_for_log(' to ONCHAIN')
|
l1.daemon.wait_for_log(' to ONCHAIN')
|
||||||
l2.daemon.wait_for_log('OUR_UNILATERAL/THEIR_HTLC')
|
l2.daemon.wait_for_log('OUR_UNILATERAL/THEIR_HTLC')
|
||||||
|
|
||||||
|
needle = l2.daemon.logsearch_start
|
||||||
# l2 should fulfill HTLC onchain, and spend to-us (any order)
|
# l2 should fulfill HTLC onchain, and spend to-us (any order)
|
||||||
l2.wait_for_onchaind_broadcast('OUR_HTLC_SUCCESS_TX',
|
l2.wait_for_onchaind_broadcast('OUR_HTLC_SUCCESS_TX',
|
||||||
'OUR_UNILATERAL/THEIR_HTLC')
|
'OUR_UNILATERAL/THEIR_HTLC')
|
||||||
|
l2.daemon.logsearch_start = needle
|
||||||
|
((_, txid1, blocks),) = l2.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
|
|
||||||
# Payment should succeed.
|
# Payment should succeed.
|
||||||
l1.bitcoin.generate_block(1)
|
l1.bitcoin.generate_block(1, wait_for_mempool=1)
|
||||||
l1.daemon.wait_for_log('THEIR_UNILATERAL/OUR_HTLC gave us preimage')
|
l1.daemon.wait_for_log('THEIR_UNILATERAL/OUR_HTLC gave us preimage')
|
||||||
err = q.get(timeout=10)
|
err = q.get(timeout=10)
|
||||||
if err:
|
if err:
|
||||||
|
@ -2241,20 +2261,16 @@ def test_onchain_middleman_simple(node_factory, bitcoind):
|
||||||
t.join(timeout=1)
|
t.join(timeout=1)
|
||||||
assert not t.is_alive()
|
assert not t.is_alive()
|
||||||
|
|
||||||
((_, txid, blocks),) = l2.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
((_, txid2, blocks),) = l2.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
'OUR_HTLC_SUCCESS_TX/DELAYED_OUTPUT_TO_US')
|
'OUR_HTLC_SUCCESS_TX/DELAYED_OUTPUT_TO_US')
|
||||||
assert blocks == 4
|
assert blocks == 4
|
||||||
|
|
||||||
# Three more, l2 can spend to-us.
|
# Four more, l2 can spend to-us, and we can spend htlc tx.
|
||||||
bitcoind.generate_block(3)
|
bitcoind.generate_block(3)
|
||||||
l2.wait_for_onchaind_broadcast('OUR_DELAYED_RETURN_TO_WALLET',
|
bitcoind.generate_block(1, wait_for_mempool=txid1)
|
||||||
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
|
||||||
|
|
||||||
# One more block, HTLC tx is now spendable.
|
|
||||||
bitcoind.generate_block(1, wait_for_mempool=1)
|
|
||||||
|
|
||||||
# 100 blocks after last spend, l2 should be done.
|
# 100 blocks after last spend, l2 should be done.
|
||||||
l1.bitcoin.generate_block(100, wait_for_mempool=txid)
|
l1.bitcoin.generate_block(100, wait_for_mempool=txid2)
|
||||||
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
||||||
|
|
||||||
# Verify accounting for l1 & l2
|
# Verify accounting for l1 & l2
|
||||||
|
@ -2359,6 +2375,10 @@ def test_onchain_middleman_their_unilateral_in(node_factory, bitcoind):
|
||||||
l2.wait_for_onchaind_broadcast('THEIR_HTLC_FULFILL_TO_US',
|
l2.wait_for_onchaind_broadcast('THEIR_HTLC_FULFILL_TO_US',
|
||||||
'THEIR_UNILATERAL/THEIR_HTLC')
|
'THEIR_UNILATERAL/THEIR_HTLC')
|
||||||
|
|
||||||
|
((_, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
|
|
||||||
# Payment should succeed.
|
# Payment should succeed.
|
||||||
l1.bitcoin.generate_block(1)
|
l1.bitcoin.generate_block(1)
|
||||||
l1.daemon.wait_for_log('OUR_UNILATERAL/OUR_HTLC gave us preimage')
|
l1.daemon.wait_for_log('OUR_UNILATERAL/OUR_HTLC gave us preimage')
|
||||||
|
@ -2369,12 +2389,10 @@ def test_onchain_middleman_their_unilateral_in(node_factory, bitcoind):
|
||||||
t.join(timeout=1)
|
t.join(timeout=1)
|
||||||
assert not t.is_alive()
|
assert not t.is_alive()
|
||||||
|
|
||||||
l1.bitcoin.generate_block(6)
|
bitcoind.generate_block(3)
|
||||||
l1.wait_for_onchaind_broadcast('OUR_DELAYED_RETURN_TO_WALLET',
|
|
||||||
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
|
||||||
|
|
||||||
# 100 blocks after last spend, l1 should be done.
|
# 100 blocks after last spend, l1 should be done.
|
||||||
l1.bitcoin.generate_block(100)
|
l1.bitcoin.generate_block(100, wait_for_mempool=txid)
|
||||||
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
||||||
l1.daemon.wait_for_log('onchaind complete, forgetting peer')
|
l1.daemon.wait_for_log('onchaind complete, forgetting peer')
|
||||||
|
|
||||||
|
@ -3129,10 +3147,15 @@ def test_permfail_htlc_out(node_factory, bitcoind, executor):
|
||||||
l1.daemon.wait_for_log('Their unilateral tx, old commit point')
|
l1.daemon.wait_for_log('Their unilateral tx, old commit point')
|
||||||
l1.daemon.wait_for_log(' to ONCHAIN')
|
l1.daemon.wait_for_log(' to ONCHAIN')
|
||||||
l2.daemon.wait_for_log(' to ONCHAIN')
|
l2.daemon.wait_for_log(' to ONCHAIN')
|
||||||
l2.daemon.wait_for_logs([
|
|
||||||
'Propose handling OUR_UNILATERAL/OUR_HTLC by OUR_HTLC_TIMEOUT_TX \\(.*\\) after 6 blocks',
|
# Could happen any order
|
||||||
'Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET .* after 5 blocks'
|
needle = l2.daemon.logsearch_start
|
||||||
])
|
l2.daemon.wait_for_log('Propose handling OUR_UNILATERAL/OUR_HTLC by OUR_HTLC_TIMEOUT_TX \\(.*\\) after 6 blocks')
|
||||||
|
|
||||||
|
l2.daemon.logsearch_start = needle
|
||||||
|
((_, txid, blocks),) = l2.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
|
|
||||||
l1.daemon.wait_for_log('Propose handling THEIR_UNILATERAL/THEIR_HTLC by THEIR_HTLC_TIMEOUT_TO_THEM \\(IGNORING\\) after 6 blocks')
|
l1.daemon.wait_for_log('Propose handling THEIR_UNILATERAL/THEIR_HTLC by THEIR_HTLC_TIMEOUT_TO_THEM \\(IGNORING\\) after 6 blocks')
|
||||||
# l1 then gets preimage, uses it instead of ignoring
|
# l1 then gets preimage, uses it instead of ignoring
|
||||||
|
@ -3145,13 +3168,11 @@ def test_permfail_htlc_out(node_factory, bitcoind, executor):
|
||||||
l2.daemon.wait_for_log('OUR_UNILATERAL/OUR_HTLC gave us preimage')
|
l2.daemon.wait_for_log('OUR_UNILATERAL/OUR_HTLC gave us preimage')
|
||||||
t.cancel()
|
t.cancel()
|
||||||
|
|
||||||
# l2 can send OUR_DELAYED_RETURN_TO_WALLET after 3 more blocks.
|
# l2 can send OUR_DELAYED_RETURN_TO_WALLET after 4 more blocks.
|
||||||
bitcoind.generate_block(3)
|
bitcoind.generate_block(3)
|
||||||
l2.wait_for_onchaind_broadcast('OUR_DELAYED_RETURN_TO_WALLET',
|
|
||||||
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
|
||||||
|
|
||||||
# Now, 100 blocks they should be done.
|
# Now, 100 blocks they should be done.
|
||||||
bitcoind.generate_block(95)
|
bitcoind.generate_block(95, txid)
|
||||||
sync_blockheight(bitcoind, [l1, l2])
|
sync_blockheight(bitcoind, [l1, l2])
|
||||||
assert not l1.daemon.is_in_log('onchaind complete, forgetting peer')
|
assert not l1.daemon.is_in_log('onchaind complete, forgetting peer')
|
||||||
assert not l2.daemon.is_in_log('onchaind complete, forgetting peer')
|
assert not l2.daemon.is_in_log('onchaind complete, forgetting peer')
|
||||||
|
@ -3162,7 +3183,7 @@ def test_permfail_htlc_out(node_factory, bitcoind, executor):
|
||||||
bitcoind.generate_block(3)
|
bitcoind.generate_block(3)
|
||||||
sync_blockheight(bitcoind, [l2])
|
sync_blockheight(bitcoind, [l2])
|
||||||
assert not l2.daemon.is_in_log('onchaind complete, forgetting peer')
|
assert not l2.daemon.is_in_log('onchaind complete, forgetting peer')
|
||||||
bitcoind.generate_block(1)
|
bitcoind.generate_block(2)
|
||||||
wait_for(lambda: l2.rpc.listpeers()['peers'] == [])
|
wait_for(lambda: l2.rpc.listpeers()['peers'] == [])
|
||||||
|
|
||||||
|
|
||||||
|
@ -3199,7 +3220,9 @@ def test_permfail(node_factory, bitcoind):
|
||||||
l1.daemon.wait_for_log('Their unilateral tx, old commit point')
|
l1.daemon.wait_for_log('Their unilateral tx, old commit point')
|
||||||
l1.daemon.wait_for_log(' to ONCHAIN')
|
l1.daemon.wait_for_log(' to ONCHAIN')
|
||||||
l2.daemon.wait_for_log(' to ONCHAIN')
|
l2.daemon.wait_for_log(' to ONCHAIN')
|
||||||
l2.daemon.wait_for_log('Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET (.*) after 5 blocks')
|
((_, txid, blocks),) = l2.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
|
|
||||||
wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['status']
|
wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['status']
|
||||||
== ['ONCHAIN:Tracking their unilateral close',
|
== ['ONCHAIN:Tracking their unilateral close',
|
||||||
|
@ -3225,12 +3248,8 @@ def test_permfail(node_factory, bitcoind):
|
||||||
l1.restart()
|
l1.restart()
|
||||||
wait_for(lambda: (closetxid, "confirmed") in set([(o['txid'], o['status']) for o in l1.rpc.listfunds()['outputs']]))
|
wait_for(lambda: (closetxid, "confirmed") in set([(o['txid'], o['status']) for o in l1.rpc.listfunds()['outputs']]))
|
||||||
|
|
||||||
# It should send the to-wallet tx.
|
|
||||||
l2.wait_for_onchaind_broadcast('OUR_DELAYED_RETURN_TO_WALLET',
|
|
||||||
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
|
||||||
|
|
||||||
# 100 after l1 sees tx, it should be done.
|
# 100 after l1 sees tx, it should be done.
|
||||||
bitcoind.generate_block(95)
|
bitcoind.generate_block(95, wait_for_mempool=txid)
|
||||||
wait_for(lambda: l1.rpc.listpeers()['peers'] == [])
|
wait_for(lambda: l1.rpc.listpeers()['peers'] == [])
|
||||||
|
|
||||||
wait_for(lambda: only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['status'] == [
|
wait_for(lambda: only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['status'] == [
|
||||||
|
|
|
@ -3833,11 +3833,13 @@ def test_upgrade_statickey_onchaind(node_factory, executor, bitcoind):
|
||||||
l2.start()
|
l2.start()
|
||||||
|
|
||||||
# They should both handle it fine.
|
# They should both handle it fine.
|
||||||
l1.daemon.wait_for_log('Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET .* after 5 blocks')
|
((_, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
l2.daemon.wait_for_logs(['Ignoring output .*: THEIR_UNILATERAL/OUTPUT_TO_US',
|
l2.daemon.wait_for_logs(['Ignoring output .*: THEIR_UNILATERAL/OUTPUT_TO_US',
|
||||||
'Ignoring output .*: THEIR_UNILATERAL/DELAYED_OUTPUT_TO_THEM'])
|
'Ignoring output .*: THEIR_UNILATERAL/DELAYED_OUTPUT_TO_THEM'])
|
||||||
bitcoind.generate_block(5)
|
bitcoind.generate_block(4)
|
||||||
bitcoind.generate_block(100, wait_for_mempool=1)
|
bitcoind.generate_block(100, wait_for_mempool=txid)
|
||||||
|
|
||||||
# This works even if they disconnect and listpeerchannels() is empty:
|
# This works even if they disconnect and listpeerchannels() is empty:
|
||||||
wait_for(lambda: len(l2.rpc.listpeerchannels()['channels']) == 0)
|
wait_for(lambda: len(l2.rpc.listpeerchannels()['channels']) == 0)
|
||||||
|
@ -3858,12 +3860,14 @@ def test_upgrade_statickey_onchaind(node_factory, executor, bitcoind):
|
||||||
l2.start()
|
l2.start()
|
||||||
|
|
||||||
# They should both handle it fine.
|
# They should both handle it fine.
|
||||||
l1.daemon.wait_for_log('Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET .* after 5 blocks')
|
((_, txid, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
l2.daemon.wait_for_logs(['Ignoring output .*: THEIR_UNILATERAL/OUTPUT_TO_US',
|
l2.daemon.wait_for_logs(['Ignoring output .*: THEIR_UNILATERAL/OUTPUT_TO_US',
|
||||||
'Ignoring output .*: THEIR_UNILATERAL/DELAYED_OUTPUT_TO_THEM'])
|
'Ignoring output .*: THEIR_UNILATERAL/DELAYED_OUTPUT_TO_THEM'])
|
||||||
|
|
||||||
bitcoind.generate_block(5)
|
bitcoind.generate_block(4)
|
||||||
bitcoind.generate_block(100, wait_for_mempool=1)
|
bitcoind.generate_block(100, wait_for_mempool=txid)
|
||||||
|
|
||||||
# This works even if they disconnect and listpeerchannels() is empty:
|
# This works even if they disconnect and listpeerchannels() is empty:
|
||||||
wait_for(lambda: len(l2.rpc.listpeerchannels()['channels']) == 0)
|
wait_for(lambda: len(l2.rpc.listpeerchannels()['channels']) == 0)
|
||||||
|
|
|
@ -357,8 +357,12 @@ def test_htlc_out_timeout(node_factory, bitcoind, executor):
|
||||||
l2.daemon.wait_for_log(' to ONCHAIN')
|
l2.daemon.wait_for_log(' to ONCHAIN')
|
||||||
|
|
||||||
# L1 will timeout HTLC immediately
|
# L1 will timeout HTLC immediately
|
||||||
l1.daemon.wait_for_logs(['Propose handling OUR_UNILATERAL/OUR_HTLC by OUR_HTLC_TIMEOUT_TX .* after 0 blocks',
|
needle = l1.daemon.logsearch_start
|
||||||
'Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET .* after 5 blocks'])
|
l1.daemon.wait_for_log('Propose handling OUR_UNILATERAL/OUR_HTLC by OUR_HTLC_TIMEOUT_TX .* after 0 blocks')
|
||||||
|
l1.daemon.logsearch_start = needle
|
||||||
|
((_, _, blocks),) = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
|
||||||
|
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
|
||||||
|
assert blocks == 4
|
||||||
|
|
||||||
l1.daemon.wait_for_log('sendrawtx exit 0')
|
l1.daemon.wait_for_log('sendrawtx exit 0')
|
||||||
bitcoind.generate_block(1)
|
bitcoind.generate_block(1)
|
||||||
|
@ -369,12 +373,11 @@ def test_htlc_out_timeout(node_factory, bitcoind, executor):
|
||||||
bitcoind.generate_block(4)
|
bitcoind.generate_block(4)
|
||||||
|
|
||||||
# It should now claim both the to-local and htlc-timeout-tx outputs.
|
# It should now claim both the to-local and htlc-timeout-tx outputs.
|
||||||
l1.daemon.wait_for_logs(['Broadcasting OUR_DELAYED_RETURN_TO_WALLET',
|
l1.daemon.wait_for_logs(['sendrawtx exit 0.*{}'.format(rawtx),
|
||||||
'sendrawtx exit 0.*{}'.format(rawtx),
|
|
||||||
'sendrawtx exit 0'])
|
'sendrawtx exit 0'])
|
||||||
|
|
||||||
# Now, 100 blocks it should be done.
|
# Now, 100 blocks it should be done.
|
||||||
bitcoind.generate_block(100)
|
bitcoind.generate_block(100, wait_for_mempool=txid)
|
||||||
l1.daemon.wait_for_log('onchaind complete, forgetting peer')
|
l1.daemon.wait_for_log('onchaind complete, forgetting peer')
|
||||||
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue