Commit Graph

266 Commits

Author SHA1 Message Date
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
Conner Fromknecht
c1b9b272cd
input/size: assert witness size constants
This commit introduces a new test case that asserts all of the witness
size constants currently in the codebase. We also reintroduce the
AcceptedHtlcSuccessWitnessSize and OfferedHtlcTimeoutWitnessSize
constants that were recently removed for the sake of completeness.

In asserting the witnes sizes, there were three uncovered discrepancies:
 * OfferedHtlcSuccessWitnessSize overestimated by about 30% because it
   included an extra signature in the calculation.

 * ToLocalPenaltyWitnessSize was underestimated by one byte, because it
   was missing the length byte for the OP_TRUE. This has implications
   the watchtower protocol since the client and server are assumed to
   share the same weight estimates used for signing. This commit keeps
   the current behavior, with the intention of rolling out negotiation
   for which weight estimate to use for a given session.

 * AcceptedHtlcScriptSize was underestimated by one byte because it was
   missing a length byte for the value 32 pushed on the stack when
   asserting the preimage's length. This affects all AcceptedHtlc*
   witness sizes.
2020-04-10 15:34:27 -07:00
Conner Fromknecht
0f94b8dc62
multi: return input.Signature from SignOutputRaw 2020-04-10 14:27:35 -07:00
nsa
ada0b78dfc lnd+server+watchtower: allow Standalone access to the tor controller
This commit lets the watchtower automatically create hidden services
by giving it a pointer to a TorController. The server was also slightly
refactored so that it was not the sole owner of the TorController.
2020-03-29 12:36:54 -04:00
Olaoluwa Osuntokun
557b930c5f
watchtower: convert to use new kvdb abstraction 2020-03-18 19:35:01 -07:00
Conner Fromknecht
2510ec00f5
watchtower/wtwire/init: use feature.ValidateRequired
This allows us to remove the custom error type originally implemented
for this purpose.
2020-01-08 12:26:00 -08: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
Conner Fromknecht
8b5f16387c
watchtower/lookout: fix double-hex encoded chainhash 2019-11-05 15:05:20 -08: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
4b65aea306
watchtower+htlcswitch: update client tower logic to recognize safu commitments
In this commit, we update the tower+link logic to tag a commitment as
the new (tweakless) format if it applies. In order to do this, the
BackupTask method has gained an additional parameter to indicate the
type of commitment that we're attempting to upload. This new tweakless
bool is then threaded through all the way to back up task creation to
ensure that we make the proper input.Input.

Finally, we've added a new test case for each existing test case to test
each case w/ and w/o the tweakless modifier.
2019-09-25 18:25:55 -07:00
Joost Jager
3d7de2ad39
multi: remove dead code 2019-09-10 17:21:59 +02:00
Johan T. Halseth
21baa7bf18
multi: fix linter errors 2019-08-07 10:53:10 +02:00
Olaoluwa Osuntokun
8c9c4b52e8
Merge pull request #3184 from wpaulino/wtclient-subserver
multi: add watchtower client RPC subserver
2019-07-30 17:26:22 -07:00
Olaoluwa Osuntokun
69c9e2b732
Merge pull request #3278 from Crypt-iQ/bbolt_options_0707
channeldb: specify freelist bbolt options by default
2019-07-30 16:52:28 -07:00
Wilmer Paulino
0690c8f627
watchtower/wtclient: only reset iterator once we've exhausted all candidates
Doing so allows us to load balance sessions better amongst all of the
tower candidates.
2019-07-30 15:18:18 -07:00
Wilmer Paulino
0431701262
multi: only allow specifying towers to TowerClient through RPC
With the introduction of the WatchtowerClient RPC subserver, the lnd
configuration flag to specify private watchtowers for the client is no
longer needed and can lead to confusion upon users. Therefore, we remove
the flag completely, and only rely on the watchtower client being active
through a new --wtclient.active flag.
2019-07-30 15:18:17 -07:00
Wilmer Paulino
359b2049b6
watchtower: load persisted towers upon TowerClient creation
We do this as a convenience for WatchtowerClient users so that they do
not need to re-add towers upon restarts. We ensure not to re-add towers
that have been previously removed by determining whether it has any
lingering active sessions.
2019-07-30 15:18:17 -07:00
Wilmer Paulino
c57128097e
watchtower/wtclient: extend TowerClient with CRUD operations for towers
In this commit, we extend the wtclient.Client interface with the
following methods:

  * AddTower
  * RemoveTower
  * RegisteredTowers
  * LookupTower
  * Stats

