Commit Graph

373 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
948646b58b
Merge pull request #2481 from joostjager/move-input
multi: move input to separate package
2019-01-31 16:48:31 -08:00
Joost Jager
9e012ecc93
multi: move Input interface and related code
This commit is a step to split the lnwallet package. It puts the Input
interface and implementations in a separate package along with all their
dependencies from lnwallet.
2019-01-31 13:25:33 +01:00
Johan T. Halseth
47918bd6ce
lnwallet/channel: add restoration sanity check
To avoid more bugs slipping through where the logIndex is not set, we
panic to catch this. This was earlier done for Adds and the htlcCounter,
which did lead us to find the resulting retoration bug.
2019-01-31 09:24:50 +01:00
Johan T. Halseth
b593c1c7c7
lnwallet/channel: set logIndex for restored FeeUpdate
Earlier versions did not write the log index to disk for fee updates, so
they will be unset. To account for this we set them to to current update
log index.
2019-01-31 09:24:49 +01:00
Olaoluwa Osuntokun
9e5723e1bc
lnwallet: modify ForceClose to disallow closing if local data loss
In this commit, we ensure that if a channel is detected to have local
data loss, then we don't allow a force close attempt, as this may not be
possible, or cause us to play an invalid state.
2019-01-28 20:24:42 -08:00
Wilmer Paulino
93754f8d37
lnwallet: add HtlcPoint() resolution helper methods
Co-authored-by: Joost Jager <joost.jager@gmail.com>
2019-01-22 20:47:13 -08:00
Olaoluwa Osuntokun
9c59ac4383
Merge pull request #2397 from halseth/reject-commitment-expected-fee-reset-bug
[bugfix] Process fee updates as any other update message
2019-01-14 17:06:27 -08:00
Olaoluwa Osuntokun
400a1d3282
Merge pull request #2431 from cfromknecht/keyring-remote-delay-retribution
lnwallet: Add keyring and remote CSV delay to BreachRetribution
2019-01-11 15:33:16 -08:00
Conner Fromknecht
eb2f5cecf6
multi: remove breach tx arg from NewBreachRetribution args
This commit removes the breach transaction from the
arguments passed to NewBreachRetribution. We already
keep all prior remote commitments on disk in the
commitment log, and load that transaction from disk
inside the method. In practice, the one loaded from
disk will be the same one that is passed in by the
caller, so there should be no change in behavior
as we've already derived the appropriate state number.

This changes makes integration with the watchtower
client simpler, since we no longer need to acquire
the breaching commitment transaction to be able to
construct the BreachRetribution. This simplifies
not only the logic surrounding transient backsups,
but also on startup (and later, retroactively
backing up historic updates).
2019-01-10 13:13:38 -08:00
Johan T. Halseth
dadfcefc07
lnwallet/channel: don't return feePerKw from computeView
Since the feerate is part of the computed view now, we don't have to
pass the found feerate as a distinct parameter.
2019-01-10 12:31:12 +01:00
Johan T. Halseth
6ffd354d63
lnwallet/channel: add fee updates to update logs
Instead of special casing the UpdateFee messages, we instead add them to
the update logs like any other HTLC update message. This lets us avoid
having to keep an extra set of variables to keep track of the fee
updates, and instead reuse the commit/ack logic used for other updates.

This fixes a bug where we would reset the pendingFeeUpdate variable
after signing our next commitment, which would make us calculate the new
fee incorrectly if the remote sent a commitment concurrently.

When restoring state logs, we also make sure to re-add any fee updates.
2019-01-10 12:31:12 +01:00
Johan T. Halseth
810c56cdb9
lnwallet/channel: process FeeUpdate found in update log
This commit makes the evaluateHTLCView method process any found
FeeUpdates in the logs, by returning the last set feerate.
2019-01-10 12:31:11 +01:00
Johan T. Halseth
277949cb0e
lnwallet/channel: remove FeeUpdates when compacting logs
When compacting the update logs we remove any fee updates when they
remove height is passed. We do this since we'll assume fee updates are
added and removed at the same commit height, as they will apply for all
commitments following the fee update.
2019-01-10 12:26:41 +01:00
Johan T. Halseth
480f43f1dc
lnwallet/channel: add lnwire<->PaymentDescriptor FeeUpdate conversion
This commit adds conversion between the lnwire.UpdateFee message and the
new FeeUpdate PaymentDescriptor. We re-purpose the existing Amount field
in the PaymentDescriptor stuct to hold the feerate.
2019-01-10 12:26:33 +01:00
Johan T. Halseth
36857a1042
lnwallet/channel: add new PaymentDescriptor type FeeUpdate
This commit adds a new updateType that can be used for
PaymentDescriptors: FeeUpdate. We repurpose the fields of the existing
PaymentDescriptor struct such that we can easily re-use the commit/ack
logic used for other update types also for fee updates.
2019-01-10 12:23:56 +01:00
Conner Fromknecht
cd54625c2d
lnwallet/channel: add keyring + remote csv to breach info 2019-01-07 17:15:33 -08:00
Alex Bosworth
a78e13929e
lnwallet: fix trivial comment typo 2019-01-06 11:39:12 -08:00
Olaoluwa Osuntokun
fa160f559c
multi: replace per channel sigPool with global daemon level sigPool
In this commit, we remove the per channel `sigPool` within the
`lnwallet.LightningChannel` struct. With this change, we ensure that as
the number of channels grows, the number of gouroutines idling in the
sigPool stays constant. It's the case that currently on the daemon, most
channels are likely inactive, with only a hand full actually
consistently carrying out channel updates. As a result, this change
should reduce the amount of idle CPU usage, as we have less active
goroutines in select loops.

