Commit Graph

1184 Commits

Author SHA1 Message Date
Elle Mouton
034283db10
channeldb: update TestGraphZombieIndex to use require 2023-11-13 20:58:05 +02:00
yyforyongyu
da8f1c084a
channeldb+routing: add new interface method TerminalInfo
This commit adds a new interface method `TerminalInfo` and changes its
implementation to return an `*HTLCAttempt` so it includes the route for
a successful payment. Method `GetFailureReason` is now removed as its
returned value can be found in the above method.
2023-11-13 16:09:11 +08:00
yyforyongyu
e8c0226e1c
routing: add AllowMoreAttempts to decide whether more attempts are allowed 2023-11-13 16:09:11 +08:00
yyforyongyu
7209c65ccf
routing: split launchShard into registerAttempt and sendAttempt
This commit removes the method `launchShard` and splits its original
functionality into two steps - first create the attempt, second send the
attempt. This enables us to have finer control over "which error is
returned from which system and how to handle it".
2023-11-13 16:09:10 +08:00
Elle Mouton
0e82293e45
multi: address linter issues 2023-11-08 14:50:35 +02:00
Elle Mouton
84cdcd6847
multi: move DB schemas to channeldb/models
This commit moves the ChannelEdgePolicy, ChannelEdgeInfo,
ChanelAuthProof and CachedEdgePolicy structs to the `channeldb/models`
package.
2023-11-08 14:50:35 +02:00
Elle Mouton
78ff28fea1
channeldb: remove unused func arguments 2023-11-08 14:50:35 +02:00
Elle Mouton
3a17479ff4
multi: remove LightningNode from ChannelEdgePolicy
Finally, The LightningNode object is removed from ChannelEdgePolicy.
This is a step towards letting ChannelEdgePolicy reflect exactly the
schema that is on disk.

This is also nice because the `Node` object is not necessarily always
required when the ChannelEdgePolicy is loaded from the DB, so now it
only get's loaded when needed.
2023-11-08 14:50:34 +02:00
Elle Mouton
6c76d31e89
multi: let FetchLightningNode take an optional tx
In preparation for the next commit which will remove the
`*LightningNode` from the `ChannelEdgePolicy` struct,
`FetchLightningNode` is modified to take in an optional transaction so
that it can be utilised in places where a transaction exists.
2023-11-08 14:50:34 +02:00
Elle Mouton
9a62a46aa3
channeldb: remove kvdb.Backend from ChannelEdgePolicy 2023-11-08 14:50:34 +02:00
Elle Mouton
f06f08f596
channeldb: remove kvdb.Backend from ChannelEdgeInfo 2023-11-08 14:50:34 +02:00
Elle Mouton
9dc1a1dfec
channeldb: convert FetchOtherNode to ChannelGraph method
To prepare for the `kvdb.Backend` member of `ChannelEdgeInfo` being
removed, the `FetchOtherNode` method is moved from the `ChannelEdgeInfo`
to the `ChannelGraph` struct.
2023-11-08 14:50:34 +02:00
Elle Mouton
6d878c65fc
channeldb: remove kvdb.Backend from LightningNode
Now that the kvdb.Backend is no longer required, it is removed from the
LightningNode struct.
2023-11-08 14:50:34 +02:00
Elle Mouton
fa7c1e250b
multi: let ForEachChannel be a method on ChannelGraph
Having a `ForEachChannel` method on the `LightningNode` struct itself
results in a `kvdb.Backend` object needing to be stored within the
LightningNode struct. In this commit, this method is replaced with a
`ForEachNodeChannel` method on the `ChannelGraph` struct will perform
the same function without needing the db pointer to be stored within the
LightningNode. This change, the LightningNode struct more closely
represents the schema on disk.