Care has been taken to ensure that any in-memory state updates are
_only_ performed after a successful database update.

These methods are currently unused, but they serve as a dependency for
the upcoming WatchtowerClient RPC subserver.
2019-07-30 15:18:13 -07:00
Wilmer Paulino
06d10d8100
watchtower/wtclient: extend TowerCandidateIterator to update candidates 2019-07-30 15:13:24 -07:00
Wilmer Paulino
1d73a6564f
watchtower: extend client databse with CRUD operations for towers
These operations are currently unused, but will be integrated into the
TowerClient at a later point as future preparation for the
WatchtowerClient RPC subserver, which will allow users to add, remove,
and list the watchtowers currntly in use.
2019-07-30 15:13:23 -07:00
Wilmer Paulino
56d66c80a1
watchtower: extend client db to filter sessions for a specific tower
This currently takes O(N) time as there does not exist an index of
active client sessions for each watchtower within the client's database.
This index is likely to be added in the future.
2019-07-30 15:13:22 -07:00
Wilmer Paulino
4abadc82f3
watchtower/wtclient: export clientStats 2019-07-30 15:13:21 -07:00
Wilmer Paulino
159883665d
wtclient: refactor client creation after database calls 2019-07-30 15:13:20 -07:00
Wilmer Paulino
76f9c9bd52
watchtower/wtclient: remove stale sessionQueue TODO
The state updates that are pending to be acked by the tower are already
loaded within newSessionQueue.
2019-07-30 15:13:17 -07:00
Wilmer Paulino
1d2aba8cd4 watchtower/wtpolicy: properly set DefaultSweepFeeRate and MinSweepFeeRate
These values were intended to be 10 sat/vbyte and 4 sat/vbyte
respectively, but the conversion was done incorrectly.
2019-07-24 18:12:48 -07:00
nsa
66d15c8e76 channeldb + wtdb: specify freelist bbolt options by default
This commit specifies two bbolt options when opening the underlying
channel and watchtower databases so that there is reduced heap
pressure in case the bbolt database has a lot of free pages in the
B+ tree.
2019-07-08 18:41:25 -04:00
Conner Fromknecht
4b549cb43c
watchtower/wtpolicy/policy: bump default fee rate to 10 sat/byte 2019-07-01 15:56:03 -07:00
Conner Fromknecht
05107ce969
watchtower/wtdb: fix double hex encoding of chanid 2019-07-01 13:11:58 -07:00
Olaoluwa Osuntokun
7f48ff6717 watchtower: fix linter errors 2019-06-28 16:10:41 -07:00
Conner Fromknecht
bf042f1271
watchtower/wtclient: filter non-target towers from candidates 2019-06-20 18:17:23 -07:00
Olaoluwa Osuntokun
0506b1e587
Merge pull request #3224 from cfromknecht/wtserver-key-family
watchtower: use separate key family for wtserver public key, add watchtower subserver
2019-06-20 18:01:21 -07:00
Conner Fromknecht
c06d71530a
watchtowerrpc/standalone: implement watchtowerrpc.WatchtowerBackend iface 2019-06-20 17:04:04 -07:00
Conner Fromknecht
fa966a4901
watchtower: add externalip CLI configuration 2019-06-20 17:04:03 -07:00
Conner Fromknecht
7e81a5144e
watchtower: rename DefaultPeerPortStr -> DefaultListenAddr 2019-06-20 17:04:03 -07:00
Conner Fromknecht
997023cd7a
Merge pull request #3226 from cfromknecht/wtclient-log-fixups
watchtower/multi: fix logging in wtclient
2019-06-20 14:10:02 -07:00
Conner Fromknecht
3a4aba463b
routing+watchtower/wtclient: prints stats once per minute 2019-06-19 20:07:11 -07:00
Conner Fromknecht
fad8932d75
watchtower/multi: fix logging in wtclient 2019-06-19 19:57:59 -07:00
Conner Fromknecht
059887bd7b
watchtower/wtdb: apply sanity checks to session policy before accepting 2019-06-13 19:54:22 -07:00
Conner Fromknecht
1979f9a7c0
watchtower/multi: use sane sweep fee rate in unit tests 2019-06-13 19:54:22 -07:00
Conner Fromknecht
a543c781fe
watchtower/wtpolicy: add basic validity constraints 2019-06-13 19:54:22 -07:00
Conner Fromknecht
37052f1561
watchtower/wtdb: only accept properly sized blobs
Modifies the bbolt and mock tower databases to only accept blobs that
are the expected size of the session's blob type. This prevents resource
exhaustion attacks where a client may provide disproportionately large
encrypted blob, even though all supported blob types are of fixed-size.
2019-06-13 19:54:22 -07:00
Conner Fromknecht
dce24d1d47
watchtower/wtdb+wtserver: pass properly sized blob in unit tests 2019-06-13 19:54:22 -07:00
Conner Fromknecht
29009fdc34
watchtower/standalone: disable reward towers 2019-06-13 19:54:22 -07:00
Conner Fromknecht
6504058c74
watchtower/wtserver: add DisableReward config option 2019-06-13 19:54:21 -07:00
Conner Fromknecht
a246d8216a
watchtower/multi: define blob TypeAltruistCommit and TypeRewardCommit 2019-06-13 19:54:21 -07:00
Conner Fromknecht
2d47618055
watchtower/multi: define AltruistSessions feature bit as 0/1 2019-06-13 19:54:21 -07:00
Conner Fromknecht
86e1d111e5
watchtower/wtwire/message: bump wtwire messages outside reserved ranges
BOLT01 reserves the following ranges:
 - Setup & Control (types 0-31)
 - Channel (types 32-127)
 - Commitment (types 128-255)
 - Routing (types 256-511)

