Commit Graph

1173 Commits

Author SHA1 Message Date
ziggie
97c4012753 multi: skip range check in pathfinder and switch for custom htlc payments 2025-08-06 14:47:41 +02:00
ziggie
15cd86c0aa multi: revert back changes from 9911
always process remote ADDs even when they are empty to trigger
the gc process when loading them back into memory.
2025-07-08 18:33:35 +02:00
ziggie
7bcb65d9e6 multi: add logs to debug potential payment sending issue 2025-07-08 16:25:39 +02:00
ziggie
81e4160d67 switch: unlock mutex lock earlier
We now unlock the mutex lock of the switch as soon as possible to
avoid potetnial deadlock in the htlc switch.
2025-07-04 15:38:52 +02:00
George Tsagkarelis
128b23e813 htlcswitch+routing: PaymentBandwidth accepts channel peer pubkey argument 2025-07-02 16:52:06 +02:00
George Tsagkarelis
ab036990b5 routing+htlcswitch: ProduceHtlcExtraData uses first hop pub key 2025-07-02 16:52:05 +02:00
Elle Mouton
9b877b94c3 multi: use the "errors" package everywhere
Replace all usages of the "github.com/go-errors/errors" and
"github.com/pkg/errors" packages with the standard lib's "errors"
package. This ensures that error wrapping and `errors.Is` checks will
work as expected.
2025-07-01 20:08:12 +02:00
yyforyongyu
69df66f1f9 htlcswitch: skip decoding hop if the htlc is already acked
We now move the check earlier in the loop so we don't even need to
decode the hop for already processed ADDs.
2025-06-20 15:49:04 -07:00
yyforyongyu
13308644d0 htlcswitch: remove batchReplayBkt
This commit removes the `batchReplayBkt` as its only effect is to allow
reforwarding htlcs during startup.

Normally for every incoming htlc added, their shared secret is used as
the key to be saved into the `sharedHashBucket`, which will be used for
check for replays. In addition, the fwdPkg's ID, which is SCID+height is
also saved to the bucket `batchReplayBkt`. Since replays of HTLCs cannot
happen at the same commitment height, when a replay happens,
`batchReplayBkt` simply doesn't have this info, and we again rely on
`sharedHashBucket` to detect it. This means most of the time the
`batchReplayBkt` is a list of SCID+height with empty values.

