Skip to content

Commit

Permalink
lightningd: use our cached channel_update for errors instead of askin…
Browse files Browse the repository at this point in the history
…g gossipd.

We also no longer strip the type off: everyone handles both forms, and
Eclair doesn't strip (and it's easier!).

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Feb 8, 2022
1 parent c346392 commit 5065bd6
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 229 deletions.
55 changes: 0 additions & 55 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,56 +1177,6 @@ static void dev_gossip_set_time(struct daemon *daemon, const u8 *msg)
}
#endif /* DEVELOPER */

/*~ lightningd: so, get me the latest update for this local channel,
* so I can include it in an error message. */
static void get_stripped_cupdate(struct daemon *daemon, const u8 *msg)
{
struct short_channel_id scid;
struct chan *chan;
const u8 *stripped_update;

if (!fromwire_gossipd_get_stripped_cupdate(msg, &scid))
master_badmsg(WIRE_GOSSIPD_GET_STRIPPED_CUPDATE, msg);

chan = get_channel(daemon->rstate, &scid);
if (!chan) {
status_debug("Failed to resolve local channel %s",
type_to_string(tmpctx, struct short_channel_id, &scid));
stripped_update = NULL;
} else {
int direction;
const struct half_chan *hc;

if (!local_direction(daemon->rstate, chan, &direction)) {
status_broken("%s is a non-local channel!",
type_to_string(tmpctx,
struct short_channel_id,
&scid));
stripped_update = NULL;
goto out;
}

/* Since we're going to use it, make sure it's up-to-date. */
local_channel_update_latest(daemon, chan);

hc = &chan->half[direction];
if (is_halfchan_defined(hc)) {
const u8 *update;

update = gossip_store_get(tmpctx, daemon->rstate->gs,
hc->bcast.index);
stripped_update = tal_dup_arr(tmpctx, u8, update + 2,
tal_count(update) - 2, 0);
} else
stripped_update = NULL;
}

out:
daemon_conn_send(daemon->master,
take(towire_gossipd_get_stripped_cupdate_reply(NULL,
stripped_update)));
}

