Commit Graph

19791 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
069888b51a graph/db: convert ChanUpdatesInHorizon to use iterators
In this commit, we refactor the ChanUpdatesInHorizon method to return
an iterator instead of a slice. This change significantly reduces
memory usage when dealing with large result sets by allowing callers to
process items incrementally rather than loading everything into memory
at once.
2025-09-26 16:57:11 -07:00
Olaoluwa Osuntokun
1d6d54e5db graph/db: convert NodeUpdatesInHorizon to use iterators
In this commit, we refactor the NodeUpdatesInHorizon method to return
an iterator instead of a slice. This change significantly reduces
memory usage when dealing with large result sets by allowing callers to
process items incrementally rather than loading everything into memory
at once.

The new implementation uses Go 1.23's iter.Seq type to provide a
standard iterator interface. The method now supports configurable batch
sizes through functional options, allowing fine-tuned control over
memory usage and performance characteristics.

Rather than reading all the entries from disk into memory (before this
commit, we did consult the cache for most entries, skipping the disk
hits), we now expose a chunked iterator instead.

We also make the process of filtering out public nodes first class. This
saves many newly created db transactions later.
2025-09-26 16:56:41 -07:00
Olaoluwa Osuntokun
f8ce00b84a graph/db: add options infrastructure for iterator configuration
In this commit, we introduce a new options pattern for configuring
iterator behavior in the graph database. This includes configuration
for batch sizes when iterating over channel and node updates, as well
as an option to filter for public nodes only.

The new functional options pattern allows callers to customize iterator
behavior without breaking existing APIs. Default batch sizes are set to
1000 entries for both channel and node updates, which provides a good
balance between memory usage and performance.
2025-09-26 16:56:20 -07:00
Olaoluwa Osuntokun
015875e455 fn: add Collect+CollertErr function for iterators
In this commit, we introduce a new utility function `Collect` to the fn
package. This function drains all elements from an iterator and returns
them as a slice. This is particularly useful when transitioning from
iterator-based APIs to code that expects slices, allowing for gradual
migration to the new iterator patterns.

The fn module's go.mod is also updated to require Go 1.23, which is
necessary for the built-in iter.Seq type support.

