Commit Graph

751 Commits

Author SHA1 Message Date
carla
d8a4b37c0e
contractcourt: persist commit sweep resolutions 2020-07-07 19:49:58 +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
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
578af99618
channeldb: save resolver outcomes in close summaries top level bucket
Add a new top level bucket which holds closed channels nested by chain
hash which contains additional information about channel closes. We add
resolver resolutions under their own key so that we can extend the
bucket with additional information if required.
2020-07-07 19:49:36 +02:00
Wilmer Paulino
6075997ebc
multi: add relative thaw height interpretation
This is useful when we wish to have a channel frozen for a specific
amount of blocks after its confirmation. This could also be done with an
absolute thaw height, but it does not suit cases where a strict block
delta needs to be enforced, as it's not possible to know for certain
when a channel will be included in the chain. To work around this, we
add a relative interpretation of the field, where if its value is below
500,000, then it's interpreted as a relative height. This approach
allows us to prevent further database modifications to account for a
relative thaw height.
2020-07-02 12:05:49 -07:00
Conner Fromknecht
11e9fd3e92
channeldb/invoices: special-case all zeros pay addr
Avoids indexing the all-zeros pay addr, since it is still in use by
legacy keysend. Without this, the pay addr index will reject all but the
first keysend since they will be detected as duplicates within the set
id index.
2020-06-26 02:00:03 -07:00
Wilmer Paulino
d23be59f53
channeldb: remove graph insertion of restored channels
This was initially done as there were a few assertions throughout the
codebase requiring a channel's policy to be known. Now that these have
been addressed, we no longer need to store restored channels in the
graph, as their policies where incomplete anyway.
2020-06-18 14:51:44 -07:00
carla
ab594ea57b
channeldb: update QueryPayments to use sequence nr index and paginator
Use the new paginatior strcut for payments. Add some tests which will
specifically test cases on and around the missing index we force in our
test to ensure that we properly handle this case. We also add a sanity
check in the test that checks that we can query when we have no
payments.
2020-06-10 12:55:05 +02:00
carla
38624e8612
channeldb: add fetchPaymentWithSequenceNumber lookup and test
With our new index of sequence number to index, it is possible for
more than one sequence number to point to the same hash because legacy
lnd allowed duplicate payments under the same hash. We now store these
payments in a nested bucket within the payments database. To allow
lookup of the correct payment from an index, we require matching of the
payment hash and sequence number.
2020-06-10 12:55:03 +02:00
carla
eea871b583
channeldb: add a paginator struct to process generic pagination
We now use the same method of pagination for invoices and payments.
Rather than duplicate logic across calls, we add a pagnator struct
which can have query specific logic plugged into it. This commit also
addresses an existing issue where a reverse query for invoices with an
offset larger than our last offset would not return any invoices. We
update this behaviour to act more like c.Seek and just start from the
last entry. This behaviour change is covered by a unit test that
previously checked for the lack of invoices.
2020-06-10 12:49:48 +02:00
carla
f4933c67fd
channeldb: add test case for index offset greater than index
In our current invoice pagination logic, we would not return any
invoices if our offset index was more than 1 off our last index and we
were paginating backwards. This commit adds a test case for this
behaviour before fixing it in the next commit.
2020-06-10 12:49:13 +02:00
carla
c8d11285f3
channeldb: index payments by sequence number
Add an entry to a payments index bucket which maps sequence number
to payment hash when we initiate payments. This allows for more
efficient paginated queries. We create the top level bucket in its
own migration so that we do not need to create it on the fly.

When we retry payments and provide them with a new sequence number, we
delete the index for their existing payment so that we do not have an
index that points to a non-existent payment.

