Commit Graph

1867 Commits

Author SHA1 Message Date
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
Olaoluwa Osuntokun
14eca4406e lnwire: update closing_complete and closing_sig to latest spec draft
Both these messages now carry the address of both parties, so you can
update an address without needing to send shutdown again.
2025-03-18 11:44:20 -05:00
Olaoluwa Osuntokun
835d7623d4 lnwallet/chancloser: ignore spurious channel flushed events
If we go to close while the channel is already flushed, we might get an extra event, so we can safely ignore it and do a self state transition.
2025-03-18 11:44:20 -05:00
Olaoluwa Osuntokun
27b24ab86a lnwallet/chancloser: add fee rate to ClosePending
This'll be useful to communicate what the new fee rate is to an RPC caller.
2025-03-18 11:44:20 -05:00
yyforyongyu
8b2ade7ec9 lnwallet+protofsm: fix logging 2025-03-18 11:44:20 -05:00
Olaoluwa Osuntokun
8432e706d3 multi: extract new DeriveHeightHint() function, use for new rbf closer
With this commit, we make sure we set the right height hint, even if the
channel is a zero conf channel.
2025-03-18 11:44:20 -05:00
Olaoluwa Osuntokun
b2794b07cb lnwallet/chancloser: enforce pubkey binding for msg mapper 2025-03-18 11:44:20 -05:00
Olaoluwa Osuntokun
1d2c22d140 protofsm: add String() method to ProtocolState 2025-03-18 11:44:20 -05:00
yyforyongyu
99d49dec6a multi: change NewBitcoindBackend to take a miner as its param
Prepares for the following commit where we assert the chain backend is
synced to the miner.
2025-02-26 19:51:52 +08:00
Oliver Gugger
1227eb1cce Merge pull request #9491 from ziggie1984/closechannel-rpc
Allow coop closing a channel with HTLCs on it via lncli
2025-02-21 05:05:53 -06:00
ziggie
f458844412 lnd: add max fee rate check to closechannel rpc 2025-02-20 17:43:18 +01:00
ziggie
9382fcb801 multi: fix debug log 2025-02-20 10:44:19 +01:00
Eng Zer Jun
e56a7945be refactor: replace math.Min and math.Max with built-in min/max
Reference: https://github.com/lightningnetwork/lnd/pull/9451#pullrequestreview-2580942691
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2025-02-06 09:46:40 +08:00