The existing `ForEachNodeChannel` method on `ChannelGraph` is renamed to
`ForEachNodeDirectedChannel`. It performs a slightly different function
since it's call-back operates on Cached policies.
2023-11-08 10:51:50 +02:00
Andras Banki-Horvath
8bf7503aa4
invoices: remove the now unused ScanInvoices method 2023-10-18 16:15:58 +02:00
Andras Banki-Horvath
8ab267ad90
channeldb: add k/v implementation for InvoiceDB.DeleteCanceledInvoices method 2023-10-18 16:15:58 +02:00
Andras Banki-Horvath
1f8065de35
channeldb: add k/v implementation for InvoiceDB.FetchPendingInvoices 2023-10-18 16:15:57 +02:00
András Bánki-Horváth
ad5cd9c8bb
multi: extend InvoiceDB methods with a context argument (#8066)
* multi: extend InvoiceDB methods with a context argument

This commit adds a context to InvoiceDB's methods. Along this refactor
we also extend InvoiceRegistry methods with contexts where it makes
sense. This change is essential to be able to provide kvdb and sqldb
implementations for InvoiceDB.

* channeldb: restrict invoice tests to only use an InvoiceDB instance

* docs: update release notes for 0.18.0
2023-10-11 13:42:59 +02:00
Carla Kirk-Cohen
fee0e05708 multi: add blinded path TLVs to onion payload / hops
This commit adds the encrypted_data, blinding_point and total_amt_msat
tlvs to the known set of even tlvs for the onion payload. These TLVs
are added in two places (the onion payload and hop struct) because
lnd uses the same set of TLV types for both structs (and they
inherently represent the same thing).

Note: in some places, unit tests intentionally mimic the style
of older tests, so as to be more consistently readable.
2023-10-06 16:38:33 -07:00
yyforyongyu
20e7e801c0 routing+channeldb: use HTLCAttempt instead of HTLCAttemptInfo
This commit refactors the params used in lifecycle to prefer
`HTLCAttempt` over `HTLCAttemptInfo`. This change is needed as
`HTLCAttempt` also wraps settled and failure info, which is useful in
the following commits.
2023-10-06 16:38:33 -07:00
yyforyongyu
34d0e5d4c5 routing+channeldb: make MPPayment into an interface
This commit turns `MPPayment` into an interface inside `routing`. Having
this interface gives us the benefit to write more granular unit tests
inside payment lifecycle. As seen from the modified unit tests, several
hacky ways of testing the `SendPayment` method is now replaced by a mock
over `MPPayment`.
2023-10-06 16:38:33 -07:00
yyforyongyu
e5840f6216 channeldb+routing: add NeedWaitAttempts to decide waiting for attempts
This commit adds a new method, `NeedWaitAttempts`, to properly decide
whether we need to wait for the outcome of htlc attempts based on the
payment's current state.
2023-10-06 16:38:33 -07:00
yyforyongyu
89ac071e56 channeldb: add HasSettledHTLC and PaymentFailed fields to state 2023-10-06 16:38:33 -07:00
yyforyongyu
52c00e8cc4 multi: move payment state handling into MPPayment
This commit moves the struct `paymentState` used in `routing` into
`channeldb` and replaces it with `MPPaymentState`. In the following
commit we'd see the benefit, that we don't need to pass variables back
and forth between the two packages. More importantly, this state is put
closer to its origin, and is strictly updated whenever a payment is read
from disk. This approach is less error-prone comparing to the previous
one, which both the `payment` and `paymentState` need to be updated at
the same time to make sure the data stay consistant in a parallel
environment.
2023-10-06 16:38:31 -07:00
yyforyongyu
c175386c4d channeldb+routing: apply method Terminated to decide a payment's terminal state
This commit applies the new method `Terminated`. A side effect from
using this method is, we can now save one query `fetchPayment` inside
`FetchInFlightPayments`.
2023-10-06 16:34:47 -07:00
yyforyongyu
fac6044501 channeldb: add unit test for decidePaymentStatus 2023-10-06 16:34:47 -07:00
yyforyongyu
390f3c8253 channeldb: expand PaymentStatus to explicitly represent payment status
This commit introduces more granular statuses to better determine a
payment's current state. Based on whether there are inflight HTLCs, the
state of each of the HTLCs, and whether the payment is failed, a total
of 5 states are derived, which can give a finer control over what action
to take based on a given state.

Also, `fetchPayment` now uses `decidePaymentStatus`. After applying the
new function, the returned payment status would be different,

```
| inflight | settled | failed | reason |       previous  ->   now          |
|:--------:|:-------:|:------:|:------:|:---------------------------------:|
|   true   |   true  |  true  |   yes  |    StatusInFlight(unchanged)      |
|   true   |   true  |  true  |   no   |    StatusInFlight(unchanged)      |
|   true   |   true  |  false |   yes  |    StatusInFlight(unchanged)      |
|   true   |   true  |  false |   no   |    StatusInFlight(unchanged)      |
|   true   |   false |  true  |   yes  |    StatusInFlight(unchanged)      |
|   true   |   false |  true  |   no   |    StatusInFlight(unchanged)      |
|   true   |   false |  false |   yes  |    StatusInFlight(unchanged)      |
|   true   |   false |  false |   no   |    StatusInFlight(unchanged)      |
|   false  |   true  |  true  |   yes  |    StatusSucceeded(unchanged)     |
|   false  |   true  |  true  |   no   |    StatusSucceeded(unchanged)     |
|   false  |   true  |  false |   yes  |    StatusSucceeded(unchanged)     |
|   false  |   true  |  false |   no   |    StatusSucceeded(unchanged)     |
|   false  |   false |  true  |   yes  |     StatusFailed(unchanged)       |
|   false  |   false |  true  |   no   |     StatusInFlight(unchanged)     |
|   false  |   false |  false |   yes  |     StatusFailed(unchanged)       |
|   false  |   false |  false |   no   |  StatusInFlight -> StatusInitiated|
```
2023-10-06 16:34:47 -07:00
yyforyongyu
09b67af48d channeldb: add method Registrable to decide adding HTLCs
This commit adds a new method, `Registrable`, to help decide whether
adding new HTLCs to a given payment is allowed. A new unit test,
`TestRegistrable` is also added to test it.
2023-10-06 16:34:47 -07:00
yyforyongyu
c71601124a channeldb: fix variable name used in RegisterAttempt
Renamed `p` to `payment` to since it's used by the method's pointer receiver.
2023-10-06 16:34:47 -07:00
yyforyongyu
105c275b91 channeldb: add method updatable to decide updating payments
This commit adds a new method, `updatable`, to help decide whether
updating a given payment is allowed.
2023-10-06 16:34:47 -07:00
yyforyongyu
a6f4f0dfc9 channeldb: add method removable to decide removing payments
This commit adds a new method, `removable`, to help decide whether
deleting a payment is allowed.
2023-10-06 16:34:47 -07:00
yyforyongyu
de33c3e009 channeldb: add method initializable to decide initiating payment
This commit adds a new method, `initializable`, to help decide whether
initiating a payment is allowed.
2023-10-06 16:34:47 -07:00
yyforyongyu
30fd29371c channeldb: add new payment status StatusInitiated
This commit adds a new payment status, `StatusInitiated`, to properly
represent the state where a payment is newly created without attempting
any HTLCs. Since the `PaymentStatus` is a memory representation of a
given payment's status, the enum used for the statuses are directly
updated.
2023-10-06 16:34:47 -07:00
yyforyongyu
6be3817eed channeldb: return error when payment is not initialized
This commit changes `fetchPaymentStatus` to return an error when the
payment creation info bucket cannot be found. Instead of using the
ambiguous status `StatusUnknown`, we tell the callsite explictly that
there's no such payment. This also means the vague `StatusUnknown` can
now be removed as it has multiple meanings.
2023-10-06 16:34:47 -07:00
yyforyongyu
21cecc40e1 channeldb: return error when payment is not found in duplicate payments
We also update the legacy code to return an error when the payment is
not found.
2023-10-06 16:34:47 -07:00
Jamal James
cbb4c27a44
docs: fix simple-taproot-channels typo [skip ci] (#7926) 2023-08-25 15:48:37 -07:00
Elle Mouton
dfec4a65cb
multi: update lightning-onion version
Update the lighting-onion dependency to include the lates changes which
support route blinding.
2023-08-23 12:09:53 +02:00
Olaoluwa Osuntokun
76f0f67b7c
channeldb: update ChanSyncMsg to populate nonce info
In this commit, we update the ChanSyncMsg to populate nonce information.
With this change, we can now hide nonce generation further down in the
pipeline and ensure that all callers will have the expected fields
populated.
2023-08-22 16:31:49 -07:00
Olaoluwa Osuntokun
349eee3263
input: ensure sessionOpts is properly threaded through 2023-08-22 16:31:47 -07:00
Olaoluwa Osuntokun
39d5dffd56
lnwallet: update genHtlcSigValidationJobs to be taproot aware
In this commit, we update the genHtlcSigValidationJobs function to be
taproot aware. As we actually need a schnorr signature for the taproot
validation, we need to coerce the entire wire type into a schnorr sig
with the ForceSchnorr() method.
2023-08-22 16:31:31 -07:00
Olaoluwa Osuntokun
05b5391614
channeldb: add new db type for taproot channels 2023-08-22 16:30:52 -07:00
Olaoluwa Osuntokun
b368e476c5
lnwire: update Sig to support both ECDSA and schnorr sigs
In this commit, we update the Sig type to support ECDSA and schnorr
signatures. We need to do this as the HTLC signatures will become
schnorr sigs for taproot channels. The current spec draft opts to
overload this field since both the sigs are actually 64 bytes in length.
The only consideration with this move is that callers need to "coerce" a
sig to the proper type if they need schnorr signatures.
2023-08-22 16:29:19 -07:00
Oliver Gugger
59b5fb1565
channeldb+funding: move policy encoding into channel DB 2023-08-22 06:22:33 +08:00
Oliver Gugger
36fcf65e97
funding+channeldb: rename fwding -> forwarding 2023-08-18 09:44:23 +02:00
Oliver Gugger
eda34a8d2a
channeldb: move fwding policy code to new file 2023-08-18 09:44:06 +02:00
ziggie
87fc58ecfe
multi: Add a channel.db migration.
The new migration removes the sweeper-last-tx top level bucket
from the channel.db database.
2023-08-15 10:00:30 +02:00
Olaoluwa Osuntokun
7f95810359
Merge pull request #7710 from carlaKC/7297-updateaddtlvs
Channeldb: Store HTLC Extra TLVs in Onion Blob Varbytes
2023-06-16 14:31:11 -05:00
Oliver Gugger
56dba2df03
multi: update linter, fix new issues 2023-06-13 11:58:33 +02:00
Carla Kirk-Cohen
7b1a288320
channeldb: store extra HTLC data in variable onion blob slot
Take advantage of the variable byte encoding for a known length field
to extend HLTCs with additional data.
2023-06-02 11:01:44 -04:00
Carla Kirk-Cohen
2fc8e9d617
multi: update channel db HTLC OnionBlob to array
We know that onion blobs in lightning are _exactly_ 1366 bytes in
lightning, but they are currently expressed as a byte slice in
channeldb's HTLC struct. Blobs are currently serialized as var bytes,
so we can take advantage of this known length and variable length
to add additional data to the inline serialization of our HTLCs, which
are otherwise not easily extensible (without creating a new bucket).
2023-06-02 11:01:43 -04:00
shaurya947
396a4cb6c4
channeldb: persist channel Memo field and read it when fetching
We add a Memo field to the OpenChannel DB struct. We also persist
it using a tlv record. We then pass the Memo value from the
InitFundingReserveMsg when creating a new reservation for the channel.
Finally, we also read Memo field when fetching channel from DB.
2023-05-18 13:02:30 -04:00
Elle Mouton
9ea3f55694
multi: update "funding locked" comments
Replace a few un-caught instances of "funding locked" in some comments
with "channel_ready"
2023-04-27 20:02:34 +02:00
Elle Mouton
fe2304efad
channeldb: add a FetchChannelByID method
Add a FetchChannelByID method that allows a caller to fetch an
OpenChannel using an lnwire.ChannelID.
2023-04-24 13:15:40 +02:00
Elle Mouton
63442cbe51
channeldb: factor out generic FetchChannel logic
This commit introduces a new `channelSelector` method and moves all
generic logic from `FetchChannel` to it. This refactor will make it
easier to add new methods that require the same open-channel db
traversal with slightly different channel selection logic.
2023-04-24 13:15:39 +02:00
Elle Mouton
908cb6060b
channeldb: optimise FetchChannel method
This commit adds a small optimisation to the FetchChannel method.
Instead of iterating over each channel bucket, an identifiable error is
thrown once the wanted channel is found so that the iteration can stop
early.
2023-04-24 13:10:13 +02:00
Elle Mouton
aebdd2375c
channeldb: lint FetchChannel method
A few lint fixes of the FetchChannel method.
2023-04-24 13:10:12 +02:00
Oliver Gugger
3beaf7c4c1
channeldb: use input.GenMultiSigScript 2023-04-11 11:15:36 +02:00
Olaoluwa Osuntokun
f9f08079d0
Merge pull request #7576 from lightningnetwork/0-17-0-staging
lnd: merge v0.17.0 staging branch into master
2023-04-05 16:48:50 -07:00
yyforyongyu
6b9217acfc
multi: replace FundingLocked related docs
This commit replaces `FundingLocked` found in docs using the following
command,
```shell
find . -name "*.go" -exec sed -i '' 's/FundingLocked/ChannelReady/g' {} \;
find . -name "*.go" -exec sed -i '' 's/FundingLock/ChannelReady/g' {} \;
```
2023-03-17 18:21:59 +08:00
yyforyongyu
f8a8326141
multi: replace FundingLocked and funding_locked strings
This commit is created by running the following commands,
```shell
find . -name "*.go" -exec sed -i '' 's/\"FundingLocked/\"ChannelReady/g' {} \;
find . -name "*.go" -exec sed -i '' 's/FundingLocked\"/ChannelReady\"/g' {} \;
find . -name "*.go" -exec sed -i '' 's/\ funding_locked/\ channel_ready/g' {} \;
```
2023-03-17 18:21:59 +08:00
positiveblue
09e87ea99b
channeldb: add serializeAndStoreInvoice helper func 2023-03-14 19:26:18 -07:00
positiveblue
65fc8d72c6
channeldb: clean updateInvoice func
All the updates type are now catched in a switch statement, we can
delete the rest of the body of this function + add a default path for
not matched flows.
2023-03-14 19:26:18 -07:00
positiveblue
6ff6c45a6b
channeldb: split addHTLCs logic in the UpdateInvoice method 2023-03-14 19:26:18 -07:00
positiveblue
27fbc2f60b
channeldb: split cancelInvoice logic in the UpdateInvoice method 2023-03-14 19:26:15 -07:00
positiveblue
cbaec4382a
channeldb: split settleHodlInvoice logic in the UpdateInvoice method 2023-03-14 19:01:52 -07:00
positiveblue
a3f6d5c97e
channeldb: split cancelHTLCs logic in the UpdateInvoice method
Previous to this commit we were able to call `UpdateInvoice` with an
updated that added and cancelled htlcs at the same time. The function
returned an error if there was overlapping between the two htlc set.
However, that behavior was not used in the LND code itself.

Eventually we want to split this method in multiple ones, among them one
for canceling htlcs and another one for adding them. For that reason,
this behavior is not supported anymore.
2023-03-14 18:56:01 -07:00
Oliver Gugger
b3e27f9ba7
Merge pull request #7415 from bitromortac/2302-max-htlc
routing+discovery: fail non-maxHTLC channel updates in validation
2023-02-22 08:45:56 +01:00
bitromortac
dd5273c88c
multi: rename due to required maxHTLC bit
We rename `ChanUpdateOptionMaxHtlc` to `ChanUpdateRequiredMaxHtlc`
as with the latest changes it is now required.

Similarly, rename `validateOptionalFields` to
`ValidateChannelUpdateFields`, export it to use it in a later commit.
2023-02-21 11:10:39 +01:00
Elle Mouton
2c786ec66f
channeldb: add local and remote balance to revocation log
This commit re-adds the LocalBalance and RemoteBalance fields to the
RevocationLog. The channeldb/migration30 is also adjusted so that anyone
who has not yet run the optional migration will not lose these fields if
they run the migration after this commit.

The reason for re-adding these fields is that they are needed if we want
to reconstruct all the info of the lnwallet.BreachRetribution without
having access to the breach spend transaction. In most cases we would
have access to the spend tx since we would see it on-chain at which time
we would want to reconstruct the retribution info. However, for the
watchtower subsystem, we sometimes want to construct the retribution
info withouth having access to the spend transaction.

A user can use the `--no-rev-log-amt-data` flag to opt-out of storing
these amount fields.
2023-02-16 20:47:35 +02:00
Elle Mouton
0730337cc7
multi: add new NoRevLogAmtData config option
In this commit, a new `--db.no-rev-log-amt-data` flag is added. The
config option is passed though to everywhere that it will be used. Note
that it is still a no-op in this commit. An upcoming commit will make
use of the flag.
2023-02-16 20:47:29 +02:00
Elle Mouton
9c01916bc0
channeldb: add NoAmountData field to MigrateRevLogConfigImpl
Add a NoAmountData field to the MigrateRevLogConfigImpl struct and set
it for tests. This field is still a no-op in the migration.
2023-02-16 20:46:05 +02:00
Elle Mouton
70e3f8f511
multi: pass in a MigrationConfig to all optional migrations
Define a MigrationConfig interface that should be used to pass the
config of an optional migration function. An implementation of this
interface is added for migration30 (the only current optional
migration).
2023-02-16 20:45:08 +02:00
Elle Mouton
33b7b9221a
channeldb+wtdb: fix migration function name lint
Rename the ApplyMigrationWithDb function to ApplyMigrationWithDB to make
the linter happy.
2023-02-16 07:51:49 +02:00
Elle Mouton
ce8e7ecfa7
channeldb: prepare RevocationLog for optional fields
This commit is a pure refactor. It restructures the RevocationLog
serialize and deserialize methods so that optional TLV fields can be
easily added.
2023-02-16 07:51:48 +02:00
yyforyongyu
3d61d157c6
channeldb: add unique output index to unit test 2023-02-10 20:52:34 +08:00
Oliver Gugger
0cf0a7dd3b
Merge pull request #7341 from bottlepay/final-settle-opt-in
channeldb: final htlc resolution storage opt-in
2023-02-06 13:21:40 +01:00
Joost Jager
7a785c74c4
channeldb: final htlc resolution storage opt-in 2023-01-26 07:02:17 +01:00
eugene
d807ff23d2
channeldb: fix DisconnectBlockAtHeight bug for zero-conf channels
When a block is disconnected due to a reorg, DisconnectBlockAtHeight
is called for the block height. Prior to this patch, it would delete
every SCID in the graph with a block height greater than the
disconnected height. This meant that a reorg would delete every
zero-conf channel edge from the graph. The fix simply iterates up
until the StartingAlias and deletes every SCID between the
disconnected height and the StartingAlias height.
2023-01-25 12:03:21 -05:00
positiveblue
8563e1f409
channeldb/invoices: add IsAMP and IsKeysend helpers
The only way to know if an invoice is AMP, Keysend, etc is to look at
its shape/characteristics. This commit adds a couple of helper functions
to encapsulate the logic of these checks.

If all these types cannot intersect: an invoice cannot be AMP and
Keysend or Keysend and Bolt12, etc it could be useful to add an extra
field to store this information instead of relying on checking how the
invoice looks like.
2023-01-20 03:43:39 -08:00
Oliver Gugger
d960fcd68a
multi: remove gomnd disable directives 2023-01-17 19:43:26 +01:00
Olaoluwa Osuntokun
ea0eb2ce72
Merge pull request #7215 from positiveblue/invoices-channeldb-dep
Invoices: invert package dependency with `channeldb`
2023-01-17 10:13:22 -08:00
positiveblue
5ff5225245
multi: break invoice depenency on channeldb
Now that we have the new package `lnd/channeldb/models` we can invert the
depenency between `channeldb` and `invoices`.

- Move all the invoice related types and errors to the
`invoices` package.

- Ensure that all the packages dealing with invoices use the types and
  interfaces defined in the `invoices` package.

- Implement the InvoiceDB interface (defined in `lnd/invoices`) in
  channeldb.

- Add new mock for InterfaceDB.

- `InvoiceRegistery` tests are now in its own subpacakge (they need to
  import both invoices & channeldb). This is temporary until we can
  decouple them.
2023-01-16 07:31:09 -08:00
positiveblue
383cb40f8d
multi: create channeldb/models package
Add a new subpackage to `lnd/channeldb` to hold some of the types that
are used in the package itself and in other packages that should not
depend on `channeldb`.
2023-01-16 07:14:55 -08:00
positiveblue
c602ac07e7
chainntnfs: move cache implementation to channeldb
This commit moves the `HeightHintCache` implementation to the
`channeldb` package and inverts the dependency relation between
`chainntnfs` and `channeldb`.

Many packages depend on channeldb for type definitions,
interfaces, etc. `chainntnfs` is an example of that. `chainntnfs`
defines the  `SpendHintCache` and `ConfirmHintCache` interfaces but
it also implments them (`HeightHintCache` struct). The implementation
uses logic that should not leak from channeldb (ex: bucket paths).
This makes our code highly coupled + it would not allow us to use any
of these interfaces in a package that is imported by `channeldb`
(circular dependency).
2023-01-16 03:13:17 -08:00
Elle Mouton
af076d8ff4
channeldb: add shouldFail param to ApplyMigrationWithDB
Add a shouldFail boolean parameter to the migtest ApplyMigrationWithDB
in order to make it easier to test migration failures.
2023-01-11 13:59:03 +02:00
yyforyongyu
271c36d348
channeldb: move payment status code into new file
This prepares the following expansion of the payment status codes.
2022-12-07 18:38:01 +08:00
yyforyongyu
2fd4c1e318
channeldb+routing: fix format 2022-12-07 18:38:01 +08:00
yyforyongyu
e9269c2093
channeldb+lnd: rpc server filters payments by date 2022-12-05 20:04:47 +08:00
yyforyongyu
234b9a3d97
channeldb+lnd: rpc server filters invoices by date 2022-12-05 20:03:58 +08:00
Joost Jager
4c8ea29336
lnwire: allow longer failure messages
This fixes an incompatibility where lnd enforces a strict 256 byte
failure message, where as the spec sets this only as the recommended
length.
2022-12-02 14:27:59 +01:00
yyforyongyu
84fd911b47
multi: fix make lint
Fixes new lint errors caught by the latest version.
2022-11-18 20:48:23 +08:00
habibitcoin
0b1e881d18
scripted-diff: replace ⛰ emoji with $ [skip ci]
-BEGIN VERIFY SCRIPT-
sed -i 's/⛰/$/g' $(git grep -l '⛰')
-END VERIFY SCRIPT-
2022-10-28 12:06:49 -04:00
Joost Jager
3a89a84744
rpcserver: add LookupHtlc call 2022-10-27 16:43:09 +02:00
Joost Jager
28256b7ea8
htlcswitch: keep final htlc outcome 2022-10-27 16:42:36 +02:00
Eng Zer Jun
c70e39cd21
multi: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-10-13 17:46:54 +08:00
Oliver Gugger
fc2d652261
channeldb: check for tombstone before opening DB
To avoid running a channel DB that was successfully migrated to another
system by accident, we check if there is a tombstone marker before we
open the DB for use.
2022-10-13 09:45:07 +02:00
Oliver Gugger
7e76326b97
channeldb: export DB migration related functions
We'll need to know whether a database was migrated to the latest version
in our upcoming data migration tool. To be able to determine the current
version of a DB and the total number of migrations in existence, we need
to export some of the functions in channeldb.
We also add some helper functions for adding tombstone and other markers
to a database.
2022-10-13 09:45:07 +02:00
Oliver Gugger
28c8e8b6dd
channeldb: remove unused tx argument 2022-10-13 09:37:53 +02:00
Slyghtning
e87412bd63 funding+channeldb: handle and persist channel fees 2022-09-29 08:21:06 -04:00
Eng Zer Jun
dd07cb850d
channeldb: use T.TempDir to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-08-24 08:58:16 +08:00
yyforyongyu
0735522194
multi: fix make fmt 2022-08-23 22:10:24 +08:00
yyforyongyu
ac6e1a836c
channeldb: skip dry run mode for optional migrations 2022-07-12 21:01:15 +08:00
yyforyongyu
b391503ddf
migration30: validate migration results before deleting old buckets
This commit adds a new method `validateMigration` to be used prior to
the deletion of the old buckets to be extraly cautious.
2022-07-12 21:01:12 +08:00
yyforyongyu
78a73f9761
migration30: cover the case where v0.15.0 is active
This commit changes how we locate the next migration height by including
the scenario where `lnd@v0.15.0` is active. In the new version, we will
see a mixed of new and old logs under the same open channel bucket.
Hence, we need to alter how we locate the next un-migrated height.
2022-07-12 21:01:12 +08:00
yyforyongyu
afb2f72ce2
channeldb: add optional meta and migration30
This commit enables the db to run optional migrations that are specified
by config flags. To achieve this, an optional meta is introduced to
manage the optional migrations. We distinguish the two types of
migrations here so it's easier to manage them for the concern a future
migration can cause trouble for us to determine the db version if we
don't.
2022-07-12 21:01:11 +08:00
yyforyongyu
1832a93d19
migration30: add benchmark test 2022-07-12 21:01:11 +08:00
yyforyongyu
5316fcd6c9
migration30+migtest: add unit tests for migration 2022-07-12 21:01:11 +08:00
yyforyongyu
61bff6086c
migration30: add migration to convert old revocation logs
This commit adds the migration that's used to convert the old revocation
logs into the new format. The migration is fault-tolerant, meaning the
process can be interrupted and the migration will pick up what's left
when running again. We also cap how many records to be processed in each
db transaction to prevent OOM.
2022-07-12 21:01:08 +08:00
yyforyongyu
2a06145137
migration30: add unit tests for iterator 2022-07-12 20:51:48 +08:00
yyforyongyu
75dbbb55ad
migration30: add supporting functions to help with unit tests
This commit adds supporting functions that will be used in the unit
test. The testing data are also added as hard-coded. We choose to copy
the most of the testing data from our itest results such that a) they
are "real" data that can be used to calculate scripts and b) we preserve
the result generated by the current code so a future change won't affect
our test.
2022-07-12 20:51:48 +08:00
yyforyongyu
ebbdf78d52
migration30: add iterator to assist migration
This commit adds several utility functions to assist the migration. In
particular, an updateLocator is added to gives us the next un-migration
position in our buckets. This locator helps us to continue the job
in case of an interrupted migration. It also serves as an indicator on
whether the migration is finished or not.
2022-07-12 20:51:45 +08:00
yyforyongyu
674b0ec5fb
migration30: add related revocation log and lnwallet code
This commit adds relevant code from the revocation_log.go and the
package lnwallet. The code is needed to migrate the data, and we choose
to copy the code instead of importing to preserve the version such that
a future change won't affect current migration. An alternative would be
tagging each of the packages imported.
2022-07-08 13:17:57 +08:00
eugene
1aa9626606
server+funding: allow scid-alias, zero-conf chantypes, scid-alias
feature-bit channels

