Commit Graph

69 Commits

Author SHA1 Message Date
yyforyongyu
614884dcb8
contractcourt: test commitment deadline logic
This commit adds two tests to check that a) the correct deadline is used
given different HTLC sets and b) when sweeping anchors the correct
deadlines are used.
2021-06-29 20:25:47 +08:00
yyforyongyu
0dc3190fec
contractcourt: update TestChannelArbitratorAnchors
This commit adds a deadline field to mockSweeper that can be used to
track the customized conf target (deadline) used for sweeping anchors.
The relevant test, TestChannelArbitratorAnchors is updated to reflect
that the deadlines are indeed taking effect.
2021-06-29 20:25:47 +08: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
Andras Banki-Horvath
14c851c8fc
kvdb: move channeldb/kvdb to top level 2021-05-07 14:18:56 +02:00
Yong
582b164c46
kvdb: add timeout options for bbolt (#4787)
* mod: bump btcwallet version to accept db timeout

* btcwallet: add DBTimeOut in config

* kvdb: add database timeout option for bbolt

This commit adds a DBTimeout option in bbolt config. The relevant
functions walletdb.Open/Create are updated to use this config. In
addition, the bolt compacter also applies the new timeout option.

* channeldb: add DBTimeout in db options

This commit adds the DBTimeout option for channeldb. A new unit
test file is created to test the default options. In addition,
the params used in kvdb.Create inside channeldb_test is updated
with a DefaultDBTimeout value.

* contractcourt+routing: use DBTimeout in kvdb

This commit touches multiple test files in contractcourt and routing.
The call of function kvdb.Create and kvdb.Open are now updated with
the new param DBTimeout, using the default value kvdb.DefaultDBTimeout.

* lncfg: add DBTimeout option in db config

The DBTimeout option is added to db config. A new unit test is
added to check the default DB config is created as expected.

* migration: add DBTimeout param in kvdb.Create/kvdb.Open

* keychain: update tests to use DBTimeout param

* htlcswitch+chainreg: add DBTimeout option

* macaroons: support DBTimeout config in creation

This commit adds the DBTimeout during the creation of macaroons.db.
The usage of kvdb.Create and kvdb.Open in its tests are updated with
a timeout value using kvdb.DefaultDBTimeout.

* walletunlocker: add dbTimeout option in UnlockerService

This commit adds a new param, dbTimeout, during the creation of
UnlockerService. This param is then passed to wallet.NewLoader
inside various service calls, specifying a timeout value to be
used when opening the bbolt. In addition, the macaroonService
is also called with this dbTimeout param.

* watchtower/wtdb: add dbTimeout param during creation

This commit adds the dbTimeout param for the creation of both
watchtower.db and wtclient.db.

* multi: add db timeout param for walletdb.Create

This commit adds the db timeout param for the function call
walletdb.Create. It touches only the test files found in chainntnfs,
lnwallet, and routing.

* lnd: pass DBTimeout config to relevant services

This commit enables lnd to pass the DBTimeout config to the following
services/config/functions,
  - chainControlConfig
  - walletunlocker
  - wallet.NewLoader
  - macaroons
  - watchtower
In addition, the usage of wallet.Create is updated too.

* sample-config: add dbtimeout option
2020-12-07 15:31:49 -08:00
carla
697dbf7f3a
contractcourt: get arbitrator state before we start each arbitrator 2020-11-12 15:32:15 +02:00
carla
f1404af475
contractcourt: pass in optional txns to lookups required for arb startup
To allow us to grab all of the information we need for our channel arbs
in a more efficient way on startup, we add an optional tx to our lookup
functions required on start.
2020-11-12 15:25:35 +02:00
carla
89fe21b79a
contractcourt: use single block subscription for block epochs 2020-11-12 15:23:24 +02:00
Joost Jager
08bb8ec54e
cnct: clear exclusive group on anchor sweep after confirmation
The sweeper call UpdateParams does not update the exclusive group
property of a pending sweep. This led to anchor outputs being swept
after confirmation with an exclusive group restriction, which is not
necessary.

This commit changes the anchor resolver to not use UpdateParams anymore,
but instead always re-offer the anchor input to the sweeper. The sweeper
is modified so that a re-offering also updates the sweep parameters.
2020-09-16 08:17:40 +02:00
eugene
c7cbacc35b multi: move mockChainIO, mockNotifier to lntest/mock 2020-08-31 19:41:09 -04:00
carla
f5b20b7429
contractcourt: store anchor resolutions on disk 2020-07-07 19:49:53 +02:00
carla
fa46db9c48
multi: add resolver reports to Checkpoint
To allow us to write the outcome of our resolver to disk, we add
optional resolver reports to the CheckPoint function. Variadic params
are used because some checkpoints may have no reports (when the resolver
is not yet complete) and some may have two (in the case of a two stage
resolution).
2020-07-07 19:49:51 +02:00
carla
8c8f857f60
contractcourt: add PutResolverReport function to chanArb config 2020-07-07 19:49:50 +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
Olaoluwa Osuntokun
320101d054
contractcourt: convert to use new kvdb abstraction 2020-03-18 19:34:52 -07:00
Joost Jager
ea397c9d6e
cnct: resolve anchors post-confirmation
Sweeping anchors and being able to bump the fee was already added in a
previous commit. This commit extends anchor sweeping with an anchor
resolver object that becomes active after the commitment tx confirms.
At that point, the anchors do not serve the purpose of getting the
commitment tranaction confirmed anymore. It is however still possible to
reclaim some of their value if using a low fee rate.
2020-03-18 12:27:01 +01:00
Joost Jager
07a39b1ebf
cnct: do not persist stateless resolvers
Preparation for the anchor resolver which does not have persistent
state.
2020-03-18 12:26:57 +01:00
Joost Jager
d2b6472843
cnct: pre-confirmation anchor sweep
Start anchor sweep attempts immediately after the commitment transaction
has been published. This makes the anchor known to the sweeper and
allows the user to bump the fee on it to get their commitment
transaction confirmed in case the fee committed too is insufficient for
timely confirmation.
2020-03-18 12:26:55 +01:00
Joost Jager
7f3d4e7d49
cnct: create channel interface for arbitrator
Allows unit testing of the channel arbitrator with fewer dependencies.
This is a preparation for the addition of anchor sweeping.
2020-03-17 16:25:31 +01:00
Joost Jager
30fc03d84d
lnwallet/test: pass in test channel type 2020-03-17 14:19:33 +01:00
carla
4eb3036f67
contractcourt: record force and breach close initiator 2020-02-21 13:53:43 +02:00
carla
c9915e027e
contractcourt/test: replace timeouts with constants 2020-02-21 13:34:26 +02: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
Roei Erez
0407b37fce contractcourt+switch: keep channels with timed-out initiated htlcs.
This commit enables the user to specify he is not interested in
automatically close channels with pending payments that their
corresponding htlcs have timed-out.
By requiring a configurable grace period uptime of our node
before closing such channels, we give a chance to the other node to
properly cancel the htlc and avoid unnecessary on-chain transaction.
In mobile it is very important for the user experience as otherwise
channels will be force closed more frequently.
2020-02-16 09:08:03 +02:00
Joost Jager
919ab60540
utxonursery: remove unused commit sweep code
Now that the commit sweep resolver is no longer relying on the nursery,
all code associated with commit sweeping can be removed.
2019-11-14 13:38:03 +01:00
Joost Jager
0d7119a8ca
cnct: parse onion for resolvers
With the introduction of additional payload fields for mpp, it becomes
a necessity to have their values available in the on-chain resolution
flow. The incoming contest resolver notifies the invoice registry of the
arrival of a payment and needs to supply all parameters for the registry
to validate the htlc.
2019-11-12 15:01:39 +01:00
Joost Jager
50abb41e94
cnct: store full htlc struct inside resolver
This change prepares for accessing the onion blob from a resolver.
2019-11-12 15:01:36 +01:00
Joost Jager
b58dbb2d70
multi: fix canceled spelling 2019-10-03 17:27:36 +02:00
Olaoluwa Osuntokun
c57bb9d86b
Merge pull request #3480 from Roasbeef/proper-resolution-supplements
contractcourt: supplement resolvers with confirmed commit set HTLCs
2019-09-25 17:08:35 -07:00
Olaoluwa Osuntokun
d0df5a4ddd
contractcourt: supplement resolvers with confirmed commit set HTLCs
In this commit, we fix an existing bug in the package, causing
resolutions to be restarted without their required supplementary
information. This can happen if a distinct HTLC set gets confirmed
compared to the HTLCs that we may have had our commitment at time of
close. Due to this bug, on restart certain HTLCS would be rejected as
they would present their state to the invoice registry, but be rejected
due to checks such as amount value.

To fix this, we'll now pass in the set of confirmed HTLCs into the
resolvers when we re-launch them, giving us access to all the
information we need to supplement the HTLCS.

We also add a new test that ensures that the proper fields of a resolver
are set after a restart.
2019-09-25 16:05:25 -07:00
Olaoluwa Osuntokun
c3bf8d2054
contractcourt: create new channel arb test context struct
In this commit, we create a new channel arb test context struct as the
current `createTestChannelArbitrator` has several return parameters, and
upcoming changes will likely at first glance need to add one or more
additional parameters. Rather than extend the existing set of return
parameters, we opt to instead create this struct that wraps the existing
state.

Along the way we add several new utility methods to this context, and
use them in the existing tests where applicable:
  * `AssertStateTransitions`
  * `AssertState`
  * `Restart`
  * `CleanUp`
2019-09-25 16:05:21 -07:00
Johan T. Halseth
02b2787e44
multi: make MarkCommitmentBroadcasted take closeTx 2019-09-25 14:04:43 +02:00
Johan T. Halseth
ce9f7faff2
contractcourt/channel_arbitrator: handle breach channel at startup
Earlier the channel arbitrator would fail to recognize channels pending
close that were in the breached state. This lead to the state machine
not progressing correctly, and in some cases crashing since we would
attempt to force close an already closed channel.

A test TestChannelArbitratorForceCloseBreachedChannel is added to
exercise one of these scenarios.
2019-09-18 13:05:35 +02:00
Johan T. Halseth
26b7ec1b94
contractcourt/channel_arbitrator: define and react to breachClose
Earlier we would not react to breaches, as these are handled by other
subsystems. Now we advances our state machine in case of breach, such
that we'll gracefully exit, and won't have leftover state in case of a
restart.

A simple test TestChannelArbitratorBreachClose to exercise this behavior
is added.
2019-09-18 13:05:35 +02:00
Joost Jager
be7fc9dd3e
cnct: do not create an action for incoming dust htlcs
This commit fixes the 'unable to find incoming resolution' error that
occured when trying to resolve incoming htlcs below the dust limit that
are not actually present on the commitment tx.
2019-09-13 12:31:26 +02:00
Joost Jager
3131bc4d64
cnct/test: test outgoing dust htlc resolution 2019-09-13 12:31:24 +02:00
Joost Jager
3d7de2ad39
multi: remove dead code 2019-09-10 17:21:59 +02:00
Olaoluwa Osuntokun
2011ccc571
contractcourt: write confirmed CommitSet to disk before MarkChannelClosed
In this commit, we make a series of changes to ensure that we'll be able
to properly survive restarts if we crash right after we call
MarkChannelClosed. In order to ensure we can survive restarts, we'll now
long the confirmed CommitSet to disk right before we close the channel.
Upon restart, we'll read these from disk so we can pick up where we left
over.

Additionally, we also will now consult the legacy chain actions if it
turns out that the channel has been closed, but we don't have a
confCommitSet written to disk. This will only be the case for nodes that
had pending close channels before this commitment.
2019-05-27 15:26:46 -07:00
Olaoluwa Osuntokun
086f4eb8b3
contractcourt: add new TestChannelArbitratorDanglingCommitForceClose test 2019-05-27 15:26:43 -07:00
Olaoluwa Osuntokun
b4a116fd07
contractcourt: update TestChannelArbitratorLocalForceClosePendingHtlc to assert resolution msg delivery 2019-05-27 15:26:42 -07:00
Olaoluwa Osuntokun
5f0fad85be multi: address lingering TODO by no longer wiping out local HTLCs on remote close
In this commit, we fix a lingering TOOD statement in the channel arb.
Before this commitment, we would simply wipe our our local HTLC set of
the HTLC set that was on the remote commitment transaction on force
close. This was incorrect as if our commitment transaction had an HTLC
that the remote commitment didn't, then we would fail to cancel that
back, and cause both channels to time out on chain.

In order to remedy this, we introduce a new `HtlcSetKey` struct to track
all 3 possible in-flight set of HTLCs: ours, theirs, and their pending.

We also we start to tack on additional data to all the unilateral close
messages we send to subscribers. This new data is the CommitSet, or the
set of valid commitments at channel closure time. This new information
will be used by the channel arb in an upcoming commit to ensure it will
cancel back HTLCs in the case of split commitment state.

Finally, we start to thread through an optional *CommitSet to the
advanceState method. This additional information will give the channel
arb addition information it needs to ensure it properly cancels back
HTLCs that are about to time out or may time out depending on which
commitment is played.

Within the htlcswitch pakage, we modify the `SignNextCommitment` method
to return the new set of pending HTLCs for the remote party's commitment
transaction and `ReceiveRevocation` to return the latest set of
commitment transactions on the remote party's commitment as well. This
is a preparatory change which is part of a larger change to address a
lingering TODO in the cnct.

Additionally, rather than just send of the set of HTLCs after the we
revoke, we'll also send of the set of HTLCs after the remote party
revokes, and we create a pending commitment state for it.
2019-05-27 14:34:13 -07:00
Johan T. Halseth
10070ecab7
lnwallet: make BlockChainIO.GetUTXO take cancel chan
Use quit channels as cancel chan for call to GetUTXO.
2019-05-09 14:44:47 +02:00
Johan T. Halseth
beb5d14ed9
lnwallet/btcwallet: add compile time check for BlockChainIO interface 2019-05-09 14:44:41 +02:00
Joost Jager
ab4da0f53d
cnct: define separate broadcast delta for outgoing htlcs
This commits exposes the various parameters around going to chain and
accepting htlcs in a clear way.

In addition to this, it reverts those parameters to what they were
before the merge of commit d1076271456bdab1625ea6b52b93ca3e1bd9aed9.
2019-04-05 11:36:07 +02:00
Olaoluwa Osuntokun
6b24b6dabd
contractcourt: simplify htlcTimeoutResolver, unify with HTLC contest logic
In this commit, we simplify the existing `htlcTImeoutResolver` with some
newly refactored out methods from the `htlcTimeoutContestResolver`. The
resulting logic is easier to follow as it's more linear, and only deals
with spend notifications rather than both spend _and_ confirmation
notifications.
2019-03-19 16:50:27 -07:00
Joost Jager
449c3d533e
contractcourt: add access to full invoice registry from resolvers
Previously a function pointer was passed to chain arbitrator to avoid a
circular dependency. Now that the routetypes package exists, we can pass
the full invoice registry to chain arbitrator.

This is a preparation to be able to use other invoice registry methods
in contract resolvers.
2019-03-15 10:08:35 +01:00
Olaoluwa Osuntokun
4af857f0c6
Merge pull request #2356 from joostjager/invoices-subserver
invoices: add subscribesingleinvoice
2019-02-01 17:19:58 -08:00
Joost Jager
bacd92418a
invoices: use lntypes.Hash and lntypes.Preimage
Previously chainhash.Hash was used, which converts to/from string in
reversed format. Payment hashes and preimages are supposed to be
non-reversed.
2019-02-01 09:42:29 +01:00
Joost Jager
9abe06f3c8
cnct: finish channel arbitrator in StateFullyResolved
Previously the arbitrator wasn't advanced to the final stage after
the last contract resolved.

Also channel arbitrator now does not ignore a log error anymore
unresolved contracts cannot be retrieved.
2019-02-01 09:10:04 +01: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