Commit Graph

1879 Commits

Author SHA1 Message Date
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
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
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
ziggie
9a83b3838f mulit: use min relay fee error 2025-09-16 14:25:42 +02:00
Olaoluwa Osuntokun
6e21bc5764 lnwallet: replace spew.Sdump with lnutils.SpewLogClosure for lazy evaluation
In this commit, we replace all instances of spew.Sdump in the lnwallet
package and its subpackages with lnutils.SpewLogClosure. This change
ensures that expensive debug dump operations are only performed when the
log level actually requires them.
2025-09-05 18:20:49 -07:00
Yong
1666764690 Merge pull request #10136 from yyforyongyu/use-btcwallet-interface
lnwallet: use btcwallet's new interface
2025-09-02 20:46:56 +08:00
Elle Mouton
06bf0c28b6 multi: let FetchPkScript take SCID by value
Instead of a pointer.
2025-09-01 12:10:30 +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
2a599bedc0 multi: don't pass err.Error() to Fatalf
It resulted in interpreting the error message as a format string.
Use Fatal(err) instead.
2025-08-30 14:13:44 -03:00
yyforyongyu
b10aca5c1b lnwallet: use the wallet interface 2025-08-26 20:36:21 +08:00
yyforyongyu
596d969881 btcwallet: fix duplicate import
The `wallet` has already imported using `base`.
2025-08-26 20:36:21 +08:00
Mohamed Awnallah
e8283e958c lnwallet/test: make the timeout err msg and actual timeout consistent 2025-08-15 06:05:21 +00:00
George Tsagkarelis
47d1365fde lnwallet: add table-driven test for evaluateNoOpHtlc helper 2025-08-08 20:03:30 +02:00
George Tsagkarelis
4a34f78fba lnwallet: add noop case to retransmit test
To make sure we don't cause force-closures because of commit sig
mismatches, we add a test case to verify that the retransmitted HTLC
matches the original HTLC.
2025-08-08 20:03:30 +02:00
George Tsagkarelis
e0486697df lnwallet: add noop HTLC tests
Adds some simple tests to check the noop HTLC logic of the lightning
channel.
2025-08-08 20:03:30 +02:00
George Tsagkarelis
a5a15f6401 lnwallet: detect and handle noop HTLCs
We update the lightning channel state machine in some key areas. If the
noop TLV is set in the update_add_htlc custom records then we change the
entry type to noop. When settling the HTLC if the type is noop we credit
the satoshi amount back to the sender.
2025-08-08 20:03:30 +02:00
George Tsagkarelis
aacefb9055 lnwallet: add IsAdd helper to AuxHtlcDescriptor
We also add the IsAdd helper to the AuxHtlcDescriptor, as external
software using the aux framework might want to know which type of HTLC
this is.
2025-08-08 20:03:29 +02:00
George Tsagkarelis
138b716519 lnwallet: add noop updateType to paymendDescriptor
We add a new update type to the payment descriptor to describe this new
type of htlc. This type of HTLC will only end up being set if explicitly
signalled by external software.
2025-08-08 20:03:27 +02:00
Oliver Gugger
1882939cd8 chancloser: fix flake by registering subscriber first
Fixes another flake in the unit-race test: Sometimes we miss startup
events if there's a high CPU load (in CI for example).
To avoid that, we register our subscriber before starting the state
machine.
2025-07-21 13:53:25 +02:00
Oliver Gugger
15d8f963ce chancloser: fix error tests
These tests previously only worked because we didn't properly wait for
all transitions to come in. We fix them by correctly asserting the
expected number of state transitions.
2025-07-21 13:49:17 +02:00
Oliver Gugger
bc33986bfa chancloser: fix flake in TestRbfCloseClosingNegotiationRemote
This fixes the actual flake: We didn't wait for next iterations to _not_
come in, so depending on timing, we could read another transition in a
second run.
But making sure we expect all transitions at the same time and then make
sure no further transitions come in makes this not depend on time.
2025-07-21 13:49:16 +02:00
Oliver Gugger
263d070624 chancloser: increase timeouts 2025-07-21 13:49:16 +02:00
Oliver Gugger
0860f2dac4 chancloser: fix nolint comments, fix formatting 2025-07-21 13:48:31 +02:00
Oliver Gugger
8023583414 chancloser: use separate broadcast channels
This doesn't change the behavior but makes the use of the broadcast
channels more clear.
2025-07-18 14:07:30 +02:00
Oliver Gugger
899131f7be chancloser: use param instead of constant
The param previously was unused so this was likely an oversight or
copy/paste error.
This does not change any behavior, as the method was always called with
the constant previously used. But it makes things more explicit.
2025-07-18 14:07:29 +02:00
Slyghtning
ab8ae542d0 chainfee: method to round up the fee for a given transaction weight 2025-06-25 10:02:04 +02:00
Olaoluwa Osuntokun
35102e7c35 Merge pull request #9652 from Roasbeef/rbf-iteration-loop-flake
lnwallet/chancloser: fix flake in TestRbfCloseClosingNegotiationLocal
2025-06-11 14:08:19 -07:00
Olaoluwa Osuntokun
eb863e46af lnwallet/chancloser: fix fllake in TestRbfCloseClosingNegotiationLocal/send_offer_rbf_wrong_local_script
In this commit, we fix a flake in the
`TestRbfCloseClosingNegotiationLocal/send_offer_rbf_wrong_local_script`
test.