This allows opening zero-conf chan-type, scid-alias chan-type, and
scid-alias feature-bit channels. scid-alias chan-type channels are
required to be private. Two paths are available for opening a zero-conf
channel:

* explicit chan-type negotiation
* LDK carve-out where chan-types are not used, LND is on the
  receiving end, and a ChannelAcceptor is used to enable zero-conf

When a zero-conf channel is negotiated, the funding manager:
* sends a FundingLocked with an alias
* waits for a FundingLocked from the remote peer
* calls addToRouterGraph to persist the channel using our alias in
  the graph. The peer's alias is used to send them a ChannelUpdate.
* wait for six confirmations. If public, the alias edge in the
  graph is deleted and replaced (not atomically) with the confirmed
  edge. Our policy is also read-and-replaced, but the counterparty's
  policy won't exist until they send it to us.

When a scid-alias-feature channel is negotiated, the funding manager:
* sends a FundingLocked with an alias:
* calls addToRouterGraph, sends ChannelUpdate with the confirmed SCID
  since it exists.
* when six confirmations occurs, the edge is deleted and re-inserted
  since the peer may have sent us an alias ChannelUpdate that we are
  storing in the graph.

Since it is possible for a user to toggle the scid-alias-feature-bit
to on while channels exist in the funding manager, care has been taken
to ensure that an alias is ALWAYS sent in the funding_locked message
if this happens.
2022-07-07 17:10:28 -04:00
eugene
01f28ba540
server+discovery: alias-handling in gossiper
An OptionalMsgField has been added that allows outside subsystems
to provide a short channel id we should insert into a ChannelUpdate
that we then sign and send to our peer.

