Commit Graph

383 Commits

Author SHA1 Message Date
Johan T. Halseth
ac49031396
chainwatcher: only continue breach handling after successfully marked
closed

This commit makes the handoff procedure between the breachabiter and
chainwatcher use a function closure to mark the channel pending closed
in the DB. Doing it this way we know that the channel has been markd
pending closed in the DB when ProcessACK returns.

The reason we do this is that we really need a "two-way ACK" to have the
breacharbiter know it can go on with the breach handling. Earlier it
would just send the ACK on the channel and continue. This lead to a race
where breach handling could finish before the chain watcher had marked
the channel pending closed in the database, which again lead to the
breacharbiter failing to mark the channel fully closed.

We saw this causing flakes during itests.
2021-05-06 12:37:11 +02:00
eugene
f8b98a1d3b
lntest/channels: introduce subpackage to deduplicate static structs 2021-01-25 14:04:39 -05:00
Andras Banki-Horvath
22711ade3a
cnct: dispatch contract breach after channel close summary is serialized
This commit moves the contract breach event dispatch after the channel
close summary has been added to the database. This is important
otherwise it may occur that we attempt to mark the channel fully closed
while the channel close summary is not yet serialized.
2021-01-11 22:48:41 +01:00
Johan T. Halseth
bb406c82a9
contractcourt/htlc_timeout_test: expand timeout tests 2020-12-10 14:24:20 +01:00
Johan T. Halseth
4992e41439
contraccourt+input: create resolver for timeout second level
In this commit we make the sweeper handle second level transactions for
HTLC timeout resolvers for anchor channels.
2020-12-10 14:24:20 +01:00
Johan T. Halseth
0c3b64a3cd
contractcourt/timeout_resolver: extract logic into sweepSecondLevelTransaction
This commit moves the logic for sweeping the confirmed second-level
timeout transaction into its own method.

We do a small change to the logic: When setting the spending tx in the
report, we use the detected commitspend instead of the presigned tiemout
tx. This is to prepare for the coming change where the spending
transaction might actually be a re-signed timeout tx, and will therefore
have a different txid.
2020-12-10 14:24:20 +01:00
Johan T. Halseth
2f33425509
contractcourt/timeout_resolver: extract logic into spendHtlcOutput
This commit moves the code doing the initial spend of the HTLC output of
the commit tx into its own method.
2020-12-10 14:24:20 +01:00
Johan T. Halseth
aabba32b34
contractcourt: add TestHtlcSuccessSecondStageResolutionSweeper
Test success resolvers going through the sweeper.
2020-12-10 14:24:20 +01:00
Johan T. Halseth
85ea181d67
contraccourt+input: create HtlcSecondLevelAnchorInput and resolver for
success tx

This commit makes the HTLC resolutions having non-nil SignDetails
(meaning we can re-sign the second-level transactions) go through the
sweeper. They will be offered to the sweeper which will cluster them and
arrange them on its sweep transaction. When that is done we will further
sweep the output on this sweep transaction as any other second-level tx.

In this commit we do this for the HTLC success resolver and the
accompanying HTLC success transaction.
2020-12-10 14:24:20 +01:00
Johan T. Halseth
d02b486195
contractcourt: revamp HTLC success unit test
We add checkpoint assertions and resume the resolver from every
checkpoint to ensure it can handle restarts.
2020-12-10 14:24:20 +01:00
Johan T. Halseth
7142a302c9
contractcourt/success_resolver: remove sweep tx checkpoint
The sweep tx is not actually part of the resolver's encoded data, so the checkpointing was essentially a noop.
2020-12-10 14:24:19 +01:00
Johan T. Halseth
0b84d5f976
contractcourt/success_resolver: extract HTLC success handling into broadcastSuccessTx 2020-12-10 14:24:19 +01:00
Johan T. Halseth
9d33b00082
contractcourt/success_resolver: extract remoteHTLC sweep into resolveRemoteCommitOutput
This move the logic for sweeping the HTLC output on the remote
commitment into its own method.
2020-12-10 14:24:19 +01:00
Johan T. Halseth
9b08ef6d4e
contractcourt/[incoming|outgoing]_contest_resolver: make inner resolver pointer
To make the linter happy, make a pointer to the inner resolver.
Otherwise the linter would complain with

copylocks: literal copies lock value

since we'll add a mutex to the resolver in following commits.
2020-12-10 14:24:19 +01:00
Johan T. Halseth
4da2b290f9
contractcourt/succes+timeout resolver: extract waitForSpend logic 2020-12-10 14:24:19 +01:00
Johan T. Halseth
5f613147ad
contractcourt: decouple waitForHeight from commit sweep resolver
To make it usable from other resolvers.
2020-12-10 14:24:19 +01:00
Johan T. Halseth
1e68cdc8cf
input+lnwallet+contractcourt: define SignDetails for HTLC resolutions 2020-12-10 14:24:18 +01: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
Johan T. Halseth
ef426be351
contractcourt/chainwatcher test: add test cases for future force close
This adds the scenario to the local force close test cases where a node
force closes one of its channels, then lose state (or do recovery)
before the commmitment is confirmed. Without the previous commit this
would go undetected.
2020-12-03 08:01:08 +01:00
Johan T. Halseth
2a7a34ae10
contractcourt+lnwallet: use state num instead of commit height when
outdated local state

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

