Commit Graph
100 Commits
Author SHA1 Message Date
Keagan McClelland 9bbd327a10 fn: add Sink to Result 2024-11-06 16:50:02 -07:00
Keagan McClelland 5dec35426c fn: add transpositions for Option and Result 2024-11-06 16:40:36 -07:00
Keagan McClelland 8971c4c3ae fn: add operations to Result API 2024-11-06 16:40:15 -07:00
Keagan McClelland 5faad77f33 fn: add conversions between Result and Option 2024-11-06 16:39:33 -07:00
Keagan McClelland a741c54175 fn: add compound slice functions 2024-11-06 16:29:41 -07:00
Keagan McClelland 7a7f3bdb2c fn: fix UnwrapOrFail semantics 2024-11-06 15:55:18 -07:00
ProofOfKeags 7bf9b59816 Merge pull request #9097 from ProofOfKeags/refactor/evaluate-htlc-view
[KILO]: DynComms Prefactor: Refactor/evaluate htlc view
2024-10-14 13:10:00 -06:00
Keagan McClelland 5307e7a5e4 lnwallet: return balance changes rather than modifying references
Here we return the balance deltas from evaluateHTLCView rather than
passing in references to variables that will be modified. It is a
far cleaner and compositional approach which allows readers of this
code to more effectively reason about the code without having to
keep the whole codebase in their head.
2024-10-14 09:40:47 -06:00
Keagan McClelland f0eecfa2cd lnwallet: inline and remove process[Add|Remove]Entry
This commit observes that processAddEntry and processRemoveEntry
are only invoked at a single call-site. Here we inline them at their
call-sites, which will unlock further simplifications of the code
that will allow us to remove pointer mutations in favor of explicit
expression oriented programming.

We also delete the tests associated with these functions, the overall
functionality is implicitly tested by the TestEvaluateHTLCView tests.
2024-10-14 09:33:39 -06:00
Keagan McClelland 1222cb8b10 lnwallet: remove continue statements from evaluateHTLCView loops
This further reduces loop complexity in evaluateHTLCView by using
explicit filter steps rather than loop continue statements.
2024-10-14 09:33:39 -06:00
Keagan McClelland d5aab4a8c1 lnwallet: consolidate loops in evaluateHTLCView
We had four for-loops in evaluateHTLCView that were exact mirror
images of each other. By making use of the new ChannelParty and
Dual facilities introduced in prior commits, we consolidate these
into two for-loops.
2024-10-14 09:33:39 -06:00
Keagan McClelland 51c28496a4 lnwallet: simplify fee calculation in evaluateHTLCView
This commit simplifies how we compute the commitment fee rate based
off of the live updates. Prior to this commit we processed all of
the FeeUpdate paymentDescriptors of both ChannelParty's. Now we only
process the last FeeUpdate of the OpeningParty
2024-10-14 09:33:38 -06:00
Keagan McClelland 4b2a4e36ad lnwallet: pack htlcView.{OurUpdates|TheirUpdates} into Dual.
This commit moves the collection of updates behind a Dual structure.
This allows us in a later commit to index into it via a ChannelParty
parameter which will simplify the loops in evaluateHTLCView.
2024-10-14 09:33:38 -06:00
Keagan McClelland 1b2cb14254 lnwallet: change bool isIncoming to new lntypes.ChannelParty
This commit removes another raw boolean value and replaces it with
a more clear type/name. This will also assist us when we later try
and consolidate the logic of evaluateHTLCView into a single
coherent computation.
2024-10-14 09:33:38 -06:00
Keagan McClelland b902d0825d lnwallet: use fn.Set API directly instead of empty struct map. 2024-10-14 09:33:38 -06:00
Keagan McClelland d82d02831d lnwallet: remove mutateState from evaluateHTLCView
In line with previous commits we are progressively removing the
mutateState argument from this call stack for a more principled
software design approach.

NOTE FOR REVIEWERS:
We take a naive approach to updating the tests here and simply
take the functionality we are removing from evaluateHTLCView and
run it directly after the function in the test suite.

