Commit Graph

494 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
af43a863cb
lnwallet: ensure MayAddOutgoingHtlc doesn't add zero-value HTLCs
In this commit, in order to allow the test added in the prior commit to
pass, we'll increment the mockHTLCAmt value by 1 to ensure we never
attempt to add a zero value HTLC.

Fixes #5468
2021-07-06 16:50:19 -07:00
yyforyongyu
adddc1442e
multi: refactor NewAnchorResolutions to return fixed values
This commit adds a new struct AnchorResolutions which wraps the anchor
resolutions for local/remote/pending remote commitment transactions. It
is then returned from NewAnchorResolutions. Thus the caller knows how to
retrieve a certain anchor resolution.
2021-06-29 20:25:47 +08:00
yyforyongyu
21626fed7c
lnwallet: remove unused variable zeroHash 2021-06-29 20:25:46 +08:00
carla
5d717cb039
multi: surface may add outgoing hltc 2021-06-22 13:56:08 +02:00
carla
e3a4d6e989
lnwallet: refactor add htlc sanity checks to separate methods 2021-06-22 13:56:07 +02:00
eugene
7da2080a3d
lnwallet: use tail() instead of tip() in getUnsignedAckedUpdates
The previous behavior would allow updates to be overwritten in some
scenarios. Upon restart, this would lead to a missing settle/fail in
the update logs.
2021-04-21 17:42:56 -04:00
eugene
97007fc4fa
lnwallet: fix logUpdate scope in restorePendingLocalUpdates 2021-04-21 17:42:56 -04:00
Johan T. Halseth
2bc37db61a
lnwallet: export HTLC generating methods 2021-03-05 10:58:42 +01:00
eugene
9b09895bde
channeldb+lnwallet: lastWasRevokeKey to store last sent rev/sig 2021-02-03 16:43:04 -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
1e68cdc8cf
input+lnwallet+contractcourt: define SignDetails for HTLC resolutions 2020-12-10 14:24:18 +01:00
Johan T. Halseth
eb8d22e194
lnwallet/channel: properly set SignDesc.Output
Only value was populated for some, which would cause code to rely on the
PkScript being there to fail.
2020-12-10 14:24:18 +01:00
Johan T. Halseth
2a7a34ae10
contractcourt+lnwallet: use state num instead of commit height when
outdated local state

This commit fixes a bug that would cause us to not sweep our local
output in case we force closed, then lost state or attempted recovery.
The reason being that we would use or local commit height when deriving
our scripts, which would be incorrect. Instead we use the extracted
state number to derive the correct scripts, allowing us to sweep the
output.

Allthough being an unlikely scenario, we would leave money on chain in
this case without any warning (since we would just end up with an empty
delay script) and forget about the spend.
2020-12-03 08:01:08 +01:00
Johan T. Halseth
953443e10c
lnwallet/channel: correct dust calculation on incoming HTLC
Similar to the previous commit, we fix a bug resulting in the wrong
commit weight being calculated when an HTLC just above the remote's
duslimit was added from the remote. This was a result of using the
successFee instead of the timeoutFee when checking whether it was dust,
making us consider it dust when it shouldn't have been.
2020-11-13 12:02:03 +01:00
Johan T. Halseth
e0b133297d
lnwallet/channel: correct dust calculation on outgoing HTLC
In this commit we fix a bug resulting in the wrong commit weight being
calculated when an HTLC just below the remote's duslimit was added. This
was a result of using the timeoutFee instead of the successFee when
checking whether it was dust, making us consider it non-dust when it
should have been.
2020-11-13 11:58:52 +01:00
Joost Jager
29602e88e8
cnct: cpfp-sweep anchors
For unconfirmed commit tx anchors, supply the sweeper with cpfp info and
a confirmation target fee estimate.

The sweeper will try to pay for the parent commit tx as long as the
current fee estimate exceeds the pre-signed commit tx fee rate.
2020-09-17 12:30:41 +02: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
07a57ae778
lnwallet: extract coop close balance calc into method 2020-09-11 11:10:58 +02:00
eugene
62e19185f1 htlcswitch+channeldb: single tx for removing fwdpkgs
This commit changes RemoveFwdPkg to RemoveFwdPkgs so that a single
tx is used instead of N where N is the number of fwd pkgs to remove.
2020-08-31 20:52:51 -04:00
nsa
e4188ba9c2 channeldb+lnwallet: store updates the peer should sign under new key
This fixes a long-standing force close bug. When we receive a
revocation, store the updates that the remote should sign next under
a new database key. Previously, these were not persisted which would
lead to force closure.
2020-07-29 19:03:44 -04:00
nsa
8c002a08a7 lnwallet: properly restore removeCommitHeightRemote
Previously, we could sign a pending commitment for the remote party,
disconnect, and not restore these signed remote updates as having been
removed at the pending commitment height. This commit fixes that to
look up whether the update under the unsigned acked updates key is
present on the pending commitment or not and appropriately set
the remove commit heights.
2020-07-27 15:41:48 -04:00
nsa
3ec081af84 lnwallet: correct fetchParent godoc 2020-07-21 10:45:57 -04:00
nsa
73757eb84d lnwallet: properly set addCommitHeightLocal in restoreStateLogs
The `restoreStateLogs` function now properly restores the
`addCommitHeightLocal` field of a settle or fail's parent add.
Previously, any updates' parent in unsignedAckedUpdates would have
the field set to the default value of 0. This would cause a force
closure when receiving a commitment due to our belt-and-suspenders
checks for update logs during commitment validation.

