Browse Source

channeld: always receive and maintain short_channel_id of failing channel.

The master tells us the short_channel_id of the outgoing channel when
failing an HTLC, but channeld didn't store it anywhere.  It also
didn't tell channeld the short_channel_id in the case where we're
reconnecting and it's feeding us an array of failed htlcs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
1119dd5577
  1. 9
      channeld/channel.c
  2. 2
      channeld/channeld_htlc.h
  3. 7
      channeld/full_channel.c
  4. 9
      common/htlc_wire.c
  5. 2
      common/htlc_wire.h
  6. 10
      lightningd/peer_htlcs.c

9
channeld/channel.c

@ -1220,6 +1220,8 @@ static u8 *got_commitsig_msg(const tal_t *ctx,
(*f)->id = htlc->id; (*f)->id = htlc->id;
(*f)->failcode = htlc->failcode; (*f)->failcode = htlc->failcode;
(*f)->failreason = cast_const(u8 *, htlc->fail); (*f)->failreason = cast_const(u8 *, htlc->fail);
(*f)->scid = cast_const(struct short_channel_id *,
htlc->failed_scid);
} }
} else { } else {
struct changed_htlc *c = tal_arr_append(&changed); struct changed_htlc *c = tal_arr_append(&changed);
@ -1508,7 +1510,7 @@ static void handle_peer_fail_htlc(struct peer *peer, const u8 *msg)
&channel_id, &id, &reason)) { &channel_id, &id, &reason)) {
peer_failed(&peer->cs, peer_failed(&peer->cs,
&peer->channel_id, &peer->channel_id,
"Bad update_fulfill_htlc %s", tal_hex(msg, msg)); "Bad update_fail_htlc %s", tal_hex(msg, msg));
} }
e = channel_fail_htlc(peer->channel, LOCAL, id, &htlc); e = channel_fail_htlc(peer->channel, LOCAL, id, &htlc);
@ -2243,6 +2245,11 @@ static void handle_fail(struct peer *peer, const u8 *inmsg)
case CHANNEL_ERR_REMOVE_OK: case CHANNEL_ERR_REMOVE_OK:
h->failcode = failcode; h->failcode = failcode;
h->fail = tal_steal(h, errpkt); h->fail = tal_steal(h, errpkt);
if (failcode & UPDATE)
h->failed_scid
= tal_dup(h, struct short_channel_id, &scid);
else
h->failed_scid = NULL;
send_fail_or_fulfill(peer, h); send_fail_or_fulfill(peer, h);
start_commit_timer(peer); start_commit_timer(peer);
return; return;

2
channeld/channeld_htlc.h

@ -33,6 +33,8 @@ struct htlc {
/* For a local failure, we might have to generate fail ourselves /* For a local failure, we might have to generate fail ourselves
* (or, if BADONION we send a update_fail_malformed_htlc). */ * (or, if BADONION we send a update_fail_malformed_htlc). */
enum onion_type failcode; enum onion_type failcode;
/* If failcode & UPDATE, this is channel which failed. Otherwise NULL. */
const struct short_channel_id *failed_scid;
}; };
static inline bool htlc_has(const struct htlc *h, int flag) static inline bool htlc_has(const struct htlc *h, int flag)

7
channeld/full_channel.c