It's possible that we should instead remove this from the test
suite altogether but I opted to take a more conservative approach
with respect to reducing the scope of tests. If you have opinions
here, please make them known.
2024-10-14 09:33:16 -06:00
Keagan McClelland 819239c5c8 lnwallet: inline processUpdateFee and remove the function entirely
In this commit we observe that the previous commit reduced the role
of this function to a single assignment statement with numerous newly
irrelevant parameters. This commit makes the choice of inlining it at
the two call-sites within evaluateHTLCView and removing the funciton
definition entirely. This also allows us to drop a huge portion of
newly irrelevant test code.
2024-10-11 11:25:58 +02:00
Keagan McClelland 05347c8392 lnwallet: bring processFeeUpdate in line with process[Add|Remove]Entry
This commit redoes the API and semantics of processFeeUpdate to make
it consistent with the semantics of it's sister functions. This is
part of an ongoing series of commits to remove mutateState arguments
pervasively from the codebase.

As with the previous commit this makes state mutation the caller's
responsibility. This temporarily increases code duplication at the
call-sites, but this will unlock other refactor opportunities.
2024-10-11 11:25:58 +02:00
Keagan McClelland 49add0f57b lnwallet: eliminate inner-most layer of evil mutateState nonsense
This commit begins the process of moving towards a more principled
means of state tracking. We eliminate the mutateState argument from
processAddEntry and processRemoveEntry and move the responsibility
of mutating said state to the call-sites.

The current call-sites of these functions still have their *own*
mutateState argument which will be eliminated during upcoming commits.
However, following the principle of micro-commits I opted to break
these changes up to make review simpler.
2024-10-11 11:25:52 +02:00
Keagan McClelland 71da6b5336 lnwallet: consolidate redundant cases using Dual.ForParty 2024-10-11 11:12:36 +02:00
Keagan McClelland b457b40f80 lnwallet: pack paymentDescriptor add/remove heights into Duals
The purpose of this commit is to begin the process of packing
symmetric fields into the newly introduced Dual structure. The
reason for this is that the Dual structure has a handy indexing
method where we can supply a ChannelParty and get back a value.
This will cut down on the amount of branching code in the main
lines of the codebase logic, making it easier to follow what is
going on.
2024-10-11 11:10:37 +02:00
Keagan McClelland 4e1579cf4c fn: add uncons, unsnoc and its component projections 2024-10-04 14:47:11 -06:00
Keagan McClelland f7264e6a5b fn: add Filter to List
This commit adds an immutable Filter method to the linked List API.
This is useful because there are several instances wherein we iterate
through the linked List and only process a subset of it in some way
or another.
2024-09-26 14:24:36 -06:00
Keagan McClelland 93d17a48a8 lnwallet: remove unnecessary chanID argument form unsignedLocalUpdates 2024-09-10 13:57:05 -07:00
Keagan McClelland 4fadbb09bd htlcswitch+lnwallet: quarantine paymentDescriptor to lnwallet
The objective of this commit is to make paymentDescriptor a private
data structure so we can quarantine it to the lnwallet package.
To accomplish this we had to prevent it from leaking out via the
arguments or return values of the public functions in lnwallet.
This naturally had consequences for the htlcswitch package as we
choose other mechanisms for tracking the data that paymentDescriptor
was responsible for.

Astoundingly, this was highly successful and allowed us to remove
a ton of redundant code. The diff for this commit represents a
substantial reduction in total lines of code as well as extraneous
arguments and return values from key functions.

