Commit graph

4053 commits

Author SHA1 Message Date
Jeffrey Czyz
e21a500668
Refactor ChainMonitor::update_channel error case
Move the handling of ChannelMonitorUpdateStatus::UnrecoverableError to
the point of error to avoid needing an unwrap later when re-wrapping the
logger.
2023-12-01 11:54:00 -06:00
Jeffrey Czyz
e6d8f350fc
Remove unused handle_error macro rule 2023-12-01 11:54:00 -06:00
henghonglee
df3ab2ee27
Use wrapper to add context to logging
Using a decorator pattern, add peer_id and channel_id to Record
stored on Logger.
2023-12-01 11:53:55 -06:00
henghonglee
a727ccab94
Add WithChannelMonitor 2023-12-01 11:50:34 -06:00
henghonglee
aa502fe948
Add WithChannelContext 2023-12-01 11:30:19 -06:00
henghonglee
973636bd2a
Add WithContext and Tests 2023-12-01 11:30:19 -06:00
Jeffrey Czyz
a42aeb5667
Add semantics to logger::Records
Include optional peer and channel ids to logger::Record. This will be
used by wrappers around Logger in order to provide more context (e.g.,
the peer that sent a message, the channel an operation is pertaining to,
etc.). Implementations of Logger can include this as metadata to aid in
searching logs.
2023-12-01 11:30:19 -06:00
henghonglee
0cba31fd38
Pass Record by value to Logger
Instead of passing a reference to a Record, pass the Logger an owned
Record so that it can be decorated with semantic context.
2023-12-01 11:30:19 -06:00
Valentine Wallace
6af786af6b
Test blinding point serialization in Channel. 2023-11-29 22:46:54 -05:00
Valentine Wallace
4d43ccdf0f
Test intro node failing blinded intercept HTLC. 2023-11-29 22:46:54 -05:00
Valentine Wallace
0a4587020e
Test intro node blinded HTLC failing in process_pending_htlc_fwds. 2023-11-29 22:46:54 -05:00
Valentine Wallace
b767d379c1
Correctly fail back downstream-failed blinded HTLCs as intro 2023-11-29 22:46:54 -05:00
Valentine Wallace
09cf4847bd
Correctly fail back blinded inbound fwd HTLCs when adding to a Channel
As the intro node.
2023-11-29 22:46:54 -05:00
Valentine Wallace
8c0c3a37db
Extract blinded route param creation into test util 2023-11-29 22:46:54 -05:00
Valentine Wallace
67d24633ae
Correctly fail back on outbound channel check for blinded HTLC
Forwarding intro nodes should always fail with 0x8000|0x4000|24.
2023-11-29 22:46:49 -05:00
Valentine Wallace
c8adb54b71
Test blinded forwarding payload encoded as receive error case 2023-11-29 22:43:13 -05:00
Valentine Wallace
918f09c529
Test blinded forward failure to calculate outbound cltv expiry
Intro node failure only.
2023-11-29 22:43:12 -05:00
Valentine Wallace
d2222c8224
Remove now-unused Readable impl for ReceiveTlvs 2023-11-29 22:43:12 -05:00
Valentine Wallace
47d34c3668
Support forwarding blinded HTLCs as intro node.
Error handling will be completed in upcoming commits.
2023-11-29 22:43:11 -05:00
Valentine Wallace
1a7254c178
Parse blinded forward-as-intro onion payloads
Previously, we only parsed blinded receive payloads.
2023-11-29 17:23:29 -05:00
Valentine Wallace
50c850fdd0
Set update_add blinding point on HTLC forward
Used by the next hop to decode their blinded onion payload.
2023-11-29 17:18:40 -05:00
Valentine Wallace
a2b2fb0ceb
Parameterize Channel's htlc forward method by outbound blinding point
Used in the next commit to set the update_add blinding point on HTLC forward.
2023-11-29 17:18:40 -05:00
Valentine Wallace
21ae9fdd69
Set HTLCPreviousHopData::blinded on intro node forward.
Useful so we know to fail back blinded HTLCs where we are the intro node with
the invalid_onion_blinding error per BOLT 4.