@ -322,6 +322,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
htlc->rhash = *payment_hash; htlc->rhash = *payment_hash;
htlc->fail = NULL; htlc->fail = NULL;
htlc->failcode = 0; htlc->failcode = 0;
htlc->failed_scid = NULL;
htlc->r = NULL; htlc->r = NULL;
htlc->routing = tal_dup_arr(htlc, u8, routing, TOTAL_PACKET_SIZE, 0); htlc->routing = tal_dup_arr(htlc, u8, routing, TOTAL_PACKET_SIZE, 0);
@ -1052,6 +1053,12 @@ bool channel_force_htlcs(struct channel *channel,
0); 0);
else else
htlc->fail = NULL; htlc->fail = NULL;
if (failed[i]->scid)
htlc->failed_scid = tal_dup(htlc,
struct short_channel_id,
failed[i]->scid);
else
htlc->failed_scid = NULL;
} }
for (i = 0; i < tal_count(htlcs); i++) { for (i = 0; i < tal_count(htlcs); i++) {

9
common/htlc_wire.c

@ -30,6 +30,10 @@ void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed)
assert(!failed->failcode || !tal_len(failed->failreason)); assert(!failed->failcode || !tal_len(failed->failreason));
towire_u64(pptr, failed->id); towire_u64(pptr, failed->id);
towire_u16(pptr, failed->failcode); towire_u16(pptr, failed->failcode);
if (failed->failcode & UPDATE)
towire_short_channel_id(pptr, failed->scid);
else
assert(!failed->scid);
towire_u16(pptr, tal_count(failed->failreason)); towire_u16(pptr, tal_count(failed->failreason));
towire_u8_array(pptr, failed->failreason, tal_count(failed->failreason)); towire_u8_array(pptr, failed->failreason, tal_count(failed->failreason));
} }
@ -88,6 +92,11 @@ struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, si
failed->id = fromwire_u64(cursor, max); failed->id = fromwire_u64(cursor, max);
failed->failcode = fromwire_u16(cursor, max); failed->failcode = fromwire_u16(cursor, max);
if (failed->failcode & UPDATE) {
failed->scid = tal(failed, struct short_channel_id);
fromwire_short_channel_id(cursor, max, failed->scid);
} else
failed->scid = NULL;
failreason_len = fromwire_u16(cursor, max); failreason_len = fromwire_u16(cursor, max);
if (failreason_len) if (failreason_len)
failed->failreason = tal_arr(failed, u8, failreason_len); failed->failreason = tal_arr(failed, u8, failreason_len);

2
common/htlc_wire.h

@ -29,6 +29,8 @@ struct failed_htlc {
/* Either this is 0 and failreason non-NULL, or vice versa. */ /* Either this is 0 and failreason non-NULL, or vice versa. */
enum onion_type failcode; enum onion_type failcode;
u8 *failreason; u8 *failreason;
/* Non-NULL if failcode & UPDATE */
struct short_channel_id *scid;
}; };
struct changed_htlc { struct changed_htlc {

10
lightningd/peer_htlcs.c

@ -1387,6 +1387,7 @@ static void add_fulfill(u64 id, enum side side,
static void add_fail(u64 id, enum side side, static void add_fail(u64 id, enum side side,
enum onion_type failcode, enum onion_type failcode,
const struct short_channel_id *failing_channel,
const u8 *failuremsg, const u8 *failuremsg,
const struct failed_htlc ***failed_htlcs, const struct failed_htlc ***failed_htlcs,
enum side **failed_sides) enum side **failed_sides)
@ -1400,6 +1401,13 @@ static void add_fail(u64 id, enum side side,
*f = tal(*failed_htlcs, struct failed_htlc); *f = tal(*failed_htlcs, struct failed_htlc);
(*f)->id = id; (*f)->id = id;
(*f)->failcode = failcode; (*f)->failcode = failcode;
if (failcode & UPDATE) {
assert(failing_channel);
(*f)->scid = tal_dup(*f, struct short_channel_id,
failing_channel);
} else
(*f)->scid = NULL;
if (failuremsg) if (failuremsg)
(*f)->failreason (*f)->failreason
= tal_dup_arr(*f, u8, failuremsg, tal_len(failuremsg), 0); = tal_dup_arr(*f, u8, failuremsg, tal_len(failuremsg), 0);
@ -1444,6 +1452,7 @@ void peer_htlcs(const tal_t *ctx,
if (hin->failuremsg || hin->failcode) if (hin->failuremsg || hin->failcode)
add_fail(hin->key.id, REMOTE, hin->failcode, add_fail(hin->key.id, REMOTE, hin->failcode,
&hin->failoutchannel,
hin->failuremsg, failed_htlcs, failed_sides); hin->failuremsg, failed_htlcs, failed_sides);
if (hin->preimage) if (hin->preimage)
add_fulfill(hin->key.id, REMOTE, hin->preimage, add_fulfill(hin->key.id, REMOTE, hin->preimage,
@ -1463,6 +1472,7 @@ void peer_htlcs(const tal_t *ctx,
if (hout->failuremsg || hout->failcode) if (hout->failuremsg || hout->failcode)
add_fail(hout->key.id, LOCAL, hout->failcode, add_fail(hout->key.id, LOCAL, hout->failcode,
hout->key.channel->scid,
hout->failuremsg, failed_htlcs, failed_sides); hout->failuremsg, failed_htlcs, failed_sides);
if (hout->preimage) if (hout->preimage)
add_fulfill(hout->key.id, LOCAL, hout->preimage, add_fulfill(hout->key.id, LOCAL, hout->preimage,

Loading…
Cancel
Save