The wtwire messages now occupy 600-607.
2019-06-13 19:54:21 -07:00
Conner Fromknecht
7cabe2667f
watchtower/wtclient/client: use existing session with same TxPolicy
This commit modifies the client's filtering when selecting from existing
sessions. The new logic compares the configured TxPolicy with the
TxPolicy of the candidate sessions, which has the effect of ignoring
operational parameters such as MaxUpdates. Prior, changing MaxUpdates
would cause the client to request a new session even if it had perfectly
good slots available in a policy with an equal TxPolicy.
2019-06-13 19:54:21 -07:00
Conner Fromknecht
98c2d329e5
watchtower/multi: embed TxPolicy in wtpolicy.Policy
This commit splits out the parameters that shape the justice transaction
into their own struct, which then embedded within the overarching
wtpolicy.Policy which may have additional parameters describing
operation of the session.

This is done as a preliminary step to support comparison of sessions
based on matching TxPolicy configurations. This prevents otherwise
identical Policies from being counted as different if operational
parameters like MaxUpdates differ, even if it has no material difference
to the justice transaction.
2019-06-13 19:54:20 -07:00
Conner Fromknecht
9b365567b6
watchtower/wtclient/client: avoid over requesting sessions
This commit fixes a bug that would cause us to request more sessions
that needed from the session negotiator. With the current stat ticker,
we'd ask the negotiator for a new session every 30s if session
session negotiation did not return before printing the stats. Now we'll
avoid requesting to sessions by jumping back into the select loop.
2019-06-13 19:54:20 -07:00
Conner Fromknecht
c823878154
watchtower/conf: abstract address normalizer to prevent import cycle 2019-06-13 19:54:19 -07:00
Conner Fromknecht
db65d7ead4
watchtower/conf: remove experimental conditional compilation 2019-06-13 19:54:19 -07:00
Conner Fromknecht
d2f3d5ef6c
server: add watchtower client 2019-06-13 19:54:18 -07:00
Conner Fromknecht
ab4a4b77f5
watchtower/wtclient/session_queue: unify logging 2019-06-13 19:54:17 -07:00
Conner Fromknecht
3b51906a78
watchtower/multi: use new blob.BreachKey for enc/dec of justice kits 2019-06-13 19:54:17 -07:00
Conner Fromknecht
59bf4857f4
watchtower/blob/breach_key: define breach key as sha(txid || txid) 2019-06-13 19:33:16 -07:00
Conner Fromknecht
d9cfa610dc
watchtower/wtdb/breach_hint: redefine breach hint as sha(txid) 2019-06-13 19:33:16 -07:00
Conner Fromknecht
1b89ba1782
watchtower/multi: move BreachHint to blob pkg 2019-06-13 17:40:04 -07:00
Conner Fromknecht
28bf49807e
watchtower/wtdb: add CSessionStatus field to ClientSession
This commit adds persisted status bit-field to ClientSessions, that can
be used to modify behavior of their handling in the client. Currently,
only a default CSessionActive status is defined. However, the intention
is that this could later be used to signal that a session is abandoned
without needing to perform a db migration to add the field. As we move
forward with testing, this will likely be useful if a session gets
borked and we need a simple method of the client to temporarily ignore
certain sessions.

