Commit Graph

1266 Commits

Author SHA1 Message Date
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
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
Oliver Gugger
f2e0ed19ff
lnwallet+fundingmgr: ignore shim channels in pending count
Externally funded channels are expected by the user and explicitly
registered through the use of a funding shim and should therefore not
count towards the max pending channel count which is primarily there to
mitigate DoS attacks.
2020-08-28 12:28:43 +02:00
Wilmer Paulino
a85c4feb17
btcwallet: skip unsupported addresses in ListTransasctionDetails
A transaction with an unsupported address would prevent the method from
returning any other transactions and would instead return an error.
2020-08-25 11:21:29 -07:00
Conner Fromknecht
fd3f7ca6c8
Merge pull request #4434 from carlaKC/labels-general
multi: add labels to lnd native transactions
2020-08-20 12:58:04 -07:00
Joost Jager
f7d85555a4
lnwallet/test: add anchor vector for no local anchor 2020-08-19 08:44:04 +02:00
Joost Jager
a682e3cb7e
lnwallet/test: add anchor vector for no remote anchor 2020-08-19 08:44:02 +02:00
Joost Jager
793b21b79e
lnwallet/test: make use of test htlcs explicit
Previously whether or not to add test htlcs was implictly controlled by
a nil value of the HtlcDescs test parameter. With the conversion to
json, that nil value got lost.

The reason that the test still passed is because with the fee rate of
the no-htlc test case, the htlcs were trimmed. Also because in the test
json, balances are specified after applying htlcs, the test didn't fail
with a mismatching balance.
2020-08-19 08:44:00 +02:00
Olaoluwa Osuntokun
e860a9e23d
lnwallet: ensure ConfirmedBalance holds the coin select mutex
In this commit, we make a new wrapper method around the internal
`WalletController` method to ensure it holds the coin select mutex while
the balance is being computed.
2020-08-13 13:01:00 -07:00
nsa
c36840c2a5 lnwallet: add regression test TestChannelLocalUnsignedUpdatesFailure
This commit includes a regression test that checks that we remember
to restore updates that we sent to the peer but they haven't sent
us a signature for yet.
2020-07-29 19:03:44 -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
carla
2a614cc596
multi: add labels to lnd native transactions
Follow up labelling of external transactions with labels for the
transaction types we create within lnd. Since these labels will live
a life of string matching, a version number and rigid format is added
so that string matching is less painful. We start out with channel ID,
where available, and a transaction "type". External labels, added in a
previous PR, are not updated to this new versioned label because they
are not lnd-initiated transactions. Label matching can check this case,
then check for a version number.
2020-07-29 13:46:07 +02:00
nsa
b6eff5b0ec lnwallet: add regression test TestChannelUnsignedAckedFailure
This commit includes a regression test that checks that a force
close won't occur and that unsigned acked updates are properly
restored.
2020-07-27 16:18:11 -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
2149157d49 channeldb: filter out unsigned acked updates in AdvanceCommitChainTail
This commit moves the deletion of all updates under the unsigned
acked updates key from AppendRemoteCommitChain to
AdvanceCommitChainTail. This is done because if we went down after
signing for these updates but before receiving a revocation, we would
incorrectly reject their commitment signature:

Alice                Bob
      -----add----->
      -----sig----->
      <----rev------
      <----sig------
      -----rev----->
      <----fail-----
      <----sig------
      -----rev----->
      -----sig----->
      *reconnect*
      <----rev------
      <----add------
      x----sig------

It is also important to note that filtering is required when we
receive a revocation to ensure that we aren't erroneously deleting
remote updates. Take the following state transitions:

 Alice                Bob
       -----add----->
       -----sig----->
       <----rev------
       <----sig------
       -----rev----->
       -----add----->
       -----sig----->
       <----fail-----
       <----sig------
       -----rev-----> (alice stores updates here)
       <----rev------

