gossipd: use per-peer information to make messages clearer.

We can (usually) indicate what peer caused the bad gossip error.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-10-08 11:44:24 +10:30 committed by neil saitug
parent 0091300ee3
commit 79ca9bf998
6 changed files with 22 additions and 18 deletions

View File

@ -382,8 +382,10 @@ static void update_local_channel(struct local_cupdate *lc /* frees! */)
* discard it (eg. non-public channel), but it should not complain
* about it being invalid! __func__ is a magic C constant which
* expands to this function name. */
msg = handle_channel_update(daemon->rstate, take(update), __func__,
NULL, NULL);
msg = handle_channel_update(daemon->rstate, take(update),
find_peer(daemon,
&chan->nodes[!direction]->id),
NULL);
if (msg)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"%s: rejected local channel update %s: %s",

View File

@ -323,8 +323,8 @@ static u8 *handle_channel_update_msg(struct peer *peer, const u8 *msg)
u8 *err;
unknown_scid.u64 = 0;
err = handle_channel_update(peer->daemon->rstate, msg, "subdaemon",
peer, &unknown_scid);
err = handle_channel_update(peer->daemon->rstate, msg, peer,
&unknown_scid);
if (err) {
if (unknown_scid.u64 != 0)
query_unknown_channel(peer->daemon, peer, &unknown_scid);

View File

@ -520,11 +520,13 @@ static void init_half_chan(struct routing_state *rstate,
c->tokens = TOKEN_MAX;
}
static void bad_gossip_order(const u8 *msg, const char *source,
static void bad_gossip_order(const u8 *msg,
const struct peer *peer,
const char *details)
{
status_debug("Bad gossip order from %s: %s before announcement %s",
source, wire_type_name(fromwire_peektype(msg)),
peer ? type_to_string(tmpctx, struct node_id, &peer->id)
: "unknown", wire_type_name(fromwire_peektype(msg)),
details);
}
@ -1859,12 +1861,14 @@ static void process_pending_channel_update(struct daemon *daemon,
if (!cupdate)
return;
/* FIXME: We don't remember who sent us updates, so can't error them */
err = handle_channel_update(rstate, cupdate, "pending update", peer,
NULL);
err = handle_channel_update(rstate, cupdate, peer, NULL);
if (err) {
status_debug("Pending channel_update for %s: %s",
/* FIXME: We could send this error back to peer if != NULL */
status_debug("Pending channel_update for %s from %s: %s",
type_to_string(tmpctx, struct short_channel_id, scid),
peer
? type_to_string(tmpctx, struct node_id, &peer->id)
: "unknown",
sanitize_error(tmpctx, err, NULL));
tal_free(err);
}
@ -2227,7 +2231,6 @@ void remove_channel_from_store(struct routing_state *rstate,
}
u8 *handle_channel_update(struct routing_state *rstate, const u8 *update TAKES,
const char *source,
struct peer *peer,
struct short_channel_id *unknown_scid)
{
@ -2300,7 +2303,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update TAKES,
if (unknown_scid)
*unknown_scid = short_channel_id;
bad_gossip_order(serialized,
source,
peer,
tal_fmt(tmpctx, "%s/%u",
type_to_string(tmpctx,
struct short_channel_id,
@ -2328,7 +2331,8 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update TAKES,
&short_channel_id),
channel_flags & 0x01,
channel_flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE",
source);
peer ? type_to_string(tmpctx, struct node_id, &peer->id)
: "unknown");
routing_add_channel_update(rstate, take(serialized), 0, peer);
return NULL;
@ -2420,7 +2424,7 @@ bool routing_add_node_announcement(struct routing_state *rstate,
pna = pending_node_map_get(rstate->pending_node_map,
&node_id);
if (!pna) {
bad_gossip_order(msg, "node_announcement",
bad_gossip_order(msg, peer,
type_to_string(tmpctx, struct node_id,
&node_id));
return false;
@ -2731,7 +2735,7 @@ void routing_failure(struct routing_state *rstate,
/* lightningd will only extract this if UPDATE is set. */
if (channel_update) {
u8 *err = handle_channel_update(rstate, channel_update, "error",
u8 *err = handle_channel_update(rstate, channel_update,
NULL, NULL);
if (err) {
status_unusual("routing_failure: "

View File

@ -386,7 +386,6 @@ struct chan *next_chan(const struct node *node, struct chan_map_iter *i);
* If the error is that the channel is unknown, fills in *unknown_scid
* (if not NULL). */
u8 *handle_channel_update(struct routing_state *rstate, const u8 *update TAKES,
const char *source,
struct peer *peer,
struct short_channel_id *unknown_scid);

View File

@ -49,7 +49,6 @@ struct timeabs gossip_time_now(const struct routing_state *rstate UNNEEDED)
{ fprintf(stderr, "gossip_time_now called!\n"); abort(); }
/* Generated stub for handle_channel_update */
u8 *handle_channel_update(struct routing_state *rstate UNNEEDED, const u8 *update TAKES UNNEEDED,
const char *source UNNEEDED,
struct peer *peer UNNEEDED,
struct short_channel_id *unknown_scid UNNEEDED)
{ fprintf(stderr, "handle_channel_update called!\n"); abort(); }

View File

@ -284,7 +284,7 @@ def test_pay_get_error_with_update(node_factory):
l1.daemon.wait_for_log(r'Extracted channel_update 0102.*from onionreply 10070088[0-9a-fA-F]{88}')
# And now monitor for l1 to apply the channel_update we just extracted
l1.daemon.wait_for_log(r'Received channel_update for channel {}/. now DISABLED \(from error\)'.format(chanid2))
l1.daemon.wait_for_log(r'Received channel_update for channel {}/. now DISABLED'.format(chanid2))
def test_pay_optional_args(node_factory):