Commit Graph

1006 Commits

Author SHA1 Message Date
Keagan McClelland
94373bd96f htlcswitch: placate confused linter 2024-01-23 12:25:06 -08:00
Keagan McClelland
ec55831229 htlcswitch+peer: remove ShutdownIfChannelClean 2024-01-22 16:08:59 -08:00
Keagan McClelland
64fda6ca65 htlcswitch: implement flush and commit lifecycle hooks for channelLink 2024-01-22 16:08:55 -08:00
Keagan McClelland
601afaf1b2 htlcswitch: implement flush api for channelLink 2024-01-22 12:19:58 -08:00
Keagan McClelland
891b00d473 htlcswitch: drop the connection when receiving an invalid add
When the link is flushing in the incoming direction, it means
adds are invalid. The best chance we have at dealing with this
is to drop the connection. This should roll back the channel
state to the last CommitSig. If the remote has already sent a
CommitSig we haven't received yet, channel state will be
re-synchronized with a ChannelReestablish message upon
reconnection and the protocol state that caused us to flush
the link will be rolled back. In the event that there was some
non-deterministic behavior in the remote that caused them to
violate the protocol, we have a decent shot at correcting it
this way, since reconnecting will put us in the cleanest
possible state to try again.
2024-01-22 12:19:58 -08:00
Keagan McClelland
a9d5235c62 htlcswitch: bounce downstream adds when flushing 2024-01-22 12:19:58 -08:00
Keagan McClelland
70292253d1 htlcswitch: make link forward eligibility flush aware 2024-01-22 12:19:58 -08:00
Keagan McClelland
9b2d1018f2 htlcswitch+peer: add flush api and lifecycle hooks to ChannelUpdateHandler
We also add dummy implementations to channelLink and various mocks.
2024-01-22 12:19:58 -08:00
Matt Morehouse
0f5ee7cc1e
htlcswitch: update fuzzPayload for route blinding
Route blinding added some new fields to hop.Payload and route.Hop, which
we need to copy over to the fuzzPayload tests.
2024-01-16 11:12:11 -06:00
ziggie
0b63989f3a
lnwallet+htlcswitch: Introduce a fee buffer.
We take into account a fee buffer of twice the current fee rate
of the commitment transaction plus an additional htlc output
when we are the opener of the channel hence pay when publishing the
commitment transaction. This buffer is not consensus critical
because we only consider it when we are in control of adding a
new htlc to the state. The goal is to prevent situations
where we push our local balance below our channel reserve due to
parallel adding of htlcs to the state. Its not a panacea for these
situations but until we have __option_simplified_update__ deployed
widely on the network its a good precaution to protect against
fee spikes and parallel adding of htlcs to the update log.

Moreover the way the available balance for a channel changed.
We now need to account for a fee buffer when we are the channel
opener. Therefore all the tests had to be adopted.
2024-01-06 20:52:46 +01:00
Carla Kirk-Cohen
af4fdcc1fd
htlcswitch/test: allow missing field errors in payload decode 2023-12-18 11:27:56 -05:00
Carla Kirk-Cohen
69d5496e7c
multi: update payload validation to account for blinded routes 2023-12-18 11:27:55 -05:00
Carla Kirk-Cohen
343a6ed831
hltcswitch/hop: add next hop to intermediate hop with custom records
Fix our existing test to have a valid intermediate hop that will pass
stricter validation. Previously, we did not specify a next channel for
an intermediate hop (which violates bolt4).
2023-12-18 11:27:53 -05:00
Carla Kirk-Cohen
585f28c5f5
multi: explicitly signal final hop in pack hop payload
Previously, we'd use the value of nextChanID to infer whether a payload
was for the final hop in a route. This commit updates our packing logic
to explicitly signal to account for blinded routes, which allow zero
value nextChanID in intermediate hops. This is a preparatory commit
that allows us to more thoroughly validate payloads.
2023-12-18 11:27:52 -05:00
Carla Kirk-Cohen
b5afd905d1
htlcswitch/hop: explicitly signal final hop from sphinx packet
Previously, we were using nextChanID to determine whether a hop
payload is for the final recipient. This is no longer suitable in a
route-blinding world where intermediate hops are allowed to have zero
nextChanID TLVs (as this information is provided to forwarding nodes
in their encrypted data). This commit updates payload reading to use
the signal provided by sphinx that we are on the last packet, rather
than implying it from the contents of a hop.
2023-12-18 11:27:51 -05:00
Carla Kirk-Cohen
2f8587341a
htlcswitch/test: do not set amount and cltv for blinded test cases 2023-12-18 11:27:50 -05:00
Carla Kirk-Cohen
fa78d21975
htlcswitch/test: add sphinx action to decoding test
Update test to include the sphinx action to more closely represent
reality. This will be required when we add more validation to the
presence of a nextChanID field. A MoreHops action is chose because
we're testing the case with a payload that contains forwarding info.
2023-12-18 11:27:48 -05:00
Carla Kirk-Cohen
b0870ea2ed
htlcswitch/test: add encrypted data to blinded intermediate hop
Blinding points will always be accompanied by encrypted data, so
update the test to more accurately represent reality.
2023-12-12 10:01:26 -05:00
Elle
4fa483f1bc
Merge pull request #7702 from ellemouton/towerClientMux
wtclient: Tower Client Multiplexer
2023-12-05 12:27:05 +02:00
Elle Mouton
fcfdf699e3
multi: move BackupState and RegisterChannel to Manager
This commit moves over the last two methods, `RegisterChannel` and
`BackupState` from the `Client` to the `Manager` interface. With this
change, we no longer need to pass around the individual clients around
and now only need to pass the manager around.

