mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-02 20:54:23 +01:00
channeld: make channel_fulfill_htlc return the HTLC it fulfulled.
This is the same pattern as channel_fail_htlc, and in fact one caller wanted it already. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
e92f244b80
commit
8155bfcf18
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user