Commit Graph

1851 Commits

Author SHA1 Message Date
Slyghtning
2937837fc0 chainfee: method to round up the fee for a given transaction weight 2025-06-25 14:56:47 +02:00
yyforyongyu
0608cc0428 channeldb+lnwallet: fix typo 2025-06-20 15:45:13 -07:00
yyforyongyu
938d78a28b lnwallet+channeldb: use BigSizeT to save space 2025-06-20 15:44:16 -07: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
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
Elle Mouton
b887c1cc5d protofsm: use updated GoroutineManager API
Update to use the latest version of the GoroutineManager which takes a
context via the `Go` method instead of the constructor.
2025-01-10 18:23:28 +02:00
yyforyongyu
1d53e7d081 multi: improve loggings 2024-12-20 17:54:03 +08:00
yyforyongyu
7882e1ccff lnwallet: add debug logs 2024-12-16 16:07:22 +08:00
Olaoluwa Osuntokun
3c5f96de7c lnwallet/chancloser: enable custom payer for rbf coop close
In this commit, we enable a custom payer for the rbf coop close. This
allows us to ensure that the party that started one side of the close
flow pays the fees.
2024-12-10 23:07:03 +01:00
Olaoluwa Osuntokun
d38c5e6222 lnwallet: update core coop close logic with custom payer
In this commit, we update the core coop close logic with the new custom
payer param. We also expand the existing unit tests to ensure that the
fee is deducted from the proper party.
2024-12-10 23:07:02 +01:00
Olaoluwa Osuntokun
d1b2bff2c8 lnwallet: update CoopCloseBalance to allow a paying party
This preps us for an upcoming change to the rbf coop state machine where
either party can pay for the channel fees. We also add a new test to
make sure the new function adheres to some key properties.
2024-12-10 23:07:02 +01:00
Olaoluwa Osuntokun
b8cf5ae98f lnwallet: for rbf coop close, log the close tx 2024-12-10 23:07:02 +01:00
Olaoluwa Osuntokun
b94ce6fa08 lnwallet: use custom LockTime for rbf coop close 2024-12-10 23:07:02 +01:00
Olaoluwa Osuntokun
ab4297e127 lnwallet/chancloser: use block height as lock time for rbf-coop 2024-12-10 23:07:02 +01:00
Olaoluwa Osuntokun
540d3c0fc7 multi: switch to lock time from sequence for coop close v2 2024-12-10 23:07:01 +01:00
Olaoluwa Osuntokun
2decea86d8 lnwallet/chancloser: add unit tests for new rbf coop close 2024-12-10 23:07:01 +01:00
Olaoluwa Osuntokun
6b90254fd3 lnwallet/chancloser: create a MsgMapper for the protofsm rbf close
This'll allow us to treat the state machine as a MsgEndpoint, and have
the readHandler in the peer automatically send new messages to it.
2024-12-10 23:07:01 +01:00
Olaoluwa Osuntokun
e47a632745 lnwallet/chancloser: add state transitions for new protofsm rbf closer
In this commit, we add the state transitions for the new protofsm based
RBF chan closer. The underlying protocol is a new asymmetric co-op close
process, wherein either side can initiate a chan closer, and use their
settled funds to pay for fees within the channel.
2024-12-10 23:07:01 +01:00
Olaoluwa Osuntokun
f6525c9e7d lnwallet: add ability to specify custom sequence for co-op close tx
In this commit, we add the ability to specify a custom sequence for a
co-op close tx. This'll come in handy later as the new co-op close
process allows a party to set a custom sequence.
2024-12-10 23:07:01 +01:00
Olaoluwa Osuntokun
62a3db1cc2 lnwallet/chancloser: add states for new protofsm rbf closer
In this commit, we add the initial set of states for the new protofsm
based rbf chan closer. A diagram outlining the new states and their
transitions can be found here:
https://gist.github.com/Roasbeef/acc4ff51b9dff127230228a05553cdfe.

Unlike the existing co-op close process, this co-op close can be
restarted at anytime if either side sends a shutdown message. From
there, we'll each obtain a new RBF'd version that can be re-broadcasted.

This commit creates the set of states, along with the environment that
our state machine will use to drive itself forward.
2024-12-10 23:07:01 +01:00
Keagan McClelland
ed2989ae33 multi: update to fn v2 2024-12-04 13:19:00 -07:00