If we delete a payment, we also delete its index entry. This prevents
us from looking up entries from indexes to payments that do not exist.
2020-06-10 12:49:06 +02:00
carla
6c4a1f4f99
channeldb: update TestQueryPayments to cover duplicate payments
Update our current tests to include lookup of duplicate payments. We
do so in preparation for changing our lookup to be based on a new
payments index. We add an append duplicate function which will add a
duplicate payment with the minimum information required to successfully
read it from disk in tests.
2020-06-10 12:34:27 +02:00
Andras Banki-Horvath
80012c3936
invoice+test: changing testitfy asserts to specific requires 2020-06-05 15:16:31 +02:00
Andras Banki-Horvath
574bbe5eba
invoices+test: replace DeepEqual + spew dump with testify
This commit replaces reflect.DeepEqual tests and spew.Dump prints with
testify's require.Equal to make diffs smaller and test outputs more
readable.
2020-06-05 15:16:27 +02:00
Andras Banki-Horvath
3e5e60cac4 lnd+kvdb: pass LND abort context to etcd 2020-06-03 17:44:44 +02:00
Andras Banki-Horvath
d3545830c9 kvdb+etcd: integrate the abort context to the STM retry loop
This commit extends the etcd.BackendConfig to also provide an abort
context and integrates it with the STM retry loop in order to be able
stop LND when conflicting transactions keep the loop running.
2020-06-03 17:44:44 +02:00
Andras Banki-Horvath
415de2f0c7 kvdb+etcd: remove retry goroutine from the STM
This commit removes the retry goroutine from the STM as the retry loop
is only running when the STM transaction is encapsulated in Update/View
whereas for self-standing transactions we use a different approach.
By removing the goroutine we won't catch panics thrown that are supposed
to be catched outside of the STM.
2020-06-03 17:44:44 +02:00
Joost Jager
d416ed59ea
multi: add explicit hodl invoice flag to invoice
Previously it wasn't possible to store a preimage in the invoice
database and signal that a payment should not be settled right away. The
only way to hold a payment was to insert the magic UnknownPreimage value
in the invoice database. This commit introduces a distinct flag to
signal that an invoice is a hold invoice and thereby allows the preimage
to be present in the database already.