When the gossiper receives a ChannelUpdate, it will query the
alias manager by the passed-in FindBaseByAlias function to determine
if the short channel id in the ChannelUpdate points to a known
channel. If this lookup returns an error, we'll fallback to using
the original id in the ChannelUpdate when querying the router.
The lookup and potential fallback must occur in order to properly
lock the multimutex, query the correct router channels, and rate
limit the correct short channel id. An unfortunate side effect of
receiving ChannelUpdates from our peer that reference on of our
aliases rather than the real SCID is that we must store this policy.
Yet it is not broadcast-able. Care has been taken to ensure the
gossiper does not broadcast *any* ChannelUpdate with an alias SCID.

The cachedNetworkMsg uses the new processedNetworkMsg struct. This
is necessary so that delete-and-reinsert in the funding manager
doesn't process a ChannelUpdate twice and end up in a deadlock since
the err chan is no longer being used.
2022-07-07 17:10:28 -04:00
eugene
c9f5912601
channeldb: BigSize migration, store zero-conf, scid-alias bits
This introduces a BigSize migration that is used to expand the width
of the ChannelStatus and ChannelType fields. Three channel "types"
are added - ZeroConfBit, ScidAliasChanBit, and ScidAliasFeatureBit.
ScidAliasChanBit denotes that the scid-alias channel type was
negotiated for the channel. ScidAliasFeatureBit denotes that the
scid-alias feature bit was negotiated during the *lifetime* of the
channel. Several helper functions on the OpenChannel struct are
exposed to aid callers from different packages.