This also sets the stage for future commits where we actually will
be attempting to rid lnwallet of paymentDescriptor completely.
2024-09-10 13:56:56 -07:00
Keagan McClelland 27ff5f085a lnwallet: remove unused function PayDescsFromRemoteLogUpdates
This function is no longer used as of the last commit and it is the
last remaining leak of the PaymentDescriptor type through the public
API.
2024-09-09 20:59:41 -06:00
Keagan McClelland dc60f78f7f htlcswitch: remove PaymentDescriptor conversion from reforwardSettleFails
This is part of a systematic removal of PaymentDescriptor from the mechanics
of the htlcswitch package.
2024-09-09 20:59:41 -06:00
Keagan McClelland 957557a937 htlcswitch+lnwallet: remove PaymentDescriptor from ReceiveRevocation returns
This is part of a systematic removal of PaymentDescriptor from the public
API of the lnwallet package. This marks the last change needed before we
make the PaymentDescriptor structure private.
2024-09-09 20:59:22 -06:00
Keagan McClelland 1ae5705954 htlcswitch: remove PaymentDescriptor from processRemoteSettleFails call signature
This is part of a systematic removal of PaymentDescriptor from the mechanics
of the htlcswitch package.
2024-09-09 17:15:31 -06:00
Keagan McClelland aa38041240 htlcswitch: remove PaymentDescriptor from processRemoteAdds call signature
This is part of a systematic removal of PaymentDescriptor from the mechanics
of the htlcswitch package.
2024-09-09 17:15:30 -06:00
Keagan McClelland d881809a4d htlcswitch: remove PaymentDescriptor from hodlHtlc
This is part of a systematic removal of PaymentDescriptor from the
mechanics of the htlcswitch package.
2024-09-09 16:53:11 -06:00
Keagan McClelland a0818a0d16 htlcswitch: remove PaymentDescriptor from the processExitHop's call signature
This is part of a systematic removal of PaymentDescriptor from the mechanics
of the htlcswitch package.
2024-09-09 16:53:10 -06:00
Keagan McClelland 07647fe53a htlcswitch: remove PaymentDescriptor from settleHTLC's call signature
This is done as part of a systematic removal of PaymentDescriptor from
the mechanics of the htlcswitch package.
2024-09-09 16:53:10 -06:00
Keagan McClelland 877d29c717 htlcswitch: remove PaymentDescriptor from sendHTLCError's call signature
This is done as part of a systematic removal of PaymentDescriptor from
the mechanics of the htlcswitch package.
2024-09-09 16:53:10 -06:00
Keagan McClelland 0fb29b2598 channeldb: add convenience functions for generating Source/Dest Refs 2024-09-09 16:53:10 -06:00
Keagan McClelland 1e2bf3e0b3 lnwallet: add function to convert paymentDescriptor to LogUpdate
Here we add a function that is capable of recovering LogUpdates from
paymentDescriptors and we refactor the lnwallet code to use this
rather than doing JIT inline construction of the LogUpdates.
2024-09-09 16:53:08 -06:00
Keagan McClelland 721a0c5edc lnwire+htlcswitch: change NewInvalidBlinding to use array instead of slice 2024-09-09 16:26:41 -06:00
Keagan McClelland 5505b6daff htlcswitch: change sendMalformedHTLCError to take array instead of slice 2024-09-09 16:26:41 -06:00
Keagan McClelland 5deb4c253a htlcswitch+lnwallet: fix OnionBlob to 1366 bytes 2024-09-09 16:26:41 -06:00
Keagan McClelland df3c6b72ab lnwallet: track ChannelID on PaymentDescriptor
In this commit we track the ChannelID on the PaymentDescriptor.
This will be useful in upcoming commits that need to be able to
reconstruct lnwire.Message values from PaymentDescriptors as the
Messages that are exchanged to update channel state all include
the ChannelID.
2024-09-09 16:26:41 -06:00
Keagan McClelland a89e24f487 lnwallet: add ChannelID method to LightningChannel
In this commit we introduce a convenience method to LightningChannel
to allow us to quickly grab the channel id. This will be important
in upcoming commits where we need to remember the ChannelID to
reconstruct update messages.
2024-09-09 16:26:41 -06:00
Keagan McClelland 1422729f80 lnwallet+htlcswitch: define expanded NumPendingUpdates
This commit squashes the below operations for a net result where
we have an expanded capability of assessing pending updates. This
is made possible by packing the components into Duals in the prior
commits. We squash the operations to simplify review.