In order to make this change, the `SigPool` itself has been publicly
exported such that outside callers can make a `SigPool` and pass it into
newly created channels. Since the sig pool now lives outside the
channel, we were also able to do away with the Stop() method on the
channel all together.

Finally, the server is the sub-system that is currently responsible for
managing the `SigPool` within lnd.
2018-12-16 15:40:14 -08:00
Olaoluwa Osuntokun
42c4597921
Merge pull request #1937 from halseth/data-loss-protect-resending
Data loss protect resending
2018-11-25 20:47:16 -06:00
Johan T. Halseth
5c294601f0
lnwallet/channel: remove startingHeight from commitmentChain
Field is not being used.
2018-11-23 08:58:45 +01:00
Johan T. Halseth
a9f93b2988
contractcourt/chain_watcher: add channel sync message to CloseChannelSummary 2018-11-21 10:28:56 +01:00
Johan T. Halseth
676a1b1407
lnwallet+link: make ChanSyncMsg take channel state as arg
This lets us get the channel reestablish message without creating the LightningChannel struct first.
2018-11-21 10:28:56 +01:00
Olaoluwa Osuntokun
6aa7c09308
lnwallet: properly set the short chan ID for remote unilateral close summaries
In this commit, we fix an existing bug wherein we wouldn't set the short
channel ID for the close summary in the database in the case that the
remote party force closed. The fix is simple, ensure that within
NewUnilateralCloseSummary we properly set the short channel ID. A test
has also been added in this commit, which fails without the
modifications to lnwallet/channel.go.

Fixes #2072.
2018-10-19 13:49:15 -07:00
maurycy
ac24b12bf2
multi: fix various typos in comments 2018-09-07 06:51:49 +02:00
Johan T. Halseth
f4f7b64b2d
lnwallet/channel: add FwdMinHtlc(), returning MinHTLC from localChanCfg 2018-08-23 07:50:17 +02:00
Conner Fromknecht
05308ec22c
lnwallet/channel: concrete HTLC errors and ack AddRefs 2018-08-21 00:31:41 -07:00
Olaoluwa Osuntokun
b06dabfcb9 lnwallet: properly set auxiliary channel recovery info in NewUnilateralCloseSummary
In this commit, we fix a slight bug by ensuring that the revocation info
at the final state of the channel, as well as the local chan config is
properly set within the channel close summary created within
NewUnilateralCloseSummary. Before this commit, for all cooperative close
transactions, this state would _only_ include the pubkey itself, which
in some cases may not be sufficient to re-derive the key if needed.
2018-08-14 19:11:18 -07:00
Conner Fromknecht
cf2c371042
multi: fix linting errors 2018-08-02 18:20:50 -07:00
Olaoluwa Osuntokun
343c1b80d2
lnwallet: update NewBreachRetribution to include pkScripts for htlc outputs
In this commit, we update the NewBreachRetribution method to include
pkScripts for htlc outputs. We do this now, as the breach arbiter will
need the raw pkScript when attempting to request spend notifications for
each HTLC.
2018-07-31 21:28:57 -07:00
Olaoluwa Osuntokun
8dd0b56d35
lnwallet: publicy export WitnessScriptHash and GenMultiSigScript
In this commit, we export WitnessScriptHash and GenMultiSigScript as
external sub-systems may now need to use these methods in order to be
able to watch for confirmations based on the script of a transaction.
2018-07-31 21:28:50 -07:00
Olaoluwa Osuntokun
a5174a2228
Merge pull request #1543 from cfromknecht/wtblob
[watchtower/blob]: Blob of Justice encryption/decryption and v0 plaintext encoding
2018-07-31 20:55:29 -07:00
Johan T. Halseth
78a4a15bb4
lnwallet/channel: check validity of received commitPoint
This commit adds a check for the LocalUnrevokedCommitPoint sent to us by
the remote during channel reestablishment, ensuring it is the same point
as they have previously sent us.
2018-07-31 15:16:23 +02:00
Johan T. Halseth
a2f2d28d0b
lnwallet/channel: enumerate error cases from remote chain desync
This commit enumerates the various error cases we can encounter when we
compare our remote commit chain to the view the remote communicates to us
via msg.NextLocalCommitHeight.

