Commit Graph

554 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
7e767eac82 discovery: only permit a single gossip backlog goroutine per peer
In this commit, we add a new atomic bool to only permit a single gossip
backlog goroutine per peer. If we get a new reuqest that needs a backlog
while we're still processing the other, then we'll drop that request.
2025-08-01 11:20:22 -05:00
Olaoluwa Osuntokun
5fcd33c50c discovery: add tests for for async timestamp range queue 2025-08-01 11:20:22 -05:00
Olaoluwa Osuntokun
f3ba372441 discovery: integrate async queue in ProcessRemoteAnnouncement
In this commit, we complete the integration of the asynchronous
timestamp range queue by modifying ProcessRemoteAnnouncement to use
the new queuing mechanism instead of calling ApplyGossipFilter
synchronously.

This change ensures that when a peer sends a GossipTimestampRange
message, it is queued for asynchronous processing rather than
blocking the gossiper's main message processing loop. The modification
prevents the peer's readHandler from blocking on potentially slow
gossip filter operations, maintaining connection stability during
periods of high synchronization activity.

If the queue is full when attempting to enqueue a message, we log
a warning but return success to prevent peer disconnection. This
design choice prioritizes connection stability over guaranteed
delivery of every gossip filter request, which is acceptable since
peers can always resend timestamp range messages if needed.
2025-08-01 11:20:21 -05:00
Olaoluwa Osuntokun
7fb289f24f discovery: add async timestamp range queue to prevent blocking
In this commit, we introduce an asynchronous processing queue for
GossipTimestampRange messages in the GossipSyncer. This change addresses
a critical issue where the gossiper could block indefinitely when
processing timestamp range messages during periods of high load.

Previously, when a peer sent a GossipTimestampRange message, the
gossiper would synchronously call ApplyGossipFilter, which could block
on semaphore acquisition, database queries, and rate limiting. This
synchronous processing created a bottleneck where the entire peer
message processing pipeline would stall, potentially causing timeouts
and disconnections.

The new design adds a timestampRangeQueue channel with a capacity of 1
message and a dedicated goroutine for processing these messages
asynchronously. This follows the established pattern used for other
message types in the syncer. When the queue is full, we drop messages
and log a warning rather than blocking indefinitely, providing graceful
degradation under extreme load conditions.
2025-08-01 11:20:21 -05:00
Olaoluwa Osuntokun
694cc15a73 discovery: make gossip filter semaphore capacity configurable
In this commit, we make the gossip filter semaphore capacity configurable
through a new FilterConcurrency field. This change allows node operators
to tune the number of concurrent gossip filter applications based on
their node's resources and network position.

The previous hard-coded limit of 5 concurrent filter applications could
become a bottleneck when multiple peers attempt to synchronize
simultaneously. By making this value configurable via the new
gossip.filter-concurrency option, operators can increase this limit
for better performance on well-resourced nodes or maintain conservative
values on resource-constrained systems.

We keep the default value at 5 to maintain backward compatibility and
avoid unexpected resource usage increases for existing deployments. The
sample configuration file is updated to document this new option.
2025-08-01 11:20:19 -05:00
yyforyongyu
cadf870dcb discovery: increase default msg rates to 1MB 2025-07-25 17:40:59 +08:00
Elle Mouton
c32bf642d2 multi: pass reset to ForEachNodeCached 2025-07-15 11:23:27 +02:00
Elle Mouton
e5fbca8299 multi: let ForEachNodeChannel take a reset param 2025-07-15 11:23:27 +02:00
Elle Mouton
793c1057bb graph: remove one context.TODO
By threading a context through to the Builder's ForAllOutgoingChannels
method.
2025-07-08 15:11:02 +02:00
Yong
ffd944e8b7 Merge pull request #10012 from ziggie1984/fix-goroutine-leak
multi: prevent goroutine leak in brontide
2025-07-03 20:11:31 +08:00
ziggie
dedb75aea4 discovery: add comments 2025-07-03 06:27:38 +02:00
Elle Mouton
2f2845dfc0 refactor+multi: use *lnwire.FeatureVector for ChannelEdgeInfo features
In this commit, we move the serialisation details of a channel's
features to the DB layer and change the `models` field to instead use a
more useful `*lnwire.FeatureVector` type.