The `batchReplayBkt` was previously used as a mechanism to check for
reforwardings during startup - when reforwarding htlcs, it quries this
bucket and finds an empty map, knowing this is a forwarding and skips
the check in `sharedHashBucket`. Given now we use a bool flag to
explicitly skip the replay check, this bucket is no longer useful.
2025-06-20 15:49:04 -07:00
yyforyongyu
c8ff379a9c htlcswitch: exit early if the fwdPkg is already completed 2025-06-20 15:49:04 -07:00
yyforyongyu
cb009119c4 htlcswitch: skip checking replays for reforwarded packets
We now rely on the forwarding package's state to decide whether a given
packet is a reforwarding or not. If we know it's a reforwarding packet,
there's no need to check for replays in the `sharedHashes` bucket, which
behaves the same as if we are querying the `batchReplayBkt`.
2025-06-20 15:49:04 -07:00
Abdullahi Yunus
43f8bf288f htlcswitch+channeldb: add htlcidx to fwding log
In this commit we add htlcindex field to the forwardingevent
struct, which is persisted alongside the other event fields.
2025-06-20 15:37:02 -07:00
ziggie
21ed1360cd htlcswitch: exit early if no adds are in the fwd pkg
This lead to the case that we would always record a HTLC
two times in the decayed log protection which is not necessary
in the first place.
2025-06-20 15:31:00 -07:00
Oliver Gugger
56d2381f51 htlcswitch+routing: add funding blob to PaymentBandwidth
For certain auxiliary bandwidth checks we need to know the funding blob
that was present when the channel was created.
2025-04-22 21:21:11 +02:00
Oliver Gugger
5fb0f43172 htlcswitch+routing: add htlc blob to ShouldHandleTraffic
Whether we should let the aux bandwidth manager decide what the
bandwidth of a channel is should also depend on whether the HTLC is a
custom HTLC, not just the channel.
2025-04-17 11:52:56 +02:00
Oliver Gugger
cf0e0ff32c switch: add trace log for circular route detection
Helps with debugging of strict forwarding issues.
2025-04-17 10:53:37 +02:00
Oliver Gugger
7381f4b221 Merge pull request #9687 from GeorgeTsagk/aux-trff-shpr-htlcview
`AuxTrafficShaper.PaymentBandwidth` uses HTLC view
2025-04-17 07:59:00 +02:00
George Tsagkarelis
d0ef248ae2 htlcswitch: add HtlcView as PaymentBandwidth argument
In order to get more precise bandwidth reports, we also need to provide
this method with the latest htlc view. Since aux data is committed to in
the channel commitment, some uncommited HTLCs may not be accounted for,
so we need to manually provide them via the HTLC view.
2025-04-14 15:42:28 +02:00
ziggie
490347b056 multi: update walletdb package 2025-04-09 18:47:53 +02:00
yyforyongyu
5a72d5258f htlcswitch+itest: catch link quit signal when processing hodlQueue
This commit makes sure when processing resolutions, e.g, settling
invoices, when the link is already broken, the process would exit with
an error. This fixes the issue we found in the itest, where an
unexpected empty remote pending commitment was created although the
remote peer is already offline.
2025-03-21 03:25:24 +08:00
yyforyongyu
be4c4cc8ff multi: improve logging 2025-03-21 03:24:26 +08:00
Olaoluwa Osuntokun
bf3007a2ce multi: thread thru RPC caller context from CloseChannel 2025-03-18 11:44:20 -05:00
Olaoluwa Osuntokun
01382f4c2a htlcswitch: change LinkDirection to be a type alias
In this commit, we change LinkDirection to be a type alias. This makes
creating wrapper structs/interfaces easier, as we don't need to leak
htlcswitch.LinkDirection, instead we can accept a bool.
2025-03-18 11:44:20 -05:00
Oliver Gugger
dac5de5ce9 htlcswitch+routing: return IsHandled from AuxBandwidth
To make it more clear whether the external traffic shaper is handling a
channel or not, we return an explicit boolean.
2025-03-13 12:26:50 -05:00
Oliver Gugger
1227eb1cce Merge pull request #9491 from ziggie1984/closechannel-rpc
Allow coop closing a channel with HTLCs on it via lncli
2025-02-21 05:05:53 -06:00
ziggie
f994c2cb9f htlcswitch: fix log output 2025-02-20 17:43:18 +01:00
ziggie
9382fcb801 multi: fix debug log 2025-02-20 10:44:19 +01:00
ziggie
17e37bd7c2 multi: introduce new traffic shaper method.
We introduce a new specific fail resolution error when the
external HTLC interceptor denies the incoming HTLC. Moreover
we introduce a new traffic shaper method which moves the
implementation of asset HTLC to the external layers.
Moreover itests are adopted to reflect this new change.
2025-01-29 09:59:02 +01:00
Elle Mouton
950194a2da htlcswitch+go.mod: use updated fn.ContextGuard
This commit updates the fn dep to the version containing the updates to
the ContextGuard implementation. Only the htlcswitch/link uses the guard
at the moment so this is updated to make use of the new implementation.
2025-01-11 06:17:43 +02:00
yyforyongyu
1d53e7d081 multi: improve loggings 2024-12-20 17:54:03 +08:00
yyforyongyu
944f16255a htlcswitch: handle nil circuit properly when settling
We have two sources which can call `handlePacketSettle`, either through
the link's `<-s.htlcPlex`, or the `<-s.resolutionMsgs`, which means the
`closeCircuit` could be call twice. Previously we already caught this
case inside `closeCircuit`, in that we would return a nil circuit upon
seeing `ErrUnknownCircuit`, indicating the circuit was removed. However,
we still need to account the case when the circuit is the process of
being closed, which is now fixed as we will ignore when seeing
`ErrCircuitClosing`.
2024-12-16 15:58:23 +08:00
Olaoluwa Osuntokun
fb429d658b Merge pull request #9330 from ProofOfKeags/update/fn2
multi: update to fn v2
2024-12-09 12:56:23 +01:00
Oliver Gugger
86b3be71fe multi: thread through and use AuxTrafficShaper 2024-12-05 12:39:34 +01:00
Oliver Gugger
a2e78c3984 htlcswitch: thread through packet's inbound wire records
For calculating the available auxiliary bandwidth of a channel, we need
access to the inbound custom wire records of the HTLC packet, which
might contain auxiliary information about the worth of the HTLC packet
apart from the BTC value being transported.
2024-12-05 12:39:33 +01:00
Oliver Gugger
117c6bc781 multi: move routing.TlvTrafficShaper => htlcswitch.AuxTrafficShaper
With this commit we move the traffic shaper definition from the routing
package to the HTLC switch package as a preparation for being able to
use it there as well.
At the same time we rename it to AuxTrafficShaper to be more in line
with the other auxiliary components.
2024-12-05 12:39:33 +01:00
Keagan McClelland
ed2989ae33 multi: update to fn v2 2024-12-04 13:19:00 -07:00
Elle Mouton
ab7aae0708 multi: rename nolint:lll to nolint:ll
Find and replace all nolint instances refering to the `lll` linter and
replace with `ll` which is the name of our custom version of the `lll`
linter which can be used to ignore log lines during linting.