The RefreshShortChanID has been renamed to Refresh.

A new function BroadcastHeight is used to guard access to the
mutable FundingBroadcastHeight member. This prevents data races.
2022-07-07 17:10:27 -04:00
Tommy Volk
834756c53c multi: migrate assert.NoError to require.NoError 2022-07-05 16:41:08 +00:00
Tommy Volk
2dd11ed249 channeldb+routing: htlcs are pruned on settle 2022-07-03 21:04:34 +00:00
Tommy Volk
8291e8a170 multi: add keep-failed-payment-attempts flag 2022-07-03 21:04:27 +00:00
yyforyongyu
0e12a91715
channeldb: fix data race in TestSerializeHTLCEntries 2022-06-28 21:28:04 +08:00
Tommy Volk
9a10c80bcb multi: move many t.Fatalf calls to require.NoError 2022-06-17 04:26:55 +00:00
yyforyongyu
2b5d535208
channeldb: fix data race in TestSerializeRevocationLog
When testing serializing revocation log, we need to also copy its
`HTLCEntries` as the serialization of the HTLC involves a writing to the
`htlc.amtTlv` field.
2022-06-01 02:20:44 +08:00
yyforyongyu
d7bb7cd9a7
migration27: add unit test to cover ChanStatusRestored 2022-05-23 05:13:56 +08:00
yyforyongyu
7cf28773bf
multi: export channel status field in migration25
Previously, in `migration25.OpenChannel`, there was a private field
`chanStatus` used to keep track of the channel status. The following
migrations, `migration26` and `migration27` also have their own
`OpenChannel` defined, with `migration26` inherited from `migration25`,
and `migration27` inherited from `migration26`. The private field
`chanStatus`, however, is NOT inherited and each of the migrations uses
its own. This is fine for reading and writing as, under the hood, the
`chanStatus` is just a `uint8` value. Because each migration has its own
fetcher and putter, it can safely access its private field to read and
write it correctly.