This makes the features easier to work with and moves the serialisation
to where it is actually used.
2025-07-01 17:02:07 +02:00
Elle Mouton
37d6390642 discovery: use a no-op hash accumluator for local networks
If LND is running on a local network, then use deterministic sampling so
that we can have deterministic peer bootstrapping.
2025-07-01 11:27:18 +02:00
Elle Mouton
339dd0c1a7 discovery: introduce hashAccumulator interface
Create an abstract hashAccumulator interface for the Channel graph
bootstrapper so that we can later introduce a deterministic accumulator
to be used during testing.
2025-07-01 11:26:14 +02:00
Elle Mouton
25daf253c0 discovery: fix log line panic
If a method returns an error, we should assume all other parameters to
be nil unless the documentation explicitly says otherwise. So here, we
fix a log line where a dereference is made to an object that will be nil
due to an error being returned.
2025-06-30 18:27:56 +02:00
Elle Mouton
8cf567b948 multi: use the "errors" package everywhere
Replace all usages of the "github.com/go-errors/errors" and
"github.com/pkg/errors" packages with the standard lib's "errors"
package. This ensures that error wrapping and `errors.Is` checks will
work as expected.
2025-06-30 09:46:55 +02:00
Elle Mouton
e0801f5a5d discovery: use errors.Is for error check
Ensure that the check works for wrapped errors. Otherwise, this breaks
for a SQLStore graph backend which wraps the error it returns.
2025-06-26 10:11:02 +02:00
Elle Mouton
9597f01ce3 graph/db: thread context through to HighestChanID 2025-06-19 14:49:32 +02:00
Elle Mouton
81c063eb96 graph/db: thread context through to UpdateEdgePolicy 2025-06-19 14:49:31 +02:00
Elle Mouton
3fdb9b84f4 graph/db: thread context to AddChannelEdge 2025-06-19 14:47:41 +02:00
Elle Mouton
dc6259fcc3 graph/db: thread context through to HasLightningNode 2025-06-17 19:20:56 +02:00
Elle Mouton
66c5a97202 graph/db: thread context through to FetchLightingNode 2025-06-17 19:20:27 +02:00
Elle Mouton
d1cfb47428 graph/db: thread context to AddLightningNode 2025-06-17 19:20:27 +02:00
Elle Mouton
6d8bc63ad6 discovery+graph: get inbound fee directly from ChannelUpdate
Remove the previously added TODOs which would extract InboundFee info
from the ExtraOpaqueData of a ChannelUpdate at the time of
ChannelEdgePolicy construction. These can now be replaced by using the
newly added InboundFee record on the ChannelUpdate message.
2025-06-09 08:44:47 +02:00
Elle Mouton
9890d74622 multi: set the InboundFee on ChannelEdgePolicy
In this commit, we make sure to set the new field wherever appropriate.
This will be any place where the ChannelEdgePolicy is constructed other
than its disk deserialisation.
2025-06-09 08:31:10 +02:00
ziggie
732d3a77b4 discovery: increase syncer gossip chan buffer 2025-06-03 21:13:42 +02:00
ziggie
74c5541147 brontide: increase logging when processing gossip msgs
We add logging to we can draw conclusions how long the processing
of gossip message last and potentially see whether the syncer
buffer channel size is a bottleneck in processing.
2025-06-03 21:13:42 +02:00
Elle Mouton
c68a19c0ba discovery: revert passing ctx through to Start methods 2025-05-22 14:14:39 +02:00
Elle Mouton
13fcb08794 autopilot: start threading contexts through
The `GraphSource` interface in the `autopilot` package is directly
implemented by the `graphdb.KVStore` and so we will eventually thread
contexts through to this interface. So in this commit, we start updating
the autopilot system to thread contexts through in preparation for
passing the context through to any calls made to the GraphSource.

Two context.TODOs are added here which will be addressed in follow up
commits.
2025-05-22 14:14:38 +02:00
Elle Mouton
3162837c32 discovery: listen on ctx in any select
For any method that takes a context that has a select that listens on
the systems quit channel, we should also listen on the ctx since we
should not need to worry about if this context is derived internally or
externally.
2025-05-22 14:14:37 +02:00
Elle Mouton
6d03df7b26 discovery: remove unnecessary context.Background() calls 2025-05-22 14:14:37 +02:00
Elle Mouton
291381ef86 discovery: pass context through to bootstrapper SampleNodeAddrs
Since the ChannelGraphBootstrapper implementation makes a call to the
graph DB.
2025-05-22 14:14:37 +02:00
Elle Mouton
f4b7cc4f4b discovery: pass context to ProcessRemoteAnnouncement
With this, we move a context.TODO() out of the gossiper and into the
brontide package - this will be removed in a future PR which focuses on
threading contexts through that code.
2025-05-22 14:14:37 +02:00
Elle Mouton
69e9ce9b24 discovery: thread contexts through sync manager
Here, we remove one context.TODO() by threading a context through to the
SyncManager.
2025-05-22 14:14:36 +02:00
Elle Mouton
2a5235a79f discovery: thread contexts to syncer
The `GossiperSyncer` makes various calls to the `ChannelGraphTimeSeries`
interface which threads through to the graph DB. So in preparation for
threading context through to all the methods on that interface, we
update the GossipSyncer accordingly by passing contexts through.

Two `context.TODO()`s are added in this commit. They will be removed in
the upcoming commits.
2025-05-22 14:14:36 +02:00
Elle Mouton
4a30d6243d discovery: pass context through to reliable sender
And remove a context.TODO() that was added in the previous commit.
2025-05-22 14:14:36 +02:00
Elle Mouton
7fd453f319 discovery: thread context through to gossiper
Pass the parent LND context to the gossiper, let it derive a child
context that gets cancelled on Stop. Pass the context through to any
methods that will eventually thread it through to any graph DB calls.

One `context.TODO()` is added here - this will be removed in the next
commit.

