Commit Graph

1139 Commits

Author SHA1 Message Date
Rusty Russell
a9f76c7541 gossipd: be stricter with non-gossip_query nodes.
We now *never* consider asking them anything, even if they are
capable (e.g. enabling full gossip stream).  This aligns with
the latest spec proposal, where lack of `gossip_queries` means
"we don't have anything useful to say".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-31 12:32:05 +02:00
Rusty Russell
9450d46db1 bitcoin/short_channel_id: pass by copy everywhere.
It's a u64, we should pass by copy.  This is a big sweeping change,
but mainly mechanical (change one, compile, fix breakage, repeat).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
e0e879c003 common: remove type_to_string files altogther.
This means including <common/utils.h> where it was indirectly included.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
37d22f9141 global: change all type_to_string to fmt_X.
This has the benefit of being shorter, as well as more reliable (you
will get a link error if we can't print it, not a runtime one!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
d8c06dccac global: expose all fmt_X functions for direct use, make uniform.
We have various functions to convert to a string, rename them all so we can
count on fmt_X being the formatter for struct X, and make them all return
`char *`.

Sometimes they existed but were private, sometimes they had a
different name.  Most take a pointer, but simple types pass by copy:
short_channel_id, amount_msat and amount_sat.

The following public functions changed:
1. psbt_to_b64 -> fmt_wally_psbt.
2. pubkey_to_hexstr -> fmt_pubkey.
3. short_channel_id_to_str -> fmt_short_channel_id (scid by copy now!)
4. fmt_signature -> fmt_secp256k1_ecdsa_signature
5. fmt_amount_sat/fmt_amount_msat pass copy not pointer, return non-const char *.
6. node_id_to_hexstr -> fmt_node_id

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
be546fc60e Makefiles: remove leftover references to $(EXP)
This was also removed a while ago, it's never set.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
ac40fdf414 Makefiles: remove dependency on wire/onion_wiregen.o where unnecessary.
Also, WIRE_ONION_OBJS hasn't existed for a while.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
1018b5449b gossipd: handle case where block closes multiple channels requiring node_announcement moves more than once.
If we delete it the first time a channel before it is closed, we will
crash when we try to move it again:

```
$ lightning_gossipd: gossip_store: get delete entry offset 47411992/51608943 (version v23.11-378-gac2a386-modded)
0x1002544b send_backtrace
        common/daemon.c:33
0x1003415f status_failed
        common/status.c:221
0x10016ef3 gossip_store_get_with_hdr
        gossipd/gossip_store.c:466
0x10016faf check_msg_type
        gossipd/gossip_store.c:491
0x1001722b gossip_store_set_flag
        gossipd/gossip_store.c:509
0x1001752b gossip_store_del
        gossipd/gossip_store.c:561
0x10017f5b remove_channel
        gossipd/gossmap_manage.c:299
0x100181cf kill_spent_channel
        gossipd/gossmap_manage.c:1144
0x1001a7df gossmap_manage_new_block
        gossipd/gossmap_manage.c:1183
0x10014673 new_blockheight
        gossipd/gossipd.c:483
0x10014d73 recv_req
        gossipd/gossipd.c:594
```

Reported-by: @microsatosi on Discord
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-16 16:02:46 +01:00
Rusty Russell
8d7a99b589 gossipd: don't try to delete node_announcement twice if it's the same node.
Theoretical problem, but still...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-16 16:02:46 +01:00
Rusty Russell
df44431f8c common: add tal_arr_eq helper.
We do `memeq(a, tal_bytelen(a), b, tal_bytelen(b))` remarkably often...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-16 15:02:38 +01:00
Rusty Russell
1350194698 gossipd: don't assert on redundant flag write, just log message.
This happens to Vincenzo, and I think it's due to previous gossip_store issues.

Fixes: https://github.com/ElementsProject/lightning/issues/7051
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-12 18:05:06 +01:00
Rusty Russell
a0ed61199a gossipd: make sure to mark node_announcement dying if we fast-path remove last channel.
Normally, channels are marked dying, the 12 blocks later, removed.
But for local channels, we can access any spliced channel already, so
we remove them immediately from our local gossip.  This left a hole in
our logic, if that channel was the last one keeping a
node_announcement alive.

Solution is to unify with the "moved node_announcement" path.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-12 11:43:33 +01:00
Rusty Russell
f57d1f460e gossipd: don't consider dying channels when seeking preceeding channel_announcements.
We make sure a node_announcement is preceeded by at least one channel_announcement,
but dying ones don't count (as they are not broadcast!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-12 11:43:33 +01:00
Rusty Russell
e86093a944 gossipd: set dying flag on node_announcements when initially created.
We accept node_announcements on dying channels, but make sure we
set the dying flag it channels are alll dying.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-12 11:43:33 +01:00
Rusty Russell
b3439a18fe gossipd: preserve the dying flag when moving node_announcement.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-12 11:43:33 +01:00
Rusty Russell
365bf2d84d gossipd: when applying a new channel_update, preserve the dying flag.
We can update dying channels, though it seems weird!  We accept gossip about them,
we just don't propagate it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-12 11:43:33 +01:00
Rusty Russell
aab283ca7e gossipd: make sure to unmark dying node_announcement if we see a new channel!
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-12 11:43:33 +01:00
Rusty Russell
450d78ad67 gossipd: set dying flag on node_announcement when all channels are dying.
This avoids us gossiping about nodes which don't have live channels.

Interstingly, we previously tested that we *did* gossip such node
announcements, and now we fix that test.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-12 11:43:33 +01:00
Rusty Russell
ca5b7b00b6 gossipd: clean up flags accessors.
We want to be able to clear them, and fetch them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-12 11:43:33 +01:00
Rusty Russell
6a02cfccd7 gossipd: simplify gossip store API.
Instead of "new" and "load", we don't really need to "load" anything,
so do everything in gossip_store_new.

Have it do the compaction/rewrite, and collect the dying records
2024-02-04 09:24:44 +10:30
Rusty Russell
c49fb2edd5 gossipd: clean up gossip_store offsets.
gossmap offsets are to the beginning of the message, whereas
the gossip_store uses the header offset.  Convert the internals
of gossip_store to use gossmap-style uniformly, even where it's
a little less convenient.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
7efa0a46a9 gossipd: clean up gossip_store routines.
We don't use the dying flag, and we can manually append the
addendum rather than having gossip_store_add present a
bizarre interface.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
f7b7cf3719 gossipd: remove routing.c and other unused functions.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
c286241ab3 gossipd: switch over to using gossmap_manage, not routing.c.
The gossip_store_load is now basically a noop, since gossmap
does that.

gossipd removes a pile of routines dealing with messages,
in favor of just handing them to gossmap_manage.

The stub gossmap_manage constructor is removed entirely.

We simplified behaviour around channel_announcements with
no channel update: we now add them to the store, and go
back to fix the timestamp later.  This changes a test,
which explicitly tests for the old behaviour.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
137b80d53e gossipd: make the query response code use gossmap_manage.
This is a bit less optimal than before, where we had an ordered map of
channels and could easily serve "channels between scids 800000x and
900000x".  We now iterate all of them.

The rest is fairly mechanical.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
70811f7ed1 gossipd: make the seeker code use gossmap_manage.
We add a temporary stub gossmap_manage constructor, which simply opens
the gossmap and doesn't do anything else.

Then seeker uses this, rather than routing.c, to probe.

We optimize our "get random node announcements" a bit by traversing a
random set of nodes directly, and seeing if we have no
node_announcement, then querying their first channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
8f768634df gossipd: re-implement flood protection.
If we've got more than 10000 pending channel_announcements,
complain and stop processing any more.

If this becomes a problem, we can limit individual peers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
8f7f76f8c6 gossipd: don't validate UTXOs on our own channels.
It's an unnecessary round-trip, and can cause us to complain in CI, in
the case where the channel has been closed by the time we ask.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
f7ff3613c6 gossipd: interface to have gossmap_manage send updates on init.
At initialization, gossipd is supposed to send all the local
channel_updates and any node_announcement it knows, so lightningd
doesn't generate fresh ones unnecessarily.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
2ae3d25461 gossipd: implement pruning timer inside gossmap_manage.
No external interfaces, we start the timer on allocation.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
2964e35699 gossipd: gossmap_manage helper to get a node's address, if any.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
1384d56db3 gossmap_manage: new file for managing the gossip store.
This is a fair amount of code, but much is taken from
the old routing.c, with the difference that this uses
common/gossmap instead of our own structures.

The interfaces are fairly clear:

1. gossmap_manage_new - allocator
2. gossmap_manage_channel_announcement
   - handle new channel announcement msg
   - if too early, keeps it in early map
   - queues it, asks lightingd about UTXO.
3. gossmap_manage_handle_get_txout_reply
   - handle response from lightningd for above.
4. gossmap_manage_channel_update
   - handle channel_update message
   - may have to wait on pending channel_announcement
5. gossmap_manage_node_announcement
   - handle node_announcement msg
   - may have to wait on pending channel_announcement
6. gossmap_manage_new_block
   - see if early announces can now be processed.
7. gossmap_manage_channel_spent
   - lightningd tells us UTXO is spent
   - may prepare channel for closing in 12 blocks.
8. gossmap_manage_channel_dying
   - gossip_store load tells us channel was spent earlier.
   - like gossmap_manage_channel_spent, but maybe < 12.
9. gossmap_manage_get_gossmap
   - gossmap accessor: seeker and queries will need this.
10. gossmap_manage_new_peer
   - a new peer has connected, give them all our gossip.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
104d6a9c78 gossip_store: remove infratructure and bits for marking ratelimited entries.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
07cd4a809b gossipd: remove spam handling.
We weakened this progressively over time, and gossip v1.5 makes spam
impossible by protocol, so we can wait until then.

Removing this code simplifies things a great deal!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: Protocol: we no longer ratelimit gossip messages by channel, making our code far simpler.
2024-02-04 09:24:44 +10:30
Rusty Russell
e7ceffd565 gossipd: remove zombie handling.
We never enabled it, because we seemed to be eliminating valid
channels.  We discard zombie-marked records on loading.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
af64d30407 gossipd: move gossip_store pointer from struct routing_state to daemon.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
66574882a3 gossipd: simplify seeker startup.
Most nodes don't really care about exact timestamps on gossip filters,
so just keep a flag on whether we have anything in the gossip_store,
and use that to determine whether we ask peers for everything.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
ddc6783cf0 gossipd: move timestamp_reasonable out of routing.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
0388343602 gossipd: move dev flags from routing struct to daemon struct.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
0498695f1f gossipd: have seeker quert interfaces take an id, not a struct peer.
Again, we don't necessarily have a peer pointer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
275d59ead4 gossipd: pass node_id to queue_peer_msg, not peer.
This is easier for future callers, which don't have a convenient peer
structure: in particular, asynchronous processing of gossip for peers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
8cfbc1e7ad gossipd: make gossip_store hold daemon ptr, not rstate.
Makes it easier to wean off routing.c.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
7f5fe52320 gossipd: remove online gossip_store compaction.
It was an obscure dev command, as it never worked reliably.
It would be much easier to re-implement once this is done.

This turned out to reveal a tiny leak on
tests/test_gossip.py::test_gossip_store_load_amount_truncated where we
didn't immedately free chan_ann if it was dangling.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
561859da0c gossipd: move tell_lightningd_peer_update from routing.c into gossipd.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
2d09af8d56 gossipd: take signature checks out of routing.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
652432a298 gossipd: take txout failure cache out of routing.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
870c996628 gossipd: new routines to support gossmap compatibility.
gossip_store_del - takes a gossmap-style offset-of-msg not offset-of-hdr.
gossip_store_flag: set an arbitrary flag on a gossip_store hdr.
gossip_store_get_timestamp/gossip_store_set_timestamp: access gossip_store hdr.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-04 09:24:44 +10:30
Rusty Russell
6031efe145 gossipd: make seeker uintmap visible to memleak code.
```
gossipd: MEMLEAK: 0x55e22ac0f8e8
gossipd:   label=gossipd/seeker.c:621:u8
gossipd:   alloc:
gossipd:     ccan/ccan/tal/tal.c:477 (tal_alloc_)
gossipd:     gossipd/seeker.c:621 (check_timestamps)
gossipd:     gossipd/seeker.c:645 (process_scid_probe)
gossipd:     gossipd/queries.c:849 (handle_reply_channel_range)
gossipd:     gossipd/gossipd.c:436 (handle_recv_gossip)
gossipd:     gossipd/gossipd.c:509 (connectd_req)
gossipd:     common/daemon_conn.c:35 (handle_read)
gossipd:     ccan/ccan/io/io.c:59 (next_plan)
gossipd:     ccan/ccan/io/io.c:407 (do_plan)
gossipd:     ccan/ccan/io/io.c:417 (io_ready)
gossipd:     ccan/ccan/io/poll.c:453 (io_loop)
gossipd:     gossipd/gossipd.c:950 (main)
gossipd:   parents:
gossipd:     gossipd/seeker.c:132:struct seeker
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-01-31 14:47:33 +10:30
Rusty Russell
58d0cc12c4 gossipd: remove node_announcement generation.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-01-31 14:47:33 +10:30
Rusty Russell
b76d589a6e lightningd: move node_announcement unit test from gossipd/
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-01-31 14:47:33 +10:30