The field may be useful in signaling other types of status changes,
though this was the primary motivation that warranted the addition.
2019-05-24 18:24:41 -07:00
Conner Fromknecht
9157c88f93
watchtower/wtclient: dedup backups across restarts
Now that the committed and acked updates are persisted across restarts,
we will use them to filter out duplicate commit heights presented by the
client.
2019-05-24 18:24:41 -07:00
Conner Fromknecht
3be651b0b3
watchtower/wtdb: add ClientDB
This commit adds the full bbolt-backed client database as well as a set
of unit tests to assert that it exactly implements the same behavior as
the mock ClientDB.
2019-05-24 18:24:41 -07:00
Conner Fromknecht
b35a5b8892
watchtower/wtclient: integrate ClientChannelSummaries
In this commit, we utilize the more generic ClientChanSummary instead of
exposing methods that only allow us to set and fetch sweep pkscripts.
2019-05-23 20:48:50 -07:00
Conner Fromknecht
25fc464a6e
watchtower/wtdb/client_chan_summary: add ClientChanSummary
A ClientChanSummary will be inserted for each channel registered with
the client, which for now will just track the sweep pkscript to use. In
the future, this will be extended with additional information to enable
the client to efficiently compute which historical states need to be
backed up under a given policy.
2019-05-23 20:48:36 -07:00
Conner Fromknecht
440ae7818a
watchtower/wtmock/client_db: adjust mock clientdb behavior
In advance of the upcoming wtdb.ClientDB, we'll modify the behavior
of the mockdb to be more like the final bbolt backed one, and assert
that all or our tests are still passing.
2019-05-23 20:48:23 -07:00
Conner Fromknecht
2a904cb69f
watchtower/wtdb: add Encode/Decode methods to wtclient structs 2019-05-23 20:48:08 -07:00
Conner Fromknecht
1db9bf2fd4
watchtower/wtdb: create embedded ClientSessionBody
This commit splits out the portions of the ClientSession into an
embedded ClientSessionBody, since these fields will be serialized
together on-disk.
2019-05-23 20:47:49 -07:00
Conner Fromknecht
5ad9530502
watchtower/wtdb: return sorted ClientSession.CommittedUpdates
This commit replaces the map-based CommittedUpdates field with a slice.
When reading from disk, these will already be sorted by bbolt, so the
client restore the updates as presented without needing to sort them
first.

Since the key in the map variant was the sequence number, we refactor
the CommittedUpdate struct to have a sequence number and an embedded
CommittedUpdateBody (which is equivalent to the old CommittedUpdate).
The database is then expected to populate the sequence number from the
key on disk.