We don't set this field for blinded received HTLCs because we don't support
receiving to multi-hop blinded paths yet, and there's no point in setting it
for HTLCs received to 1-hop blinded paths because per the spec they should fail
back using an unblinded error code.
2023-11-29 17:18:39 -05:00
Valentine Wallace
ae15ba8462
Persist whether an HTLC is blinded in HTLCPreviousHopData.
Useful so we know to fail blinded intro node HTLCs back with an
invalid_onion_blinding error per BOLT 4.

Another variant will be added to the new Blinded enum when we support
receiving/forwarding as a non-intro node.
2023-11-29 17:18:39 -05:00
Valentine Wallace
b64523780b
Store whether a forwarded HTLC is blinded in PendingHTLCRouting
We need to store the inbound blinding point in PendingHTLCRouting in order to
calculate the outbound blinding point.

The new BlindedForward struct will be augmented when we add support for
forwarding as a non-intro node.
2023-11-29 17:18:38 -05:00
Valentine Wallace
1596116fa4
Persist outbound blinding points in Channel
A blinding point is provided in update_add_htlc messages if we are relaying or
receiving a payment within a blinded path, to decrypt the onion routing packet
and the recipient-provided encrypted payload within. Will be used in upcoming
commits.
2023-11-29 17:10:43 -05:00
Valentine Wallace
b70525df28
Parse blinded onion errors in tests only.
So we can make sure they're encoded properly.
2023-11-29 17:10:43 -05:00
Valentine Wallace
7f765a39bc
onion_utils: extract decrypting faiure packet into method
Will be used in the next commit to parse onion errors from blinded paths in
tests only.
2023-11-29 17:10:43 -05:00
Valentine Wallace
1e12bdfb3b
Parse blinding point in UpdateAddHTLC
A blinding point is provided in update_add_htlc messages if we are relaying or
receiving a payment within a blinded path, to decrypt the onion routing packet
and the recipient-provided encrypted payload within. Will be used in upcoming
commits.
2023-11-29 17:10:41 -05:00
valentinewallace
f07f4b90f8
Merge pull request #2739 from Evanfeenstra/channelmanager-utils
move static channelmanager functions into their own file
2023-11-29 15:41:26 -05:00
Wilmer Paulino
c2bbfffb1e
Merge pull request #2721 from TheBlueMatt/2023-11-log-forward-peer
Handle missing case in reestablish local commitment number checks
2023-11-29 10:03:56 -08:00
Arik Sosman
c70ea1d987
Remove unused Taproot import. 2023-11-28 16:18:35 -08:00
Arik Sosman
6e5065d93d
Move validate_counterparty_revocation to ChannelSigner. 2023-11-28 16:14:09 -08:00
Arik Sosman
007e6788f5
Remove superfluous commitment_number parameter. 2023-11-28 16:11:15 -08:00
Arik Sosman
5965fb8375
Gate Taproot-related todos behind cfg flag. 2023-11-28 16:08:10 -08:00
Evan Feenstra
9f4dcd0bd5 move static channelmanager functions into their own file 2023-11-28 12:06:01 -08:00
Matt Corallo
2659a2375e
Merge pull request #2512 from arik-so/taproot/2023-08-taproot-signer-variant
Taproot signer variant
2023-11-28 18:10:53 +00:00
Arik Sosman
88ce7d6575
Move ECDSA-specific signers into ecdsa.rs
To separate out the logic in the `sign` module, which will start to be
convoluted with multiple signer types, we're splitting out each signer
type into its own submodule, following the taproot.rs example from a
previous commit.
2023-11-27 16:28:55 -08:00
Arik Sosman
de4dd95d29
Reparametrize ChannelSignerType by SignerProvider.
ChannelSignerType is an enum that contains variants of all currently
supported signer types. Given that those signer types are enumerated
as associated types in multiple places, it is prudent to denote one
type as the authority on signer types.

SignerProvider seemed like the best option. Thus, instead of
ChannelSignerType declaring the associated types itself, it simply
uses their definitions from SignerProvider.
2023-11-27 16:27:21 -08:00
Arik Sosman
c6bcf75848
Add TaprootSigner variant to SignerProvider.
Previously, SignerProvider was not laid out to support multiple signer
types. However, with the distinction between ECDSA and Taproot signers,
we now need to account for SignerProviders needing to support both.