NOTE: for any internal methods that the context gets passed to, if those
methods already listen on the gossiper's `quit` channel, then then don't
need to also listen on the passed context's Done() channel because the
quit channel is closed at the same time that the context is cancelled.
2025-05-22 14:14:36 +02:00
Olaoluwa Osuntokun
30f3d7ce89 discovery: lower bandwidth rate limiting log to Debugf 2025-05-19 17:46:08 -07:00
Olaoluwa Osuntokun
c7ed5d65c6 multi: add new config options to tune gossip msg allocated bandwidth
We go with the defaults of if no values are set.
2025-03-24 19:21:45 -07:00
Olaoluwa Osuntokun
05702d48b2 discovery: switch to bytes based rate limiting for outbound msgs
In this commit, we revamp the old message based rate limiting. First, we
move to meter by bytes/s instead of messages/s. The old logic had an
error in that it limited groups of message replies, instead of each
message. With this new approach, we'll use the newly added
SerializedSize method to implement fine grained bandwidth metering.

We need to pick two values, the burst rate, and the msg bytes rate. The
burst rate is the max amt that can be sent in a given period of time. We
need to set this above 65 KB, or the max msg limit, otherwise no
messages can be sent. The bucket starts with this many tokens (bytes).
As those are depleted, the amount of tokens is refilled at the msg
bytes rate.

As conservative values, we've chosen 200 KB as the burst rate, and 100
KB/s as the limit.
2025-03-24 19:21:45 -07:00
Eugene Siegel
6eb746fbba server.go+accessman.go: introduce caches for access permissions
Here we introduce the access manager which has caches that will
determine the access control status of our peers. Peers that have
had their funding transaction confirm with us are protected. Peers
that only have pending-open channels with us are temporary access
and can have their access revoked. The rest of the peers are granted
restricted access.
2025-03-11 20:42:34 -04:00
yyforyongyu
37799b95b7 discovery: fix state transition in GossipSyncer
Previously, we would set the state of the syncer after sending the msg,
which has the following flow,

1. In state `queryNewChannels`, we send the msg `QueryShortChanIDs`.
2. Once the msg is sent, we change to state `waitingQueryChanReply`.

But there's no guarantee the remote won't reply back inbetween the two
step. When that happens, our syncer would still be in state
`queryNewChannels`, causing the following error,
```
[ERR] DISC gossiper.go:873: Process query msg from peer [Alice] got unexpected msg *lnwire.ReplyShortChanIDsEnd received in state queryNewChannels
```

To fix it, we now make sure the state is updated before sending the msg.
2025-03-10 16:58:16 +08:00
Elle Mouton
2e85e08556 discovery: grab channel mutex before any DB calls
In `handleChanUpdate`, make sure to grab the `channelMtx` lock before
making any DB calls so that the logic remains consistent.
2025-03-05 14:12:55 +02:00
Elle Mouton
5e35bd8328 discovery: demonstrate channel update rate limiting bug
This commit adds a test to demonstrate that if we receive two identical
updates (which can happen if we get the same update from two peers in
quick succession), then our rate limiting logic will be hit early as
both updates might be counted towards the rate limit. This will be fixed
in an upcoming commit.
2025-03-05 14:12:23 +02:00
Elle Mouton
e5db0d6314 graph+discovery: move funding tx validation to gossiper
This commit is a pure refactor. We move the transaction validation
(existence, spentness, correctness) from the `graph.Builder` to the
gossiper since this is where all protocol level checks should happen.
All tests involved are also updated/moved.
2025-02-12 15:48:08 +02:00
Elle Mouton
39bb23ea5e discovery: lock the channelMtx before making the funding script
As we move the funding transaction validation logic out of the builder
and into the gossiper, we want to ensure that the behaviour stays
consistent with what we have today. So we should aquire this lock before
performing any expensive checks such as building the funding tx or
valdating it.
2025-02-12 13:59:09 +02:00
Elle Mouton
7853e36488 graph+discovery: calculate funding tx script in gossiper
In preparation for an upcoming commit which will move all channel
funding tx validation to the gossiper, we first move the helper method
which helps build the expected funding transaction script based on the
fields in the channel announcement. We will still want this script later
on in the builder for updating the ChainView though, and so we pass this
field along with the ChannelEdgeInfo. With this change, we can remove
the TapscriptRoot field from the ChannelEdgeInfo since the only reason
it was there was so that the builder could reconstruct the full funding
script.
2025-02-12 13:15:54 +02:00
Elle Mouton
8a07bb0950 discovery: prepare tests for preparing the mock chain
Here, we add a new fundingTxOption modifier which will configure how we
set-up expected calls to the mock Chain once we have moved funding tx
logic to the gossiper. Note that in this commit, these modifiers don't
yet do anything.
2025-02-12 13:15:54 +02:00
Elle Mouton
22e391f055 discovery: add AssumeChannelValid config option
in preparation for later on when we need to know when to skip funding
transaction validation.
2025-02-12 13:15:54 +02:00
Elle Mouton
00f5fd9b7f graph: add IsZombieEdge method
This is in preparation for the commit where we move across all the
funding tx validation so that we can test that we are correctly updating
the zombie index.
2025-02-12 13:15:54 +02:00