In the above case, if Alice deleted all updates rather than filtering
when receiving the final revocation from Bob, then Alice would have
to force close the channel due to missing updates. Since Alice hasn't
signed for any of the unsigned acked updates, she should not filter any
of them out.
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
Olaoluwa Osuntokun
14a047ffba
Merge pull request #4455 from cfromknecht/psbt-no-publish
PSBT: add no_publish flag for safe batch channel opens v2
2020-07-20 12:04:10 -07:00
Conner Fromknecht
7e08322d40
chainntfns: rename to CacheConfig and QueryDisabled 2020-07-14 19:24:44 -07:00
Conner Fromknecht
b907035438
Merge pull request #4412 from aantonop/height_hint_cache_query_disable
New config option - disable height hint cache queries
2020-07-14 18:58:15 -07:00
Oliver Gugger
56b916a313
lnwallet: don't publish funding TX if flag set on assembler
The first channels of a batch shouldn't publish the batch TX
to avoid problems if some of the funding flows can't be completed.
Only the last channel of a batch should publish. We set the channel flag
accordingly depending on the flag in the assembler.
2020-07-08 17:13:14 -07:00
Oliver Gugger
258996233f
lnwallet+rpcserver: add no_publish flag to PSBT assembler 2020-07-08 17:12:57 -07:00
Joost Jager
16577d7d0e
lnwallet/test: anchor test vectors 2020-07-06 12:45:17 +02:00
Joost Jager
1c775d131b
lnwallet/test: close database after test 2020-07-06 12:45:15 +02:00
Joost Jager
c65f60b101
lnwallet/test: convert test vectors to json 2020-07-06 12:45:13 +02:00
Wilmer Paulino
6075997ebc
multi: add relative thaw height interpretation
This is useful when we wish to have a channel frozen for a specific
amount of blocks after its confirmation. This could also be done with an
absolute thaw height, but it does not suit cases where a strict block
delta needs to be enforced, as it's not possible to know for certain
when a channel will be included in the chain. To work around this, we
add a relative interpretation of the field, where if its value is below
500,000, then it's interpreted as a relative height. This approach
allows us to prevent further database modifications to account for a
relative thaw height.
2020-07-02 12:05:49 -07:00
Andreas M. Antonopoulos
61ea9fad78 New config option - disable height hint cache queries
typo broke test


leftover junk


Fix to comply with linter 

and also, D'oh conditional
2020-06-26 21:40:00 -04:00
yyforyongyu
987edc9d81 multi: add a rpc endpoint to track the recovery process 2020-06-25 15:49:54 +08:00
Olaoluwa Osuntokun
bd1728606b
Merge pull request #4328 from joostjager/anchor-test-vectors
lnwallet/test: reproduce test vectors in commit and htlc tx test
2020-06-23 16:09:05 -07:00
Conner Fromknecht
5eb798a23e
Merge pull request #4365 from Crypt-iQ/chancloser_pkg_0609
lnwallet/chancloser: cooperative channel closure pkg
2020-06-18 13:38:41 -07:00
Joost Jager
f1fbdb1b84
lnwallet/test: remove unused index field 2020-06-17 22:59:14 +02:00
Joost Jager
24e1126776
lnwallet/test: reproduce test vectors in commit and htlc tx test
This commit changes the verification of our code against the spec test
vectors to use a more black box approach. It exercises the channel state
machine via its external interface as much as possible, making this test
more robust. A consequence of this is that the test now runs from the
'root' data from which the test vectors are also derived, meaning that
more code is covered too.

Running from the root data is also a preparation for _producing_ test
vectors for the new anchor commitment format. This will be a matter of
changing the channel type and recording the produced commitment and htlc
txes.

