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>
This commit is contained in:
Rusty Russell 2017-04-01 21:31:11 +10:30
parent 85fd8218e2
commit 2d635a381b
3 changed files with 10 additions and 12 deletions

View File

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

View File

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

View File

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