We now compare this height to our remote tail and tip height, returning
relevant error in case of a unrecoverable desync, and re-send a
commitment signature (including log updates) in case we owe one.
2018-07-31 15:16:23 +02:00
Johan T. Halseth
f1757d6da4
lnwallet/channel: enumerate error cases from local chain desync
This commit enumerates the various error cases we can encounter when we
compare our local commit chain to the view the remote communicates to us
via msg.RemoteCommitTailHeight.

We now compare this height to our local tail height (note that there's
never a local "tip" at this point), returning relevant error in case of
a unrecoverable desync, and re-send a revocation in case we owe one.
2018-07-31 15:16:23 +02:00
Johan T. Halseth
48f1458ae5
lnwallet/channel: define channel sync errors
This commit defines a few new errors that we can potentially encounter
during channel reestablishment:
* ErrInvalidLocalUnrevokedCommitPoint
* ErrCommitSyncLocalDataLoss
* ErrCommitSyncRemoteDataLoss

in addition to the already defined errors
* ErrInvalidLastCommitSecret
* ErrCannotSyncCommitChains
2018-07-31 15:16:23 +02:00
Johan T. Halseth
3825ca71dd
lnwallet/channel: reduce scope of commitSecretCorrect 2018-07-31 15:16:22 +02:00
Johan T. Halseth
eed052eba5
lnwallet/channel: extract local balance from spend instead of stored commit 2018-07-31 08:27:03 +02:00
Johan T. Halseth
06ceba429f
lnwallet/channel: make NewUnilateralCloseSummary take commitPoint 2018-07-31 08:27:03 +02:00
Conner Fromknecht
b0379dfa59
lnwallet/channel: use exposed CommitScriptUnencumbered 2018-07-24 16:54:30 -07:00
Olaoluwa Osuntokun
6f60f139f4 multi: switch over import paths from roasbeef/* to btcsuite/* 2018-07-13 17:05:39 -07:00
Conner Fromknecht
bb808a1937
lnwallet/channel: use public variant of script helpers 2018-07-03 17:07:48 -07:00
Olaoluwa Osuntokun
8885c3de8d
server: defer cancelling the outbound connection until the tie-breaker 2018-06-10 23:02:22 -07:00
maurycy
3be08e69cf multi: 64bit aligment of atomic vars on arm/x86-32 2018-06-04 20:02:34 -07:00
Johan T. Halseth
07629e5da1
lnwallet/channel: use FullySynced to check chanSync special case
We check if the channel is FullySynced instead of comparing the local
and remote commit chain heights, as the heights might not be in sync.
Instead we call FullySynced which recently was modified to use compare
the message indexes instead, which is _should_ really be in sync between
the chains.

The test TestChanSyncOweRevocationAndCommitForceTransition is altered to
ensure the two chains at different heights before the test is started, to
trigger the case that would previously fail to resend the commitment
signature.
2018-06-04 15:09:51 +02:00
Olaoluwa Osuntokun
31aa8553e7
Merge pull request #1294 from halseth/add-commit-height
lnwallet/channel: set add heights based on the locked in commits
2018-05-29 15:46:39 -07:00
Johan T. Halseth
cb52151123
lnwallet/channel: set add heights based on the locked in commits
This commit fixes a bug which would cause the add heights of the HTLCs
in the update log to be set wrongly. At times, an add height could be
incorrecly set, leading to the HTLCs not being accounted for correctly
during evaluating the HTLC views. This was caused by the assumption that
if the HTLC was not on the pending remote commit, then it was locked in
on both the local and the remote commit, which is not always true.

Instead of making this assumption, we instead now inspect the three
commits: the local, remote and pending remote; and set the add heights
accordingly. This should ensure that HTLCs are subtracted from the
balances only when they are first added.
2018-05-29 08:35:01 +02:00
Conner Fromknecht
e693f89cb0
lnwallet/channel: locked in settle/fail 2018-05-28 13:17:28 -07:00
Olaoluwa Osuntokun
04f576ee6e
lnwallet: reject duplicate fails for the same HTLC 2018-05-25 20:26:01 -07:00
Olaoluwa Osuntokun
28f37def7c
lnwallet: reject duplicate settles for the same HTLC 2018-05-25 20:26:01 -07:00
Olaoluwa Osuntokun
b6d046ad84
lnwallet: mark HTLCs modified for updates restored in restoreStageLogs 2018-05-25 20:26:01 -07:00