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:
Rusty Russell 2017-11-28 15:33:20 +10:30 committed by Christian Decker
parent db372211c0
commit ee8274b7a1
3 changed files with 19 additions and 22 deletions

View File

@ -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);

View File

@ -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

1 # Received and sent funding_locked
92 # Ping/pong test.
93 channel_ping,1011
94 channel_ping,,num_pong_bytes,u16
95 channel_ping,,len,u16
channel_ping_reply,1111
channel_ping_reply,,totlen,u16
96 # Channeld tells the master to announce the channel (with first update) channel_ping_reply,1111
97 channel_announce,1012 channel_ping_reply,,totlen,u16
98 # Channeld tells the master to announce the channel (with first update)
99 channel_announce,1012
100 channel_announce,,announce_len,u16
101 channel_announce,,announce,announce_len*u8
102 channel_announce,,update_len,u16

View File

@ -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)));
}
}