Preparation for (key send) hodl invoices for which we already know the
preimage.
2020-06-02 07:34:23 +02:00
Conner Fromknecht
66652ec4bc
channeldb/db: lower-case ErrDryRunMigrationOk message 2020-05-27 22:42:22 -07:00
Conner Fromknecht
eae8e6de17
channeldb/invoices: correct stray kvdb.ReadBucket to RBucket
We recently renamed kvdb.ReadBucket to kvdb.RBucket in #4252, but this
was not detected in #4285 since this new code didn't produce a
conflict.
2020-05-27 20:20:29 -07:00
Conner Fromknecht
0f3ab775c7
Merge pull request #4285 from cfromknecht/pay-addr-index
channeldb: index payments by payment addr, use payment hash as fallback
2020-05-27 17:36:30 -07:00
Olaoluwa Osuntokun
d2d8793afd
Merge pull request #4298 from cfromknecht/sub-inv-fixes
channeldb+invoices: minor invoice subscription fixes
2020-05-27 15:56:47 -07:00
Conner Fromknecht
cbf71b5452
channeldb+invoices: use payment addr as primary index 2020-05-26 18:55:27 -07:00
Conner Fromknecht
3522f09a08
channeldb+invoices: track invoices by InvoiceRef 2020-05-26 18:55:27 -07:00
Conner Fromknecht
e80e21d1a8
channeldb/migration: add generic CreateTLB migration
This commit creates a generic migration for creating top-level buckets.
2020-05-26 18:55:27 -07:00
Conner Fromknecht
24cce7a6ec
channeldb: consolidate top-level bucket create/wipe 2020-05-26 18:55:27 -07:00
Conner Fromknecht
d343575104
channeldb/migtest: log migration failure instead of failing
This line was incorrectly moved when the migtest package was created for
migration 12. This PR introduces a negative test for CreateTLB which
surfaced this.
2020-05-26 18:55:22 -07:00
Conner Fromknecht
ef9068319b
multi: rename ReadCursor to RCursor 2020-05-26 18:21:08 -07: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
Conner Fromknecht
1332575482
channeldb/invoices: ignore error when no settles exist
This fixes a bug that would cause no backlog to be delivered at all.
2020-05-26 17:50:45 -07:00
Andras Banki-Horvath
c3fcfd1530 etcd: add namespace support to separate key spaces
This commit extends etcd db with namespaces without additional storage
space requirements. This is simply done by instead of using an all zero
root bucket id, we use the sha256 hash of the name space as our root
bucket id.
2020-05-22 11:26:25 +02:00
Andras Banki-Horvath
bce0597643 channeldb: silence linter 2020-05-22 11:26:25 +02:00
Andras Banki-Horvath
85aee9b064 kvdb+lncfg: fully move etcd behind build tag
This commit separates all etcd related sources (sans a few stubs and
config) from the rest of the source tree and makes compilation conditional
depending on whether the kvdb_etcd build tag is specified.
2020-05-22 11:26:25 +02:00
Andras Banki-Horvath
3ef331e016 lncfg+etcd: add TLS config
This commit extends lncfg with etcd TLS config and passes these
parameters to the etcd client upon construction.
2020-05-22 11:26:25 +02:00
Andras Banki-Horvath
b54f8a1b97 kvdb+channeldb: create ExtendedBackend interface to allow rich tx logic
This commit adds the ExtendedBackend interface which is an extension to
the walletdb.DB interface. This paves the way to using etcd.db.View and
etcd.db.Update in the global View and Update functions without much code
rewrite.
2020-05-22 11:26:25 +02:00
Andras Banki-Horvath
23fcb59a2b channeldb: convert payment tests to use test backend 2020-05-22 11:26:25 +02:00
Andras Banki-Horvath
02f9d91e49 kvdb+etcd: only lock on bucket path mod revision for reads and writes
This commit reduces the compare set size the STM will submit in
transactions by adding only the bucket keys along the bucket path to a
specific lock set. This lock set then used to filter the read set,
effectively removing all read only keys from the transaction predicate
that are not bucket keys.
By tracking if a read-write tx actually changes something, we can also
"bump" the mod revision of the bucket keys.
With this trick we essentially implement a read-write lock for our
bucket structure greatly reducing transaction processing time.
2020-05-22 11:26:25 +02:00
Andras Banki-Horvath
859a457e48 kvdb+etcd: extend kvdb and STM with stats
The commit itslef adds stats to the transactions such that we can see
how LND behaves with and etcd backend.
2020-05-22 11:26:25 +02:00
Andras Banki-Horvath
248a00f211 kvdb+etcd: enable channeldb testing with both bdb/etcd 2020-05-22 11:26:25 +02:00
Andras Banki-Horvath
3b7525659c channeldb+kvdb: add walletdb interface test
This commit adds walletdb interface test suite to the existing test set.
2020-05-22 11:26:25 +02:00
Andras Banki-Horvath
6a24a03cec channeldb+kvdb: walletdb/kvdb interface etcd implementation
This commit adds a full interface implementation of the walletdb/kvdb
interface with detailed tests.
2020-05-22 11:26:25 +02:00
Andras Banki-Horvath
137dee04e8 channeldb+kvdb: an extended STM on top of etcd clientv3
This commit adds an extended STM, similar to what available in etcd's
clientv3 module. This incarnation of said STM supports additional
features, like positioning in key intervals while taking into account
deletes and writes as well. This is a preliminary work to support all
features of the kvdb interface.
2020-05-22 11:26:24 +02:00
Oliver Gugger
a17ddc5dd1
channeldb+htlcswitch: don't use fastsha256 in tests
The btcsuite/fastsha256 registers itself in the crypto package of
golang as a replacement for sha256. This causes problems in TLS1.3
connections that require the hash implementations to be serializable
and results in the "tls: internal error: failed to clone hash" error.
By removing all uses of the library we fix that error.
2020-05-20 11:07:38 +02:00
Conner Fromknecht
2f84d1a819
Merge pull request #4280 from cfromknecht/read-for-each-node
channeldb: remove Tx arg from ForEachNode
2020-05-13 16:37:10 -07:00
Conner Fromknecht
90d3bf532d
channeldb+routing: remove tx arg for ForEachNode 2020-05-12 17:53:20 -07:00
Joost Jager
cc37485432
routing: return full htlc attempt from shard handler 2020-05-12 19:56:50 +02:00