Commit graph

8865 commits

Author SHA1 Message Date
Matt Corallo
74018b0244 Rename SpendableOutputDescriptor::outpoint()
We support some languages (okay, just JavaScript) where functions
and fields exist in the same namespace. Sadly, because we map
enums as base classes with child classes that add additional
fields, this requires that fields in enum variants do not have the
same name as functions implemented on that enum.

We violated this in 0.1.1 with
`SpendableOutputDescriptor::outpoint` which aliases the `outpoint`
fields on two `SpendableOutputDescriptor` variants.

Here we rename the new `outpoint` method, which we'll have to carry
on the 0.1-bindings branch in addition to going in 0.2.
2025-03-02 03:02:26 +00:00
Matt Corallo
6f7e1c5ed4
Mark a few TLVs as required when reading Channels
e23d32dadd removed support for
reading ancient `Channel`s but left a bit of cleanup for later.

Here we mark a few TLVs as `required` which were always written
in 0.0.113.
2025-02-28 15:49:49 -06:00
Jeffrey Czyz
43a57fa6fa
Remove unnecessary channel_value_satoshis overwrite
21ed477841 changed
ChannelTransactionParameters deserialization to pass in
channel_value_satoshis, so it does not actually need to be overwritten
as was done in an earlier draft of the commit.
2025-02-28 14:48:06 -06:00
Jeffrey Czyz
13b0598294
Reject channels serialized with version <= 2
e23d32dadd removed support for these
versions, so serializations with them should be explicitly rejected.
2025-02-28 14:48:06 -06:00
Matt Corallo
36ba27aee4
Merge pull request #3604 from jkczyz/2025-02-channel-funding-pubkeys
Refactor `ChannelTransactionParameters` into `FundingScope`
2025-02-28 15:47:24 +00:00
Jeffrey Czyz
4f681304e2
Merge pull request #3627 from TheBlueMatt/2025-02-fix-invalid-state
Fix Channel being left in indeterminite state from 9f9a7a92e1
2025-02-28 08:31:30 -06:00
Joost Jager
447148d2b3 Add test coverage for process_onion_failure 2025-02-28 14:23:58 +01:00
Jeffrey Czyz
0d127cfe22
Move get_funding_redeemscript implementation 2025-02-27 14:17:25 -06:00
Jeffrey Czyz
e0a8eeed18
Remove custom derive_channel_signer methods
The custom derive_channel_signer methods on AnchorDescriptor and
HTLCDescriptor simply delegate to the passed SignerProvider now that
providing ChannelTransactionParameters is no longer needed. Drop these
methods and replace them with the method bodies at the call sites.
2025-02-27 14:17:25 -06:00
Jeffrey Czyz
9cde57e24f
Remove channel_value_satoshis from SignerProvider
Now that channel_value_satoshis has been moved to
ChannelTransactionParameters, it no longer needs to be used when
deriving a signer. This is a breaking API change, though InMemorySigner
did not make use of channel_value_satoshis when being derived.
2025-02-27 14:17:25 -06:00
Jeffrey Czyz
88bcf88716
Remove ChannelSigner::provide_channel_parameters
Now that the copy of ChannelTransactionParameters is no longer used by
InMemorySigner, remove it and all remaining uses. Since it was set by
ChannelSigner::provide_channel_parameters, this method is no longer
needed and can also be removed.
2025-02-27 14:17:24 -06:00
Jeffrey Czyz
c8df41dc23
Use channel parameters in sign_holder_htlc_transaction
Now that channel_value_satoshis has been moved to
ChannelTransactionParameters, InMemorySigner no longer needs a copy.
Remove indirect uses of the copy from TestChannelSigner.
2025-02-27 14:17:24 -06:00
Jeffrey Czyz
6caaa54a2f
Use channel parameters in sign_counterparty_payment_input
Now that channel_value_satoshis has been moved to
ChannelTransactionParameters, InMemorySigner no longer needs a copy.
Remove uses of the copy from sign_counterparty_payment_input.
2025-02-27 14:17:24 -06:00
Jeffrey Czyz
e74c698e0b
Pass channel params to sign_splicing_funding_input
Now that channel_value_satoshis has been moved to
ChannelTransactionParameters, pass the entire parameters when calling
each method on EcdsaChannelSigner. This will remove the need for
ChannelSigner::provide_channel_parameters. Instead, the parameters from
the FundingScope will be passed in to each method. This simplifies the
interaction with a ChannelSigner when needing to be called for more than
one FundingScope, which will be the case for pending splices and RBF
attempts.
2025-02-27 14:17:24 -06:00
Jeffrey Czyz
dcea1ac876
Pass channel params to sign_holder_anchor_input
Now that channel_value_satoshis has been moved to
ChannelTransactionParameters, pass the entire parameters when calling
each method on EcdsaChannelSigner. This will remove the need for
ChannelSigner::provide_channel_parameters. Instead, the parameters from
the FundingScope will be passed in to each method. This simplifies the
interaction with a ChannelSigner when needing to be called for more than
one FundingScope, which will be the case for pending splices and RBF
attempts.
2025-02-27 14:17:24 -06:00
Jeffrey Czyz
8379161ad9
Pass channel params to sign_closing_transaction
Now that channel_value_satoshis has been moved to
ChannelTransactionParameters, pass the entire parameters when calling
each method on EcdsaChannelSigner. This will remove the need for
ChannelSigner::provide_channel_parameters. Instead, the parameters from
the FundingScope will be passed in to each method. This simplifies the
interaction with a ChannelSigner when needing to be called for more than
one FundingScope, which will be the case for pending splices and RBF
attempts.
2025-02-27 14:17:24 -06:00
Jeffrey Czyz
18e0d6aa7f
Pass channel params to sign_counterparty_htlc_transaction
Now that channel_value_satoshis has been moved to
ChannelTransactionParameters, pass the entire parameters when calling
each method on EcdsaChannelSigner. This will remove the need for
ChannelSigner::provide_channel_parameters. Instead, the parameters from
the FundingScope will be passed in to each method. This simplifies the
interaction with a ChannelSigner when needing to be called for more than
one FundingScope, which will be the case for pending splices and RBF
attempts.
2025-02-27 14:17:23 -06:00
Jeffrey Czyz
a3420d0e05
Pass channel params to sign_justice_revoked_htlc
Now that channel_value_satoshis has been moved to
ChannelTransactionParameters, pass the entire parameters when calling
each method on EcdsaChannelSigner. This will remove the need for
ChannelSigner::provide_channel_parameters. Instead, the parameters from
the FundingScope will be passed in to each method. This simplifies the
interaction with a ChannelSigner when needing to be called for more than
one FundingScope, which will be the case for pending splices and RBF
attempts.
2025-02-27 14:17:23 -06:00
Jeffrey Czyz
3e9ab723c3
Pass channel params to sign_justice_revoked_output
Now that channel_value_satoshis has been moved to
ChannelTransactionParameters, pass the entire parameters when calling
each method on EcdsaChannelSigner. This will remove the need for
ChannelSigner::provide_channel_parameters. Instead, the parameters from
the FundingScope will be passed in to each method. This simplifies the
interaction with a ChannelSigner when needing to be called for more than
one FundingScope, which will be the case for pending splices and RBF
attempts.
2025-02-27 14:17:23 -06:00
Jeffrey Czyz
f638ba48d2
Pass channel params to sign_holder_commitment
Now that channel_value_satoshis has been moved to
ChannelTransactionParameters, pass the entire parameters when calling
each method on EcdsaChannelSigner. This will remove the need for
ChannelSigner::provide_channel_parameters. Instead, the parameters from
the FundingScope will be passed in to each method. This simplifies the
interaction with a ChannelSigner when needing to be called for more than
one FundingScope, which will be the case for pending splices and RBF
attempts.
2025-02-27 14:17:23 -06:00
Jeffrey Czyz
ee72c4a9b4
Pass channel params to sign_counterparty_commitment
Now that channel_value_satoshis has been moved to
ChannelTransactionParameters, pass the entire parameters when calling
each method on EcdsaChannelSigner. This will remove the need for
ChannelSigner::provide_channel_parameters. Instead, the parameters from
the FundingScope will be passed in to each method. This simplifies the
interaction with a ChannelSigner when needing to be called for more than
one FundingScope, which will be the case for pending splices and RBF
attempts.
2025-02-27 14:17:23 -06:00
Jeffrey Czyz
dc995eafcd
Remove channel_value_satoshis from FundingScope
Now that ChannelTransactionParameters are in FundingScope,
channel_value_satoshis can be dropped from the latter.
2025-02-27 14:15:31 -06:00
Jeffrey Czyz
21ed477841
Include channel_value_satoshis in ChannelTransactionParameters
Since channel_value_satoshis is needed by the signer and may change for
each new FundingScope, included it in ChannelTransactionParameters so it
can be passed to each signer call in the upcoming commits.
2025-02-27 14:12:53 -06:00
Jeffrey Czyz
e23d32dadd
Remove InMemorySigner (de-)serialization support
InMemorySigner no longer holds channel_value_satoshis and
channel_parameters. Instead of writing 0 and None, respectively, drop
(de-)serialization support entirely since InMemorySigner hasn't been
serialized since SERIALIZATION_VERSION 2.
2025-02-27 14:12:53 -06:00
Jeffrey Czyz
fa867f35e0
Move funding_transaction to FundingScope
Since the funding transactions changes for each new FudningScope,
include it there instead of ChannelContext.
2025-02-27 14:12:06 -06:00
Jeffrey Czyz
d796878589
Move channel_transaction_parameters to FundingScope
Rather than moving relevant fields of ChannelTransactionParameters to
FundingScope, move the entire struct there instead. This prevents API
churn wherever ChannelTransactionParameters is used, which otherwise
would need a FundingScope in addition.
2025-02-27 14:02:33 -06:00
Jeffrey Czyz
b0a441f3a7
Reduce ChannelContext::channel_transaction_parameters visibility 2025-02-27 13:50:28 -06:00
Matt Corallo
fea68f7069 Fix Channel being left in indeterminite state from 9f9a7a92e1
9f9a7a92e1 introduced some changes
to channel state transitions but left one case where we'd leave a
channel in an undefined phase (upon receiving a `commitment_signed`
in the wrong state), which we fix here.
2025-02-27 19:33:22 +00:00
Matt Corallo
eaeed77ab0
Merge pull request #3423 from dunxen/2024-11-PR3137-followups
Follow-ups to PR 3137
2025-02-27 19:29:44 +00:00
Arik
d136406d44
Merge pull request #3626 from arik-so/tx-sync-pin-litemap
Pin idna_adapter for older Rust versions in CI
2025-02-27 08:58:50 -08:00
Arik Sosman
8487970431
Pin idna_adapter@1.1.0 for older Rust versions 2025-02-27 05:39:40 -08:00
Duncan Dean
9f9a7a92e1
Promote V2 channels to FundedChannel on initial commitment_signed receipt
Before this commit, unfunded V2 channels were promoted to `FundedChannel`s in
`PendingV2Channel::funding_tx_constructed`.
Since a monitor is only created upon receipt of an initial
`commitment_signed`, this would cause a crash if the channel was read
from persisted data between those two events.