This approach does mean that if ever we introduced another signer type
in the future, all implementers of SignerProvider would need to add it
as an associated type, and would also need to write a set of dummy
implementations for any Signer trait they do not wish to support.

For the time being, the TaprootSigner associated type is cfg-gated.
2023-11-27 16:27:21 -08:00
Arik Sosman
f862aa9f5f
Introduce TaprootSigner trait.
For Taproot support, we need to define an alternative trait to
EcdsaChannelSigner. This trait will be implemented by all signers
that wish to support Taproot channels.
2023-11-27 16:27:21 -08:00
Arik Sosman
27b9794bed
Rename SignerProvider's Signer to EcdsaSigner. 2023-11-27 16:27:20 -08:00
Matt Corallo
ac3fd98ec1 Handle missing case in reestablish local commitment number checks
If we're behind exactly one commitment (which we've revoked), we'd
previously force-close the channel, guaranteeing we'll lose funds
as the counterparty has our latest local commitment state's
revocation secret.

While this shouldn't happen because users should never lose data,
sometimes issues happen, and we should ensure we always panic.

Further, `test_data_loss_protect` is updated to test this case.
2023-11-27 23:59:12 +00:00
Matt Corallo
f24830719a Clean up error messages and conditionals in reestablish handling
When we reestablish there are generally always 4 conditions for
both local and remote commitment transactions:
 * we're stale and have possibly lost data
 * we're ahead and the peer has lost data
 * we're caught up
 * we're nearly caught up and need to retransmit one update.

In especially the local commitment case we had a mess of different
comparisons, which is improved here. Further, the error messages
are clarified and include more information.
2023-11-27 23:59:12 +00:00
Matt Corallo
d5710fd6ae Add channel_keys_id to SpendableOutputDescriptor::StaticOutput
In 7f0fd868ad, `channel_keys_id` was
added as an argument to `SignerProvider::get_destination_script`,
allowing implementors to generate a new script for each channel.

This is great, however users then have no way to re-derive the
corresponding private key when they ultimately receive a
`SpendableOutputDescriptor::StaticOutput`. Instead, they have to
track all the addresses as they derive them separately. In many
cases this is fine, but we should support both deployments, which
we do here by simply including the missing `channel_keys_id` for
the user.
2023-11-27 21:37:42 +00:00
Wilmer Paulino
146a291f15
Merge pull request #2744 from rmalonson/destinationscript
Add channel_keys_id as param in get_destination_script to support gen…
2023-11-27 12:20:19 -08:00
Matt Corallo
74078c4bef
Merge pull request #2675 from yellowred/delayed_payment_key_types
Implement struct wrappers for Payment, DelayedPayment, HTLC and Revocation channel keys
2023-11-27 18:57:37 +00:00
Rachel Malonson
7f0fd868ad Add channel_keys_id as param in get_destination_script
This enables implementers to generate a different destination script for each channel.
2023-11-27 10:42:01 -08:00
olegkubrakov
935a716cc6 Implement struct wrappers for channel key types to avoid confusion.
Currently all channel keys and their basepoints exist uniformly as
`PublicKey` type, which not only makes in harder for a developer to
distinguish those entities, but also does not engage the language
type system to check if the correct key is being used in any
particular function.

Having struct wrappers around keys also enables more nuanced
semantics allowing to express Lightning Protocol rules in language.
For example, the code allows to derive `HtlcKey` from
`HtlcBasepoint` and not from `PaymentBasepoint`.

This change is transparent for channel monitors that will use the
internal public key of a wrapper.

Payment, DelayedPayment, HTLC and Revocation basepoints and their
derived keys are now wrapped into a specific struct that make it
distinguishable for the Rust type system. Functions that require a
specific key or basepoint should not use generic Public Key, but
require a specific key wrapper struct to engage Rust type
verification system and make it more clear for developers which
key is used.
2023-11-27 17:52:12 +00:00
Matt Corallo
fa0d015d1f
Merge pull request #2685 from tnull/2022-12-add-electrum-sync
Add electrum support to `lightning-transaction-sync`
2023-11-27 17:10:00 +00:00