To do this change, all the goroutines that handle channel closes,
closable sessions needed to be moved to the Manager and so a large part
of this commit is just moving this code from the TowerClient to the
Manager.
2023-11-28 10:59:40 +02:00
yyforyongyu
85f4b13632
multi: enhance logging around channel reestablishment 2023-11-28 14:06:53 +08:00
yyforyongyu
09a5d235ec
routing: fail attempt when no shard is found or circuit generation fails 2023-11-13 16:09:11 +08:00
Oliver Gugger
e1fb1e484a
Merge pull request #7967 from morehouse/fuzz_onion
htlcswitch: fuzz onion encoding/decoding
2023-10-19 15:30:03 +00:00
Oliver Gugger
82838e4a62
Merge pull request #8090 from ziggie1984/add-additional-log-chan-closure
Add more information when a co-op close is failing.
2023-10-17 10:27:21 +00:00
ziggie
e4dd911778
multi: clarify co-op closure failures. 2023-10-13 20:35:08 +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
Eugene
9478b85e59
htlcswitch/hop: use InvalidOnionVersion for replayed packets (#7937)
* htlcswitch/hop: use InvalidOnionVersion for replayed packets

The link will send an update_fail_malformed_htlc, so we need to set
the BADONION bit. Since there isn't a replay-specific error, we
set the failure code to InvalidOnionVersion which has the BADONION bit.

* release-notes: update for 0.17.1
2023-10-11 10:08:43 +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
66b8700c0b multi: add debug logs to catch slow shutdown 2023-10-06 16:34:47 -07:00
Elle Mouton
7fa05f92f5 htlcswitch: remove Network type 2023-10-06 16:34:47 -07:00
Matt Morehouse
5863b9f2fc
htlcswitch: fuzz hop.Payload and route.Hop
hop.Payload and route.Hop are analogs, with onion payloads encoded from
route.Hops and decoded to hop.Payloads. For checking equality of
encoding/decoding, we implement a helper function to convert
hop.Payloads into route.Hops.
2023-09-07 17:15:43 -05:00
Matt Morehouse
9c51bea790
htlcswitch: fuzz lightning-onion onions and payloads
Fuzz tests for:
- HopData
- HopPayload
- OnionPacket
2023-09-07 17:15:40 -05:00
Olaoluwa Osuntokun
01c64712a3
multi: ensure link is always torn down due to db failures, add exponential back off for sql-kvdb failures (#7927)
* lnwallet: fix log output msg

The log message is off by one.

* htlcswitch: fail channel when revoking it fails.

When the revocation of a channel state fails after receiving a new
CommitmentSigned msg we have to fail the channel otherwise we
continue with an unclean state.

* docs: update release-docs

* htlcswitch: tear down connection if revocation processing fails

If we couldn't revoke due to a DB error, then we want to also tear down
the connection, as we don't want the other party to continue to send
updates. That may lead to de-sync'd state an eventual force close.
Otherwise, the database might be able to recover come the next
reconnection attempt.

* kvdb: use sql.LevelSerializable for all backends

In this commit, we modify the default isolation level to be
`sql.LevelSerializable. This is the strictness isolation type for
postgres. For sqlite, there's only ever a single writer, so this doesn't
apply directly.

* kvdb/sqlbase: add randomized exponential backoff for serialization failures

In this commit, we add randomized exponential backoff for serialization
failures. For postgres, we''ll his this any time a transaction set fails
to be linearized. For sqlite, we'll his this if we have many writers
trying to grab the write lock at time same time, manifesting as a
`SQLITE_BUSY` error code.

As is, we'll retry up to 10 times, waiting a minimum of 50 miliseconds
between each attempt, up to 5 seconds without any delay at all. For
sqlite, this is also bounded by the busy timeout set, which applies on
top of this retry logic (block for busy timeout seconds, then apply this
back off logic).

* docs/release-notes: add entry for sqlite/postgres tx retry

---------

Co-authored-by: ziggie <ziggie1984@protonmail.com>
2023-08-30 16:48:00 -07:00
Olaoluwa Osuntokun
28c086f1fc
htlcswitch: remove call to InitRemoteMusigNonces
In this commit, we remove the internal call to `InitRemoteMusigNonces`.
We don't need this since when we go to process the remote party's chan
reest message, we'll already call this method. Otherwise, we'll get an
error here since the pending verification nonce has been wiped out after
each call.
2023-08-22 16:34:02 -07:00
Olaoluwa Osuntokun
e8b6e0ca45
htlcswitch: add awareness of new partial sig fields and musig2 nonces 2023-08-22 16:32:13 -07:00
Olaoluwa Osuntokun
15978a8691
funding+peer: add support for new musig2 channel funding flow
In this commit, we add support for the new musig2 channel funding flow.
This flow is identical to the existing flow, but not both sides need to
exchange local nonces up front, and then signatures sent are now partial
signatures instead of regular signatures.

The funding manager also gains some new state of the local nonces it
needs to generate in order to send the funding locked message, and also
process the funding locked message from the remote party.

In order to allow the funding manger to generate the nonces that need to
be applied to each channel, then AddNewChannel method has been modified
to accept a set of options that the peer will then use to bind the
nonces to a new channel.
2023-08-22 16:32:07 -07:00
Olaoluwa Osuntokun
aaba144804
multi: fix linter warnings 2023-08-22 16:32:00 -07:00
Olaoluwa Osuntokun
3270a29e3e
lnwallet: handle nonce init in ProcessChanSyncMsg
In this commit, we update the logic to handle nonce init in
ProcessChanSyncMsg. Once a channel is already open, this is where we'll
get the new nonce data from the remote party we'll use to gain the nonce
we need to sign for their next state.
2023-08-22 16:31:54 -07:00
Olaoluwa Osuntokun
11c62e3951
lnwallet+htlcswitch: add NewCommitState struct, modify send/recv sig to accept
In this commit, we add a new NewCommitState struct. This preps us for
the future change wherein a partial signature is also added to the mix.
All related tests and type signatures have also been updated
accordingly.
2023-08-22 16:31:18 -07:00
Olaoluwa Osuntokun
9a65806c09
input+wallet: extract musig2 session management into new module
In this commit, we extract the musig2 session management into a new
module. This allows us to re-use the session logic elsewhere in unit
tests so we don't need to instantiate the entire wallet.
2023-08-22 16:30:39 -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
d5c504c8de
multi: use fwding policy from models pkg 2023-08-22 06:22:33 +08:00
yyforyongyu
927572583b
multi: remove pending channel from Brontide when funding flow failed
This commit adds a new interface method, `RemovePendingChannel`, to be
used when the funding flow is failed after calling `AddPendingChannel`
such that the Brontide has the most up-to-date view of the active
channels.
2023-08-09 01:29:18 +08:00
yyforyongyu
e46bd8e177
multi: add AddPendingChannel to peer interface
The funding manager has been updated to use `AddPendingChannel`. Note
that we track the pending channel before it's confirmed as the peer may
have a block height in the future(from our view), thus they may start
operating in this channel before we consider it as fully open.

The mocked peers have been updated to implement the new interface method.
2023-08-09 00:17:22 +08:00
Matt Morehouse
b1a3c46759
htlcswitch: TODO for obviating type assertions
memoryMailBox uses multiple container/list.List objects to track
messages and packets, which use interface{} to accept objects of any
type. go1.18 added generics to the language, which means we could use a
typed list instead, allowing us to stop using forced type assertions
when reading objects from the list.

I'm not aware of any standard library implementation of a typed list yet,
so let's just add a TODO for now.
2023-07-31 09:52:33 -05:00
Matt Morehouse
15f6e7a80a
htlcswitch: split mailCourier by courierType
The goroutine is very long and littered with switches on courierType. By
separating the implementations into different methods for each
courierType we eliminate the cruft and improve readability.
2023-07-20 14:53:46 -05:00
Elle Mouton
552ef4bf81
wtclient: replay pending tasks on sessionQueue stop
This commit does a few things:
- First, it gives the sessionQueue access to the TowerClient task
  pipeline so that it can replay backup tasks onto the pipeline on Stop.
- Given that the above is done, the ForceQuit functionality of the
  sessionQueue and TowerClient can be removed.
- The bug demonstrated in a prior commit is now fixed due to the above
  changes.
2023-07-18 16:28:26 +02:00
Keagan McClelland
7b179a8e64 htlcswitch: optimize tests to not tear down harness 2023-07-07 13:30:25 -06:00
Keagan McClelland
36bf471a1f invoices+htlcswitch: add tests for relaxed link and invoice checks 2023-07-07 10:48:57 -06:00
Keagan McClelland
1b1eedb434 htlcswitch: relax final onion packet check
The spec allows the final HTLC value and CLTV expiry to exceed
the value and expiry specified in the payload of the last hop
of the onion packet. We were over-restricting it to require
that it matches exactly.
2023-06-29 17:13:36 -06:00