Consequently, we also need to hold an `interactive_tx_signing_session`
for both of our unfunded V2 channel structs.
2025-02-27 12:38:22 +02:00
Duncan Dean
d71c31d8ae
Clean up conditional assignment of funding_ready_for_sig_event
We don't yet support contibuting inputs to V2 channels, so we need to
debug_assert and return an error if our signing session somehow has
local inputs.

We also return an error if for some mystical reason, in the no input
contributions case, the input count does not equal the witness count of
zero.
2025-02-27 12:00:53 +02:00
Duncan Dean
a86a745a62
s/Option<TxSignatures>/() for return from provide_holder_witnesses
In a following commit we change the state at which a V2 channel is
promoted to a `Channel` (after monitor persistence) to avoid a crash
upon reading a `Channel` with no corresponding monitor persisted.
This means that we will have no need for an optional (based on signing
order) `TxSignatures` being returned when `provide_holder_witnesses` is
called.

The above is also the reason for removing the
`received_commitment_signed` and signing order checks in the body of
`provide_holder_witnesses`.

These checks will only be important when we actually contribute inputs.
Currently, we don't so we always send `tx_signatures` first in
accordance with the Interactive Transaction Construction specification:

https://github.com/lightning/bolts/blob/aa5207aea/02-peer-protocol.md?plain=1#L404
2025-02-27 11:59:36 +02:00
Duncan Dean
f0f6a35846
Remove unnecessary funding tx clone & remote tx_sigs received check
We actually don't need to check if the counterparty had already sent
their `tx_signatures` in `InteractiveTxSigningSession::received_tx_signatures`.

