Commit Graph

1110 Commits

Author SHA1 Message Date
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
carla
77222d8b69
channeldb: Add upfront shutdown script to OpenChannel
This commit adds fields for upfront shutdown scripts set
by the local and remote peer to the OpenChannel struct.
These values are optional, so they are added with their
own keys in the chanBucket in the DB.
2019-12-03 11:38:29 +02:00
carla
f86d63144c
multi: Set and check upfront shutdown address on close
This commit sets our close addresss to the address
specified by option upfront shutdown, if specified,
and disconnects from peers that fail to provide
their upfront shutdown address for coopertaive closes
of channels that were opened with the option set.
2019-12-03 11:38:29 +02:00
Olaoluwa Osuntokun
b1940d6779
lnwallet: fix bug in verifyFundingInputs skip dual funder tests for neutrino
In this commit, we fix a long standing bug within the newly created
`verifyFundingInputs` method. Before this commit, the method would
attempt to derive the pkScript by looking at the last items on the
witness stack, and making a p2wsh output script from that. This is
incorrect as typically non of these scripts will actually be p2wsh, and
instead will be p2wkh. We fix this by using the newly available
`txscript.ComputePkScript` method to derive the proper pkScript.

This resolves an issue w.r.t passing incorrect arguments for all
backends, but an issue still stands for the neutrino backend. As is, we
pass a height hint of zero into the `GetUtxo` method call. With the way
the current utxo scanner is set up for neutrino, this'll cause it to
never find the UTXO, as it takes the height hint as a UTXO birth height,
rather than a lower bound of the birth of the UTXO.
2019-12-02 17:12:05 -06:00
Olaoluwa Osuntokun
6b729ec9f5
lnwallet: break early in TestLightningWallet when a sub-test fails 2019-12-02 17:11:58 -06:00
Olaoluwa Osuntokun
c3a7da5ce7
lnwallet: add new test to exercise external channel funding 2019-12-02 17:11:54 -06:00
Olaoluwa Osuntokun
9926259da0
lnwallet: add new RegisterFundingIntent method
In this commit, we add a new method `RegisterFundingIntent` that allows
a caller to "inject" a pre-populated chanfunding.Intent into a funding
workflow. As an example, if we've already agreed upon the "shape" of the
funding output _outside_ the protocol, then we can use this to pass down
the details of the output, then leverage the normal wire protocol to
carry out the remainder of the funding flow.
2019-12-02 17:11:51 -06:00
Olaoluwa Osuntokun
6e9cbc19f9
lnwallet+funding: pass the pending channel ID into the reservation context
In this commit, we start to thread the pending channel ID from wire
protocol all the way down into the reservation context. This change will
allow negotiation to take place _outside_ the protocol that may result
in a particular chanfunding.Assembler being dispatched.
2019-12-02 17:11:46 -06:00
Olaoluwa Osuntokun
c3157ae2c4
lnwallet: add awareness of chanfunding.ShimIntents
In this commit, we make the wallet aware of the second type of funding
intent: the ShimIntent. If we have one of these, then we don't need to
construct the funding transaction, and can instead just obtain the
outpoint directly from it.
2019-12-02 17:11:41 -06:00
Olaoluwa Osuntokun
7a64a7d3a4
lnwallet: delegate all channel funding logic to the new chanfunding package
In this commit, we begin to integrate the new channel funding package
into the existing codebase. With this set of changes, we'll no longer
construct and sign the funding transaction within this package, instead
delegating it to the new chanfunding package. We use the new
chanfunding.WalletAssembler to carry out all channel funding, providing
it with an implementation of all its interfaces backed by the wallet.
2019-12-02 17:11:36 -06:00
Olaoluwa Osuntokun
d422ebbc66
lnwallet/chanfunding: introduce new channel funding abstractions
In this commit, we introduce a series of new abstractions for channel
funding. The end goal is to enable uses cases that construct the funding
transaction externally, eventually handing the funding outpoint to lnd.
An example of such a use case includes channel factories and external
channel funding using a hardware wallet.

