Commit Graph
65 Commits
Author SHA1 Message Date
positiveblue e7d82fa530 tools: update sqlc version to v1.25.0 2024-03-01 10:08:07 +01:00
positiveblue 49e099f0a0 lnrpc: run make rpc
The docker image have been updated so we are using another protobuf
version to generate the files. The generate files include the version of
the compiler used to creating them, so we need this commit to pass the
`rpc-check` step in our CI.
2023-09-05 10:11:51 -07:00
positiveblue 09d21345e1 multi: bump Go version
Bump all build go versions to v1.21.0
Bump the minimum build package version to v1.19.0

Debian "buster" is not longer supported. Security updates have been
discontinued since June 30th 2022. We will build using the latest
version, "bookworm".
2023-09-05 10:11:42 -07:00
positiveblue 099907c43f docs: add release note for 7343 2023-07-27 03:31:15 -07:00
positiveblue 5a7d7c2e4f sqldb: add the sqldb package
This commit provides the scaffolding for using the new sql stores.
The new interfaces, structs and methods are in sync with other projects
like Taproot Assets.

- Transactional Queries: the sqldb package defines the interfaces required
to execute transactional queries to our storage interface.

- Migration Files Embedded: the migration files are embedded into the binary.

- Database Migrations: I kept the use of 'golang-migrate' to ensure our
codebase remains in sync with the other projects, but can be changed.

- Build Flags for Conditional DB Target: flexibility to specify our database
target at compile-time based on the build flags in the same way we do
with our kv stores.

- Update modules: ran `go mod tidy`.
2023-07-27 03:31:12 -07:00
positiveblue 83ccf61df9 routing: fix index out of range panic
Make sure that we do not crash the node trying to access an invalid
position for an array (-1) in `BuildRoute`.
2023-07-25 10:13:26 -07:00
positiveblue aadf385f67 routing: split BuildRoute
Create a couple of subroutines that we can unit test separately.
2023-07-25 10:12:55 -07:00
positiveblue 8fcb404161 docs: add release note for 7354 2023-07-10 17:57:09 -07:00
positiveblue ff1379a633 CI: Add sqlc code generation check 2023-07-10 17:57:09 -07:00
positiveblue 730db7ee8c sqlc: generate go code from SQL
run `make sqlc`

All the code in this commit is auto-generated.
2023-07-10 17:57:06 -07:00
positiveblue 877b711360 sqldb: add invoice event queries 2023-07-10 17:56:29 -07:00
positiveblue fb16287b31 sqldb: add invoice events SQL schema 2023-07-10 17:56:27 -07:00
positiveblue 6deb916216 sqldb: add AMP invoice queries 2023-07-10 17:53:57 -07:00
positiveblue eda95e6607 sqldb: add AMP invoices SQL schema
Schema for AMP invocies.

AMP invoices can be paid multiple times and each payment to an AMP invoice
is identified by a `set_id`.

The A in AMP stands for `Atomic`. All the htlcs belonging to the same
AMP payment (share the same set_id) will be resolved at the same time
with the same result: settled/canceled.

AMP invoices do not have an "invoice preimage". Instead, each htcl has
its own hash/preimage. When a new htlc is added the hash for that htlc
is attached to it. When all the htlcs of a set_id have been received we
are able to compute the preimage for each one of them.
2023-07-10 17:53:56 -07:00
positiveblue 7aa2f390fe sqldb: add invoice queries
Set of queries to deal with invoices. A couple of things to take into
account:

    - Because the queries are not rewritten at runtime, we cannot have a
      generic `INSERT` with different tuples.
    - Because the queries are not rewritten at runtime, we cannot build
      one query with only the filters that matter for that queries. The
      two options are a combinatorial approach (a new query for every
      permutation) or a generic query using the pattern

          ```
            SELECT *
            FROM table
            WHERE (
                -- Can be read as:
                -- Match the filter 1 value if filter_1 != nil
                column_1 >= sqlc.narg('filter_1') OR
                sqlc.narg('filter_1') IS NULL
            ) AND (
                column_2 >= sqlc.narg('filter_2') OR
                sqlc.narg('filter_2') IS NULL
            ) ...
          ```
2023-07-10 17:53:29 -07:00
positiveblue e3663b9942 sqldb: add invoices SQL schema
This is the schema for "ordinal" BOLT11 invoices.

The invoices table aims to keep an entry for each invoice, BOLT11 or not,
that will be supported.

Invoice related HTLCs will be stored in a separete table than forwarded
htlcs.

