Skip to content
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: 6 additions & 1 deletion lightningd/onchain_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ static void handle_onchaind_spend_to_us(struct channel *channel,
struct onchain_signing_info *info;
struct bitcoin_outpoint out;
struct amount_sat out_sats;
u32 sequence;

info = new_signing_info(msg, channel, WIRE_ONCHAIND_SPEND_TO_US);

Expand All @@ -1293,6 +1294,7 @@ static void handle_onchaind_spend_to_us(struct channel *channel,

if (!fromwire_onchaind_spend_to_us(info, msg,
&out, &out_sats,
&sequence,
&info->minblock,
&info->u.htlc_timedout.commit_num,
&info->wscript)) {
Expand All @@ -1304,8 +1306,11 @@ static void handle_onchaind_spend_to_us(struct channel *channel,
/* No real deadline on this, it's just returning to our wallet. */
info->deadline_block =
slow_sweep_deadline(channel->peer->ld->topology, channel);

/* sequence is usually channel->channel_info.their_config.to_self_delay,
* but for leases it can be greater. */
create_onchain_tx(channel, &out, out_sats,
channel->channel_info.their_config.to_self_delay, 0,
sequence, 0,
sign_tx_to_us, info,
__func__);
}
Expand Down
8 changes: 5 additions & 3 deletions onchaind/onchaind.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,7 @@ static void resolve_htlc_tx(struct tracked_output ***outs,

msg = towire_onchaind_spend_to_us(NULL,
&outpoint, amt,
to_self_delay[LOCAL],
rel_blockheight(out, to_self_delay[LOCAL]),
commit_num,
wscript);
Expand Down Expand Up @@ -2129,7 +2130,7 @@ static void our_unilateral_to_us(struct tracked_output ***outs,
const struct bitcoin_outpoint *outpoint,
u32 tx_blockheight,
struct amount_sat amt,
u16 sequence,
u32 sequence,
const u8 *local_scriptpubkey,
const u8 *local_wscript)
{
Expand All @@ -2156,7 +2157,8 @@ static void our_unilateral_to_us(struct tracked_output ***outs,

msg = towire_onchaind_spend_to_us(NULL,
outpoint, amt,
rel_blockheight(out, to_self_delay[LOCAL]),
sequence,
rel_blockheight(out, sequence),
commit_num,
local_wscript);

Expand All @@ -2166,7 +2168,7 @@ static void our_unilateral_to_us(struct tracked_output ***outs,
* output is *resolved* by the spending transaction
*/
propose_resolution_to_master(out, take(msg),
rel_blockheight(out, to_self_delay[LOCAL]),
rel_blockheight(out, sequence),
OUR_DELAYED_RETURN_TO_WALLET);
}

Expand Down
1 change: 1 addition & 0 deletions onchaind/onchaind_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ msgdata,onchaind_notify_coin_mvt,mvt,chain_coin_mvt,
msgtype,onchaind_spend_to_us,5040
msgdata,onchaind_spend_to_us,outpoint,bitcoin_outpoint,
msgdata,onchaind_spend_to_us,outpoint_amount,amount_sat,
msgdata,onchaind_spend_to_us,sequence,u32,
msgdata,onchaind_spend_to_us,minblock,u32,
msgdata,onchaind_spend_to_us,commit_num,u64,
msgdata,onchaind_spend_to_us,wscript_len,u32,
Expand Down
2 changes: 1 addition & 1 deletion onchaind/test/run-grind_feerate.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ u8 *towire_onchaind_spend_htlc_timeout(const tal_t *ctx UNNEEDED, const struct b
u8 *towire_onchaind_spend_penalty(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, struct amount_sat outpoint_amount UNNEEDED, const struct secret *remote_per_commitment_secret UNNEEDED, const u8 *stack_elem UNNEEDED, const u8 *wscript UNNEEDED)
{ fprintf(stderr, "towire_onchaind_spend_penalty called!\n"); abort(); }
/* Generated stub for towire_onchaind_spend_to_us */
u8 *towire_onchaind_spend_to_us(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, struct amount_sat outpoint_amount UNNEEDED, u32 minblock UNNEEDED, u64 commit_num UNNEEDED, const u8 *wscript UNNEEDED)
u8 *towire_onchaind_spend_to_us(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, struct amount_sat outpoint_amount UNNEEDED, u32 sequence UNNEEDED, u32 minblock UNNEEDED, u64 commit_num UNNEEDED, const u8 *wscript UNNEEDED)
{ fprintf(stderr, "towire_onchaind_spend_to_us called!\n"); abort(); }
/* Generated stub for towire_onchaind_spent_reply */
u8 *towire_onchaind_spent_reply(const tal_t *ctx UNNEEDED, bool interested UNNEEDED)
Expand Down
17 changes: 14 additions & 3 deletions tests/test_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,12 @@ def test_channel_lease_unilat_closes(node_factory, bitcoind):
_, txid, blocks = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
assert blocks == 4

# Note that l3 has the whole lease delay (minus blocks already mined)
_, _, l3blocks = l3.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
assert l3blocks == 4032 - 6 - 2 - 1

bitcoind.generate_block(blocks)
l1.mine_txid_or_rbf(txid, numblocks=1)
l1.daemon.wait_for_log('Resolved OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by our proposal OUR_DELAYED_RETURN_TO_WALLET')
Expand Down Expand Up @@ -1006,9 +1012,14 @@ def test_channel_lease_unilat_closes(node_factory, bitcoind):

l2.rpc.withdraw(l2.rpc.newaddr()['bech32'], "all", utxos=[utxo1])

# l3 cleans up their to-self after their lease expires
l3.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
# We actually mined this many blocks already, so we should see this message:
l3.daemon.wait_for_log('waiting confirmation that we spent DELAYED_OUTPUT_TO_US .* using OUR_DELAYED_RETURN_TO_WALLET')
l3.daemon.wait_for_log('sendrawtx exit 0')

# Depending on timing, l3 might have already got this to bitcoind before
# the last block. But generate one just in case.
bitcoind.generate_block(1)
l3.daemon.wait_for_log('Resolved OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by our proposal OUR_DELAYED_RETURN_TO_WALLET')

# We were making a journal_entry for anchors, but now we ignore them
incomes = l2.rpc.bkpr_listincome()['income_events']
Expand Down