Previously the success transaction was skipped during verification. With
this commit, the proper preimage insertion is carried out, allowing the
success tx to be checked too.
2020-06-17 22:59:12 +02:00
nsa
2d68a64a5b chancloser: new package for cooperative channel closure
Introduces a new chancloser package which exposes a ChanCloser
struct that handles the cooperative channel closure negotiation
and is meant to replace chancloser.go in the lnd package. Updates
all references to chancloser.go to instead use chancloser package.
2020-06-16 20:34:44 -04:00
Joost Jager
4e945f6083
lnwallet/test: name test cases 2020-06-15 13:51:07 +02:00
Joost Jager
8b55c10e45
lnwallet/test: name testCase struct 2020-06-15 13:51:05 +02:00
Joost Jager
997bab0343
lnwallet/test: move htlcDesc struct 2020-06-15 13:51:03 +02:00
Joost Jager
c27406b579
lnwallet/test: move test htlcs out of function 2020-06-15 13:51:01 +02:00
Joost Jager
98ec8bf502
lnwallet/test: move test cases out of function 2020-06-15 13:50:59 +02:00
Joost Jager
3b7f084509
lnwallet/test: remove impossible test case
In this test case, the funder cannot pay the commit fee.
2020-06-15 13:50:57 +02:00
Joost Jager
4421894c4c
lnwallet/test: remove zero fee test case
This is currently not supported in lnd.
2020-06-15 13:50:55 +02:00
Wilmer Paulino
2a5b66ec00
lnwallet: note requirement of global coin selection lock 2020-06-12 11:22:30 -07:00
Wilmer Paulino
9d9e54f83e
btcwallet: ensure output isn't locked by in-memory impl in LeaseOutput
The current implementation of LeaseOutput already checked whether the
output had already been leased by the persisted implementation, but not
the in-memory one used by lnd internally. Without this check, we could
potentially end up with a double spend error if lnd acquired the UTXO
internally before the LeaseOutput call.
2020-06-12 11:22:28 -07:00
Wilmer Paulino
ae7335ce3b
lnwallet: expose output leases on WalletController interface 2020-06-03 18:49:39 -07:00
carla
baeef63aab
lnwallet: add label transaction to WalletController interface 2020-05-25 08:38:05 +02:00
Olaoluwa Osuntokun
53da66a6fc
Merge pull request #4302 from wpaulino/btcwallet-fetchinputinfo-bounds-check
btcwallet: add transaction outputs bounds check to FetchInputInfo
2020-05-21 17:22:25 -07:00
Wilmer Paulino
f287ac3cea
btcwallet: add transaction outputs bounds check to FetchInputInfo
This prevents a panic when providing an incompatible output index for
the transaction.
2020-05-20 11:42:12 -07:00
carla
e8ca306f12
lnrpc: display transaction label in transaction details 2020-05-19 13:31:51 +02:00
carla
099161ed0b
multi: add label to WalletController SendOutputs and dependent rpcs
Add a label parameter to the WalletController SendOutputs endpoint and
update rpcs that use it to allow optional provision of labels.
2020-05-19 13:31:51 +02:00
carla
75370ce6b4
multi: update WalletController PublishTransaction to include label
Add label parameter to PublishTransaction in WalletController
interface. A labels package is added to store generic labels that are
used for the different types of transactions that are published by lnd.

