Commit Graph

64 Commits

Author SHA1 Message Date
Keagan McClelland
4b2a4e36ad
lnwallet: pack htlcView.{OurUpdates|TheirUpdates} into Dual.
This commit moves the collection of updates behind a Dual structure.
This allows us in a later commit to index into it via a ChannelParty
parameter which will simplify the loops in evaluateHTLCView.
2024-10-14 09:33:38 -06:00
Olaoluwa Osuntokun
625d426a56
lnwallet: modify CoopCloseBalance to not depend on chan commit 2024-09-19 10:18:40 +02:00
Keagan McClelland
4fadbb09bd
htlcswitch+lnwallet: quarantine paymentDescriptor to lnwallet
The objective of this commit is to make paymentDescriptor a private
data structure so we can quarantine it to the lnwallet package.
To accomplish this we had to prevent it from leaking out via the
arguments or return values of the public functions in lnwallet.
This naturally had consequences for the htlcswitch package as we
choose other mechanisms for tracking the data that paymentDescriptor
was responsible for.

Astoundingly, this was highly successful and allowed us to remove
a ton of redundant code. The diff for this commit represents a
substantial reduction in total lines of code as well as extraneous
arguments and return values from key functions.

This also sets the stage for future commits where we actually will
be attempting to rid lnwallet of paymentDescriptor completely.
2024-09-10 13:56:56 -07:00
Oliver Gugger
9dfbde7013
lnwallet: thread thru input.AuxTapleaf to all relevant areas
In this commit, we start to thread thru the new aux tap leaf structures to all relevant areas. This includes: commitment outputs, resolution creation, breach handling, and also HTLC scripts.
2024-08-28 13:28:48 +02:00
Olaoluwa Osuntokun
d95c1f93f3
lnwallet+channeldb: add new AuxLeafStore for dynamic aux leaves
In this commit, we add a new AuxLeafStore which can be used to dynamically fetch the latest aux leaves for a given state. This is useful for custom channel types that will store some extra information in the form of a custom blob, then will use that information to derive the new leaf tapscript leaves that may be attached to reach state.
2024-08-28 13:21:08 +02:00
Olaoluwa Osuntokun
12352d9e6e
lnwallet: export the HtlcView struct
We'll need this later on to ensure we can always interact with the new aux blobs at all stages of commitment transaction construction.
2024-08-28 11:52:32 +02:00
Olaoluwa Osuntokun
1aae47fd71
input+lnwallet: update taproot scripts to accept optional aux leaf
In this commit, we update all the taproot scripts to also accept an
optional aux leaf. This aux leaf can be used to add more redemption
paths for advanced channels, or just as an extra commitment space.
2024-08-28 11:52:31 +02:00
Oliver Gugger
efbaf90caf
lnwallet: add Tree() method, fix formatting 2024-08-23 10:58:13 +02:00
Oliver Gugger
f0648e24a5
lnwallet: export GenTaprootHtlcScript 2024-08-23 10:58:13 +02:00
Oliver Gugger
cf2174fc2d
lnwallet: export AnchorSize 2024-08-23 10:58:13 +02:00
Keagan McClelland
0996e4f163
multi: refactor lnwallet/channel.go to use ChannelParty in select places
We also include changes to contractcourt, htlcswitch and peer to stitch the
boundaries together.
2024-07-31 14:50:26 -07:00
Keagan McClelland
3a15085014
input+lnwallet: refactor select methods in input to use ChannelParty 2024-07-31 14:50:26 -07:00
yyforyongyu
8da68bb7db
multi: apply the new type lntypes.WeightUnit 2024-05-25 13:37:13 +08:00
zhiqiangxu
74a290b46d lnwallet+input: fix a few typoes 2024-03-21 15:44:45 +08:00
Olaoluwa Osuntokun
92da6b1d44
multi: fix linter warnings with updated linter 2023-08-22 16:34:47 -07:00
Olaoluwa Osuntokun
ff055ce0a4
lnwallet: uniformly use sighash default everywhere for taproot chans
We use a helper function to ensure that anytime we're about to make a
normal sighash, we consult the channel type to check if we should use
the default value or sighash all explicitly.
2023-08-22 16:34:23 -07:00
Olaoluwa Osuntokun
a2b277cf1d
multi: fix linter errors 2023-08-22 16:34:15 -07:00
Olaoluwa Osuntokun
4b0139c9ba
lnwallet: update channel state machine to use new ScriptDescriptor interface
In this commit, we update the channel state machine to use the new
ScriptDescriptor interface. This fixes some subtle issues with the
existing commits, as for p2wsh we always sign the same witness script,
but for p2tr, the witness script differs depending on which branch is
taken.

With the new abstractions, we can treat p2wsh and p2tr as the same
mostly, right up until we need to obtain a control block or a tap tweak.