Allthough being an unlikely scenario, we would leave money on chain in
this case without any warning (since we would just end up with an empty
delay script) and forget about the spend.
2020-12-03 08:01:08 +01:00
Johan T. Halseth
5bb8996162
contractcourt/chain_watcher: handleUnknownLocalState
Similar to what we did for other states, we extract handling of acting
on a local future state into its own method.
2020-12-03 08:01:08 +01:00
Johan T. Halseth
93d917d82a
contractcourt/chain_watcher: handleUnknownRemoteState
This commit extracts the data loss protect recovery procedure into its
own method.
2020-12-03 08:01:08 +01:00
Johan T. Halseth
743ea7be74
contractcourt/chain_watcher: handleKnownRemoteState
Similar to what we did for the local state handling, we extract handling
all known remote states we can act on (breach, current, pending state)
into its own method.

Since we want to handle the case where we lost state (both in case of
local and remote close) last, we don't rely on the remote state number
to check which commit we are looking at, but match on TXIDs directly.
2020-12-03 08:01:08 +01:00
Johan T. Halseth
acc45934f8
contraccourt/chain_watcher: define handleKnownLocalState
We can only rely on the commit set and height being correct for the
current commit, so check that first.
2020-12-03 08:01:08 +01:00
Johan T. Halseth
450da3d2f4
contractcourt/chain_watcher test: do proper state rollback
The tests didn't really roll back the channel state, so we would only
rely on the state number to determine whether we had lost state. Now we
properly roll back the channel to a previous state, in preparation for
upcoming changes.
2020-12-03 08:00:02 +01: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
Andras Banki-Horvath
d89f51d1d0
multi: add reset closure to kvdb.Update
Similarly as with kvdb.View this commits adds a reset closure to the
kvdb.Update call in order to be able to reset external state if the
underlying db backend needs to retry the transaction.
2020-11-05 17:57:12 +01:00
Andras Banki-Horvath
2a358327f4
multi: add reset closure to kvdb.View
This commit adds a reset() closure to the kvdb.View function which will
be called before each retry (including the first) of the view
transaction. The reset() closure can be used to reset external state
(eg slices or maps) where the view closure puts intermediate results.
2020-11-05 17:57:12 +01:00
Joost Jager
29602e88e8
cnct: cpfp-sweep anchors
For unconfirmed commit tx anchors, supply the sweeper with cpfp info and
a confirmation target fee estimate.

The sweeper will try to pay for the parent commit tx as long as the
current fee estimate exceeds the pre-signed commit tx fee rate.
2020-09-17 12:30:41 +02:00
Joost Jager
681496b474
sweep: make sweeper aware of unconfirmed parent transactions.
Extend the fee estimator to take into account parent transactions with
their weights and fees.

Do not try to cpfp parent transactions that have a higher fee rate than
the sweep tx fee rate.
2020-09-17 12:30:39 +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
eugene
49d8f04197 multi: migrate instances of mockSigner to the mock package
This commit moves all localized instances of mock implementations of
the Signer interface to the lntest/mock package. This allows us to
remove a lot of code and have it housed under a single interface in
many cases.
2020-08-28 15:43:51 -04:00
yyforyongyu
acc0ec13e1
trivial: remove unused print 2020-08-28 17:09:39 +08: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
yyforyongyu
57f7115437
trivial: typo fix 2020-08-13 07:33:52 +08: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
carla
d8a4b37c0e
contractcourt: persist commit sweep resolutions 2020-07-07 19:49:58 +02:00
carla
d0ec872ef3
contractcourt: store htlc timeout sweeps 2020-07-07 19:49:57 +02:00
carla
a38dc256fd
contractcourt: persist remote outgoing htlc claim outcome on disk
When a remote peer claims one of our outgoing htlcs on chain, we do
not care whether they claimed with multiple stages. We simply store
the claim outgome then forget the resolver.
2020-07-07 19:49:56 +02:00
carla
03b76ad9a4
contractcourt: save htlc success resolvers, including first stage
Checkpoint our htlc claims with on chain reasolutions, including our
first stage success tx where required.
2020-07-07 19:49:55 +02:00
carla
eb07f89090
contractcourt/test: add test context for success resolver 2020-07-07 19:49:54 +02:00
carla
cf739f3f87
contractcourt: persist timed out incoming htlc resolver reports
Incoming htlcs that are timed out or failed (invalid htlc or invoice
condition not met), save a single on chain resolution because we don't
need to take any actions on them ourselves (we don't need to worry
about 2 stage claims since this is the success path for our peer).
2020-07-07 19:49:54 +02:00
carla
f5b20b7429
contractcourt: store anchor resolutions on disk 2020-07-07 19:49:53 +02:00
carla
0a01d5d17c
contractcourt: add resolver report function to ContractReport
Our current set of reports contain much of the information we will
need to persist contract resolutions. We add a function to create
resolver reports from our exiting set of resolutions.
2020-07-07 19:49:52 +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
Olaoluwa Osuntokun
1de7e30cd1
Merge pull request #4361 from yyforyongyu/add-channel-status
contractcourt: add ChannelStatus in MarkChannelClosed
2020-06-23 16:23:30 -07:00