This flake can happen if the test shuts down _before_ the state machine
is actually able to process the sent event. In this case, the
expectations are triggered, and we find that the error isn't sent.

To resolve this, we create a new wrapper function that'll use a sync
channel send to assert that the error has been sent before we exit the
test.
2025-06-10 18:44:34 -07:00
yyforyongyu
870e16bdd7 channeldb+lnwallet: fix typo 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
yyforyongyu
8f936aa9eb itest: update num of sweeps in AssertNumPendingSweeps
Since we now return all sweeps, we need to update the call to include
immature sweeps.
2025-04-29 14:15:31 +08:00
Boris Nagaev
429000e360 lnwallet: fix InternalKeyForAddr for imported addr
An address imported using ImportTapscript doesn't provide a private key
so it can't satisfy waddrmgr.ManagedPubKeyAddress interface. So we don't
return an error for imported addresses.
Fix https://github.com/lightninglabs/loop/issues/923
2025-04-23 11:17:00 -03:00
Boris Nagaev
b5c9df81f0 lnwallet: fix error message
Include the variable of interest (walletAddr), not the outcome of the check
(pubKeyAddr) which is always nil.
2025-04-23 11:17:00 -03:00
ziggie
b2087a8a2e lnwallet: skip aux resolution call for non-anchor channels. 2025-04-21 11:09:00 +02:00
Oliver Gugger
7381f4b221 Merge pull request #9687 from GeorgeTsagk/aux-trff-shpr-htlcview
`AuxTrafficShaper.PaymentBandwidth` uses HTLC view
2025-04-17 07:59:00 +02:00
George Tsagkarelis
53254c79b4 lnwallet: add FetchLatestHTLCView to LightningChannel
We add a public method for the lightning channel to expose the latest
HtlcView. This is used in a follow up commit by the channel link.
2025-04-14 15:34:09 +02:00
George Tsagkarelis
a279058408 lnwallet: replace HtlcView with AuxHtlcView in existing code 2025-04-14 15:34:09 +02:00
George Tsagkarelis
b96d57e88f lnwallet: add AuxHtlcView 2025-04-14 15:34:09 +02:00
ziggie
490347b056 multi: update walletdb package 2025-04-09 18:47:53 +02:00
Olaoluwa Osuntokun
40f58da161 lnwallet/chancloser: fix flake in TestRbfCloseClosingNegotiationLocal
In this commit, we fix a flake in the rbf loop sub-test for the
TestRbfCloseClosingNegotiationLocal test case.

The fix here is that when we go from ClosePending for an RBF iteration
loop, we first transition to LocalCloseStart. However we only do this
extra transition if we're doing an iteration (starting from ClosePending).