To keep commit size down, the two endpoints that require a label
parameter be passed down have a todo added, which will be removed in
subsequent commits.
2020-05-19 13:30:00 +02:00
Wilmer Paulino
0e3fc4c7a6
build: update to latest btcd and btcwallet versions
This update introduces backwards compatibility for btcd nodes running
versions prior to v0.20.1-beta.
2020-05-15 17:00:16 -07:00
Joost Jager
7c4e57c53d
lnwallet: return signer error 2020-05-12 13:33:50 +02:00
carla
537dac3c62
multi: specify start and end height for ListTransactionDetails
Add start and end height parameters to the rpc and cli GetTransactions
endpoints. Default to returning all transactions from genesis to tip,
including unconfirmed transactions to maintain backwards compatibility.
2020-05-05 21:10:06 +02:00
carla
2a3d1cb6fa
lnwallet/test: add tests for process fee update and add and remove 2020-05-03 14:10:33 +02:00
carla
3743fc6cf4
lnwallet/test: add unit test for evaluateHtlcView 2020-05-03 14:10:01 +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
Andras Banki-Horvath
e9d7ba635c lnwallet: remove redundant return 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
Conner Fromknecht
2b2c8b5a10
lnwallet/interface_test: wait for bitcoind startup
Flakes locally for me on darwin.
2020-04-09 12:49:07 -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
b0c3072ff7
lnwallet/channel_test: assert commit sorting of commit diff htlcs
This commit adds a test to exercise that HTLC signatures are sent in the
correct order, i.e. they match the sorting of the HTLC outputs on the
commitment after applying BOLT 3's BIP69+CLTV sort.
2020-04-02 17:51:02 -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
294e13eefc
lnwallet/commitment: split our/theirBalance comment 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
Oliver Gugger
5a52420ab6
lnwallet+fundingmgr: interrupt funding flow for PSBT
In case the funding manager detects that a funding flow is requested
to be executed with the help of a PsbtIntent, the normal channel
negotiation with the remote peer is interrupted, as soon as the
accept_channel message was received. With the remote peer's funding
multisig key and our local key, we can derive the funding output
script and its address. This is enough to start the PSBT funding
and signing process which the user will do externally to the daemon.
2020-03-31 09:17:24 +02:00
Oliver Gugger
126f79dbb1
chanfunding: add PSBT assembler and intent
We add a new funding assembler and intent type that handle channel
funding through the use of a PSBT. The PsbtIntent is in itself a
simple state machine that can be stepped through the process of
assembling the required information for the funding output, verifying
a user supplied PSBT for correctness, accepting a fully signed PSBT
and then assembling the funding wire message.
2020-03-31 09:17:23 +02:00
Olaoluwa Osuntokun
1c398d5f26
Merge pull request #4078 from yyforyongyu/bitcoind-estimatemode
multi: support config bitcoind fee estimate mode
2020-03-26 16:21:17 -07:00
yyforyongyu
97da7b3444 multi: support config bitcoind fee estimate mode 2020-03-25 14:59:23 +08:00
Oliver Gugger
95a6796778
lnwallet/btcwallet: use fast scrypt options in itest 2020-03-24 09:52:40 +01:00
Olaoluwa Osuntokun
c85f6bb364
lnwallet: mark channel as frozen based on ShimIntent
In this commit, we make the internal channel funding flow aware of
frozen channels. We also update the testSingleFunderReservationWorkflow
method to ensure that the created channels have the proper type bit set.
2020-03-23 16:57:00 -07:00
Olaoluwa Osuntokun
8bce48d3cc
lnwallet/chanfunding: add new ThawHeight() method to ShimIntent+CannedAssembler
As frozen channels can only be created via the non-default channel
assembler, we extend both the ShimIntent and CannedAssembler to also
accept and expose this new channel status along with the thaw height.
2020-03-23 16:56:57 -07:00
Johan T. Halseth
c1d00a0c9b
Merge pull request #4101 from ErikEk/typo_fixes_trivial
trivial: typo fixes
2020-03-19 21:36:38 +01:00
ErikEk
4e47181b99 trivial: typo fix 2020-03-19 05:43:49 +01:00
Olaoluwa Osuntokun
98170e00ef
lnwallet: convert to use new kvdb abstraction 2020-03-18 19:35:13 -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
Joost Jager
30fc03d84d
lnwallet/test: pass in test channel type 2020-03-17 14:19:33 +01:00
Olaoluwa Osuntokun
de2fefe52a
lnwallet+lncfg: fix typos 2020-03-16 17:07:21 -07:00
Olaoluwa Osuntokun
3dda93e30d
Merge pull request #3821 from halseth/pluggable-anchors-lnwallet
[anchor] pluggable anchor commitments
2020-03-09 19:49:05 -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
ea2a58e80f
fundingmanager+lnwallet: enable anchor commitments
If both nodes are signalling the feature, make all opened channels using
this type.
2020-03-09 12:59:35 +01:00
Johan T. Halseth
f95a82bf5f
lnwallet+funding: create CommitmentType enum 2020-03-09 12:59:34 +01:00
Johan T. Halseth
8741b93723
lnwallet/reservation: add non-initiator balance check
If we are the initiator, we check that our starting balance after
subtracting fees are not less than two times the default dust limit.

This commit adds a similar check for the non-initiator case, checking
that the remote party has a starting balance of reasonable size.
2020-03-09 12:59:34 +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
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
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
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
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
Conner Fromknecht
4c2bc7bc79
lnwallet+input: move size_test.go to input pkg 2020-03-04 08:01:37 -08:00
Conner Fromknecht
4c402ab9d4
lnwallet/size_test: refactor and expand unit tests 2020-03-04 08:00:48 -08:00
Conner Fromknecht
be74d94c48
lnwallet/size_test: add test exercising nested input count bug
This commit modifies the NP2WKH and NP2WSH input tests to ensure the
input count is properly incremented and accounted for in the size
estimate. 253 is chosen because it is the lowest value that, when
serialized, occupies more than one byte on the wire.
2020-03-04 08:00:09 -08: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
Johan T. Halseth
f94464d987
lnwallet: take remote initiator's balance into account
When we send non-dust HTLCs as the non-initiator, the remote party will
have to pay the extra commitment fee. To account for this we figure out
if they can afford paying this fee, if not we report that we only have
balance available for dust HTLCs, since these HTLCs won't increase the
commitment fee.
2020-02-19 12:27:42 +01:00
Johan T. Halseth
9ff79ae595
lnwallet/channel: account for HTLC fee when reporting available balance 2020-02-19 12:27:42 +01:00
Johan T. Halseth
5e89d5b6c2
link+lnwallet: move bandwidth channel reserve validation into channel
Since we want to handle the edge case where paying the HTLC fee would
take the initiator below the reserve, we move the subtraction of the
reserve into availableBalance where this calculation will be performed.
2020-02-19 12:27:42 +01:00
Johan T. Halseth
58dec10680
lnwallet/channel: break up availableBalance 2020-02-19 12:27:41 +01:00
Johan T. Halseth
0d9a1b8656
lnwallet: check local commitment sanity when adding HTLC
This commit adds an extra validation step when adding HTLCs. Previously
we would only validate the remote commitment resulting from adding an
HTLC, which in most cases is enough. However, there are situations where
the dustlimits are different, which could lead to the resulting remote
commitment from adding the HTLC being valid, but not the local
commitment.

