lnd.xprv/channeldb
Conner Fromknecht fc9af92dd9
channeldb: only accept/settle non-empty HTLC sets
Prior to AMP, there could only be one HTLC set. Now that there can be
multiple, we introduce the inherent risk that we might be persisting a
settle/accept of the wrong HTLC set. To migitigate this risk, we add a
check to assert that an invoice can only be transitioned into an
Accepted or Settled state if the specified HTLC set is non-empty, i.e.
has accepted HTLCs.

To do this check, we unroll the loops in UpdateInvoice to first process
any added or canceled HTLCs. This ensures that the set of accepted HTLCs
is up-to-date when we got to transition the invoice into a new state, at
which point we can accurately check that the HTLC set is non-empty.
Previously this sort of check wasn't possible because a newly added HTLC
wouldn't be populated on the invoice when going to call
updateInvoiceState.

Once the invoice-level transition checks have completed, we complete a
final pass to move the HTLCs into their final states and recompute the
amount paid.

With this refactor, it is now possible to make stronger assertions
about the invoice and the state transitions being made by the
invoiceregistry before those changes are ultimately persisted.
2021-03-03 16:28:02 -08:00
..
kvdb etcd: add support for user specified ports for testing 2021-01-08 15:39:11 +01:00
migration channeldb/migration: copy current lnwire to migration dir 2021-02-24 14:34:57 +01:00
migration_01_to_11 channeldb/migration: copy current lnwire to migration dir 2021-02-24 14:34:57 +01:00
migration12 channeldb/migration: copy current lnwire to migration dir 2021-02-24 14:34:57 +01:00
migration13 channeldb: convert to uniformly use new kvdb abstractions 2020-03-18 19:34:49 -07:00
migration16 channeldb: index payments by sequence number 2020-06-10 12:49:06 +02:00
migration20 channeldb/migration20: TestMigrateOutpointIndex 2020-12-10 17:37:59 -08:00
migration21 channeldb/migration21: add body and tests for migration 21 2021-02-24 17:31:55 +01:00
migtest channeldb: mark ApplyMigration as a test helper 2021-02-24 14:34:57 +01:00
addr_test.go channeldb/addr_test: add tests for invalid onion addresses 2019-01-17 14:16:15 +01:00
addr.go channeldb/addr: sanity check onion address length before writing to db 2019-01-17 14:16:15 +01:00
channel_cache_test.go channeldb/channel_cache: add channelCache w/ randomized eviction 2019-04-01 16:25:31 -07:00
channel_cache.go channeldb/channel_cache: add channelCache w/ randomized eviction 2019-04-01 16:25:31 -07:00
channel_test.go lnwire: prep wire messages for TLV extensions 2021-02-24 17:31:55 +01:00
channel.go channeldb+htlcswitch: write wire messages using length prefix 2021-02-24 17:15:27 +01:00
codec.go channeldb+htlcswitch: write wire messages using length prefix 2021-02-24 17:15:27 +01:00
db_test.go channeldb/db: properly reinit wallet during Wipe 2020-12-10 17:37:58 -08:00
db.go channeldb/invoices: add invoices to set id index on update 2021-03-03 16:28:01 -08:00
doc.go channeldb: create new channeldb package, update lnwallet to use new API 2015-12-26 12:35:15 -06:00
duplicate_payments.go multi: rename: ReadBucket to RBucket 2020-05-26 18:21:08 -07:00
error.go channeldb+invoices: use payment addr as primary index 2020-05-26 18:55:27 -07:00
fees.go channeldb: create new channeldb package, update lnwallet to use new API 2015-12-26 12:35:15 -06:00
forwarding_log_test.go channeldb: fix for Windows clock resolution 2020-08-05 09:15:03 +02:00
forwarding_log.go multi: add reset closure to kvdb.View 2020-11-05 17:57:12 +01:00
forwarding_package_test.go kvdb: add timeout options for bbolt (#4787) 2020-12-07 15:31:49 -08:00
forwarding_package.go channeldb/migration21: copy over legacy types+codec for migration21 2021-02-24 17:15:21 +01:00
graph_test.go discovery: adhere to proper channel chunk splitting for ReplyChannelRange 2020-12-08 15:18:07 -08:00
graph.go channeldb: add SchedulerOp arg to graph update methods 2021-02-10 23:54:03 +01:00
invoice_test.go channeldb: only accept/settle non-empty HTLC sets 2021-03-03 16:28:02 -08:00
invoices.go channeldb: only accept/settle non-empty HTLC sets 2021-03-03 16:28:02 -08:00
legacy_serialization.go Revert "channeldb: remove unsupported migrations" 2019-10-12 00:47:45 -07:00
log.go channeldb: implement compaction 2020-11-13 10:19:50 +01:00
meta_test.go multi: add reset closure to kvdb.Update 2020-11-05 17:57:12 +01:00
meta.go multi: add reset closure to kvdb.Update 2020-11-05 17:57:12 +01:00
mp_payment.go routing: return full htlc attempt from shard handler 2020-05-12 19:56:50 +02:00
nodes_test.go channeldb: move makeTestDB out of test to make it available for other tests 2020-07-28 17:57:29 +02:00
nodes.go multi: add reset closure to kvdb.Update 2020-11-05 17:57:12 +01:00
options_test.go kvdb: add timeout options for bbolt (#4787) 2020-12-07 15:31:49 -08:00
options.go kvdb: add timeout options for bbolt (#4787) 2020-12-07 15:31:49 -08:00
paginate.go channeldb: add a paginator struct to process generic pagination 2020-06-10 12:49:48 +02:00
payment_control_test.go channeldb: add failedHtlcsOnly option to DeletePayments 2021-02-22 12:50:25 +01:00
payment_control.go multi: add reset closure to kvdb.View 2020-11-05 17:57:12 +01:00
payments_test.go channeldb/payments_test: handle that dupe payments will always have StatusSuccess 2021-02-22 12:50:24 +01:00
payments.go channeldb: add failedHtlcsOnly option to DeletePayments 2021-02-22 12:50:25 +01:00
peers_test.go multi: store peer flap rate on disk on best effort basis 2020-09-08 13:49:46 +02:00
peers.go multi: add reset closure to kvdb.Update 2020-11-05 17:57:12 +01:00
README.md multi: unify code blocks in READMEs 2021-01-22 09:14:11 +01:00
reject_cache_test.go channeldb/reject_cache: add rejectCache w/ randomized eviction 2019-04-01 16:25:31 -07:00
reject_cache.go channeldb/reject_cache: add rejectCache w/ randomized eviction 2019-04-01 16:25:31 -07:00
reports_test.go multi: add reset closure to kvdb.Update 2020-11-05 17:57:12 +01:00
reports.go multi: add reset closure to kvdb.Update 2020-11-05 17:57:12 +01:00
waitingproof_test.go lnwire: prep wire messages for TLV extensions 2021-02-24 17:31:55 +01:00
waitingproof.go multi: add reset closure to kvdb.Update 2020-11-05 17:57:12 +01:00
witness_cache_test.go channeldb: move makeTestDB out of test to make it available for other tests 2020-07-28 17:57:29 +02:00
witness_cache.go multi: add reset closure to kvdb.View 2020-11-05 17:57:12 +01:00

channeldb

Build Status MIT licensed GoDoc

The channeldb implements the persistent storage engine for lnd and generically a data storage layer for the required state within the Lightning Network. The backing storage engine is boltdb, an embedded pure-go key-value store based off of LMDB.

The package implements an object-oriented storage model with queries and mutations flowing through a particular object instance rather than the database itself. The storage implemented by the objects includes: open channels, past commitment revocation states, the channel graph which includes authenticated node and channel announcements, outgoing payments, and invoices

Installation and Updating

⛰  go get -u github.com/lightningnetwork/lnd/channeldb