diff --git a/channeld/channel.c b/channeld/channel.c index a635a8b1a..99ac871ae 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -1472,7 +1472,7 @@ static void handle_peer_fulfill_htlc(struct peer *peer, const u8 *msg) "Bad update_fulfill_htlc %s", tal_hex(msg, msg)); } - e = channel_fulfill_htlc(peer->channel, LOCAL, id, &preimage); + e = channel_fulfill_htlc(peer->channel, LOCAL, id, &preimage, NULL); switch (e) { case CHANNEL_ERR_REMOVE_OK: /* FIXME: We could send preimages to master immediately. */ @@ -1509,11 +1509,10 @@ static void handle_peer_fail_htlc(struct peer *peer, const u8 *msg) "Bad update_fulfill_htlc %s", tal_hex(msg, msg)); } - e = channel_fail_htlc(peer->channel, LOCAL, id, NULL); + e = channel_fail_htlc(peer->channel, LOCAL, id, &htlc); switch (e) { case CHANNEL_ERR_REMOVE_OK: /* Save reason for when we tell master. */ - htlc = channel_get_htlc(peer->channel, LOCAL, id); htlc->fail = tal_steal(htlc, reason); start_commit_timer(peer); return; @@ -2202,7 +2201,7 @@ static void handle_preimage(struct peer *peer, const u8 *inmsg) if (!fromwire_channel_fulfill_htlc(inmsg, &id, &preimage)) master_badmsg(WIRE_CHANNEL_FULFILL_HTLC, inmsg); - switch (channel_fulfill_htlc(peer->channel, REMOTE, id, &preimage)) { + switch (channel_fulfill_htlc(peer->channel, REMOTE, id, &preimage, NULL)) { case CHANNEL_ERR_REMOVE_OK: msg = towire_update_fulfill_htlc(NULL, &peer->channel_id, id, &preimage); diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 4443705cc..fe87c8941 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -493,9 +493,10 @@ struct htlc *channel_get_htlc(struct channel *channel, enum side sender, u64 id) } enum channel_remove_err channel_fulfill_htlc(struct channel *channel, - enum side owner, - u64 id, - const struct preimage *preimage) + enum side owner, + u64 id, + const struct preimage *preimage, + struct htlc **htlcp) { struct sha256 hash; struct htlc *htlc; @@ -556,6 +557,9 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel, dump_htlc(htlc, "FULFILL:"); + if (htlcp) + *htlcp = htlc; + return CHANNEL_ERR_REMOVE_OK; } diff --git a/channeld/full_channel.h b/channeld/full_channel.h index a899e82ac..b8ef156c8 100644 --- a/channeld/full_channel.h +++ b/channeld/full_channel.h @@ -129,6 +129,7 @@ enum channel_remove_err channel_fail_htlc(struct channel *channel, * @channel: The channel state * @owner: the side who offered the HTLC (opposite to that fulfilling it) * @id: unique HTLC id. + * @htlcp: optional pointer for resulting htlc: filled in if and only if CHANNEL_ERR_FULFILL_OK. * * If the htlc exists, is not already fulfilled, the preimage is correct and * HTLC committed at the recipient, this will add a pending change to @@ -138,7 +139,8 @@ enum channel_remove_err channel_fail_htlc(struct channel *channel, enum channel_remove_err channel_fulfill_htlc(struct channel *channel, enum side owner, u64 id, - const struct preimage *preimage); + const struct preimage *preimage, + struct htlc **htlcp); /** * approx_max_feerate: what's the max funder could raise fee rate to? diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index 8dab6a609..aa5e5e395 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -250,7 +250,7 @@ static void send_and_fulfill_htlc(struct channel *channel, assert(ret); ret = channel_sending_revoke_and_ack(channel); assert(!ret); - assert(channel_fulfill_htlc(channel, LOCAL, 1337, &r) + assert(channel_fulfill_htlc(channel, LOCAL, 1337, &r, NULL) == CHANNEL_ERR_REMOVE_OK); ret = channel_rcvd_commit(channel, &changed_htlcs); assert(ret); @@ -271,7 +271,7 @@ static void send_and_fulfill_htlc(struct channel *channel, assert(ret); ret = channel_rcvd_revoke_and_ack(channel, &changed_htlcs); assert(!ret); - assert(channel_fulfill_htlc(channel, REMOTE, 1337, &r) + assert(channel_fulfill_htlc(channel, REMOTE, 1337, &r, NULL) == CHANNEL_ERR_REMOVE_OK); ret = channel_sending_commit(channel, &changed_htlcs); assert(ret);