SQLite does not support `SEQUENCE`. We achieve atomic autoincrementals
using primary keys with autoincrement/serial. An invoice `AddIndex`
translates to `invoices(id)` while `SettleIndex` is `invoice_payments(id)`.
2023-07-10 17:53:26 -07:00
positiveblue 43a9e2f1ca multi: add sqlc support
sqlc is a tool that generates fully type-safe idiomatic code from SQL.
The result is Go code can then used execute the queries in the database.

The noraml flow looks like:
- The developer write some sql that will update the schema in the
  database: new tables, indices, etc
- The developer updates the set of queries that will use the new schema.
- `sqlc` generates type-safe interfaces to those queries.
- The developer can then write application code that calls the methods
  generated by sqlc.

The tool configuration needs to live in the repo's root and its name is
`sqlc.yaml`.

LND will support out of the box sqlite and postgres. The sql code needs to
be (almost) the same for both engines, so we cannot use custom functions
like `ANY` in postgres.

The SQLC config file needs to define what is the target engine, we will
set postgres but the generated code can be executed by sqlite too.

In some specific cases, we will `match and replace` some sql lines to be
sure the table definitions are valid for the targeted engine.
2023-07-10 17:36:58 -07:00
positiveblue 034853a0a8 docs: add release notes 2023-03-14 19:26:18 -07: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
positiveblue 84387992ec invoices: add UpdateType to InvoiceUpdateDesc
Make the kind of update explicit in the `InvoiceUpdateDesc` struct.
2023-03-13 13:11:06 -07:00
positiveblue 4a0a15586b multi: make linter happy
Fix all the linter problems for the `v0.16.0-beta.rc3`.
2023-03-11 23:29:41 -08:00
positiveblue 2942f1201b docs: update release notes 2023-01-20 03:43:43 -08: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
positiveblue 057d38e2fc docs: update release notes 2023-01-17 14:26:48 -08:00
positiveblue 0a4f062e22 routing: fix race condition in TestUpdatePaymentState
The test cases in `TestUpdatePaymentState` run in parallel. One of the
parameters is a pointer and the value to the struct it points to gets
modified during the test.

The race condition was introduced in 8d49dfb07e
To test the fix run from the main folder `go test  ./routing/. -race`
before this fix and after.
2023-01-17 14:26:37 -08:00
positiveblue 4665770aaf docs: update release notes
- Added a new entry for the changes in this PR.
- Properly format older entries.
- Delete duplicated contributors.
2023-01-16 07:31:14 -08:00
positiveblue 824e792dc2 config: expose the InvoiceDB interface in DatabaseInstances
By now the only implementation is still the one in channeldb but other
project can use their custom implementations if needed.
2023-01-16 07:31:13 -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
positiveblue 292ee1b123 docs: add release notes 2023-01-04 04:42:40 -08:00
positiveblue 2204cbfd30 rpc: validate closing channel address in open channel requests
Our OpenChannelRPC was accepting invalid values for the closing address
field. If we were able to decode the address we would use it in the
script even if the address is for another bitcoin net.
2023-01-04 04:42:39 -08:00
positiveblue cba5095902 docs: add release notes for warning message fix 2022-10-26 08:09:12 -07:00
positiveblue 4d4d8e480c multi: stop casting peer warning messages as errors
Split the logic for processing `error` and `warning` messages from our
peers.
2022-10-26 08:09:08 -07:00
positiveblue 85d88cd004 [skip ci] build: fix makefile targets using RELEASE_LDFLAGS
I forgot the `-ldflags` before setting the ldflags for the `install`
target.
2022-10-18 02:06:15 -07:00
positiveblue a92d7ad6d3 docs: update release notes for v0.16.0-beta 2022-10-17 00:55:16 -07:00
positiveblue 5924964a9b build: get binary build info from debug/buildinfo
Since `go1.18` the runtime has a package that provides information about module
versions, version control information, and build flags embedded in executable
files built by the go command.

The new packages allows us to get information needed by the `version` command
without having to rely on `ldflags` set at build time.

This can be really helpful while debugging errors from people using custom
binaries. For example a build from master.
2022-10-17 00:52:37 -07:00
positiveblue 55ddbd41c4 docs: add release notes for hop hint selection refactor 2022-09-30 06:55:16 -07:00
positiveblue 584f1089f7 aliasmgr: cache peer alias in memory 2022-09-30 06:55:16 -07:00
positiveblue 4b0bc9a7c6 invoicesrpc: unit tests for invoice hop hints 2022-09-30 06:55:16 -07:00
positiveblue fbe79811cf invoicesrpc: refactor addinvocie hop hint selection
In order to reduce the number of calls to the db we try to process as
few channels as we can + try to not do extra work for each of them.

- First fetch all the channels. Then, filter all the public ones and
  sort the potential candidates by remote balance.

