mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
channeld: handle wrapping error messages messages.
Currently lightningd does this, but channeld is perfectly capable of doing it. channeld is also in a far better position to add channel_updates to it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
db372211c0
commit
ee8274b7a1
@ -1990,35 +1990,37 @@ static void handle_fail(struct peer *peer, const u8 *inmsg)
|
||||
u8 *msg;
|
||||
u64 id;
|
||||
u8 *errpkt;
|
||||
u16 malformed;
|
||||
u16 failcode;
|
||||
enum channel_remove_err e;
|
||||
struct htlc *h;
|
||||
|
||||
if (!fromwire_channel_fail_htlc(inmsg, inmsg, NULL, &id, &malformed,
|
||||
&errpkt))
|
||||
if (!fromwire_channel_fail_htlc(inmsg, inmsg, NULL, &id, &errpkt,
|
||||
&failcode))
|
||||
master_badmsg(WIRE_CHANNEL_FAIL_HTLC, inmsg);
|
||||
|
||||
if (malformed && !(malformed & BADONION))
|
||||
if ((failcode & BADONION) && tal_len(errpkt))
|
||||
status_failed(STATUS_FAIL_MASTER_IO,
|
||||
"Invalid channel_fail_htlc: bad malformed 0x%x",
|
||||
malformed);
|
||||
"Invalid channel_fail_htlc: %s with errpkt?",
|
||||
onion_type_name(failcode));
|
||||
|
||||
e = channel_fail_htlc(peer->channel, REMOTE, id, &h);
|
||||
switch (e) {
|
||||
case CHANNEL_ERR_REMOVE_OK:
|
||||
if (malformed) {
|
||||
if (failcode & BADONION) {
|
||||
struct sha256 sha256_of_onion;
|
||||
status_trace("Failing %"PRIu64" with code %u",
|
||||
id, malformed);
|
||||
id, failcode);
|
||||
sha256(&sha256_of_onion, h->routing,
|
||||
tal_len(h->routing));
|
||||
msg = towire_update_fail_malformed_htlc(peer,
|
||||
&peer->channel_id,
|
||||
id, &sha256_of_onion,
|
||||
malformed);
|
||||
failcode);
|
||||
} else {
|
||||
u8 *reply = wrap_onionreply(inmsg, h->shared_secret,
|
||||
errpkt);
|
||||
msg = towire_update_fail_htlc(peer, &peer->channel_id,
|
||||
id, errpkt);
|
||||
id, reply);
|
||||
}
|
||||
msg_enqueue(&peer->peer_out, take(msg));
|
||||
start_commit_timer(peer);
|
||||
|
@ -92,11 +92,11 @@ channel_fulfill_htlc,,payment_preimage,struct preimage
|
||||
# Main daemon says HTLC failed
|
||||
channel_fail_htlc,1006
|
||||
channel_fail_htlc,,id,u64
|
||||
# If malformed is non-zero, it's a BADONION code
|
||||
channel_fail_htlc,,malformed,u16
|
||||
# Otherwise, error_pkt contains failreason.
|
||||
# If this is non-zero length, you need to wrap this and pass it on.
|
||||
channel_fail_htlc,,len,u16
|
||||
channel_fail_htlc,,error_pkt,len*u8
|
||||
# If it errcode is != 0, it's a local error, otherwise we're passing thru.
|
||||
channel_fail_htlc,,errcode,u16
|
||||
|
||||
# Ping/pong test.
|
||||
channel_ping,1011
|
||||
|
|
@ -99,18 +99,13 @@ static void fail_in_htlc(struct htlc_in *hin,
|
||||
subd_send_msg(hin->key.peer->owner,
|
||||
take(towire_channel_fail_htlc(hin,
|
||||
hin->key.id,
|
||||
hin->failcode,
|
||||
NULL)));
|
||||
NULL,
|
||||
hin->failcode)));
|
||||
} else {
|
||||
u8 *reply;
|
||||
|
||||
/* This obfuscates the message, whether local or forwarded. */
|
||||
reply = wrap_onionreply(hin, &hin->shared_secret,
|
||||
hin->failuremsg);
|
||||
subd_send_msg(hin->key.peer->owner,
|
||||
take(towire_channel_fail_htlc(hin, hin->key.id,
|
||||
0, reply)));
|
||||
tal_free(reply);
|
||||
hin->failuremsg,
|
||||
0)));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user