Now we also validate the local commitment. A test to trigger the case is
added.
2020-02-19 12:27:41 +01:00
Johan T. Halseth
4ea822efeb
lnwallet tests: add test for dipping remote below chan reserve
This commit adds a test that was previously not performed, namely that
adding a HTLC would dip the remote initiator below its channel reserve.
2020-02-19 12:27:41 +01:00
Johan T. Halseth
05fb272deb
lnwallet/channel: make validateCommitmentSanity take our/their predict
add

To ba able to validate the commitment sanity both for remote and local
commitments, and at the same time predict both our and their add, we let
validateCommitmentSanity take an extra payment descriptor to make this
possible.
2020-02-19 12:27:41 +01:00
Olaoluwa Osuntokun
92b79f6b6a
Merge pull request #3910 from Crypt-iQ/htlc_add_0113
lnwallet: limit received htlc's to MaxAcceptedHTLCs
2020-02-18 17:35:42 -08:00
nsa
5a5e095684
lnwallet: adding TestMaxAsynchronousHtlcs unit test
Adds a new test which asserts that the new ReceiveHTLC logic can
handle proper commitment overflow calculation in the face of
asynchronous updates.
2020-02-15 09:59:50 -05:00
nsa
4af00c6b25
lnwallet: fixing unit tests to properly handle new receive validation
This commit fixes the TestMaxAcceptedHTLCs, TestMaxPendingAmount,
TestMinHTLC, & TestChanReserve unit tests to pass with the new
ReceiveHTLC logic. Instead of asserting specific failures upon
receiving a new commitment signature, the various assertions were
moved to assert on the error returned from ReceiveHTLC.
2020-02-15 09:59:50 -05:00
nsa
56c07a52d8
lnwallet: call valdiateCommitmentSanity in ReceiveHTLC
This commit checks the commitment sanity when receiving an HTLC so
that if a commitment transaction will overflow from an ADD, it is
caught earlier rather than in ReceiveNewCommitment.
2020-02-15 09:59:49 -05:00
Johan T. Halseth
5943e5d8b1
lnwallet: state transition from correct node during test, remove panic
The unit test TestNewBreachRetributionSkipsDustHtlcs triggered a state
transition from Bob, even though it was Alice that had added the HTLCs.
This is wrong since it will lead to Bob still owing Alice a commitment,
which is not accounted for in the unit tests.

We add a sanity check that the add heights has been set for all entries
found in the logs, and return an error otherwise. This won't happen
during normal operation, but it does reveal the mistake in the unit
test, which is fixed by making Alice trigger the transition.

In addition we resolve a long standing TODO by removing a (purposeful)
panic in the channel state machine. Old version of lnd had a bug that
could lead to the parent entries being lost during channel restore. A
panic was added to get to the bottom of if.

This is now fixed, so new nodes shouldn't encounter it. However, to be
on the safe side, instead of panicking we return an error back to
gracefully exit the channel state machine.
2020-02-12 11:10:19 +01:00
Johan T. Halseth
e114f58b5e
lnwallet: unify remote and local update log fetch 2020-02-12 11:10:18 +01:00
Joost Jager
88eae6eafe
lnwallet: fix invalid value use in restoreUpdate
Updates were always restored with the same log index. This could cause a
crash when the logs were compacted and possibly other problems
elsewhere.

