Commit Graph

264 Commits

Author SHA1 Message Date
Conner Fromknecht
e0e57642b6
wtclient/client: fix missed prefix log 2021-01-04 08:33:34 -08:00
Conner Fromknecht
1d3535582b
wtclient/seseion_queue: add prefix logging 2021-01-04 08:32:34 -08:00
Conner Fromknecht
de09b8d9bd
wtclient/session_negotiator: add prefix logging 2021-01-04 08:32:34 -08:00
Conner Fromknecht
505901d7b8
wtclient/task_pipeline: add prefix logging 2021-01-04 08:32:31 -08: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
Conner Fromknecht
6b4df04950
wtclient_tests: remove expErr param from nextKeyIndex
This command cannot fail (apart from commit errors) so the linter
complained that the argument was always nil.
2020-12-01 16:55:24 -08:00
Conner Fromknecht
9bd73c0a85
wtdb+wtclient: segregate session-key-index reservations by blob-type
This commit introduces a change in the key format used to reserve/lookup
session-key-indexes. Currently the reservations are stored under the
tower id, however this creates issues when multiple clients are using
the same database since only one reservation is permitted per tower.

We fix this by appending the blob type to the session-key-index locator.
This allows multiple clients to reserve keys for the same tower, but
still limits each client to one outstanding reservation. The changes are
made in a way such that we fall back to the legacy format if the a
reservation under the new format is not found, but only if the blob type
matches blob.TypeAltruistCommit, which is so far the only actively
deployed blob type.
2020-12-01 16:24:16 -08:00
Olaoluwa Osuntokun
94f8311667
Merge pull request #4782 from cfromknecht/anchor-wtserver
watchtower: anchor channel support
2020-11-30 17:49:32 -08:00
Conner Fromknecht
1f86526250
wtclient: add backoff in negotiation when createSession() fails
Currently if the tower hangs up during session negotiation there is no
backoff applied. We add backoff here to avoid excessive CPU/network
utilization during unexpected failures.
2020-11-30 13:08:18 -08:00
Conner Fromknecht
5aa59906b5
wtclient: schedule ForceQuit first during Stop
Currently the ForceQuit call is scheduled after trying to stop the
backup queue. In certain cases, the call to stop the queue never
finishes, which means the force quit is never scheduled. We rememdy by
scheduling this call before any other operations to ensure we can always
exit ungracefully if necessary.
2020-11-30 13:08:04 -08:00
Conner Fromknecht
7fc4c7c412
wtclient: prefix client logs w/ legacy or anchor 2020-11-25 15:39:14 -08:00
Conner Fromknecht
781c6e5bea
wtclient: add anchor-aware session negotiation and filtering 2020-11-25 15:05:36 -08:00
Conner Fromknecht
eb00e496bf
watchtower/wtclient: add anchor backup tasks 2020-11-25 15:05:17 -08:00
Conner Fromknecht
97cb030854
wtclient: error on unknown witness type for backup task 2020-11-25 15:04:57 -08:00
Conner Fromknecht
74416c63f8
watchtower/wtpolicy: add IsAnchorChannel helper 2020-11-25 15:04:23 -08:00
Conner Fromknecht
dd325f04d2
watchtower/wtclient: parameterize backup task with channel type 2020-11-25 15:04:12 -08:00
Conner Fromknecht
3856acce50
wathtower/blob+wtserver: support anchor sessions 2020-11-25 15:04:00 -08:00
Conner Fromknecht
069296c46c
watchtower/wtwire: add AnchorCommit feature bits
Adds the optional/required feature bit pair for negotiating sessions for
anchor channels under features bits 2+3.
2020-11-25 15:03:49 -08:00
Conner Fromknecht
b9f031b3e3
Merge pull request #4746 from wpaulino/tower-last-addr
watchtower: prevent removal of last tower addr
2020-11-11 09:27:54 -08: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
Wilmer Paulino
d3157bcaf8
watchtower: prevent removal of last tower addr
This addresses a potential panic when a tower has one of its candidate
sessions chosen, but its only reachable address was removed by a
user-initiated RPC before the fact.
2020-11-04 15:43:18 -08:00
Olaoluwa Osuntokun
50976e5418
Merge pull request #4576 from cfromknecht/anchor-justice-txn
watchtower: conditionally reconstruct justice txns for anchor channels
2020-09-22 21:10:53 -07:00
yyforyongyu
ef38b12fda
multi: use timeout field in dialer 2020-09-16 11:50:04 +08:00
Conner Fromknecht
a0e54a9650
watchtower/lookout: use correct to-local-penalty size for anchors
This commit fixes the to-local-witness estimate to use the correct
witness size estimate for anchor channels. We retain the off-by-one bug
from the original constant otherwise.
2020-09-15 12:48:23 -04:00
Conner Fromknecht
d440cc4024
watchtower/lookout/justice_descriptor: anchor justice txn
This commit modifies the JusticeDescriptor to support creation of
justice transactions spending from anchor commitments. Rather than the
unencumbered p2wkh scripts from before, the tower will now use the
to-remote-confirmed that includes the additional CSV delay of 1. This
also requires setting the sequence number appropriately on the to-remote
input.
2020-09-15 12:44:00 -04:00
Conner Fromknecht
cfbde5d2ce
watchtower/lookout/justice_descriptor_test: use require 2020-09-15 12:43:52 -04:00
Conner Fromknecht
ac2e1d7d96
watchtower/blob/justice_kit: conditional anchor to-remote script
This commit modifies the ToRemoteWitnessScript function to be
conditioned on the blob type, and return either the legacy or anchor
to-remote script. The same witness satisfies either script, so no
changes are necessary to ToRemoteWitnessStack.
2020-09-15 12:43:44 -04:00
Conner Fromknecht
ffe15e2820
watchtower/blob/justice_kit: add BlobType to JusticeKit struct
This is preparation for later commits where the values returned by
member methods will need to be conditioned on the blob type used during
decryption.
2020-09-15 12:43:37 -04:00
Conner Fromknecht
b82695dbcc
watchtower/blob/justice_kit_test: convert to require
This is also a prepatory step to making
TestJusticeKitRemoteWitnessConstruction parameteried by the blob type so
we can test both anchor and legacy witness construction.
2020-09-15 12:43:26 -04:00
Conner Fromknecht
0477c80732
watchtower/blob/type: add new FlagAnchorChannel 2020-09-15 12:43:20 -04:00
Conner Fromknecht
ed67ce7678
watchtower/blob/type: remove use of iota for flag constants 2020-09-15 12:43:06 -04:00
Olaoluwa Osuntokun
05fbd5a9a0
Merge pull request #4548 from cfromknecht/remove-dev-wt-tests
watchtower: remove dev tag from unit test files
2020-08-20 18:43:18 -07:00
Conner Fromknecht
04e1e2298f
watchtower: remove dev tag from unit test files
Several watchtower unit tests were not being executed by make unit since
they require the dev tag to be passed in. All tests still pass.
2020-08-20 12:12:51 -07: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
Conner Fromknecht
455ddfebdb
multi: rename: ReadBucket to RBucket 2020-05-26 18:21:08 -07:00
Conner Fromknecht
d0d2ca403d
multi: rename ReadTx to RTx 2020-05-26 18:20:37 -07:00
Oliver Gugger
f97e7b9951
watchtower: use ECDH interface for watchtower session 2020-05-20 09:06:57 +02:00
Oliver Gugger
535a22c590
server+brontide: use ECDH interface for brontide handshake 2020-05-20 09:06:56 +02:00
Oliver Gugger
6f702a43aa
watchtower: extend and rename SecretKeyRing 2020-05-20 09:05:15 +02:00
Oliver Gugger
b0cb110e86
watchtower: rename SessionPrivKey to SessionKeyECDH 2020-05-20 09:05:15 +02:00
Oliver Gugger
140731af00
lnd+watchtower: rename NodePrivKey to NodeKeyECDH 2020-05-20 09:05:14 +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
c760700545
wtmock: prevent race conditions by not using ClientSession pointers
These race conditions originate from the mock database storing and
returning pointers, rather than returning a copy.

