Skip to content
Open
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
9 changes: 9 additions & 0 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2275,6 +2275,9 @@ void peer_sending_commitsig(struct channel *channel, const u8 *msg)
/* Tell it we've got it, and to go ahead with commitment_signed. */
subd_send_msg(channel->owner,
take(towire_channeld_sending_commitsig_reply(msg)));

/* Maybe graceful wants to know? */
check_graceful_shutdown(ld);
}

static bool channel_added_their_htlc(struct channel *channel,
Expand Down Expand Up @@ -2542,6 +2545,9 @@ void peer_got_commitsig(struct channel *channel, const u8 *msg)
/* Tell it we've committed, and to go ahead with revoke. */
msg = towire_channeld_got_commitsig_reply(msg);
subd_send_msg(channel->owner, take(msg));

/* Maybe graceful wants to know? */
check_graceful_shutdown(ld);
}

/* Shuffle them over, forgetting the ancient one. */
Expand Down Expand Up @@ -2723,6 +2729,9 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
}
wallet_channel_save(ld->wallet, channel);

/* Maybe graceful wants to know? */
check_graceful_shutdown(ld);

if (penalty_tx == NULL)
return;

Expand Down
31 changes: 12 additions & 19 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4412,20 +4412,17 @@ def capture(message, **kwargs):

fut = executor.submit(run_graceful)

inotif = 0
# If graceful catches the commitment dance mid-flight, it notifies
# about each transient state (e.g. RCVD_ADD_REVOCATION) on the way,
# so match expected notifications as an ordered subsequence.
seen = [0]

# Wait until graceful has sent at least one HTLC expiry notification
wait_for(lambda: len(notifications) >= inotif + 1)
def wait_notif(expected):
wait_for(lambda: expected in notifications[seen[0]:])
seen[0] = notifications.index(expected, seen[0]) + 1

# Depending on on timing between the sendpay and `l2.rpc.graceful`, we may get
# RCVD_ADD_REVOCATION or we may be too late to get that.
if notifications[inotif] == f'Next HTLC RCVD_ADD_REVOCATION expires at block #118 (10 blocks from now) going to peer {l3.info["id"]} (connected)':
# If we get RCVD_ADD_REVOCATION, ignore it and move onto the next notification
inotif += 1
wait_for(lambda: len(notifications) >= inotif + 1)

wait_for(lambda: notifications[inotif] == f'Next HTLC SENT_ADD_ACK_REVOCATION expires at block #118 (10 blocks from now) going to peer {l3.info["id"]} (connected)')
inotif += 1
# Once the HTLC is fully committed, we get told.
wait_notif(f'Next HTLC SENT_ADD_ACK_REVOCATION expires at block #118 (10 blocks from now) going to peer {l3.info["id"]} (connected)')

# This will tell us about htlcs and the peers (peers unordered)
ret = l2.rpc.graceful(1)
Expand All @@ -4436,16 +4433,12 @@ def capture(message, **kwargs):

# Close incoming connection, so incoming HTLC gets stuck.
l1.rpc.disconnect(l2.info['id'], force=True)
wait_for(lambda: len(notifications) >= inotif + 1)
wait_for(lambda: notifications[inotif] == f'Next HTLC SENT_ADD_ACK_REVOCATION expires at block #118 (10 blocks from now) going to peer {l3.info["id"]} (connected)')
inotif += 1

# Release the hold so the *outgoing* HTLC resolves
# Release the hold so the *outgoing* HTLC resolves: the incoming HTLC
# can't (peer is disconnected), and becomes the next expiry to report.
open(os.path.join(l3.daemon.lightning_dir, TEST_NETWORK, "unhold"), "w").close()

wait_for(lambda: len(notifications) >= inotif + 1)
wait_for(lambda: notifications[inotif] == f'Next HTLC SENT_REMOVE_HTLC expires at block #124 (16 blocks from now) coming from peer {l1.info["id"]} (disconnected)')
inotif += 1
wait_notif(f'Next HTLC SENT_REMOVE_HTLC expires at block #124 (16 blocks from now) coming from peer {l1.info["id"]} (disconnected)')

ret = l2.rpc.graceful(1)
assert ret == {'pending_htlc_expiries': [124]}
Expand Down
Loading