The issue pops up when we use the method
`migration25.FundingTxPresent()`. Because it's evaluating its channel
status using its own private field `chanStatus`, this field would always
be the default value(`ChanStatusDefault`), leading the statement
`!c.hasChanStatus(ChanStatusRestored)` to always be true. Thus a
restored channel will be mistakenly considered to have funding tx
present, causing failures in reading the channel info in the following
migrations.

We fix this by exporting the `ChanStatus` field so its value can be set
by following migrations.
2022-05-23 03:55:00 +08:00
yyforyongyu
3458b2eb7d
channeldb+migration27: patch balance fields for historical chan
This commit adds a new migration to patch the two balance fields,
`InitialLocalBalance` and `InitialRemoteBalance` for the historical
channels. Because they are not saved previously, for historical channels
prior to the revocation log PR, these fields will be empty.
2022-05-20 06:55:31 +08:00
yyforyongyu
55746e427e
channeldb+migration26: migrate balance fields into tlv records 2022-05-19 03:34:24 +08:00
yyforyongyu
de2bcbf925
migration25: export methods to be used for following migrations
This commit exports several private methods to be used in later
migrations. It's safe to do so as no actual logic or migration scheme is
changed.
2022-05-19 03:34:13 +08:00
yyforyongyu
2ec459df6c
channeldb: use TLV for InitialLocalBalance and InitialRemoteBalance
This commit changes the encoding scheme for the fields
`InitialLocalBalance` and `InitialRemoteBalance` and use TLV instead.
2022-05-18 19:46:09 +08:00
eugene
2e3246aafe
channeldb: copy value from boltdb's Get instead of using it directly
This can cause an intermittent panic otherwise if bbolt remaps itself
via munmap and mmap. From bbolt's documentation:

* Byte slices returned from Bolt are only valid during a transaction.
Once the transaction has been committed or rolled back then the memory
they point to can be reused by a new page or can be unmapped from
virtual memory and you'll see an unexpected fault address panic when
accessing it.
2022-05-17 11:14:40 -04:00
eugene
4eea395a7f
channeldb+invoices: refactor invoice logic when updating 2022-05-11 13:57:46 -04:00
Olaoluwa Osuntokun
0ec88b5346
Merge pull request #6347 from yyforyongyu/5388-rm-revc-log
lnwallet+channeldb: store minimal info in revocation log bucket
2022-05-05 15:52:59 -07:00
Oliver Gugger
bdd1c5c4e1
Merge pull request #6423 from tvolk131/fix_typos
Typo fixes and code cleanup
2022-05-05 09:42:39 +02:00
Tommy Volk
bd9904e11e channeldb: remove empty files 2022-05-03 20:56:44 +00:00
Tommy Volk
5ae2ce984e multi: typo fixes [skip ci] 2022-05-03 20:55:40 +00:00
Oliver Gugger
c42330d9c5
channeldb: add CountTotal option to payment query 2022-05-02 12:32:06 +02:00
yyforyongyu
b288284566
channeldb: use BigSize to encode htlc amount
This commit uses bigsize record to encode the htlc amount, which could
save us 3 more bytes if the encoded value is no greater than roughly
0.043 bitcoin. The uint test has been updated with a more realistic
values to reflect the actual gain.
2022-04-20 01:19:40 +08:00
yyforyongyu
37b11c4503
channeldb+lnwallet: store revocation log using the new format
This commit removes the usage of the old revocation log bucket and
starts to perform db operations using the new sub-bucket.
2022-04-20 01:18:14 +08:00
yyforyongyu
a129930a95
channeldb: add unit test for revocation log 2022-04-20 01:18:13 +08:00
yyforyongyu
dc137bed8b
channel: move deprecated log handling into the new file 2022-04-20 01:18:13 +08:00
yyforyongyu
c41175f233
channeldb: re-introduce revocationLogBucket
This commit adds `revocationLogBucket` using the new sub-bucket key
"revocation-log" to store the minimal info needed. Two structs,
`RevocationLog` and `HTLCEntry` are created to represent the disk
records.
2022-04-20 01:18:13 +08:00
yyforyongyu
4609ac2008
channeldb: deprecate old revocation log bucket
This commit marks the sub-bucket identified by "revocation-log-key" as
deprecated.
2022-04-20 01:18:13 +08:00
yyforyongyu
f42d1f2d62
multi: remove function BalancesAtHeight
This commit deletes the function `BalancesAtHeight` since its only
usague is to find the push amount, which can be achieved by saving the
initial balances.
Another reason to remove it is to pave the way to incooperate our new
revocation log. If we ever need this function again, we can add it back
by visiting all the revocation logs to calculate the balances at a given
height.
2022-04-20 01:18:13 +08:00
yyforyongyu
7eaf0d0089
channeldb+migration: add migration test for patching balances 2022-04-20 01:18:13 +08:00
yyforyongyu
c9843fd206
channeldb+migration: add migration to save the initial balances
This commit adds a migration to patch the newly added fields,
`InitialLocalBalance` and `InitialRemoteBalance` to channel info.
2022-04-20 01:18:12 +08:00
yyforyongyu
8b289e79f5
channeldb+migration: export commonly used methods
This commit exports several commonly used methods that can be used by
later migrations. It also adds a channel commit deserializer.
2022-04-20 01:18:12 +08:00
yyforyongyu
22f8f6ed4a
channeldb+lnwallet: save initial balances during channel opening 2022-04-20 01:18:12 +08:00
yyforyongyu
5f508f9278
channeldb: replace method RevocationLogTail
This commit replaces the method RevocationLogTail which in used in our
unit test with a private method revocationLogTailCommitHeight. The new
method returns the commit height only since that's what's needed in the
test.
2022-04-20 01:18:11 +08:00
Joost Jager
9195f29e61
routing+channeldb: send payment metadata from invoice 2022-04-13 22:55:40 +02:00
eugene
4373faa818
channeldb: change to ErrTypeForDecodingErr for amp state
Was instead returning ErrTypeForEncodingErr.
2022-03-23 12:05:11 -04:00
Oliver Gugger
7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
Oliver Gugger
13f187046b
multi: fix issues reported by whitespace linter 2022-02-15 16:26:08 +01:00