Observed on Travis:

WARNING: DATA RACE
Read at 0x00c0003222b8 by goroutine 149:
  github.com/lightningnetwork/lnd/watchtower/wtclient.(*sessionQueue).drainBackups()
      /home/runner/work/lnd/lnd/watchtower/wtclient/session_queue.go:288 +0xed
  github.com/lightningnetwork/lnd/watchtower/wtclient.(*sessionQueue).sessionManager()
      /home/runner/work/lnd/lnd/watchtower/wtclient/session_queue.go:281 +0x450

Previous write at 0x00c0003222b8 by goroutine 93:
  github.com/lightningnetwork/lnd/watchtower/wtclient.getClientSessions()
      /home/runner/work/lnd/lnd/watchtower/wtclient/client.go:365 +0x24f
  github.com/lightningnetwork/lnd/watchtower/wtclient.(*TowerClient).handleNewTower()
      /home/runner/work/lnd/lnd/watchtower/wtclient/client.go:1063 +0x23e
  github.com/lightningnetwork/lnd/watchtower/wtclient.(*TowerClient).backupDispatcher()
      /home/runner/work/lnd/lnd/watchtower/wtclient/client.go:784 +0x10b9
2020-05-14 15:39:03 -07:00
Wilmer Paulino
f6f0d3819f
wtclient: test case re-add removed tower 2020-05-14 13:48:08 -07:00
Wilmer Paulino
ec5c941512
wtclient: filter out inactive sessions upon adding existing/new tower 2020-05-14 13:35:02 -07:00
Wilmer Paulino
75c2ebd794
wtclient: load missing info into client sessions upon new tower
This addresses a potential panic in where we relied on this missing info
being populated.
2020-05-14 13:35:00 -07:00
Wilmer Paulino
01ab551b22
wtclient: refactor existing candidate session filtering into method 2020-05-14 13:34:59 -07:00
Andras Banki-Horvath
f3f482d9f9 watchtower: one append instead of appends in a loop 2020-04-24 19:15:08 +02:00
Andras Banki-Horvath
e1385af5a6 watchtower: remove dead logging code 2020-04-24 19:15:08 +02:00