We also add a new chanfunding.Assembler meant to allow external channel
funding in contexts similar to how channel factories
can be constructed. With this channel funder, we'll only obtain the
channel point and funding output from it, as this alone is enough to
carry out a funding flow as normal.
2019-12-02 17:11:32 -06:00
Olaoluwa Osuntokun
4e955dfac6
lnwallet: remove unused openChanDetails struct
We also remove some related and also unused attributes as well along the
way.
2019-12-02 17:11:29 -06:00
Olaoluwa Osuntokun
9eefdef262
chanfunding+lnwallet: move coin selection code into new chanfunding package
In this commit, we make an incremental change to move the existing coin
selection code into a new chanfunding package. In later commits, this
package will grow to serve all the lower level channel funding needs in
the daemon.
2019-12-02 17:11:25 -06:00
Wilmer Paulino
9587a2259f
lnwallet: fix test inconsistencies to support bitcoind 0.19.0
bitcoind's sendrawtransaction API in v0.19.0 now enforces a maximum fee
rate of 0.1 BTC/kb and valid output scripts.
2019-11-12 20:34:37 -08:00
Olaoluwa Osuntokun
86bed393f9
Merge pull request #2927 from joostjager/hodl-drop-fix-better
htlcswitch: fix empty commit sig and no commit sig
2019-11-08 17:16:48 -08:00
Joost Jager
c7fad2d7cf
lnwallet: fix loop binding bug 2019-11-07 11:45:06 +01:00
Joost Jager
03b32d046a
htlcswitch+lnwallet: replace updateNeeded by check on channel itself
Instead of tracking local updates in a separate link variable, query
this state from the channel itself.

This commit also fixes the issue where the commit tx was not updated
anymore after a failed first attempt because the revocation window was
closed. Also those pending updates will be taken into account when the
remote party revokes.
2019-11-06 09:21:25 +01:00
Joost Jager
f59b4d62bf
htlcswitch: check for signature owed in link
Previously the channel method FullySynced was used to decide whether to
send a new commit sig message. However, it could happen that FullySynced
was false, but that we didn't owe a commitment signature. Instead we
were waiting on the other party to send us a signature. If that
happened, we'd send out an empty commit sig. This commit modifies the
condition that triggers a new commit sig and fixes this deviation from
the spec.
2019-11-06 09:21:23 +01:00
Joost Jager
517ad4e4f5
lnwallet: log empty commit sig event
To facilitate the logging, this commit adds a new OweCommitment method.
For the logging, we only need to consider the remote perspective. In a
later commit, we'll also start using the local perspective to support
the decision to send another signature.
2019-11-06 09:21:19 +01:00
Olaoluwa Osuntokun
4592f87033
Merge pull request #3653 from Roasbeef/external-funding-chainfees
chainfees: create new chainfees package extracting fees from lnwallet
2019-10-31 17:44:00 -07:00
Olaoluwa Osuntokun
777ed104a3
chainfee: create new chainfee package extracting fees from lnwallet
In this commit, we create a new chainfee package, that houses all fee
related functionality used within the codebase. The creation of this new
package furthers our long-term goal of extracting functionality from the
bloated `lnwallet` package into new distinct packages. Additionally,
this new packages resolves a class of import cycle that could arise if a
new package that was imported by something in `lnwallet` wanted to use
the existing fee related functions in the prior `lnwallet` package.
2019-10-31 16:41:57 -07:00
Olaoluwa Osuntokun
a73ee28e46
multi: convert the existing channeldb.ChannelType uint8 into a bit field
In this commit, we convert the existing `channeldb.ChannelType` type
into a _bit field_. This doesn't require us to change the current
serialization or interpretation or the type as it is, since all the
current defined values us a distinct bit. This PR lays the ground work
for any future changes that may introduce new channel types (like anchor
outputs), and also any changes that may modify the existing invariants
around channels (if we're the initiator, we always have the funding
transaction).
2019-10-31 16:34:37 -07:00
Conner Fromknecht
dbc0e88584
Merge pull request #3564 from joostjager/htlcswitch-logging
build+htlcswitch+lnwallet: add prefix logger
2019-10-16 13:00:36 +02:00
Olaoluwa Osuntokun
5ef1f85998
Merge pull request #3578 from wpaulino/no-freelist-sync-option
config: add sync freelist cli flag
2019-10-04 15:16:30 -07:00
Olaoluwa Osuntokun
c03fb8aca0
Merge pull request #3561 from Roasbeef/chan-validation-cleanup
chanvalidate: create new channel validation package
2019-10-04 12:32:07 -07:00
Wilmer Paulino
194a9dea81
multi: support sync freelist option within btcwallet 2019-10-04 12:19:40 -04:00
Johan T. Halseth
6765b8668a
Merge pull request #3574 from wpaulino/max-fee-allocation-fee-floor
htlcswitch: enforce fee floor on max fee allocation
2019-10-04 14:12:02 +02:00
Wilmer Paulino
fa96d707c5
lnwallet: enforce fee floor on max fee allocation
Without this, it was possible for a combination of our balance and max
fee allocation to result in a fee rate below the fee floor causing the
remote party to reject the update and close the channel.
2019-10-03 20:13:26 -04:00
Olaoluwa Osuntokun
0e13c5ac3f
lnwallet+funding: expose new ValidateChannel method for 1st party validation
In this commit, we use the recently added `chanvalidate` package to
verify channels once they have been confirmed in the funding manager. We
expose a new method on the `LightningWallet` struct: `ValidateChannels`
which calls the new shared 1st party verification code.

