Commit Graph

19640 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
9913d791ff brontide: pool attempt 2025-09-10 18:59:01 -07:00
Olaoluwa Osuntokun
3615a351ac brontide: revise 2025-09-10 18:22:52 -07:00
Olaoluwa Osuntokun
a58e329b2c brontide: address old TODO to reset the brontide state
In this commit, we address a suuuper old TODO to reset the brontide
state. We were allocating a read buf which we now set to nil, and we
free up the original brontide reference.
2025-09-03 13:05:18 -07:00
Olaoluwa Osuntokun
21c21b7bd5 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-08-30 15:51:05 +01:00
Olaoluwa Osuntokun
6ce19a26d5 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 Machien 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
```

With this, we now have eliminated 100% of the allocations!

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

                │    old.txt     │              final.txt              │
                │      B/op      │    B/op     vs base                 │
WriteMessage-16   73788.000 ± 0%   2.000 ± 0%  -100.00% (p=0.000 n=10)

                │  old.txt   │              final.txt              │
                │ allocs/op  │ allocs/op   vs base                 │
WriteMessage-16   5.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=10)
```
2025-08-30 15:51:05 +01:00
Olaoluwa Osuntokun
4ee62921d6 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-08-30 15:51:05 +01:00
Olaoluwa Osuntokun
81a1564477 brontide: create fixed size arrays for nextHeaderSend and nextBodySend
In this commit, we create fized sized arrays for `nextHeaderSend` and
`nextBodySend`. This enables us to reuse these buffers, as we can pass
them into Encrypt/Seal directly, which avoids allocations for each write
that we do.

After this patch, we see the benchmarks improve:
```
goos: darwin
goarch: arm64
pkg: github.com/lightningnetwork/lnd/brontide
cpu: Apple M4 Max
BenchmarkWriteMessage-16    	   25198	     46795 ns/op	      34 B/op	       3 allocs/op
BenchmarkWriteMessage-16    	   26331	     46186 ns/op	      34 B/op	       3 allocs/op
BenchmarkWriteMessage-16    	   25608	     46308 ns/op	      34 B/op	       3 allocs/op
BenchmarkWriteMessage-16    	   25849	     46302 ns/op	      34 B/op	       3 allocs/op
BenchmarkWriteMessage-16    	   26318	     46285 ns/op	      34 B/op	       3 allocs/op
BenchmarkWriteMessage-16    	   25622	     46147 ns/op	      34 B/op	       3 allocs/op
BenchmarkWriteMessage-16    	   26287	     46506 ns/op	      34 B/op	       3 allocs/op
BenchmarkWriteMessage-16    	   26155	     46827 ns/op	      34 B/op	       3 allocs/op
BenchmarkWriteMessage-16    	   25256	     46910 ns/op	      34 B/op	       3 allocs/op
BenchmarkWriteMessage-16    	   25318	     46876 ns/op	      34 B/op	       3 allocs/op
PASS
ok  	github.com/lightningnetwork/lnd/brontide	17.092s
```

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

                │    old.txt    │              new.txt               │
                │     B/op      │    B/op     vs base                │
WriteMessage-16   73788.00 ± 0%   34.00 ± 0%  -99.95% (p=0.000 n=10)

                │  old.txt   │              new.txt               │
                │ allocs/op  │ allocs/op   vs base                │