Since the sequence number is now directly integrated in the
CommittedUpdate struct, this allow allows us to remove the now redundant
seqNum argument from CommitUpdate.
2019-05-23 20:47:36 -07:00
Conner Fromknecht
3509c0c991
watchtower/multi: use proper TowerID type
This allows serialization methods to be added with TowerID method
receivers.
2019-05-23 20:47:22 -07:00
Conner Fromknecht
ec7c16fdc1
watchtower/wtdb: prepare for addition of client db
This commit renames the variables dbName to towerDBName and dbVersions
to towerDBVersions, to distinguish between the upcoming clientDBName
clientDBVersions. We also move resusable portions of the database
initialization and default endianness to its own file so that it can be
shared between both tower and client databases.
2019-05-23 20:47:08 -07:00
Conner Fromknecht
17b2140cb5
multi: fix spelling mistakes 2019-05-04 15:35:37 -07:00
Conner Fromknecht
54c908be1a
watchtower/wtserver/create_session: log missing error in create session 2019-04-26 17:22:02 -07:00
Conner Fromknecht
b7cd70f186
watchtower/wtdb/tower_db_test: add mock+bolt iface tests 2019-04-26 17:21:48 -07:00
Conner Fromknecht
3ef2a36733
watchtower/wtdb/tower_db: add TowerDB and db versioning 2019-04-26 17:21:35 -07:00
Conner Fromknecht
c99d1313fe
watchtower/wtdb/log: add WTDB logs 2019-04-26 17:21:20 -07:00
Conner Fromknecht
a36397e21a
watchtower/wtdb/codec_test: encode/decode quick checks 2019-04-26 17:21:05 -07:00
Conner Fromknecht
7ba197c6a7
watchtower/wtdb: add encode/decode to session info + updates 2019-04-26 17:20:52 -07:00
Conner Fromknecht
dccef4c8bf
watchtower/wtdb/codec: import channeldb code for extension 2019-04-26 17:20:36 -07:00
Conner Fromknecht
2ce6228021
watchtower/wtmock/tower_db: move mock tower db to wtmock pkg 2019-04-26 17:19:58 -07:00
Conner Fromknecht
d1ff783a9e
watchtower/wtclient/client_test: test no ack create session 2019-04-23 20:08:02 -07:00
Conner Fromknecht
71f72894f8
watchtower/wtclient/client: ensure dispatcher can force quit...
during session creation.
2019-04-23 20:07:46 -07:00
Conner Fromknecht
9603bfa602
watchtower/wtclient/session_negotiator: don't backoff on first attempt 2019-04-23 20:07:29 -07:00
Conner Fromknecht
1622a212d7
watchtower/wtserver: add NoAckCreateSession for testing 2019-04-23 20:07:12 -07:00
Conner Fromknecht
1000223c71
watchtower/wtwire/error_code: add DeleteSessionCodeNotFound string 2019-04-23 20:06:56 -07:00
Conner Fromknecht
590f5811e8
watchtower/wtserver/server: print connFailure error code name 2019-04-23 20:06:38 -07:00
Conner Fromknecht
ec6e2010d6
watchtower/wtmock: validate key index reservation 2019-04-23 20:06:20 -07:00
Conner Fromknecht
978a0a8de6
watchtower/wtserver/server: permit unused session overrwite 2019-04-23 20:06:04 -07:00
Conner Fromknecht
9b1bc9fd79
watchtower/wtwire/create_session_reply: return last applied 2019-04-23 20:05:47 -07:00
Conner Fromknecht
9aa775e64e
watchtower/wtserver/server: only generate addrs for reward sessions 2019-04-23 20:05:29 -07:00
Conner Fromknecht
999cbbdc54
watchtower/wtserver/server: check blob type first 2019-04-23 20:05:12 -07:00
Conner Fromknecht
bebe6461a9
watchtower/wtclient: use HD session key derivation 2019-04-23 20:04:55 -07:00
Conner Fromknecht
0404aedede
watchtower/wtclient/interface+wtmock: add session key reservation 2019-04-23 20:04:40 -07:00
Conner Fromknecht
df390df966
watchtower/wtmock/client_db: clone bytes w/ nil 2019-04-23 20:04:23 -07:00
Conner Fromknecht
c6f95c5667
watchtower/wtdb/client_session: replace keydesc w/ KeyIndex 2019-04-23 20:04:06 -07:00
Conner Fromknecht
2f9f46cf24
keychain/derivation: adds watchtower session key family 2019-04-23 20:03:48 -07:00
Conner Fromknecht
3af6eafc8e
watchtower/wtclient/interface: add SecretKeyRing iface 2019-04-23 20:03:15 -07:00
Conner Fromknecht
7d99005dde
watchtower/wtclient/interface: add LoadTower and mock impl 2019-04-23 19:17:21 -07:00
Olaoluwa Osuntokun
8e3a8f2d01
watchtower/wtclient: fix linter issue 2019-03-20 19:36:59 -07:00
Conner Fromknecht
0c519778a1
watchtower/wtserver/server_test: add TestServerDeleteSession 2019-03-19 19:41:17 -07:00
Conner Fromknecht
3564406dc1
watchtower/wtserver/server_test: cleanup test framework, remove test case indexes 2019-03-19 19:38:57 -07:00