After the channel is fully confirmed in the funding manager, we'll now
use this newly exposed method to handle all validation. As a result, we
can remove the existing validation code in the funding manager, and rely
on the new code in isolation.
2019-10-03 16:23:23 -07:00
Olaoluwa Osuntokun
c199ad30ac
lnwallet/chanvalidate: create new channel validation package
In this commit, we create a new `chanvalidate` package which it to house
all logic required for 1st and 3rd party channel verification. 1st party
verification occurs when we find a channel in the chain that is
allegedly ours, while 3rd party verification will occur when a peer
sends us a channel proof of a new channel.

In the scope of the recent CVE, we actually fully verified 3rd party
channels, but failed to also include those checks in our 1st party
verification code. In order to unify this logic, and prevent future
issues, in this PR we move to concentrate all validation logic into a
single function. Both 1st and 3rd party validation will then use this
function. Additionally, having all the logic in a single place makes it
easier to audit, and also write tests against.
2019-10-03 16:23:14 -07:00
Olaoluwa Osuntokun
1e67040145
lnwallet: copy commitment transaction in getSignedCommitTx
In this commit, we move to make a full deep copy of the commitment
transaction in `getSignedCommitTx` to ensure that we don't mutate the
commitment on disk, possibly resulting in a "hot commitment".
2019-10-03 16:23:10 -07:00
Joost Jager
b58dbb2d70
multi: fix canceled spelling 2019-10-03 17:27:36 +02:00
Joost Jager
57562d6c4d
lnwallet: create channel specific log methods 2019-10-03 10:22:01 +02:00
Olaoluwa Osuntokun
6d97bcbacd
lnwallet+contractcourt: publicly export DeriveCommitmentKeys use in chain watcher
In this commit, we consolidate the number of areas where we derive our
commitment keys. Before this commit, the `isOurCommitment` function in
the chain watcher used a custom routine to derive the expected
scripts/keys for our commitment at that height. With the recent changes,
we now have additional logic in `DeriveCommitmentKeys` that wasn't
copied over to this area. As a result, the prior logic would erroneously
detect if it was our commitment that had hit the chain or not.

In this commit, we remove the old custom code, and use
`DeriveCommitmentKeys` wihtin the chain watcher as well. This ensures
that we only need to maintain the key derivation code in a single place,
preventing future bugs of this nature.
2019-09-25 18:26:13 -07:00
Olaoluwa Osuntokun
a58cfa65ff
lnwallet+breacharbiter: update breach logic to be aware of new commitment format
In this commit, we update the brar logic in the channel state machine,
and also the brar itself to be aware of the new commitment format.
Similar to the unilateral close summary, we'll now blank out the
SingleTweak field in `NewBreachRetribution` if it's a tweakless
commitment. The brar will then use this to properly identify the
commitment type, to ensure we use the proper witness generation function
when we're handling our own breach.
2019-09-25 18:25:58 -07:00
Olaoluwa Osuntokun
0b62126067
multi: update funding workflow to be aware of new tweakless commits
In this commit, we update the funding workflow to be aware of the new
channel type that doesn't tweak the remote party's output within the
non-delay script on their commitment transaction. To do this, we now
allow the caller of `InnitChannelReservation` to signal if they want the
old or new (tweakless) commitment style.

The funding tests are also updated to test both funding variants, as
we'll still need to understand the legacy format for older nodes.
2019-09-25 18:25:46 -07:00
Olaoluwa Osuntokun
b399203e71
lnwallet: update channel state machine to be aware of tweakless commits
In this commit, we update the channel state machine to be aware of
tweakless commits. In several areas, we'll now check the channel's type
to see if it's `SingleFunderTweakless`. If so, then we'll opt to use the
remote party's non-delay based point directly in the script, skipping
any additional cryptographic operations. Along the way we move the
`validateCommitmentSanity` method to be defined _before_ it's used as is
cutomary within the codebase.

Notably, within the `NewUnilateralCloseSummary` method, we'll now _blank
out_ the `SingleTweak` value if the commitment is tweakless. This
indicates to callers the witness type they should map to, as the value
isn't needed at all any longer when sweeping a non-delay output.