htlcswitch+lnwallet: rename PendingLocalUpdateCount

lnwallet: complete pending update queries API for LightningChannel

lnwallet+htlcswitch: consolidate NumPendingUpdates using ChannelParty

This commit makes the observation that we can cleanly define the
NumPendingUpdates function using a single expression by taking
advantage of the relevant fields being properly packed into Duals.
2024-08-28 14:03:00 -07:00
Keagan McClelland ce7fcd30f8 lnwallet: pack commitment message indices into Dual
This is yet another commit that packs a symmetric structure into
a Dual. This is the last one needed for the time being to consolidate
Num{X}UpdatesPendingOn{Y} functions into a single one.
2024-08-28 14:02:59 -07:00
Keagan McClelland 2e7fbc446f lnwallet: pack update logs into Dual
This commit, like the last one packs the update logs into a symmetric
Dual structure. This will allow us to index into them more concisely
in higher order logic.
2024-08-28 13:58:33 -07:00
Keagan McClelland 8077862225 lnwallet: pack commit chains into Dual
This commit packs the LightningChannel's localCommitmentChain and
remoteCommitmentChain into a Dual structure for better symmetric
access. This will be leveraged by an upcoming commit where we want
to more concisely express how we compute the number of pending
updates.
2024-08-28 13:51:23 -07:00
Keagan McClelland a0515a16db htlcswitch: extract error handling for syncChanStates 2024-08-28 13:46:52 -07:00
Keagan McClelland 34f7c31dc8 lntypes: Add Dual[A] primitive type
This commit introduces a new type Dual[A] to make it easier to
manage symmetric configurations or state for lightning channels.
2024-08-15 10:53:18 -07:00
ProofOfKeags 747abb4a0e Merge pull request #8980 from ProofOfKeags/refactor/modified-htlcs-fn-set
[NANO]: lnwallet: update updateLog.modifiedHtlcs to use fn.Set
2024-08-06 11:56:57 -06:00
Keagan McClelland c3c4e79593 lnwallet: update updateLog.modifiedHtlcs to use fn.Set 2024-08-06 10:05:20 -07:00
Keagan McClelland 935e7f1bee lnwallet: remove unused parameters in LightningChannel methods 2024-08-05 18:14:11 -07:00
Keagan McClelland 14e371948b lnwallet: remove unnecessary duplicate definition 2024-08-05 18:14:11 -07:00
Keagan McClelland 2ddc3db5f8 peer: add message summary for Stfu 2024-08-05 17:23:19 -07:00
Keagan McClelland b172227cb3 lnwire: add Stfu to LinkUpdater interface 2024-08-05 17:23:19 -07:00
Keagan McClelland 0176fca826 lnwire: add wire type for stfu 2024-08-05 17:22:56 -07:00
Keagan McClelland a2b19afe59 channeldb+lnwallet: define Initiator for OpenChannel and LightningChannel
This commit introduces a new API to return information on which party opened
the channel using the new ChannelParty type. It does not change the underlying
structure of how we store this information.
2024-08-05 12:58:46 -07:00
ProofOfKeags e3dd886580 Merge pull request #8962 from ProofOfKeags/refactor/quiescence-micro-spinoffs
[NANO]: Refactor/quiescence micro spinoffs
2024-08-01 13:57:29 -06:00
Keagan McClelland 22e34702d8 funding: replace newly edited log values with lazier variants 2024-08-01 12:11:52 -07:00
Keagan McClelland e3a9d0acbe multi: break ChannelConstraints into two sub-structures
This commit breaks the ChannelConstraints structure into two
sub-structures that reflect the fundamental differences in how
these parameters are used. On its face it may not seem necessary,
however the distinction introduced here is relevant for how we
will be implementing the Dynamic Commitments proposal.
2024-08-01 12:00:32 -07:00
Keagan McClelland dc03637ae3 htlcswitch: rename for test parameters for accuracy 2024-08-01 11:56:50 -07:00
Keagan McClelland f54c9ea8f7 htlcswitch: replace errors package implementation 2024-07-31 17:54:21 -07:00
Keagan McClelland 1f9cac5f80 htlcswitch: refactor dust handling to use ChannelParty 2024-07-31 14:50:27 -07:00
Keagan McClelland 1d65f5bd12 peer: refactor createChanCloser to use ChannelParty 2024-07-31 14:50:27 -07:00
Keagan McClelland 0996e4f163 multi: refactor lnwallet/channel.go to use ChannelParty in select places
We also include changes to contractcourt, htlcswitch and peer to stitch the
boundaries together.
2024-07-31 14:50:26 -07:00
Keagan McClelland 33934449ac multi: refactor select methods within channeldb to use ChannelParty
Also in this commit is a small adjustment to the call-sites to get
the boundaries stitched back together.
2024-07-31 14:50:26 -07:00
Keagan McClelland 3a15085014 input+lnwallet: refactor select methods in input to use ChannelParty 2024-07-31 14:50:26 -07:00
Keagan McClelland 1a5b5c5f62 lntypes: Add a ChannelParty type.
This commit introduces a ChannelParty type to LND. It is useful for
consolidating all references to the duality between the local and
remote nodes. This is currently handled by having named struct rows
or named boolean parameters, named either "local" or "remote". This
change alleviates the programmer from having to decide which node
should be bound to `true` or `false`. In an upcoming commit we will
change callsites to use this.
2024-07-31 14:50:23 -07:00
Keagan McClelland 04c37344ae lnwallet: refactor channel to use new typed List 2024-07-31 13:03:34 -07:00
Keagan McClelland 2c6d229a69 fn: harden and refine the Req[I,O] API.
In this commit we opt to make the internal response channel fully
private and instead expose methods for doing resolution. This
prevents internal implementation details from leaking a little bit
better than the previous iteration.
2024-07-31 12:59:10 -07:00
Keagan McClelland 4835fdf237 fn: Add new Req type to abstract the pattern of remote processing.
It is common throughout the codebase to send data to a remote
goroutine for processing. Typically, along with the data we are
processing, we also send a one-shot channel where we intend to
listen for the response. This type encapsulates that pattern.
2024-07-31 12:59:03 -07:00
ProofOfKeags 67c5fa9478 Merge pull request #8946 from ziggie1984/fix-bumpforceclose-behaviour
Fix bumpforceclose behavior for force closes without htlcs.
2024-07-30 14:42:19 -06:00
Keagan McClelland 82ff360ad2 lnwallet: fix linter errors resulting from commitmentChain move. 2024-07-30 10:22:23 -07:00
Keagan McClelland 4cf7555922 lnwallet: move commitChain to its own file. 2024-07-30 10:18:28 -07:00
Keagan McClelland 3e7866d85c lnwallet: fix linter errors introduced by updateLog move 2024-07-30 10:17:47 -07:00
Keagan McClelland 51060aed45 lnwallet: move updateLog to its own file. 2024-07-29 15:26:35 -07:00
Keagan McClelland 39db0221f0 lnwallet: move PaymentDescriptor definition to its own file 2024-07-29 15:26:35 -07:00
Keagan McClelland 09f5e08d32 contractcourt: Fix heuristic for identifying STC commit broadcaster.
This commit fixes the heuristic we use for identifying the party
that broadcast a Simple Taproot Channel commitment transaction.

