1269 Commits
Author SHA1 Message Date
bitromortac 19860bb9f6 lnwallet: expose channel state
We create a deep copy of the channel state as we want to later expose
the data structure to the rpc, which already has helper methods to
marshal this representation to the rpc representation.
2026-02-20 10:43:52 +01:00
ziggie d9fb9092b6 multi: make sure previous inconsitent states are fixed
We make sure that nodes previously suffering from this error will
have a consitent db view when restarting their node.
2026-01-06 14:34:52 +01:00
ziggie 51f3c6f528 channeldb: fix race condition in link node pruning
This commit fixes a critical race condition in MarkChanFullyClosed and
pruneLinkNode where link nodes could be incorrectly deleted despite
having pending or open channels.

The race occurred because the check for open channels and the link node
deletion happened in separate database transactions:

  Thread A: TX1 checks open channels → [] (empty)
  Thread A: TX1 commits
  Thread B: Opens new channel with same peer
  Thread A: TX2 deletes link node (using stale data)
  Result: Link node deleted despite pending channel existing

This creates a TOCTOU (time-of-check to time-of-use) vulnerability where
database state changes between reading the channel count and deleting
the node.

Fix for MarkChanFullyClosed:
- Move link node deletion into the same transaction as the channel
  closing check, making the check-and-delete operation atomic

Fix for pruneLinkNode:
- Add double-check within the write transaction to verify no channels
  were opened since the caller's initial check
- Maintains performance by keeping early return for common case
- Prevents deletion if channels exist at delete time

This ensures the invariant: "link node exists iff channels exist"
is never violated, preventing database corruption and potential
connection issues.
2026-01-06 10:52:41 +01:00
Elle Mouton 80e70096cb multi: add models.Node V1 constructor
Add a version field to models.Node and a V1 constructor for it.
2025-11-12 22:54:05 +08:00
Elle Mouton 8f205e2d1c multi: remove HaveNodeAnnouncement field from Node
Remove the 2 sources of truth here. If we have a signature for the
node, then we have the announcement.
2025-11-12 22:54:04 +08:00
ziggie d2d56f2968 linter: remove unsupported linters from the codebase 2025-11-12 22:54:02 +08:00
Yong 5082566ed7 Merge pull request #9677 from NishantBansal2003/conf-count
Expose confirmation count for pending 'channel open' transactions
2025-09-11 22:36:05 +08:00
Nishant Bansal 222f49c593 channeldb: add MarkConfirmationHeight to OpenChannel
Add the MarkConfirmationHeight method to the OpenChannel struct
to record the block height at which the funding transaction was
first confirmed. Also, introduce the ConfirmationHeight field
to persist this information in the database.

Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
2025-09-11 18:26:16 +05:30
Elle Mouton 6e98b336f6 graph/db+channeldb: rename test helper 2025-09-03 10:14:35 +02:00
Elle Mouton c663a557c4 multi: rename models.LightningNode to models.Node 2025-09-03 10:14:35 +02:00
Boris Nagaev dee8ad3754 multi: context.Background() -> t.Context()
Use the new feature of Go 1.24, fix linter warnings.

This change was produced by:
 - running golangci-lint run --fix
 - sed 's/context.Background/t.Context/' -i `git grep -l context.Background | grep test.go`
 - manually fixing broken tests
 - itest, lntest: use ht.Context() where ht or hn is available
 - in HarnessNode.Stop() we keep using context.Background(), because it is
   called from a cleanup handler in which t.Context() is canceled already.