Extended unit test to cover the crash scenario.
2020-02-10 13:56:33 +01:00
Joost Jager
1413995ab7
Merge pull request #3872 from joostjager/invalid-sig-fix
htlcswitch+lnwallet+channeldb: invalid sig fix
2020-01-23 21:08:07 +01:00
Joost Jager
82579400b3
lnwallet: restore unsigned acked remote updates
This commit updates the channel state machine to
persistently store remote updates that we have received a
signature for, but that we haven't yet included in a commit
signature of our own.

Previously those updates were only stored in memory and
dropped across restarts. This lead to the production of
an invalid signature and channel force closure. The remote
party expects us to include those updates.
2020-01-15 13:09:35 +01:00
Joost Jager
ed8fa35ed4
lnwallet: extract pending local updates restore method
Extract method in preparation for restoring dangling remote updates. We
need to get rid of the early return.
2020-01-15 12:37:26 +01:00
Joost Jager
6a866890a8
lnwallet/test: test remote update after restart
This test asserts that remote updates that are locked-in on the local
commitment, but haven't been signed for on the remote commitment, are
properly restored after a restart.
2020-01-15 12:37:20 +01:00
Joost Jager
41c207e247
lnwallet/test: describe existing bug after restart with dangling remote updates 2020-01-06 15:30:23 +01:00
Joost Jager
b3bd470962
lnwallet: restore missing field in local log update
When restoring an htlc fulfill update from disk, the payment hash wasn't
restored previously.
2020-01-06 15:13:21 +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
Johan T. Halseth
fff9dbe6f3
lnwallet: pass chan cfgs to CreateCommitTx
Instead of passing delays and dustlimits separately, we pass the correct
channel config to CreateCommitTx from the POV of the local party that
owns the commit tx.

To make it more clear which commitment we are actually creating, we
rename variables to denote local and remote, to prepare for the case
when both outputs might be delayed.
2020-01-06 11:42:03 +01:00
Johan T. Halseth
1a4f81ed90
lnwallet: remove duplicate chanCfg fields, use channelState 2020-01-06 11:42:02 +01:00
Johan T. Halseth
e2b050aca3
lnwallet: make addHtlc non-LightningChannel method
It has no dependency on LightningChannel
2020-01-06 11:42:02 +01:00
Johan T. Halseth
f0019006a7
lnwallet: remove unused initiator param to CreateCooperativeCloseTx 2020-01-06 11:42:02 +01:00
Johan T. Halseth
2c46640dd0
channeldb+lnwallet: note that balance is after subtracting commit fee
It was incorrectly stated that the commitment balance was before
subctracting the commit fee, which led to some confusion.
2020-01-06 11:42:02 +01:00
Olaoluwa Osuntokun
7eacc40419
Merge pull request #3722 from Roasbeef/external-funding-rpc
lnrpc+lnwallet+funding: implement new RPCs to enable external channel funding
2019-12-23 14:41:46 -06:00
Matheus Degiovani
5dffa7da1c lnwallet: Re-enable tests
Tests were erroneously disabled in commit b1940d67.
2019-12-23 10:32:03 -03:00
Matheus Degiovani
02d616d9b7 lnwallet: Fix external funding test 2019-12-23 10:31:03 -03:00
Olaoluwa Osuntokun
bc176b5aa3
rpc+lnwallet: implement new FundingStateStep RPC method
In this commit, we implement the currently defined transition methods
for the new `FundingStateStep` method. At this point, we're now able to
serve the "responder" of the externally initiated channel funding flow
by being able to register and cancel a funding flow according to its
expected pending channel ID.
2019-12-20 19:09:44 -08:00
Conner Fromknecht
f3398c0c0e
Merge pull request #3789 from cfromknecht/coop-close-rpc-status
republish force and coop closes on startup
2019-12-05 10:35:53 -08:00
Conner Fromknecht
d9cf0396b3
peer+chancloser: mark coop broadcasted 2019-12-04 14:25:28 -08:00
carla
9b35c349de
multi: Set upfront shutdown from open and accept chanel messages
This commit gets upfront shutdown scripts from openchannel and
acceptchannel wire messages sent from our peer and sets upfront
shutdown scripts in our open and accept channel messages when
the remote peer supports option upfront shutdown and we have
the feature enabled.
2019-12-03 11:38:29 +02:00