Prior to this change we checked if the last script element was an
OP_DROP. However, both the local and remote commitment outputs
have an OP_DROP at the end.

The new approach checks the resolver's SignDescriptor and compares
that key to the keys in the channel's local ChannelConfig. If the
key is the delay key, we know that it is our commitment transaction.
2024-07-17 14:57:28 -07:00
Keagan McClelland 31d45757a4 contractcourt: properly detect RBF coop close transactions
This commit fixes an issue where we did not properly detect and
therefore record the coop close transaction if it used the newer
RBF coop close v2 scheme. This only affects coop closes of
taproot channels today.
2024-07-17 14:48:20 -07:00
Keagan McClelland eaa5e4a039 fn: remove redundant Reduce function
This commit removes Reduce since we already have both Foldl and Foldr.
2024-07-10 17:06:09 -07:00
Keagan McClelland fa2e25d5f4 fn: remove lru dependency 2024-07-10 17:06:04 -07:00
Keagan McClelland 364d79e552 fn: add generic version of List 2024-07-10 16:55:29 -07:00
Keagan McClelland fb1437cb6d fn: add Elem function for set membership 2024-07-10 15:37:27 -07:00
Keagan McClelland 9c30bce10c fn: add curried (in)equality functions 2024-07-10 15:37:27 -07:00
Keagan McClelland c4df2f1dce fn: reimplement internals of either, add tests 2024-07-10 15:37:27 -07:00
Keagan McClelland 1dd56f1b2a fn: fix and finish the either API 2024-07-10 15:37:27 -07:00
Keagan McClelland c3603ccf96 fn: add FindIdx function 2024-07-10 15:34:57 -07:00
Keagan McClelland 5902aa5159 fn: add concurrent map operation for slices 2024-07-10 15:29:16 -07:00
Keagan McClelland 94acbe90a8 fn: add fundamental functional primitives 2024-07-10 14:42:11 -07:00
Keagan McClelland 1fea14f69f docs: update release notes 2024-06-10 11:38:22 -07:00
Keagan McClelland 30e10322b2 contractcourt: consider delivery addresses when evaluating toSelfAmount
This commit fixes #8535 by changing how we assess toSelfAmount inside
the chainWatcher.