All tests have been updated accordingly.
2023-08-22 16:33:46 -07:00
Olaoluwa Osuntokun
a128b74dc1
lnwallet: add tapscript tree to ScriptInfo
In this commit, we add the tapscript tree to the ScriptInfo struct, as
in many cases the caller needs the tree in order to generate the control
block or obtain the taptweak which is needed to spend revoked outputs.
2023-08-22 16:32:56 -07:00
Olaoluwa Osuntokun
a74c30fbdd
lnwallet: update HtlcSuccessFee + HtlcTimeoutFee for taproot chans
There's no fee, as taproot channels are always zero fee HTLC.
2023-08-22 16:32:54 -07:00
Olaoluwa Osuntokun
ebc61818a3
lnwallet: update CommitWeight to return taproot commit weight 2023-08-22 16:32:51 -07:00
Olaoluwa Osuntokun
0d3bed66c0
lnwallet: properly set witness script in CommitScriptToSelf 2023-08-22 16:32:40 -07:00
Olaoluwa Osuntokun
d2526c75f4
lnwallet: update genHTLC script to support segwit v0 + v1 (taproot) HTLCs 2023-08-22 16:31:23 -07:00
Olaoluwa Osuntokun
2a22f5b959
lnwallet: update CreateHtlcTimeoutTx+CreateHtlcSuccessTx for taproot 2023-08-22 16:31:20 -07:00
Olaoluwa Osuntokun
5e511e35fd
lnwallet: update CommitScriptAnchors to add taproot awareness
We also update some of the resolutions (even though they aren't hooked
up yet), as they need to be able to properly re-create the set of
scripts.
2023-08-22 16:31:02 -07:00
Olaoluwa Osuntokun
cb0229d437
lnwallet: update CommitScriptToRemote to add taproot awareness 2023-08-22 16:31:00 -07:00
Olaoluwa Osuntokun
0e7e29455a
lnwallet: update CommitScriptToSelf to add taproot awareness 2023-08-22 16:30:57 -07:00
yyforyongyu
df810114cf
lnwallet: add method to compute output indexes
This commit adds a new method, findOutputIndexesFromRemote to compute
the our/their output indexes. As we will see in the following commit,
saving these two fields(4+4=8 bytes) will end up saving us some disk
space.
2022-04-20 01:18:13 +08:00
Oliver Gugger
7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
Oliver Gugger
895a2e497b
multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
Oliver Gugger
ffee7d1bcf
multi: fix newly detected linter issues 2022-02-10 11:02:02 +01:00
Dimitris Apostolou
530a2059e5
multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
Wilmer Paulino
8cfb53f64a
lnwallet: support transactions and scripts for new commitment type
This commit modifies the channel state machine to be able to derive the
proper commitment and second-level HTLC output scripts required by the
new script-enforced leased channel commitment type.
2021-10-19 18:30:32 -07:00
Wilmer Paulino
01e9bb2bff
lnwallet: coalesce different supported output scripts into single method 2021-10-19 18:30:30 -07:00
eugene
7d16e58b5c
lnwallet: introduce GetDustSum method to calculate worst-case dust sum
It over-estimates the local or remote commitment's dust sum by
counting all updates in both updateLogs that are dust using the
trimmed-to-dust mechanism if applicable. The over-estimation is done
because ensuring an accurate counting is a trade-off between code
simplicity and accuracy.
2021-09-30 13:44:26 -04:00
eugene
bc238ee84c
lnd+lnwallet: make capacity check stricter by adding fee
Also patches breacharbiter tests by using the correct commitment
fee and balances.
2021-02-22 12:07:21 -05:00
Johan T. Halseth
0fd76e53b8
multi: cap anchors feerate at configurable maximum
This commit caps the update fee the initiator will send when the anchors
channel type is used. We do not limit anything on the receiver side.

10 sat/vbyte is the current default max fee rate we use. This should be
enough to ensure propagation before anchoring down the commitment
transaction.
2020-12-15 19:54:50 +01:00
Johan T. Halseth
d5cd9861d2
channeldb+lnwallet: define zero-fee channel type 2020-12-15 10:13:07 +01:00
Johan T. Halseth
1e68cdc8cf
input+lnwallet+contractcourt: define SignDetails for HTLC resolutions 2020-12-10 14:24:18 +01:00
Johan T. Halseth
a48c369250
lnwallet: check coop close fee negative balance
Also modify the test to check for this condition.
2020-09-11 11:10:58 +02:00
Johan T. Halseth
09a126b29f
lnwallet: add anchor size back to balance on coop close
To be spec compliant, we require the initiator to not pay the anchor
values into fees on coop close. We extract the balance calculation into
commitment.go, and add back the value of the anchors to the initiator's
balance.
2020-09-11 11:10:58 +02:00
Johan T. Halseth
07a57ae778
lnwallet: extract coop close balance calc into method 2020-09-11 11:10:58 +02:00
Conner Fromknecht
3ea3b1d0b5
lnwallet/channel: tie-break HTLCs by cltv when locating
This commit fixes #4118 by properly sorting the HTLC signatures sent
over the wire to match the BOLT3 BIP69+CLTV sorting of the commitment
outputs.

To do so, we expose the slice of cltv deltas for HTLCs on the unsigned
commitment after applying the commitment sorting. This will be used to
locate the proper output index, as the CLTV serves as a tie breaker
between HTLCs that otherwise have the same payment hash and amount.

Note that #3412 fixed the issue partially by ensuring the commitment was
constructed properly (and the second-level prev outpoint's txid was
correct), but failed to address that the HTLC signatures were still sent
out in the incorrect order. With this, we pass the test case introduce
in the next commit.
2020-04-02 17:51:02 -07:00
Conner Fromknecht
294e13eefc
lnwallet/commitment: split our/theirBalance comment 2020-04-02 17:51:02 -07:00
Olaoluwa Osuntokun
de2fefe52a
lnwallet+lncfg: fix typos 2020-03-16 17:07:21 -07:00
Johan T. Halseth
b7885dbbae
lnwallet+size: select HTLC fees based on channel type 2020-03-09 12:59:35 +01:00
Johan T. Halseth
c5d58b4762
lnwallet: set 2nd level sequence according to channel type 2020-03-09 12:59:33 +01:00
Johan T. Halseth
bddd3e128c
lnwallet: make second level sigs using sighash single|anyonecanpay 2020-03-09 12:59:33 +01:00
Johan T. Halseth
6810912c86
lnwallet: choose HTLC scripts based on channel type 2020-03-09 12:59:33 +01:00
Johan T. Halseth
ea94dbbe34
input+lnwallet: use individual commit weight calculations for channel type
Based on the channel type, the commitment weight will be calculated.
2020-03-09 12:10:59 +01:00