From 4547afba335e41509e63463c173a5ed74ed1239e Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 2 Apr 2018 15:48:39 +0200 Subject: [PATCH] onchaind: Move preimage transfer into onchaind startup We used to queue the preimages to be sent to onchaind only after receiving the onchaind_init_reply. Once we start replaying we might end up in a situation in which we queue the tx that onchaind should react to before providing it with the preimages. This commit just moves the preimages being sent, making it atomic with the init, and without changing the order. Signed-off-by: Christian Decker --- lightningd/onchain_control.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 293af7c8a..175c1dcdc 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -47,13 +47,10 @@ static void onchaind_tell_fulfill(struct channel *channel) } } -static void handle_onchain_init_reply(struct channel *channel, const u8 *msg) +static void handle_onchain_init_reply(struct channel *channel, const u8 *msg UNUSED) { /* FIXME: We may already be ONCHAIN state when we implement restart! */ channel_set_state(channel, FUNDING_SPEND_SEEN, ONCHAIN); - - /* Tell it about any preimages we know. */ - onchaind_tell_fulfill(channel); } static enum watch_result onchain_tx_watched(struct channel *channel, @@ -201,7 +198,7 @@ static void handle_onchain_htlc_timeout(struct channel *channel, const u8 *msg) onchain_failed_our_htlc(channel, &htlc, "timed out"); } -static void handle_irrevocably_resolved(struct channel *channel, const u8 *msg) +static void handle_irrevocably_resolved(struct channel *channel, const u8 *msg UNUSED) { /* FIXME: Implement check_htlcs to ensure no dangling hout->in ptrs! */ free_htlcs(channel->peer->ld, channel); @@ -429,6 +426,9 @@ enum watch_result funding_spent(struct channel *channel, subd_send_msg(channel->owner, take(msg)); } + /* Tell it about any preimages we know. */ + onchaind_tell_fulfill(channel); + watch_tx_and_outputs(channel, tx); /* We keep watching until peer finally deleted, for reorgs. */