Browse Source

lightningd/channel: pass owner, not sender to channel_fulfill_htlc / channel_fail_htlc

I got this wrong when using them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
2d635a381b
  1. 10
      lightningd/channel.c
  2. 8
      lightningd/channel.h
  3. 4
      lightningd/test/run-channel.c

10
lightningd/channel.c

@ -481,15 +481,14 @@ 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 sender,
enum side owner,
u64 id,
const struct preimage *preimage)
{
struct sha256 hash;
struct htlc *htlc;
/* Fulfill is done by !creator of HTLC */
htlc = channel_get_htlc(channel, !sender, id);
htlc = channel_get_htlc(channel, owner, id);
if (!htlc)
return CHANNEL_ERR_NO_SUCH_ID;
@ -541,12 +540,11 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
}
enum channel_remove_err channel_fail_htlc(struct channel *channel,
enum side sender, u64 id)
enum side owner, u64 id)
{
struct htlc *htlc;
/* Fail is done by !creator of HTLC */
htlc = channel_get_htlc(channel, !sender, id);
htlc = channel_get_htlc(channel, owner, id);
if (!htlc)
return CHANNEL_ERR_NO_SUCH_ID;

8
lightningd/channel.h

@ -261,19 +261,19 @@ enum channel_remove_err {
/**
* channel_fail_htlc: remove an HTLC, funds to the side which offered it.
* @channel: The channel state
* @sender: the side fulfilling the HTLC (opposite to side which sent it)
* @owner: the side who offered the HTLC (opposite to that failing it)
* @id: unique HTLC id.
*
* This will remove the htlc and credit the value of the HTLC (back)
* to its offerer.
*/
enum channel_remove_err channel_fail_htlc(struct channel *channel,
enum side sender, u64 id);
enum side owner, u64 id);
/**
* channel_fulfill_htlc: remove an HTLC, funds to side which accepted it.
* @channel: The channel state
* @sender: the side fulfilling the HTLC (opposite to side which sent it)
* @owner: the side who offered the HTLC (opposite to that fulfilling it)
* @id: unique HTLC id.
*
* If the htlc exists, is not already fulfilled, the preimage is correct and
@ -282,7 +282,7 @@ enum channel_remove_err channel_fail_htlc(struct channel *channel,
* and return CHANNEL_ERR_FULFILL_OK. Otherwise, it will return another error.
*/
enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
enum side sender,
enum side owner,
u64 id,
const struct preimage *preimage);

4
lightningd/test/run-channel.c

@ -255,7 +255,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, REMOTE, 1337, &r)
assert(channel_fulfill_htlc(channel, LOCAL, 1337, &r)
== CHANNEL_ERR_REMOVE_OK);
ret = channel_rcvd_commit(channel, NULL, NULL);
assert(ret);
@ -277,7 +277,7 @@ static void send_and_fulfill_htlc(struct channel *channel,
ret = channel_rcvd_revoke_and_ack(channel, NULL, do_nothing,
NULL);
assert(!ret);
assert(channel_fulfill_htlc(channel, LOCAL, 1337, &r)
assert(channel_fulfill_htlc(channel, REMOTE, 1337, &r)
== CHANNEL_ERR_REMOVE_OK);
ret = channel_sending_commit(channel);
assert(ret);

Loading…
Cancel
Save