The next commit will do the configuration of the custom linter and
disable the default one.
2024-12-02 09:14:21 +02:00
Elle Mouton
439a6c7d6c multi: rename chan DB Open method to OpenForTesting 2024-11-28 13:51:15 +02:00
Elle Mouton
9f54ec90aa multi+refactor: move models package to graph/db
All the structs defined in the `channeldb/models` package are graph
related. So once we move all the graph CRUD code to the graph package,
it makes sense to have the schema structs there too. So this just moves
the `models` package over to `graph/db/models`.
2024-11-28 13:34:33 +02:00
Elle Mouton
c2923e2214 multi: remove PrefixLog
And instead use the new btclog Logger `WithPrefix` method.
2024-11-27 10:44:32 +02:00
Keagan McClelland
127e4fff28 htlcswitch: add logging to quiescer 2024-11-26 14:13:44 -07:00
Keagan McClelland
ac0c24aa7b htlcswitch: don't pass pending update counts into quiescer
This change simplifies some of the quiescer responsibilities in
favor of making the link check whether or not it has a clean state
to be able to send or receive an stfu. This change was made on the
basis that the only use the quiescer makes of this information is
to assess that it is or is not zero. Further the difficulty of
checking this condition in the link is barely more burdensome than
selecting the proper information to pass to the quiescer anyway.
2024-11-26 14:13:43 -07:00
Keagan McClelland
a4c49a88f1 htlcswitch: add quiescence timeout that is aborted by Resume 2024-11-26 14:13:43 -07:00
Keagan McClelland
111c9b05f3 htlcswitch+peer: allow the disabling of quiescence
Here we add a flag where we can disable quiescence. This will be used
in the case where the feature is not negotiated with our peer.
2024-11-26 14:13:39 -07:00
Keagan McClelland
48ee643c0d htlcswitch: implement noop quiescer
In this commit we implement a noop quiescer that we will use when
the feature hasn't been negotiated. This will make it far easier to
manage quiescence operations without having a number of if statements
in the link logic.
2024-11-26 13:52:54 -07:00
Keagan McClelland
5906ca2537 htlcswitch: add test for deferred processing remote adds when quiescent 2024-11-26 13:52:54 -07:00
Keagan McClelland
4fbab45a5f htlcswitch: defer processRemoteAdds when quiescent
In this commit we defer processRemoteAdds using a new mechanism on
the quiescer where we capture a closure that needs to be run. We
do this because we need to avoid the scenario where we send back
immediate resolutions to the newly added HTLCs when quiescent as
it is a protocol violation. It is not enough for us to simply defer
sending the messages since the purpose of quiescence itself is to
have well-defined and agreed upon channel state. If, for whatever
reason, the node (or connection) is restarted between when these
hooks are captured and when they are ultimately run, they will
be resolved by the resolveFwdPkgs logic when the link comes back
up.

In a future commit we will explicitly call the quiescer's resume
method when it is OK for htlc traffic to commence.
2024-11-26 13:52:53 -07:00
Keagan McClelland
7255b7357c htlcswitch: implement InitStfu link operation 2024-11-26 13:51:57 -07:00
Keagan McClelland
70e3804121 htlcswitch: add link operation for initiating quiescence 2024-11-26 13:51:57 -07:00
Keagan McClelland
6d30ab6c4f htlcswitch: drop connection if link updates after stfu 2024-11-26 13:51:56 -07:00