We also update the signing+verification tests to also test that we're
able to properly generate a valid witness for the new tweakless
commitment format.
2019-09-25 18:25:43 -07:00
Johan T. Halseth
2a6ad6e634
channeldb+lnwallet: don't pass isRestoredChan to ChanSyncMsg
Since we have access to the internal state of the channel, we can
instead get it directly instead of passing it in as a parameter.
2019-09-25 14:04:44 +02:00
Johan T. Halseth
6e361d04cf
lnwallet+link: move marking channel states to link
Instead of marking the database state when processing the channel
reestablishment message, we wait for the result of this processing to
arrive in the link, and mark it accordingly in the database here.

We do this move the logic determining whether we should force close the
channel or not, and what state to mark it in the DB, to the same place,
as these need to be consistent.
2019-09-25 14:04:43 +02:00
Johan T. Halseth
f40f4620f7
lnwallet/channel: make ErrCommitSyncLocalDataLoss type
This commit converts the ErrCommitSyncLocalDataLoss error into a struct,
that also holds the received last unrevoked commit point from the remote
party.
2019-09-25 14:04:43 +02:00
Johan T. Halseth
07a42971bf
lnwallet/test_utils: make CreateTestChannel return random funding op
Previously it would always be the same, resulting in multiple calls to
the method not being usabel to create more than one set of channels.
2019-09-25 14:04:43 +02:00
Johan T. Halseth
02b2787e44
multi: make MarkCommitmentBroadcasted take closeTx 2019-09-25 14:04:43 +02:00
Johan T. Halseth
eb1b84c0b4
channeldb+lnwallet: make ChanSyncMsg method on OpenChannel 2019-09-25 14:04:42 +02:00
Johan T. Halseth
0122dda88a
channeldb/channel: remove unused FullSync method
The exported FullSync method is only used by test code, so we remove it
and instead use SyncPending.
2019-09-25 14:04:42 +02:00
Johan T. Halseth
2e9452916e
lnwallet/interface_test: add RBF test cases to testPublishTransaction
Checks that we get ErrDoubleSpend as expected when publishing a
conflicting mempool transaction with the same fee as the existing one,
and that we can publish a replacement with a higher fee successfully.
2019-09-25 08:04:04 +02:00
Johan T. Halseth
61e1b48f57
lnwallet/btcwallet: check publication error types, handle replacement
error

Since btcwallet will return typed errors now, we can simplify the
matching logic in order to return ErrDoubleSpend.

In case a transaction cannot be published since it did not satisfy the
requirements for a valid replacement, return ErrDoubleSpend to indicate
it was not propagated.
2019-09-25 08:04:04 +02:00
Johan T. Halseth
7897b96e6a
lnwallet/interface_test: extract local utility functions
In preparation for extending the testPublishTransaction test, shorten it
by moving utility methods out of the local scope.
2019-09-25 08:01:42 +02:00
Conner Fromknecht
934b11fdac
Merge pull request #3509 from alrs/fix-lnwallet-test-goroutine
lnwallet: fix goroutines in tests
2019-09-19 14:01:45 -07:00
Lars Lehtonen
a600d1eefe lnwallet: fix in-goroutine tests 2019-09-19 19:49:45 +00:00
Johan T. Halseth
c308042ae0
lnwallet/channel: add missing chanpoint to log 2019-09-19 10:40:32 +02:00
Johan T. Halseth
1a4ba97562
Merge pull request #3274 from esneider/fix-typo-in-doc
Fix typo in doc
2019-09-18 08:37:06 +02:00
Olaoluwa Osuntokun
7b1166bbb7
Merge pull request #3458 from Roasbeef/go1.13
build: update travis and Makefile to build using Go 1.13
2019-09-14 11:18:51 +03:00
Lars Lehtonen
3b29ecb921 routing: Fix dropped errors in tests.
lnd: Fix dropped errors in tests.

contractcourt: Fix dropped errors in tests.

htlcswitch: Fix dropped errors in tests.

invoices: Fix dropped error in tests.

lnwallet: Fix dropped errors in tests.

macaroons: Fix dropped error in tests.
2019-09-13 06:28:05 +00:00
Olaoluwa Osuntokun
5ecde6d552
lnwallet+chainntnfs: update to use latest neutrino APIs 2019-09-11 05:57:06 -07:00
Joost Jager
3d7de2ad39
multi: remove dead code 2019-09-10 17:21:59 +02:00
Wilmer Paulino
59d19e0ca9
lnwallet: add MaxFeeRate method to LightningChannel 2019-09-03 16:49:54 -07:00
Wilmer Paulino
9e8a1707cc
lnwallet: modify FetchInputInfo to return additional information for utxos 2019-08-22 13:49:41 -07:00