Commit Graph

1141 Commits

Author SHA1 Message Date
Elle Mouton
f0558babf3
multi: send MPP payment to blinded path
Make various sender side adjustments so that a sender is able to send an
MP payment to a single blinded path without actually including an MPP
record in the payment.
2024-07-26 09:54:38 +02:00
Oliver Gugger
fdd28c8d88
Merge pull request #8915 from linghuying/master
chore: fix some comments for struct field
2024-07-16 08:40:33 -06:00
linghuying
91930d4ab8 chore: fix some comments for struct field
Signed-off-by: linghuying <1599935829@qq.com>
2024-07-16 11:44:35 +08:00
Elle Mouton
e9c89ae0ec
multi+refactor: create ForEachNodeChannel with no tx param
In prep for a clean Graph DB interface, we add a version of
ForEachNodeChannel that does not take in an existing db transaction.
2024-07-15 15:13:58 +02:00
Elle Mouton
c20d759d41
refactor: create FetchLightningNode with no tx param
In preparation for adding a clean Graph DB interface, we create a
version of FetchLightningNode that doesnt allow a caller to provide in a
transaction.
2024-07-15 15:13:57 +02:00
Elle Mouton
71e93526d6
multi+refactor: let FetchChanInfos not take tx
In preparation for having a clean graph DB interface, refactor
FetchChanInfos so that no transaction can be provided.
2024-07-15 15:13:57 +02:00
Elle Mouton
8c0df98439
multi: add abstraction for Router and SessionSource graph access
In this commit, we completely remove the Router's dependence on a Graph
source that requires a `kvdb.RTx`. In so doing, we are more prepared for
a future where the Graph source is backed by different DB structure such
as pure SQL.

The two areas affected here are: the ChannelRouter's graph access that
it uses for pathfinding. And the SessionSource's graph access that it
uses for payments.

The ChannelRouter gets given a Graph and the SessionSource is given a
GraphSessionFactory which it can use to create a new session. Behind the
scenes, this will acquire a kvdb.RTx that will be used for calls to the
Graph's `ForEachNodeChannel` method.
2024-07-15 15:13:57 +02:00
yyforyongyu
e61cba8d22
multi: return verbose errors when fetching edges 2024-06-10 08:40:18 +08:00
djkazic
1542424782
invoices: if there are no invoices make gc noop 2024-04-30 11:58:18 -04:00
Olaoluwa Osuntokun
fe8784aa0c
channeldb: fix race in TestPackager by removing global test var
In this commit, we fix a race in the `TestPackager` series on channeldb.
A few tests were sharing the same global variable of the set of log
updates, which includes a pointer to an HTLC. The `ExtraData` value of
the HTLC would then be mutated once we go to encode the message on disk.

To fix this, we the global with a function that returns a new instance
of all the test data.