/*~ We queue incoming channel_announcement pending confirmation from lightningd
* that it really is an unspent output. Here's its reply. */
static void handle_txout_reply(struct daemon *daemon, const u8 *msg)
Expand Down Expand Up @@ -1382,10 +1332,6 @@ static struct io_plan *recv_req(struct io_conn *conn,
gossip_init(daemon, msg);
goto done;

case WIRE_GOSSIPD_GET_STRIPPED_CUPDATE:
get_stripped_cupdate(daemon, msg);
goto done;

case WIRE_GOSSIPD_GET_TXOUT_REPLY:
handle_txout_reply(daemon, msg);
goto done;
Expand Down Expand Up @@ -1448,7 +1394,6 @@ static struct io_plan *recv_req(struct io_conn *conn,

/* We send these, we don't receive them */
case WIRE_GOSSIPD_INIT_REPLY:
case WIRE_GOSSIPD_GET_STRIPPED_CUPDATE_REPLY:
case WIRE_GOSSIPD_GET_TXOUT:
case WIRE_GOSSIPD_DEV_MEMLEAK_REPLY:
case WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY:
Expand Down
8 changes: 0 additions & 8 deletions gossipd/gossipd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ msgdata,gossipd_dev_set_time,dev_gossip_time,u32,
msgtype,gossipd_dev_set_max_scids_encode_size,3030
msgdata,gossipd_dev_set_max_scids_encode_size,max,u32,

# Given a short_channel_id, return the latest (stripped) update for error msg.
msgtype,gossipd_get_stripped_cupdate,3010
msgdata,gossipd_get_stripped_cupdate,channel_id,short_channel_id,

msgtype,gossipd_get_stripped_cupdate_reply,3110
msgdata,gossipd_get_stripped_cupdate_reply,stripped_update_len,u16,
msgdata,gossipd_get_stripped_cupdate_reply,stripped_update,u8,stripped_update_len

# gossipd->master: we're closing this channel.
msgtype,gossipd_local_channel_close,3027
msgdata,gossipd_local_channel_close,short_channel_id,short_channel_id,
Expand Down
6 changes: 0 additions & 6 deletions gossipd/test/run-onion_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ bool fromwire_gossipd_dev_suppress(const void *p UNNEEDED)
/* Generated stub for fromwire_gossipd_get_addrs */
bool fromwire_gossipd_get_addrs(const void *p UNNEEDED, struct node_id *id UNNEEDED)
{ fprintf(stderr, "fromwire_gossipd_get_addrs called!\n"); abort(); }
/* Generated stub for fromwire_gossipd_get_stripped_cupdate */
bool fromwire_gossipd_get_stripped_cupdate(const void *p UNNEEDED, struct short_channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_gossipd_get_stripped_cupdate called!\n"); abort(); }
/* Generated stub for fromwire_gossipd_get_txout_reply */
bool fromwire_gossipd_get_txout_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct amount_sat *satoshis UNNEEDED, u8 **outscript UNNEEDED)
{ fprintf(stderr, "fromwire_gossipd_get_txout_reply called!\n"); abort(); }
Expand Down Expand Up @@ -323,9 +320,6 @@ u8 *towire_gossipd_dev_memleak_reply(const tal_t *ctx UNNEEDED, bool leak UNNEED
/* Generated stub for towire_gossipd_get_addrs_reply */
u8 *towire_gossipd_get_addrs_reply(const tal_t *ctx UNNEEDED, const struct wireaddr *addrs UNNEEDED)
{ fprintf(stderr, "towire_gossipd_get_addrs_reply called!\n"); abort(); }
/* Generated stub for towire_gossipd_get_stripped_cupdate_reply */
u8 *towire_gossipd_get_stripped_cupdate_reply(const tal_t *ctx UNNEEDED, const u8 *stripped_update UNNEEDED)
{ fprintf(stderr, "towire_gossipd_get_stripped_cupdate_reply called!\n"); abort(); }
/* Generated stub for towire_gossipd_get_txout */
u8 *towire_gossipd_get_txout(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED)
{ fprintf(stderr, "towire_gossipd_get_txout called!\n"); abort(); }
Expand Down
2 changes: 0 additions & 2 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
switch (t) {
/* These are messages we send, not them. */
case WIRE_GOSSIPD_INIT:
case WIRE_GOSSIPD_GET_STRIPPED_CUPDATE:
case WIRE_GOSSIPD_GET_TXOUT_REPLY:
case WIRE_GOSSIPD_OUTPOINT_SPENT:
case WIRE_GOSSIPD_NEW_LEASE_RATES:
Expand All @@ -172,7 +171,6 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIPD_INIT_REPLY:
case WIRE_GOSSIPD_DEV_MEMLEAK_REPLY:
case WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY:
case WIRE_GOSSIPD_GET_STRIPPED_CUPDATE_REPLY:
case WIRE_GOSSIPD_ADDGOSSIP_REPLY:
case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY:
case WIRE_GOSSIPD_GET_ADDRS_REPLY:
Expand Down
7 changes: 2 additions & 5 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ static void shutdown_subdaemons(struct lightningd *ld)
/*~ The three "global" daemons, which we shutdown explicitly: we
* give them 10 seconds to exit gracefully before killing them. */
ld->connectd = subd_shutdown(ld->connectd, 10);
ld->gossip = subd_shutdown(ld->gossip, 10);
ld->hsm = subd_shutdown(ld->hsm, 10);

/* Now we free all the HTLCs */
free_htlcs(ld, NULL);
Expand Down Expand Up @@ -558,11 +560,6 @@ static void shutdown_subdaemons(struct lightningd *ld)
tal_free(p);
}

/*~ Now they're all dead, we can stop gossipd: doing it before HTLCs is
* problematic because local_fail_in_htlc_needs_update() asks gossipd */
ld->gossip = subd_shutdown(ld->gossip, 10);
ld->hsm = subd_shutdown(ld->hsm, 10);

/*~ Commit the transaction. Note that the db is actually
* single-threaded, so commits never fail and we don't need
* spin-and-retry logic everywhere. */
Expand Down
12 changes: 4 additions & 8 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ void payment_store(struct lightningd *ld, struct wallet_payment *payment TAKES)
}

void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
const char *localfail, const u8 *failmsg_needs_update)
const char *localfail)
{
struct wallet_payment *payment;
struct routing_failure* fail = NULL;
Expand Down Expand Up @@ -566,10 +566,7 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
if (localfail) {
/* Use temporary_channel_failure if failmsg has it */
enum onion_wire failcode;
if (failmsg_needs_update)
failcode = fromwire_peektype(failmsg_needs_update);
else
failcode = fromwire_peektype(hout->failmsg);
failcode = fromwire_peektype(hout->failmsg);

fail = local_routing_failure(tmpctx, ld, hout, failcode,
payment);
Expand Down Expand Up @@ -780,14 +777,13 @@ static const u8 *send_onion(const tal_t *ctx, struct lightningd *ld,
{
const u8 *onion;
unsigned int base_expiry;
bool dont_care_about_channel_update;

base_expiry = get_block_height(ld->topology) + 1;
onion = serialize_onionpacket(tmpctx, packet);
return send_htlc_out(ctx, channel, first_hop->amount,
base_expiry + first_hop->delay,
final_amount, payment_hash,
blinding, partid, groupid, onion, NULL, hout,
&dont_care_about_channel_update);
blinding, partid, groupid, onion, NULL, hout);
}

static struct command_result *check_offer_usage(struct command *cmd,
Expand Down
5 changes: 2 additions & 3 deletions lightningd/pay.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ struct routing_failure;
void payment_succeeded(struct lightningd *ld, struct htlc_out *hout,
const struct preimage *rval);

/* failmsg_needs_update is if we actually wanted to temporary_channel_failure
* but we haven't got the update msg yet */
/* hout->failmsg or hout->failonion must be set. */
void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
const char *localfail, const u8 *failmsg_needs_update);
const char *localfail);

/* Inform payment system to save the payment. */
void payment_store(struct lightningd *ld, struct wallet_payment *payment);
Expand Down
Loading

0 comments on commit 5065bd6

Please sign in to comment.