The bug in question occurs because the `addCommitHeightLocal` field
is only populated for a restored add if the add is on the local
commitment. `TestChannelRestoreCommitHeight` is expanded in
`lnwallet/channel_test.go` to demonstrate restoration now works.

The faulty state transition:
```
<----fail----
<----sig-----
-----rev----> (add no longer on Alice's commitment)
*Alice restores* (addCommitHeightLocal of failed htlc is 0)
```

NOTE: Alice dies after sending a revocation but before signing a
commitment. This is possible because there is a select block in the link
that can potentially exit after sending over the revocation but before
signing the next commitment state for the counterparty.
2020-07-21 10:45:57 -04:00
Joost Jager
7c4e57c53d
lnwallet: return signer error 2020-05-12 13:33:50 +02:00
carla
54a06cb96a
lnwallet: extract fetchparent for individual testing 2020-05-03 14:09:58 +02:00
Andras Banki-Horvath
556e3525ea misc: fix error formatting in multiple files 2020-04-24 19:15:08 +02:00
Conner Fromknecht
89bd58786e
lnwallet/channel: enforce absolute fee floor of 250 sat/kw
This enforces the _actualized_ fee rate of the  commitment transaction,
rather than the fee floor used for estimation. The new value of 250
sat/kw corresponds to 1 sat/byte, rather than 253 which is only rounded
up during estimation to account for the fact that BOLT 3 rounds down to
the nearest satoshi and that the vbyte fee estimation is lossy.

Previously we would incorrectly fail to sign the next commitment even
though the fee was technically high enough. Restarting with this commit
should solve the issue as long as the channel hasn't already gone to
chain.
2020-04-21 12:37:34 -07:00
Conner Fromknecht
3ab5899853
lnwallet/channel: fix log typo 2020-04-20 22:12:49 -07:00
Conner Fromknecht
f2b6e2af04
input: pass input.Signature to multisig spend
Modifies SpendMultiSig to accept input.Signature, so that we can
ultimately assert the size of multisig witnesses.
2020-04-10 14:27:35 -07:00
Conner Fromknecht
0f94b8dc62
multi: return input.Signature from SignOutputRaw 2020-04-10 14:27:35 -07:00
Conner Fromknecht
37dffb225a
input: introduce Signature iface
This commit introduces the Signature interface which will be used by our
witness construction methods instead of passing in raw byte slices. This
will be used later to inject various kinds of mock signatures, e.g.
73-byte signatures for simulating worst-case witness weight.
2020-04-09 12:49:11 -07:00
Olaoluwa Osuntokun
173f7d88e0
Merge pull request #4121 from cfromknecht/sort-htlc-sigs
lnwallet: apply BIP69+CLTV tie-break to HTLC signature order
2020-04-03 18:12:58 -07:00
Conner Fromknecht
3f4dc0decd
lnwallet/channel: increase htlc validation strictness
This commit adds an additional santity check that rejects zero-value
HTLCs, preventing them from being added to the channel state even if the
channel config's minhtlc value is zero.
2020-04-02 18:03:06 -07: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
97761833d2
lnwallet/channel: populate htlc indexes from disk commit
We currently write each HTLCs OutputIndex to disk, but we don't use it
when restoring. The restoration is modified to use these directly, since
we will have lost access to the sorting of CLTVs after the initial
signing process.
2020-04-02 17:50:59 -07:00
Conner Fromknecht
9385b8cdc6
channeldb+lnwallet: move ActiveHtlcs calc to OpenChannel 2020-04-02 17:39:10 -07:00
Conner Fromknecht
422928b8a3
lnwallet/channel: remove unused RemoteCommitHeight method 2020-04-02 17:38:54 -07:00
Johan T. Halseth
dc6c4637b6
lnwallet+channeldb: add anchor resolutions
Co-authored-by: Joost Jager <joost.jager@gmail.com>
2020-03-17 14:19:35 +01: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
ad8e9f30c6
lnwallet+breacharbiter: record local csv delay 2020-03-09 12:59:34 +01:00
Johan T. Halseth
92af2342da
lnwallet+nursery+input: set sequence=1 for direct HTLC spends 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
21c5a957bc
lnwallet/channel: add feerate sanity check 2020-03-09 12:59:22 +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
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
865776c776
lnwallet/channel: use genHtlcScript to create scripts
It takes into account the necessary variables and will prepare us for
doing commitment type dependent script generation later.
2020-03-09 12:10:57 +01:00
carla
d3cb6ad869
channeldb: store close initiator status
This commit adds two new channel statuses which indicate the party that
initatited closing the channel. These statuses are set in conjunction
with the existing commit broadcast status so that we do not need to
migrate existing logic to handle multiple types of closes. This status
is set for locally initiated force closes in this commit because they
follow a similar pattern to cooparative closes, marking the commitment
broadcast then proceeding with tx broadcast. Remote force closes are
added in the following commit, as they are handled differently.
2020-02-21 13:33:49 +02:00
Johan T. Halseth
3e5f2e437d
lnwallet/channel: add TODO 2020-02-19 12:27:42 +01:00
Johan T. Halseth
e398544b8b
lnwallet/channel: take remote commitment view into availableBalance calculation
Since our HTLC must also be added to the remote commitment, we do the
balance caluclation also from the remote chain perspective and report
our minimum balance from the two commit views as our available balance.
2020-02-19 12:27:42 +01:00