```
==================
WARNING: DATA RACE
Write at 0x0000021b0a48 by goroutine 2896:
  github.com/lightningnetwork/lnd/lnwire.(*ExtraOpaqueData).PackRecords()
      /home/runner/work/lnd/lnd/lnwire/extra_bytes.go:74 +0x546
  github.com/lightningnetwork/lnd/lnwire.EncodeMessageExtraData()
      /home/runner/work/lnd/lnd/lnwire/extra_bytes.go:121 +0x4d
  github.com/lightningnetwork/lnd/lnwire.(*UpdateAddHTLC).Encode()
      /home/runner/work/lnd/lnd/lnwire/update_add_htlc.go:164 +0x5af
  github.com/lightningnetwork/lnd/lnwire.WriteMessage()
      /home/runner/work/lnd/lnd/lnwire/message.go:330 +0x351
  github.com/lightningnetwork/lnd/channeldb.WriteElement()
      /home/runner/work/lnd/lnd/channeldb/codec.go:186 +0x1975
  github.com/lightningnetwork/lnd/channeldb.WriteElements()
      /home/runner/work/lnd/lnd/channeldb/codec.go:247 +0x14f
  github.com/lightningnetwork/lnd/channeldb.serializeLogUpdate()
      /home/runner/work/lnd/lnd/channeldb/channel.go:2529 +0x3c
  github.com/lightningnetwork/lnd/channeldb.putLogUpdate()
      /home/runner/work/lnd/lnd/channeldb/forwarding_package.go:525 +0xae
  github.com/lightningnetwork/lnd/channeldb.(*ChannelPackager).AddFwdPkg()
      /home/runner/work/lnd/lnd/channeldb/forwarding_package.go:489 +0x684
  github.com/lightningnetwork/lnd/channeldb_test.TestPackagerOnlyAdds.func1()
      /home/runner/work/lnd/lnd/channeldb/forwarding_package_test.go:283 +0x4c
  github.com/btcsuite/btcwallet/walletdb/bdb.(*db).Update()
      /home/runner/go/pkg/mod/github.com/btcsuite/btcwallet/walletdb@v1.4.2/bdb/db.go:429 +0xe5
  github.com/lightningnetwork/lnd/kvdb.Update()
      /home/runner/go/pkg/mod/github.com/lightningnetwork/lnd/kvdb@v1.4.6/interface.go:16 +0x258
  github.com/lightningnetwork/lnd/channeldb_test.TestPackagerOnlyAdds()
      /home/runner/work/lnd/lnd/channeldb/forwarding_package_test.go:282 +0x17b
  testing.tRunner()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:1595 +0x238
  testing.(*T).Run.func1()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:1648 +0x44

Previous write at 0x0000021b0a48 by goroutine 2898:
  github.com/lightningnetwork/lnd/lnwire.(*ExtraOpaqueData).PackRecords()
      /home/runner/work/lnd/lnd/lnwire/extra_bytes.go:74 +0x546
  github.com/lightningnetwork/lnd/lnwire.EncodeMessageExtraData()
      /home/runner/work/lnd/lnd/lnwire/extra_bytes.go:121 +0x4d
  github.com/lightningnetwork/lnd/lnwire.(*UpdateAddHTLC).Encode()
      /home/runner/work/lnd/lnd/lnwire/update_add_htlc.go:164 +0x5af
  github.com/lightningnetwork/lnd/lnwire.WriteMessage()
      /home/runner/work/lnd/lnd/lnwire/message.go:330 +0x351
  github.com/lightningnetwork/lnd/channeldb.WriteElement()
      /home/runner/work/lnd/lnd/channeldb/codec.go:186 +0x1975
  github.com/lightningnetwork/lnd/channeldb.WriteElements()
      /home/runner/work/lnd/lnd/channeldb/codec.go:247 +0x14f
  github.com/lightningnetwork/lnd/channeldb.serializeLogUpdate()
      /home/runner/work/lnd/lnd/channeldb/channel.go:2529 +0x3c
  github.com/lightningnetwork/lnd/channeldb.putLogUpdate()
      /home/runner/work/lnd/lnd/channeldb/forwarding_package.go:525 +0xae
  github.com/lightningnetwork/lnd/channeldb.(*ChannelPackager).AddFwdPkg()
      /home/runner/work/lnd/lnd/channeldb/forwarding_package.go:489 +0x684
  github.com/lightningnetwork/lnd/channeldb_test.TestPackagerAddsThenSettleFails.func1()
      /home/runner/work/lnd/lnd/channeldb/forwarding_package_test.go:490 +0x4c
  github.com/btcsuite/btcwallet/walletdb/bdb.(*db).Update()
      /home/runner/go/pkg/mod/github.com/btcsuite/btcwallet/walletdb@v1.4.2/bdb/db.go:429 +0xe5
  github.com/lightningnetwork/lnd/kvdb.Update()
      /home/runner/go/pkg/mod/github.com/lightningnetwork/lnd/kvdb@v1.4.6/interface.go:16 +0x2cd
  github.com/lightningnetwork/lnd/channeldb_test.TestPackagerAddsThenSettleFails()
      /home/runner/work/lnd/lnd/channeldb/forwarding_package_test.go:489 +0x1e7
  testing.tRunner()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:1595 +0x238
  testing.(*T).Run.func1()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:1648 +0x44

Goroutine 2896 (running) created at:
  testing.(*T).Run()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:1648 +0x82a
  testing.runTests.func1()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:2054 +0x84
  testing.tRunner()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:1595 +0x238
  testing.runTests()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:2052 +0x896
  testing.(*M).Run()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:1925 +0xb57
  github.com/lightningnetwork/lnd/kvdb.RunTests()
      /home/runner/go/pkg/mod/github.com/lightningnetwork/lnd/kvdb@v1.4.6/test_utils.go:23 +0x26
  github.com/lightningnetwork/lnd/channeldb.TestMain()
      /home/runner/work/lnd/lnd/channeldb/setup_test.go:10 +0x308
  main.main()
      _testmain.go:321 +0x303

Goroutine 2898 (running) created at:
  testing.(*T).Run()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:1648 +0x82a
  testing.runTests.func1()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:2054 +0x84
  testing.tRunner()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:1595 +0x238
  testing.runTests()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:2052 +0x896
  testing.(*M).Run()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.4.linux-amd64/src/testing/testing.go:1925 +0xb57
  github.com/lightningnetwork/lnd/kvdb.RunTests()
      /home/runner/go/pkg/mod/github.com/lightningnetwork/lnd/kvdb@v1.4.6/test_utils.go:23 +0x26
  github.com/lightningnetwork/lnd/channeldb.TestMain()
      /home/runner/work/lnd/lnd/channeldb/setup_test.go:10 +0x308
  main.main()
      _testmain.go:321 +0x303
==================
```
2024-04-26 12:36:53 -07:00
erik
619c8f4eb8 multi: repleace ioutil.ReadAll 2024-04-25 11:21:18 +02:00
Olaoluwa Osuntokun
0609431a0c
channeldb: fix payment control unit tests w/ errors.Is 2024-04-11 15:04:04 +02:00
Oliver Gugger
648fb22f63
multi: wrap all errors 2024-04-11 15:04:03 +02:00
Olaoluwa Osuntokun
120d6dd297
channeldb: explicitly catch error in pruneGraphNodes
With the new postgres concurrency control, an error may come from a
bucket function that's actually a postgres error. In this case, we need
to return early so we can retry the txn. Otherwise, we'll be working
with an aborted tx, and never actually return the error so we don't auto
retry.
2024-04-11 15:04:03 +02:00
Joost Jager
0bae781785 routing: add inbound fee support to pathfinding
Add sender-side support for inbound fees in pathfinding
and route building.
2024-03-31 18:12:28 +02:00
Joost Jager
d97e7d30fb channeldb/test: refactor TestGraphCacheForEachNodeChannel 2024-03-31 18:12:28 +02:00
Joost Jager
e8c97deaef htlcswitch: add receiver-side inbound fee support 2024-03-31 16:49:19 +02:00
Joost Jager
3e6adbf1c0 lnwire+channeldb: parse inbound fees
In this commit, the tlv extension of a channel update message is parsed.
If an inbound fee schedule is encountered, it is reported in the
graph rpc calls.
2024-03-31 16:33:26 +02:00
Carla Kirk-Cohen
f090a64142
multi: add blinding point to payment descriptor and persist
This commit adds an optional blinding point to payment descriptors and
persists them in our HTLC's extra data. A get/set pattern is used to
populate the ExtraData on our disk representation of the HTLC so that
callers do not need to worry about the underlying storage detail.
2024-03-27 09:38:56 -04:00
Carla Kirk-Cohen
7596e764ac
channeldb: include extra data in htlc clone function 2024-03-27 09:38:55 -04:00
Carla Kirk-Cohen
e4f90ec593
lnwire: add blinding point to update_add_htlc TLVs
Add blinding points to update_add_htlc. This TLV will be set for
nodes that are relaying payments in blinded routes that are _not_
the introduction node.
2024-03-27 09:38:50 -04:00
zhiqiangxu
5fd46b0dce channeldb: check return value of ReadWriteBucket 2024-03-26 17:28:09 +08:00
Keagan McClelland
db39a905cb multi: make NewChanIDFromOutpoint accept value instead of pointer 2024-03-08 15:47:55 -08:00
Olaoluwa Osuntokun
7feb8b21e1
multi: upgrade new taproot TLVs to use tlv.OptionalRecordT
In this commit, we update new Taproot related TLVs (nonces, partial sig,
sig with nonce, etc). Along the way we were able to get rid of some
boiler plate, but most importantly, we're able to better protect against
API misuse (using a nonce that isn't initialized, etc) with the new
options API. In some areas this introduces a bit of extra boiler plate,
and where applicable I used some new helper functions to help cut down
on the noise.

Note to reviewers: this is done as a single commit, as changing the API
breaks all callers, so if we want things to compile it needs to be in a
wumbo commit.
2024-02-29 11:32:26 -06:00
Olaoluwa Osuntokun
72764b1473
Merge pull request #8100 from bhandras/updateinvoice-refactor
channeldb: refactor `UpdateInvoice` to make it simpler to create SQL specific implementation
2024-02-27 16:50:02 -08:00
ffranr
cd566eb097
multi: fix fmt.Errorf error wrapping
Refactor fmt.Errorf usage to correctly wrap errors instead of using
non-wrapping format verbs.
2024-02-27 11:13:40 +00:00
Elle Mouton
dc25b425c0
channeldb+lnwallet: add ShutdownInfo with read and write methods
ShutdownInfo contains any info about a previous Shutdown message that we
have sent. This commit adds this type along with read and write methods
for it in the channel db. The existence of the ShutdownInfo on disk
represents the fact that we have previously sent the Shutdown message
and hence that we should resend it on re-establish.
2024-02-21 11:56:15 +02:00
Andras Banki-Horvath
5e746b4d2c
invoices: move InvoiceDB tests unrelated to kvdb to invoices package 2024-02-19 20:47:24 +01:00
Andras Banki-Horvath
6b0931af82
invoices: move UpdateInvoice implementation to the invoices package
With the introducation of the `InvoiceUpdater` interface we are now
able to move the non-kv parts of `UpdateInvoice` completely under
the invoices package. This is a preprequisite for being able to use
the same code-base for the sql InvoiceDB implementation of
UpdateInvoice.
2024-02-19 20:47:24 +01:00
Andras Banki-Horvath
ecbfc46312
invoices+channeldb: add InvoiceUpdater interface and the KV impl
This commit introduces the InvoiceUpdater interface which is meant
to abstract and assist the in-memory invoice update procedure with
the accompanying database updates. These abstract updater steps will
enable further refactoring later while also ensuring that a full
SQL implementation of the InvoiceDB interface will be possible.
2024-02-19 20:47:24 +01:00
Andras Banki-Horvath
998156930f
invoices: refactor updateInvoiceAmpState to return new state
With this commit updateInvoiceAmpState becomes getUpdatedInvoiceAmpState
which will only return the new AMP state but that needs to be applied at
the call site. This is a part of a larger refactor to gather all
mutations of an invoice update to be later applied by the invoice
updater.
2024-02-19 20:47:24 +01:00
Andras Banki-Horvath
08df7f4175
invoices: change cancelSingleHtlc to be purely used for validation
This change moves the HTLC state change out of the cancelSingleHtlc
function. This is part of the larger refactor of collecting all changes
to be later applied by the invoice updater.
2024-02-19 20:47:23 +01:00
Andras Banki-Horvath
87044b815c
invoices: rename updateInvoiceState to getUpdatedInvoiceState
This commit turns updateInvoiceState "const" by moving preimage update
out of the function while also removing it to getUpdatedInvoiceState.
2024-02-19 20:47:23 +01:00
Andras Banki-Horvath
342eb4eac2
invoices: refactor updateHtlc to return new state
With this refactor updateHtlc is renamed to getUpdatedHtlcState and
changed such that it won't change the HTLC's state and resolve time but
instead returns whether the change is needed. This change is part of a
multi-commit refactor to ensure that all changes to the invoice will be
tracked individually.
2024-02-19 20:47:23 +01:00
Andras Banki-Horvath
ef5a31733e
channeldb: do not change the update descriptor when cancelling htlcs 2024-02-19 20:47:23 +01:00
Andras Banki-Horvath
7298b2d190
channeldb: extract AMP state updates to updateInvoiceAmpState() 2024-02-19 20:47:23 +01:00
Andras Banki-Horvath
4bf6b52158
channeldb: fetch the invoice before calling into updateInvoice 2024-02-19 20:47:22 +01:00
Andras Banki-Horvath
eb4198b970
channeldb: extract store update methods when updaing an invoice
This commit is a small refactor to move all actual DB updates after
an invoice state is update to separate methods. This is a small
preliminary change before we completely decouple DB updates from
in-memory invocie update.
2024-02-19 20:47:22 +01:00
yyforyongyu
605211823d
multi: fix timestamp filters for payment query
This commit fixes the timestamp precision to always compare the dates
using unix seconds for payments.
2024-02-05 15:26:49 +08:00
yyforyongyu
18333e8c7d
multi: fix timestamp filters for invoice query
This commit fixes the timestamp precision to always compare the dates
using unix seconds for invoices.
2024-02-05 15:26:43 +08:00
Yong
59feec44ca
Merge pull request #7976 from w3irdrobot/serialize-deserialize-amp
Serialize/deserialize AMP struct in hop
2024-01-29 09:48:05 +08:00
Elle Mouton
6c427a6ba9
multi: update FetchChanInfos to take in an optional tx
In this commit, the FetchChanInfos ChannelGraph method is updated to
take in an optional read transaction for the case where it is called
from within another transaction.
2024-01-22 21:07:55 +02:00
Elle Mouton
8cf4044215
channeldb: rename delChannelEdge to delChannelEdgeUnsafe
In order to emphasise the fact that the ChannelGraph's cacheMu should be
acquired before calling the `delChannelEdge` method, we add the `Unsafe`
postfix and add a comment to alert readers.
2024-01-22 21:07:55 +02:00
Elle Mouton
ab06665fde
channeldb: acquire mutexes in the same order throughout
In this commit, we ensure that the channeldb cacheMu mutex is only ever
aquired _before_ acquiring the main DB lock in the cases where the two
locks need to be held simultaneously.

With this commit, the deadlock demonstrated in the previous commit is
now fixed.
2024-01-22 21:07:55 +02:00
Elle Mouton
76748bdbf7
channeldb: add ChannelGraph stress test
This commit adds a test that calls many of the ChannelGraph methods
concurrently and in a random order. This test demonstrates that a
deadlock currently exists in the ChannelGraph since the test does not
complete. This is fixed in the next commit.
2024-01-22 21:07:54 +02:00
Oliver Gugger
2b83ea309a
Merge pull request #8407 from mohamedawnallah/fix-typo-channel.go
fix: fix typo "(cltv_expiry" to "(cltv_expiry)" in `channeldb/channel.go` [skip ci]
2024-01-22 00:46:06 -06:00
Mohamed Awnallah
8407e6989e
fix: fix typo "(cltv_expiry" to "(cltv_expiry)" [skip ci] 2024-01-20 17:31:19 +02:00
Keagan McClelland
239103c2b3 multi: make tlv onion compulsory 2024-01-11 09:43:31 -08:00
Alex Sears
4521894ed2
channeldb: Serialize/deserialize AMP struct in hop
The AMP struct in a hop was never being set when deserizlied. Also,
the AMP TLV record was not being added when the hop was serialized.
This sets the TLV record when serializing and correctly sets the
AMP struct on the hop when that record is present.

Co-authored-by: BitcoinCoderBob <90647227+BitcoinCoderBob@users.noreply.github.com>
Co-authored-by: Tee8z <tee8z@protonmail.com>
2024-01-09 10:02:16 -05:00
bitcoin-lightning
b72fc9529e docs: fix typos 2023-12-21 15:21:35 +00:00