- Filter out each potential candidate as soon as possible.

- Only check the alias if the channel supports scid aliases.

- Because we sort the channels by remote balance, we will hit the
  target amount, if possible, as soon as we can.

We do not want to leak information about our remote balances, so we
shuffle the hop hints (the forced ones go always first) so the invoice
receiver does not know which channels have more balance than others.
2022-09-30 06:55:10 -07:00
positiveblue 0e803172d6 style: format invoicesrpc/addinvoice.go 2022-09-28 02:19:55 -07:00
positiveblue 12fa11f685 ci: fix go version for travis jobs
Golang uses semver `X.Y.Z` but when `Z` is zero it gets dropped from the
version. Ex: `1.18`, `1.19` instead of `1.18.0` and `1.19.0`.
2022-09-06 15:40:07 -07:00
positiveblue b8bf884bcd docs: Add release notes for feature bit fix (#6809) 2022-08-08 10:45:31 -07:00
positiveblue aee52294c7 feature: remove ScidAliasOptional dependency on ExplicitChannelTypeOptional
The [spec](https://github.com/lightning/bolts/blob/master/09-features.md)
does not specify a dependency between `ScidAliasOptional` (47) and
`ExplicitChannelTypeOptional` (45).

This bug lead to some connectivity issues with peers not setting the
45 feature bit while setting the 47.

The issue [6802](https://github.com/lightningnetwork/lnd/issues/6802) is
an example of this.
2022-08-08 10:11:06 -07:00
positiveblue fdfdd10e86 docs: add release notes 2022-04-02 19:10:28 -07:00
positiveblue f3fdf8d28e lncli: add peers updatenodeannouncement 2022-04-02 19:10:27 -07:00
positiveblue ae2aa5671f lnrpc/peers: handle feature bit changes in updateNodeAnnouncement 2022-04-02 19:10:25 -07:00
positiveblue 76196db70e lnrpc/peers: handle net address changes in updateNodeAnnouncement 2022-04-02 19:09:10 -07:00
positiveblue aacb2565f5 lnrpc/peers: handle color changes in updateNodeAnnouncement 2022-04-01 18:36:26 -07:00
positiveblue ce4813940d lnrpc/peers: handle alias changes in updateNodeAnnouncement 2022-04-01 18:36:26 -07:00
positiveblue e4e0935816 lnrpc/peers: skeleton logic for updateNodeAnnouncement
Basic logic for the endpoint:

- Get the current nodeAnn information
- Calculate modifications
- Apply modifications
- Return changes
2022-04-01 18:36:21 -07:00
positiveblue 5ab0cbd433 lnrpc: add updatenodeannouncement to Peers service
New endpoint for the `Peers` subrpc.
2022-04-01 18:20:05 -07:00
positiveblue d4021c5aca lnrpc: fix log.go files
The `log.go` file of each subserver is a copy and paste of the others.
All of them have the same typo, an extra space in a comment, and the
the definition of a function not used anywhere.
2022-04-01 18:12:59 -07:00
positiveblue 9db17d7a22 lnrpc: add peersrpc subsever 2022-04-01 18:12:58 -07:00
positiveblue d2f016c105 lnrpc: add peers .proto files 2022-04-01 18:12:58 -07:00
positiveblue d2143bd40f docs: add guidelines for func declarations [skip ci] 2022-02-01 08:31:19 -08:00
positiveblue 3c3bce3415 makefile: fail rpc-check after finding any changes
`rpc-check` is used in our CI pipeline to detect any difference
between the committed and the automatically generated rpc files.
Unfortunately, the current method only detects changes in the
already existing files and won't fail if `make rpc` generates
a totally new file.

`git status --porcelain` makes the trick, it returns a line for
each file that has been modified, created or deleted.
2022-01-29 11:23:24 -08:00
positiveblue 416a96e2c1 lnrpc: migrate deprecated go get to go install
Starting in Go 1.17, installing executables with go get is deprecated.
Migrate our docker file for lnrpc protos.
2021-10-22 09:25:22 -07:00
positiveblue 5089cfc1be aezeed: fix mnemonic word validation
A user complained about getting a misleading error after a typo in the
mnemonic. The word was `hear` and it passed the check even when it is
not in the list of valid words.

The reason is that we where checking if the word is in the variable
`englishWordList` (which includes all the words) instead of checking if the
variable is in the `defaultWordList` (which is basically `englishWoldList`
split by spaces). That means that `hear` passed the check because `heart`
appears in the list.

Related issue [4733](https://github.com/lightningnetwork/lnd/issues/4733)
2020-11-02 23:25:50 +01:00