Further, we can get rid of the clone of `funding_tx_opt` in
`FundedChannel::tx_signatures` when setting the `ChannelContext::funding_transaction`
as we don't actually need to propagate it through to
`ChannelManager::internal_tx_complete` as we can use
`ChannelContext::unbroadcasted_funding()` which clones the
`ChannelContext::funding_transaction` anyway.
2025-02-27 11:59:34 +02:00
Matt Corallo
cd2e1698c8 Only generate a post-close lock ChannelMonitorUpdate if we need one
If a channel is closed on startup, but we find that the
`ChannelMonitor` isn't aware of this, we generate a
`ChannelMonitorUpdate` containing a
`ChannelMonitorUpdateStep::ChannelForceClosed`. This ensures that
the `ChannelMonitor` will not accept any future updates in case we
somehow load up a previous `ChannelManager` (though that really
shouldn't happen).

Previously, we'd apply this update only if we detected that the
`ChannelManager` had not yet informed the `ChannelMonitor` about
the channel's closure, even if the `ChannelMonitor` would already
refuse any other updates because it detected a channel closure
on chain.

This doesn't accomplish anything but an extra I/O write, so we
remove it here.

Further, a user reported that, in regtest, they could:
 (a) coop close a channel (not generating a `ChannelMonitorUpdate`)
 (b) wait just under 4032 blocks (on regtest, taking only a day)
 (c) restart the `ChannelManager`, generating the above update
 (d) connect a block or two (during the startup sequence), making
     the `ChannelMonitor` eligible for archival,
 (d) restart the `ChannelManager` again (without applying the
     update from (c), but after having archived the
     `ChannelMonitor`, leading to a failure to deserialize as we
     have a pending `ChannelMonitorUpdate` for a `ChannelMonitor`
     that has been archived.

Though it seems very unlikely this would happen on mainnet, it is
theoretically possible.
2025-02-26 21:10:49 +00:00
Matt Corallo
489d70a208 Drop return value from provide_latest_holder_commitment_tx
`provide_latest_holder_commitment_tx` is used to handle
`ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo` updates
and returns an `Err` if we've set `holder_tx_signed`.

However, later in `ChannelMonitorImpl::update_monitor` (the only
non-test place that `provide_latest_holder_commitment_tx` is
called), we will fail the entire update if `holder_tx_signed` is
(or a few other flags are) are set if the update contained a
`LatestHolderCommitmentTXInfo` (or a few other update types).

Thus, the check in `provide_latest_holder_commitment_tx` is
entirely redundant and can be removed.
2025-02-26 21:10:49 +00:00
Matt Corallo
1f0e69d771 Cancel claims signed by a remote ChannelMonitor when reorging
In `ChannelMonitorImpl::cancel_prev_commitment_claims` we need to
cancel any claims against a removed commitment transaction. We
were checking if `holder_tx_signed` before checking if either the
current or previous holder commitment transaction had pending
claims against it, but (a) there's no need to do this, there's not
a big performance cost to just always trying to remove claims and
(b) we can't actually rely on `holder_tx_signed`.

`holder_tx_signed` being set doesn't necessarily imply that the
`ChannelMonitor` was persisted (i.e. it may simply be lost in a
poorly-timed restart) but we also (somewhat theoretically) allow
for multiple copies of a `ChannelMonitor` to exist, and a different
one could have signed the commitment transaction which was
confirmed (and then unconfirmed).

Thus, we simply remove the additional check here.
2025-02-26 21:10:04 +00:00
Duncan Dean
eb189134d3
Move txid check to start of tx_signatures handling
By moving the txid check to the start of `tx_signatures` handling, we
can avoid spurious witness count mismatch errors. Also, it just makes
more sense to check the txid earlier.
2025-02-26 17:50:24 +02:00
Duncan Dean
ac060f93f2
Remove dual_funding cfg-flags
Since we now have release branches, and dual-funded channels are expected
in v0.2.0, we can remove the cfg flags. This should also speed up CI a
bit as a bonus.
2025-02-26 17:50:24 +02:00
Duncan Dean
7fc2cf4c3c
Use debug_assert & error on unexpected initial commitment_signed
This replaces the hard panic from this case.
2025-02-26 17:50:24 +02:00
valentinewallace
047bd6175f
Merge pull request #3622 from TheBlueMatt/2025-02-legacy-move-semantics
Avoid accessing `legacy` TLV fields after the TLV-stream read
2025-02-26 10:31:24 -05:00
Matt Corallo
0452241b4b Avoid accessing legacy TLV fields after the TLV-stream read
`legacy` fields in TLV stream reads may be used to read fields
which are later moved into some other field using either
`default_value` or `static_value` "reads". This works fine if the
field supports copy semantics, however if it does not, the
accessing of the field in `_decode_and_build` after the TLV stream
read completes but before the struct is built results in a "use
after move" error.

Instead, here, we drop the attempt to hide unused variable warnings
entirely, dropping the post-TLV-stream access to legacy variables,
allowing their use in move semantics for later fields.
2025-02-25 22:41:16 +00:00
Matt Corallo
1610854561
Merge pull request #3621 from TheBlueMatt/2025-02-3342-rustfmt-cleanups
Clean up rustfmt verbosity introduced in 50644df9c7
2025-02-25 19:39:01 +00:00
Matt Corallo
242759b49f Clean up rustfmt verbosity introduced in 50644df9c7
50644df9c7 added a new parameter to
`pay_for_offer` and `pay_for_offer_from_human_readable_name`, but
updated the tests by writing out the verbose parameter
construction. This resulted in some tests blowing up from rustfmt
nonsense, which we fix here.
2025-02-25 15:20:07 +00:00
Matt Corallo
ece4ab7cb7
Merge pull request #3342 from shaavan/i3262
Introduce RouteParametersConfig
2025-02-25 15:12:49 +00:00
shaavan
78f6ccb5ca Use RouteParametersConfig to create new RouteParameters
- This finally allow overriding the {Route, Payment} parameters with the
  RouteParametersConfig value provided by the user.
2025-02-25 18:42:08 +05:30
shaavan
50644df9c7 Extend bolt12 payers and builder to accept RouteParametersConfig
This update allows users to call `pay_for_offer`,
`pay_for_offer_from_human_readable` and `create_refund_builder` with a
set of parameters they wish to manually set for routing the corresponding
invoice. By accepting `RouteParametersConfig`, users gain greater control
over the routing process.
2025-02-25 18:40:51 +05:30
shaavan
cd7227c3c3 Update AwaitingInvoice & AwaitingOffer to include RouteParametersConfig
When Bolt12 payers & builders are called, they creates a new `PendingOutboundPayment`
entry with relevant values that will be used when the corresponding invoice
is received. This update modifies `AwaitingInvoice` & `AwaitingOffer` to include
the entire `RouteParametersConfig` struct instead of just `max_total_routing_fee_msat`.

This change ensures all manual routing parameters are available when finding
payment routes.

Decisions & Reasoning:

 **Introduction of `route_params_config` in `InvoiceReceived`:**

  This was added for the same reason that `max_total_routing_fee_msat` was originally
  introduced in PR #2417. The documentation has been updated to reflect this, based
  on [this comment](d7e2ff6220 (r1334619765)).
2025-02-25 18:40:51 +05:30
shaavan
4c6074f264 Introduce RouteParametersConfig
With the current architecture, Bolt12 payers & builders only allows setting
`max_total_routing_fee_msat` as a route parameter. However, it doesn't
provide users the flexibility to set other important parameters.

This commit introduces a new struct, `RouteParametersConfig`,
that optionally allows users to set additional routing parameters.
In later commits, this struct will be utilized when paying BOLT12 invoices.
2025-02-25 18:40:51 +05:30