To fix this, we add a new bool that tracks if this is an iteration or
not. We can then also eliminate the extra assertion at the end, as we'll
terminate in `ClosePending` which is checked by
`assertLocalClosePending()` in `assertSingleRbfIteration`.

Fixes https://github.com/lightningnetwork/lnd/issues/9526.
2025-04-01 17:03:24 -07:00
Olaoluwa Osuntokun
f08e7fe0d6 lnwallet/chancloser: fix flake in TestRbfChannelFlushingTransitions/early_offer
In this commit, we fix a flake in the
`TestRbfChannelFlushingTransitions/early_offer` test. The fix is simple:
this is actually an "iteration", as we have a self transition to the
ChannelNegotiation state first. We also don't need to send the
remoteOffer, so we set `sendInit` to false. The offer still needs to be
passed in to ensure that the assertions work however.
2025-03-26 16:36:13 -07:00
yyforyongyu
f0300762c0 lnwallet: move btcwallet log under BTWL
So we can focus on debugging `BTWL` without concerning `lnwallet`, which
has a lot of channel-specific loggings.
2025-03-21 08:06:18 +08:00
yyforyongyu
07c60c85f9 lnwallet: remove direct walletdb reference
To make sure the db layer is not exposed and is only managed by the
`btcwallet` package.
2025-03-21 08:06:18 +08:00
Olaoluwa Osuntokun
8df58a984c lnwallet/chancloser: add docs for new rbf chan closer 2025-03-18 11:44:59 -05:00
Olaoluwa Osuntokun
80b48fb49b peer: update rbf close client logic w/ error and iteration awareness
We'll properly handle a protocol error due to user input by halting, and
sending the error back to the user.

When a user goes to issue a new update, based on which state we're in,
we'll either kick off the shutdown, or attempt a new offer. This matches
the new spec update where we'll only send `Shutdown` once per
connection.
2025-03-18 11:44:21 -05:00
Olaoluwa Osuntokun
23a9a761e3 peer: add initial awareness of new rbf coop closer
In this commit, we use the interfaces we created in the prior commit to
make a new method capable of spinning up the new rbf coop closer.
2025-03-18 11:44:20 -05:00
Olaoluwa Osuntokun
84b6d95b91 lnwallet/chancloser: increase test coverage of state machine 2025-03-18 11:44:20 -05:00
Olaoluwa Osuntokun
7370617aaa lnwallet/chancloser: update RBF state machine to handle early offer case
In this commit, we update the RBF state machine to handle early offer
cases. This can happen if after we send out shutdown (to kick things
off), the remote party sends their offer early. This can also happen if
their outgoing shutdown (to ACK ours) was delayed for w/e reason, and we
get their offer first.

The alternative was to modify the state machine itself, but we feel that
handling this early case is better in line with the Robustness principle.
2025-03-18 11:44:20 -05:00
Olaoluwa Osuntokun
333492e657 lnwallet: implement special case for OP_RETURN in rbf-coop
In this commit, we implement a special case for OP_RETURN scripts
outlined in the spec. If a party decides that its output will be too
small even after the dust check, then they can opt to set it to zero by sending an `OP_RETURN` as their script.
2025-03-18 11:44:20 -05:00
Olaoluwa Osuntokun
e6d7a1a2ec protofsm: update state machine w/ new spec flow
In this commit, we implement the latest version of the RBF loop as
described in the spec. We remove the self loop back based on sending or
receiving shutdown. Instead, from the ClosePending state, we can trigger
a new loop by sending SendOfferEvent (we bump), or OfferReceivedEvent
(they bump).

We also update the rbf state machine w/ the new close addr logic. This
log ensures that the remote party always sends our current address, and
that if they send a new address, we'll update our view of it, and
counter sign the correct transaction.

We also add a CloseErr state. With this new state, we can ensure that
we're able to properly report errors back to the RPC client, and also
optionally force a reconnection or send a warning to the remote party.
2025-03-18 11:44:20 -05:00