Commit Graph

28 Commits

Author SHA1 Message Date
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
Johan T. Halseth
af68ff1640
lnwallet: add anchor commitmenttype
With this commitment type, we'll add extra anchor outputs to the
commitment transaction if the anchor channel type is active.
2020-03-09 12:10:59 +01:00
Johan T. Halseth
8c0deb81c2
input+lnwallet: Add scripts for CSV delayed HTLC outputs
We also increase the witness size for these types to account for the 3
extra bytes. The size won't be correct in all cases, but it is just an
upper bound in any case.
2020-03-09 12:10:58 +01:00
Johan T. Halseth
6ecb379088
lnwallet: thread chanType down into genHtlcScript, gen[..]SigJobs,
create[..]Tx

NO FUNCTIONAL CHANGES
This is a commit just supplying the channel types to various methods.
2020-03-09 12:10:58 +01:00
Johan T. Halseth
9c3218c51e
lnwallet/channel: reuse derived SingleTweak on local force close
When creating the keyring, the tweak is already calculated in the remote
commitment case. We add the calculation also for our own commitment, so
we can use it in all cases without deriving the tweak.
2020-01-06 12:08:29 +01:00
Johan T. Halseth
3711597fef
input: remove duplicate commit weight constant 2020-01-06 12:08:25 +01:00
Johan T. Halseth
a56ed72bd7
lnwallet: use channel type to derive remote script
Based on the current channel type, we derive the script used for the
to_remote output. Currently only the unencumbered p2wkh type is used,
but that will change with upcoming channel types.
2020-01-06 12:08:19 +01:00
Johan T. Halseth
f92c7a3af0
lnwallet: nil single tweak when creating keyring
To make the channel state machine less concerned about the type of
commitment, we nil the local tweak when creating the keyring, depending
on the commitment type.
2020-01-06 12:08:09 +01:00
Johan T. Halseth
5e3718a1b5
lnwallet: use channel type to derive keys
We abstract away how keys are generated for the different channel types
types (currently tweak(less)).

Intention is that more of the logic that is unique for each commitment
type lives in commitment.go, making the channel state machine oblivious
to the keys and outputs being created on the commitment tx for a given
channel state.
2020-01-06 12:08:05 +01:00
Johan T. Halseth
4fde31229c
lnwallet: rename DelayKey->ToLocalKey, NoDelayKey->ToRemoteKey
Since both parties are going to have their ouputs delayed, we move way
from the DelayKey naming, and instead use ToLocalKey and ToRemoteKey.
2020-01-06 12:08:01 +01:00
Johan T. Halseth
7b9c54996b
lnwallet/commitment: clarify keyring key ownership 2020-01-06 12:07:56 +01:00
Johan T. Halseth
76ce51301e
lnwallet: return instead evaluated commitment instead of mutating
createCommitmentTx would earlier mutate the passed commitment struct
after evaluating the htlc view and calculating the final balances, which
was confusing since the balances are supposed to only be *after*
subtracting fees.

Instead we take the needed parameters as arguments, and return the final
balances, tx and fee to populate the commitment struct in a proper way.
2020-01-06 12:07:49 +01:00
Johan T. Halseth
613d771daf
lnwallet: create CommitmentBuilder
We define a new struct CommitmentBuilder that will be used to craft the
final commitment transaction based on the current active channel type.
2020-01-06 11:42:03 +01:00
Johan T. Halseth
13a108e578
lnwallet: make fundingTxIn not depend on LightningWallet 2020-01-06 11:42:03 +01:00
Johan T. Halseth
83e0d47ba3
lnwallet: move methods to commitment.go
PURE CODE MOVE:
Moving createCommitmentTx, CreateCommitTx, createStateHintObfuscator,
CommitmentKeyRing, DeriveCommitmentKeys, addHTLC, genHtlcScripts

We move the methods and structs to a new file commitment.go in
preparation for defining all the logic that is dependent on the channel
type in this new file.
2020-01-06 11:42:03 +01:00