WriteMessage-16   5.000 ± 0%   3.000 ± 0%  -40.00% (p=0.000 n=10)
```
2025-08-30 15:51:05 +01:00
Olaoluwa Osuntokun
df98ce1c6e brontide: add new maxMessageSize variable 2025-08-30 15:51:05 +01:00
Olaoluwa Osuntokun
f538ee8be7 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-08-30 15:51:05 +01:00
Yong
0c2f045f5d Merge pull request #10102 from yyforyongyu/fix-UpdatesInHorizon
Catch bad gossip peer and fix `UpdatesInHorizon`
2025-08-20 22:35:31 +08:00
Yong
8f489d0f12 Merge pull request #10153 from ziggie1984/refactor-payments-code-05
Refactor Payment PR 5
2025-08-20 21:18:04 +08:00
ziggie
bf6131ba02 routing: Add comment to DeleteFailedAttempts func call 2025-08-20 09:08:19 +02:00
ziggie
039b5994f3 routing: add more comments to the ControlTower interface 2025-08-20 09:08:19 +02:00
ziggie
b16782caeb multi: move DBMPPayment to paymentsdb package 2025-08-20 09:08:19 +02:00
ziggie
9ac93e75ac paymentsdb: fix linter 2025-08-20 09:08:18 +02:00
ziggie
f87841d638 paymentsdb: declare helper functions and add comments 2025-08-20 09:07:53 +02:00
ziggie
82242f5342 multi: rename KVPaymentDB to KVStore
This matches the same naming as used in the graph package.
2025-08-20 09:07:53 +02:00
ziggie
6abd539a2d paymentsdb: add missing function comments 2025-08-20 09:07:53 +02:00
ziggie
8245e356e5 paymentsdb: move serialization methods to kv_store file 2025-08-20 09:07:53 +02:00
ziggie
7423bfece9 paymentsdb: rename assertPaymentstatus 2025-08-20 09:07:53 +02:00
ziggie
a1fc8a3eee paymentsdb: rename db agnostic tests to highlight their behaviour 2025-08-20 09:07:52 +02:00
ziggie
68a8cf199d paymentsdb: rename assertPayments 2025-08-20 09:07:52 +02:00
ziggie
8726ba3d7c paymentsdb: move more tests
we make the index assertion db independant so it is a noop for
a future native sql backend. This allows us to reuse even more
tests for the different db architectures.
2025-08-20 09:07:52 +02:00
ziggie
e22b898c1e paymentsdb: move db interface dependant tests to different file
This commit starts reusing test cases which are not dependant on
the kv db backend. So they can be later used with the native db
implementation as well.
2025-08-20 09:07:52 +02:00
ziggie
39b7417797 paymentsdb: use querypayments method to make test db agnostic 2025-08-20 09:07:52 +02:00
ziggie
46500f94e0 multi: fix comment of InitPayment method 2025-08-20 09:07:51 +02:00
ziggie
9f824fe1ee multi: introduce interface for payment database 2025-08-20 09:07:48 +02:00
Oliver Gugger
e259456585 Merge pull request #10168 from ziggie1984/move-pgp-check-to-daily
move pgp check to daily builds
2025-08-19 05:34:43 -06:00
ziggie
1fb284fa26 github actions: move pgp key to daily builds 2025-08-19 08:35:42 +02:00
Yong
9a4968656a Merge pull request #8825 from Abdulkbk/restore-node-announcement
lnd: use persisted node announcement settings across restarts
2025-08-18 18:21:00 +08:00
Abdullahi Yunus
fbac73011f docs: add release note 2025-08-16 16:39:53 +01:00
Abdullahi Yunus
2dc9ca43f3 itest: test for node ann persistence
This commit adds an itest that verify the behaviour of correctly
reusing persisted node ann configs across restarts. It also ensures
that the node ann configs are applied using the correct hierarchy.
2025-08-16 16:39:53 +01:00
Abdullahi Yunus
75895dbe3a lnd: use saved node ann config from previous run
This commit ensures that we start with the alias, node color,
addresses, and features as advertised in the node's previous
runtime. This approach maintains consistency in the node's
advertised information across restarts.
2025-08-16 16:39:52 +01:00
Oliver Gugger
fb1adfc218 Merge pull request #10160 from mohamedawnallah/increase-wait-wallet-sync-timeout
lnwallet/test: increase wait for wallet to sync to `30s` to match with the returned error in case of timeout
2025-08-15 06:54:11 -06:00
Oliver Gugger
365f1788e5 Merge pull request #10157 from ziggie1984/remove-pgp-key
remove expired key
2025-08-15 01:10:05 -06:00
Oliver Gugger
c428b7f430 Merge pull request #10158 from ellemouton/graphTest
graph/db: expand TestPopulateViaMigration for easy testing
2025-08-15 00:52:51 -06:00
Mohamed Awnallah
e8283e958c lnwallet/test: make the timeout err msg and actual timeout consistent 2025-08-15 06:05:21 +00:00
Yong
3841d55549 Merge pull request #10112 from GustavoStingelin/check-pgp-keys-expiry
CI: add pgp keys expiry check
2025-08-15 12:12:33 +08:00
Yong
dfc29b3f71 Merge pull request #9847 from ziggie1984/refactor-payments-code-04
Refactor Payment PR 4
2025-08-15 12:03:33 +08:00
Gustavo Stingelin Cardoso Filho
7ba28c4961 CI: add pgp keys expire check 2025-08-14 15:36:10 -03:00
Gustavo Stingelin Cardoso Filho
29bfeb2084 scripts: add pgp keys expire check 2025-08-14 15:35:55 -03:00
ziggie
2b856f036e multi: fix linter 2025-08-14 19:53:18 +02:00
ziggie
e24ae0d7f3 paymentsdb: add missing comments for variables 2025-08-14 19:53:18 +02:00
ziggie
df9bac2ecf multi: move PaymentCreationInfo to payment pkg 2025-08-14 19:53:18 +02:00
ziggie
d138e23919 multi: move FailureReason to payment package 2025-08-14 19:53:18 +02:00
ziggie
d77b2f9c26 mulit: move payment query code to separate file
We also rename the struct since it is now in its own package
there is no need to prefix it.
2025-08-14 19:53:18 +02:00
ziggie
03af9858d2 multi: move payment related code into own package
This commit moves most of the code into its own package. It is
the smallest code move possible without moving import cycles and
keeping the changes to the code base as small as possible during
refactor.
2025-08-14 19:53:15 +02:00
Oliver Gugger
31fc556507 Merge pull request #10155 from ziggie1984/add-missing-invoice-settle-index
Add missing invoice index for native sql
2025-08-14 09:23:37 -06:00
Elle Mouton
ec17f8bc4e graph/db: expand TestPopulateViaMigration for easy testing
Expand the test and make it easily configurable for the purposes of
locally testing the graph SQL migration.
2025-08-14 16:31:04 +02:00
Oliver Gugger
4b3ede5cb0 Merge pull request #10154 from ellemouton/graphPerf11
graph/db: use batch validation to improve SQL migration performance
2025-08-14 05:54:21 -06:00