In certain cases users may wish to close out channel funds to external
delivery addresses set either during open or close.

Prior to this change we only consider addresses that our wallet is
aware of.

This change now identifies outputs as to_self outputs if the delivery
script matches OR if our wallet is aware of the address. In certain
edge cases it can be possible for there to be more than one output
that matches these criteria and in that case we will return the sum
of those values.
2024-06-10 11:38:17 -07:00
Keagan McClelland 56048133f2 itest+lntest: add itest to reproduce bug #8535 2024-06-05 12:56:04 -07:00
Keagan McClelland cd3c17e1c0 fn: add predicate combinators for && and || 2024-06-03 12:24:02 -07:00
Keagan McClelland fce2ef15a5 scripts: add gpg key for proofofkeags [skip ci] 2024-05-28 17:29:36 -07:00
Keagan McClelland 1148e572bf peer: triple timeout parameters to give tor more grace 2024-05-21 13:36:46 -07:00
Keagan McClelland 61191a576d peer: make PingManager.Stop infallible 2024-05-21 13:29:31 -07:00
Keagan McClelland 94a9baefeb peer: reduce upper bound of pong bytes to ease bandwidth load 2024-05-21 13:27:56 -07:00
Keagan McClelland 6257df31e0 tlv: add axiomatic RecordProducer implementation for Record
This commit introduces a RecordProducer implementation for Record
that serves as the identity function. This makes it easier for us
to mix Primitive and Dynamic records in the same RecordProducer
collections.
2024-04-18 12:03:27 -06:00
Keagan McClelland 939e3cc6c1 docs: update release notes 2024-04-04 12:28:37 -07:00
Keagan McClelland dd2da29cba peer: re-add AuthGossiper nil check 2024-04-03 15:47:50 -07:00
Keagan McClelland dad53b3f9a Revert "feature: make gossip queries compulsory"
This reverts commit 717facc202.

It turns out that we can't do this since it would result in
incompatibility with LDK. The spec has been updated to reallow
optional gossip queries so we revert this commit.
2024-04-02 16:43:27 -07:00
ProofOfKeags b575460bca Merge pull request #8418 from Crypt-iQ/feefilter_0117
chainfee: introduce filterManager and use it for fee floor
2024-03-20 19:15:35 -06:00