The replace directive will be removed once the fn package changes are
merged and a new version is tagged.
2025-09-26 16:55:46 -07:00
Yong
b09b20c699 Merge pull request #10133 from GeorgeTsagk/rpc-find-base-alias
Add `XFindBaseLocalChanAlias` RPC
2025-09-25 21:06:41 +08:00
George Tsagkarelis
e7f7fe418b docs: add release note 2025-09-25 11:15:31 +02:00
George Tsagkarelis
f14190c02d lnrpc: add XFindBaseLocalChanAlias rpc
Add the new RPC method that looks up the base scid for a given alias.
Given the previous stepping stones this commit is fairly simple, we just
call into the alias manager and return the lookup result.
2025-09-25 11:15:31 +02:00
George Tsagkarelis
472a2f967e multi: add base lookup option to AddLocalAlias
We add an extra option to the AddLocalAlias method which only controls
whether we store a reverse lookup from the alias back to the base scid
it corresponds to. The previous flag "gossip" is still maintained, and
in a way supercedes the new flag (it will also store the base scid
lookup even if the base lookup flag isn't set). The only call that sets
this option is the XAddLocalChanAlias RPC endpoint, where we want to
make sure that a reverse lookup is stored in the alias manager in order
to later expose it via the new RPC method.
2025-09-25 11:15:27 +02:00
Yong
f293566849 Merge pull request #10235 from Abdulkbk/fix-externalip-retention-issue
lnd: fix externalip retention issue
2025-09-25 14:23:51 +08:00
Olaoluwa Osuntokun
df46d18626 Merge pull request #10182 from GeorgeTsagk/aux-feature-bits
Aux feature bits
2025-09-24 18:26:35 -07:00
Olaoluwa Osuntokun
8be5de6185 Merge pull request #10183 from Roasbeef/brontide-static-alloac
brontide: eliminate all allocations from WriteMessage+Flush
2025-09-24 15:49:05 -07:00
Abdullahi Yunus
ed2880ef17 lnd: update docs on nodeann addresses retaining 2025-09-24 21:08:04 +01:00
Olaoluwa Osuntokun
4c737d3f02 brontide+peer: use internal sync/pool to reduce allocations
This ensures that under medium to high load, we eliminate all
allocations once we arrive a steady state, re working memory.
2025-09-24 11:52:01 -07:00
Olaoluwa Osuntokun
f968206849 docs: add docs explaining usage of pprof+benchmarks to optimize
In this commit, we add some docs that explain how to use tools like
heap escape analysis and memory profiling to fully eliminate allocations
in a sample program.

This guide is meant to help devs/contributors use Go's excellent perf
tools to zoom in on an optimization problem.
2025-09-24 11:52:01 -07:00
Olaoluwa Osuntokun
83e2811903 brontide: use a static buffer for the packet length
In this commit, we eliminate the final allocation that takes place when
we write out messages. Once again this was escaping to the heap, so we
make it an attribute on the Machine struct, which allows pure static
allocation.

```
goos: darwin
goarch: arm64
pkg: github.com/lightningnetwork/lnd/brontide
cpu: Apple M4 Max
BenchmarkWriteMessage-16    	   25840	     46376 ns/op	       2 B/op	       0 allocs/op
BenchmarkWriteMessage-16    	   25646	     46672 ns/op	       2 B/op	       0 allocs/op
BenchmarkWriteMessage-16    	   25874	     46391 ns/op	       2 B/op	       0 allocs/op
BenchmarkWriteMessage-16    	   25512	     46427 ns/op	       2 B/op	       0 allocs/op
BenchmarkWriteMessage-16    	   25760	     46309 ns/op	       2 B/op	       0 allocs/op
BenchmarkWriteMessage-16    	   25789	     46520 ns/op	       2 B/op	       0 allocs/op
BenchmarkWriteMessage-16    	   25602	     46619 ns/op	       2 B/op	       0 allocs/op
BenchmarkWriteMessage-16    	   25766	     46464 ns/op	       2 B/op	       0 allocs/op
BenchmarkWriteMessage-16    	   25820	     46487 ns/op	       2 B/op	       0 allocs/op
BenchmarkWriteMessage-16    	   25634	     46553 ns/op	       2 B/op	       0 allocs/op
PASS
ok  	github.com/lightningnetwork/lnd/brontide	16.907s
```
2025-09-24 11:52:01 -07:00
Olaoluwa Osuntokun
1fe156f2f4 brontide: use a fixed size buffer for the nonce within the brontide machine
In this commit, we use a fixed sized buffer for the nonce when we
read/write messages. This was actually escaping to the heap. We can
avoid this by statically allocating it alongside the struct itself.

The benchmark state at this point:

```
goos: darwin
goarch: arm64
pkg: github.com/lightningnetwork/lnd/brontide
cpu: Apple M4 Max
BenchmarkWriteMessage-16    	   25264	     47012 ns/op	       4 B/op	       1 allocs/op
BenchmarkWriteMessage-16    	   23542	     46809 ns/op	       4 B/op	       1 allocs/op
BenchmarkWriteMessage-16    	   25989	     47256 ns/op	       4 B/op	       1 allocs/op
BenchmarkWriteMessage-16    	   25542	     46388 ns/op	       4 B/op	       1 allocs/op
BenchmarkWriteMessage-16    	   26083	     46612 ns/op	       4 B/op	       1 allocs/op
BenchmarkWriteMessage-16    	   25860	     46367 ns/op	       4 B/op	       1 allocs/op
BenchmarkWriteMessage-16    	   24967	     46748 ns/op	       4 B/op	       1 allocs/op
BenchmarkWriteMessage-16    	   26088	     46485 ns/op	       4 B/op	       1 allocs/op
BenchmarkWriteMessage-16    	   25561	     46425 ns/op	       4 B/op	       1 allocs/op
BenchmarkWriteMessage-16    	   25474	     47249 ns/op	       4 B/op	       1 allocs/op
PASS
ok  	github.com/lightningnetwork/lnd/brontide	16.911s
```

```
goos: darwin
goarch: arm64
pkg: github.com/lightningnetwork/lnd/brontide
cpu: Apple M4 Max
                │   old.txt   │              new2.txt              │
                │   sec/op    │   sec/op     vs base               │
WriteMessage-16   50.34µ ± 1%   46.68µ ± 1%  -7.28% (p=0.000 n=10)

                │    old.txt     │              new2.txt              │
                │      B/op      │    B/op     vs base                │
WriteMessage-16   73788.000 ± 0%   4.000 ± 0%  -99.99% (p=0.000 n=10)

                │  old.txt   │              new2.txt              │
                │ allocs/op  │ allocs/op   vs base                │
WriteMessage-16   5.000 ± 0%   1.000 ± 0%  -80.00% (p=0.000 n=10)
```
2025-09-24 11:52:01 -07:00
Olaoluwa Osuntokun
06826f85d8 brontide: add new maxMessageSize variable 2025-09-24 11:52:01 -07:00
Olaoluwa Osuntokun
6e0083a369 brontide: add benchark for WriteMessage
In this commit, we add a benchmark for the WriteMessage method. This is
the first step in an upcoming optimizooor series of commits.

The baseline is:
```
goos: darwin
goarch: arm64
pkg: github.com/lightningnetwork/lnd/brontide
cpu: Apple M4 Max
BenchmarkWriteMessage-16    	   22736	     50667 ns/op	   73788 B/op	       5 allocs/op
BenchmarkWriteMessage-16    	   23217	     50463 ns/op	   73788 B/op	       5 allocs/op
BenchmarkWriteMessage-16    	   24241	     49941 ns/op	   73788 B/op	       5 allocs/op
BenchmarkWriteMessage-16    	   23574	     51021 ns/op	   73788 B/op	       5 allocs/op
BenchmarkWriteMessage-16    	   23784	     49926 ns/op	   73788 B/op	       5 allocs/op
BenchmarkWriteMessage-16    	   24230	     50538 ns/op	   73788 B/op	       5 allocs/op
BenchmarkWriteMessage-16    	   24058	     49971 ns/op	   73788 B/op	       5 allocs/op
BenchmarkWriteMessage-16    	   23762	     50224 ns/op	   73788 B/op	       5 allocs/op
BenchmarkWriteMessage-16    	   24266	     53034 ns/op	   73788 B/op	       5 allocs/op
BenchmarkWriteMessage-16    	   23317	     50045 ns/op	   73788 B/op	       5 allocs/op
PASS
ok  	github.com/lightningnetwork/lnd/brontide	17.433s
```
2025-09-24 11:51:59 -07:00
Abdullahi Yunus
141cc571ab itest: check for config addrs precedence
In this commit, we update the itest to check for precedence of the
config addresses over the persisted addresses.

We did not check for address persistence after restart (without the
extraArgs `--externalip`) because in `lntest/node/config.goL300`,
`GenArg` by default sets the `--externalip` flag, which makes
the config addrs to always take precedence over the persisted
addrs, for the tests.
2025-09-24 10:51:19 +01:00
Abdullahi Yunus
cf287e9693 lnd: use persisted addrs if not set in config 2025-09-24 10:51:19 +01:00
Abdullahi Yunus
783c887824 lnd: stop using prev persisted addresses
In this commit we stop using persisted address in LND's prev run.
This means addresses set using `externalip` will be used without
merging them with the ones from prev run. We will introduce the
condition to use persisted addresses in the next commit.
2025-09-24 10:51:19 +01:00
George Tsagkarelis
2302debd6c docs: add release note 2025-09-23 19:05:47 +02:00
George Tsagkarelis
a58a52ee35 funding: notify aux negotiator on ChannelReady
We notify the aux channel negotiator that an established channel is now
ready to use.
2025-09-23 19:05:47 +02:00
George Tsagkarelis
be4134553f lnwallet: include peer pub key in aux chan state
In order to help external components to query the custom records of a
channel we need to expose the remote peer pub key. We could look-up
custom records based on the funding outpoint, but that relation is
established when receiving the ChannelReady message. The external
components may query the AuxChanState before that message is received,
so let's make sure the peer pub key is also available.
2025-09-23 19:05:47 +02:00
George Tsagkarelis
6dff1bd5de htlcswitch+peer: set and read aux custom records
This is the final step, we actually call the interface and either
provide or retrieve the custom features over the message. We also notify
the aux components when channel reestablish is received.
2025-09-23 19:05:46 +02:00
George Tsagkarelis
68bd35f7ad lnwire: update tests for init message 2025-09-23 19:05:46 +02:00
George Tsagkarelis
7724d0fa6d lnwire: add custom records to init
Before calling the new interface we first add the ability for the peer
message itself to encode the new data records.
2025-09-23 19:02:59 +02:00
George Tsagkarelis
56c56060aa lnd: add AuxChannelNegotiator to AuxComponents
We now plug-in the aux channel negotiator to the server impl config. We
also provide it to the peer config as that's where it's needed in order
to inject custom records in the appropriate peer messages.
2025-09-23 19:02:59 +02:00
George Tsagkarelis
44406db82a lnwallet: introduce AuxChannelNegotiator interface
We introduce this new interface with the purpose of injecting and
handling custom records on the init message, and also notifying
external components when receiving the ChannelReady or
ChannelReestablish message.
2025-09-23 19:02:57 +02:00
Yong
2d8c9d48a4 Merge pull request #10211 from yyforyongyu/remove-flap-count
chanfitness: track flap counts for peers with channels
2025-09-23 23:53:00 +08:00
Yong
82f77e542f Merge pull request #10200 from bitromortac/2509-lnd-issue-form
github: change to form-based issue template
2025-09-22 22:32:16 +08:00
Elle
055fb436e1 Merge pull request #9175 from ellemouton/g175UpdateMessageStructure
lnwire+netann: update structure of g175 messages to be pure TLV
2025-09-22 10:04:44 +02:00
bitromortac
f23b4d1ff1 github: change to form-based issue template
This commit introduces a more structured approach to issue generation,
where we can make certain info required.
2025-09-19 11:40:49 +02:00
yyforyongyu
7b6589366d docs: update release notes 2025-09-18 22:29:40 +08:00
yyforyongyu
2d59976e16 rpcserver+itest: skip err from FlapCount
We need to make sure the `ListPeers` to be robust against errors from
the `FlapCount` so this RPC won't fail due to no flap count info. Also
updated the itest to check this field.
2025-09-18 22:29:40 +08:00
yyforyongyu
e50ecac2f2 lnrpc: update docs for FlapCount and LastFlapNs 2025-09-18 22:24:45 +08:00
yyforyongyu
22fddd626b lntest+rpcserver: ignore chanfitness.ErrPeerNotFound in rpc
Similar to how we handle `chanfitness.ErrChannelNotFound`, we now also
ignore the `ErrPeerNotFound`. This is needed as previously we will
always see the peer in the channel event store given it'd added when
connected. This is no longer the case as we only add the peer to the map
when the channel is added.
2025-09-18 22:24:45 +08:00
yyforyongyu
6c56f33a70 lntest: fix error msg in ReceiveChannelEvent 2025-09-18 22:24:43 +08:00
yyforyongyu
455e4564eb chanfitness: send peer online event when we see the first channel
We rename `getPeerMonitor` to `getOrCreatePeerMonitor` for clarity - it
will now send an online event when the peer monitor is being created,
which means we will only start counting the peer as online when it has
opened a channel with us.
2025-09-18 22:18:28 +08:00
yyforyongyu
92de9424ce chanfitness: only process online events for peers with channels 2025-09-18 22:18:28 +08:00
Yong
b34fc964ba Merge pull request #10228 from ellemouton/fixNilAssignment
autopilot: fix nil map assignment
2025-09-18 14:59:12 +08:00
Elle Mouton
a5cf958c2c autopilot: fix nil map assignment
Use the `clear` call to reset a map on `reset` instead of assigning nil
to the entry.
2025-09-18 07:37:53 +02:00
Yong
1ee3b95f6d Merge pull request #10221 from ziggie1984/update-bbolt
Update bbolt
2025-09-17 19:45:39 +08:00
ziggie
1dda376404 mod: update etcd/bbolt lib to newest version
Version v1.4.3 has some important bugfixes. We bump both version
in the same go so we do not need to tag the kvdb package and the
latest version of will be used.
2025-09-16 23:08:27 +02:00
Yong
cbed86e21d Merge pull request #10189 from ziggie1984/fix-fee-estimation
bugfix error matching sweeper
2025-09-17 00:53:10 +08:00
ziggie
1f23c8b0eb docs: add release-notes 2025-09-16 14:25:42 +02:00
ziggie
9a83b3838f mulit: use min relay fee error 2025-09-16 14:25:42 +02:00
ziggie
5bcea78dc2 sweep: fix bug in mock interface 2025-09-16 14:25:42 +02:00
ziggie
d257198365 sweep: add missing output to the weight estimation
When overlay channels are used the extra output needs to be
considered.
2025-09-16 14:25:42 +02:00
ziggie
22ac4082a4 chainntfs: zero out pkscript in logging when taproot is enabled 2025-09-16 14:25:42 +02:00