2025-08-30 14:13:44 -03:00
Boris Nagaev 612ad7da27 multi: fix non-constant input of fmt.Errorf
Fixed multiple cases in which a non-constact string variable was used as a
format string for fmt.Errorf.
2025-08-30 14:13:44 -03:00
ziggie 2b856f036e multi: fix linter 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 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
ziggie 77a6b577eb channeldb: move helper function to codec.go
This method is not only used by the payment logic so we need to
move it to a generalized place because in the following commits
we move payment related code into its own package.
2025-08-14 08:08:51 +02:00
ziggie 4bb21a7284 channeldb: export pagination method
We export some methods related to the pagination logic be the
kv store implemenation of the payment data will live in another
package.
2025-08-14 08:08:50 +02:00
ziggie 4e0af2f495 channeldb: rename storedPaymentSeq 2025-08-11 16:44:15 +02:00
ziggie a4b1569647 channeldb: rename currPaymentSeq 2025-08-11 16:44:15 +02:00
ziggie 6bae3c98b3 channeldb: rename paymentSeqMx 2025-08-11 16:44:14 +02:00
ziggie 88da582526 mulit: use kvdb.Backend for the kv payment db
Instead of the ChannelState struct we now use the kv backend
interface for the payment kv database.
2025-08-11 16:44:14 +02:00
ziggie 18afd4442d multi: introduce new paymentsDB package
We introduce a new package paymentsDB and start by moving the
payment specifc errors from the channeldb package to the
paymentsDB package. We also fix linter issues which showed up
due to changing this code part.
2025-08-11 16:44:14 +02:00
ziggie db2c50a599 channeldb: add context to query method
We add a context for the query method because the query method
is part of the paymentDB interface and for the SQL case
we will need the context for this method because the native
SQL drivers demand one. So we add it for the kv implementation
here as well so we can then make use of the new interface type.
2025-08-11 16:44:13 +02:00
ziggie 2b3b27f5a9 multi: fix linter issues 2025-08-02 13:24:27 +02:00
ziggie 0aef5fa44c multi: unify all payment related kv data
All interactions related to the payment db are now part of the
kvPaymentDB struct.
2025-08-02 13:24:27 +02:00
ziggie aaa1ee0b74 channeldb: move kv related code
We move all kv particular code which was in the payments.go file
to the kv related file. Code which will be backend independant
will remain in the payments.go file although only the kv backend
is currently supported.
2025-08-02 13:24:25 +02:00
ziggie 84b2a94da2 multi: fix linter issues 2025-08-02 13:21:45 +02:00
ziggie 8bd4744ee8 channeldb: rename pControl to paymentDB in tests 2025-08-02 11:48:01 +02:00
ziggie 2d07d44d1a channeldb: rename PaymentControl struct
In the following commits we will gradually unify the current
payment db operations into an interface to later down the road
support both backends (sql+kv).
2025-08-02 11:24:59 +02:00
ziggie 252ebdea5b channeldb: rename payment_control files
We rename the file to payment_kv_store to highlight that this
is the kv implementation of the payment db backend.
2025-08-01 17:51:11 +02:00
ziggie 923cafb989 multi: revert back changes from 9911
always process remote ADDs even when they are empty to trigger
the gc process when loading them back into memory.
2025-07-08 10:25:26 +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
ziggie d220b87b60 multi: Add decayedlog db migration code
This commit adds the migration code for the decayedlog db which
is optional and will default to true.
2025-06-21 09:20:19 +02:00
ziggie c7e773132b channeldb: update optional migration code for multiple versions 2025-06-21 09:20:18 +02:00
ziggie c19d89149f channeldb: add migration34
Migration34 garbage collects the decayed log database. This commit
only adds the migration code and does not use it.
2025-06-21 09:20:17 +02:00
Olaoluwa Osuntokun faa68a220e Merge pull request #9880 from yyforyongyu/accessman
Improve access control in peer connections
2025-06-20 15:26:24 -07:00
yyforyongyu 32d8e2123d channeldb+lnd: rename peerCounts to peerChanInfo for clarity 2025-06-19 16:48:13 +08:00
Elle Mouton e724e1c3e4 multi: thread context through to AddrsForNode 2025-06-17 19:20:59 +02:00
Oliver Gugger 5d161e8cd0 Merge pull request #9653 from djkazic/reorder-buckets-check
channeldb: perform init of top level buckets first
2025-06-16 08:24:03 +02:00
djkazic 759a870072 channeldb: perform init of top level buckets first 2025-06-13 09:02:07 -04:00
Shivam Chawla bfe1edf4ec lnrpc: add filters to forwardhistoryrequest
This commit adds incoming and outgoing channel ids filter to forwarding history request to filter events received/forwarded from/to a particular channel
2025-06-11 09:10:13 +05:30
Oliver Gugger a0f658b44d Merge pull request #9889 from yyforyongyu/fix-htlcindex
Use `BigSizeT` for `HtlcIndex` in retribution log
2025-06-06 15:50:50 +02:00
Oliver Gugger e1c9825b8a Merge pull request #9813 from Abdulkbk/htlcidx-to-fwdingevent
lnrpc: add HtlcIndex to ForwardingEvents
2025-06-06 14:32:29 +02:00
yyforyongyu 870e16bdd7 channeldb+lnwallet: fix typo 2025-06-06 19:55:59 +08:00
yyforyongyu 4efd99774e channeldb: add customized encoding for HtlcIndex 2025-06-06 19:55:59 +08:00
yyforyongyu f5ffe82280 lnwallet+channeldb: use BigSizeT to save space 2025-06-06 19:55:58 +08:00
Abdullahi Yunus f79e6137c1 htlcswitch+channeldb: add htlcidx to fwding log
In this commit we add htlcindex field to the forwardingevent
struct, which is persisted alongside the other event fields.
2025-06-06 12:21:39 +01:00
Elle Mouton 7571acbe81 channeldb: remove unnecessary for loop from Query method
This commit simplifies the code of the ForwardingLog.Query method by
removing a confusing for-loop. The for-loop makes it seem as though
multiple events could be encoded under a single timestamp. But from the
time that this forwarding log was introduced, it was never possible to
encode multiple events under the same timestamp and so this loop will
never execute successfully more than once per timestamp and can thus be
removed. This paves the way such that future expansions of the method
can be added easily.

See the initial commit that introduced this code [here](https://github.com/lightningnetwork/lnd/commit/f2cd668bcfb423fb212e78282c786dea166e0168).
In this commit you can see that from the start it was never possible to
have more than one event in a single timestamp since any previous event
in that timestamp would be overwritten. Then see [this commit](https://github.com/lightningnetwork/lnd/pull/4475/commits/97c73706b55fb5520d2f3001dfa13dc1da986972)
where even more protection was added to ensure that each event had a
unique timestamp.
2025-06-05 11:07:46 +02:00
Elle Mouton 5d7c6c4b60 channeldb: remove graph calls from tests
The channeldb no longer depends on the graph. So remove the use of
MakeTestGraph from tests.
2025-05-22 14:14:40 +02:00