rust-lightning
20 months agoAvoid querying the chain for outputs for channels we already have 2022-08-no-double-access
Matt Corallo [Sun, 21 Aug 2022 20:34:22 +0000 (20:34 +0000)]
Avoid querying the chain for outputs for channels we already have

If we receive a ChannelAnnouncement message but we already have the
channel, there's no reason to do a chain lookup. Instead of
immediately calling the user-provided `chain::Access` when handling
a ChannelAnnouncement, we first check if we have the corresponding
channel in the graph.

Note that if we do have the corresponding channel but it was not
previously checked against the blockchain, we should still check
with the `chain::Access` and update if necessary.

20 months agoMerge pull request #1676 from arik-so/2022-08-gossip-error-message-fix
Matt Corallo [Fri, 19 Aug 2022 19:03:08 +0000 (19:03 +0000)]
Merge pull request #1676 from arik-so/2022-08-gossip-error-message-fix

Fix script order in gossip key mismatch error.

20 months agoMerge pull request #1575 from NicolaLS/hash-invoice
Matt Corallo [Fri, 19 Aug 2022 17:45:11 +0000 (17:45 +0000)]
Merge pull request #1575 from NicolaLS/hash-invoice

20 months agoFix script order in gossip key mismatch error.
Arik Sosman [Fri, 19 Aug 2022 17:07:55 +0000 (10:07 -0700)]
Fix script order in gossip key mismatch error.

20 months agoderive Hash for Invoice
NicolaLS [Mon, 27 Jun 2022 12:41:46 +0000 (14:41 +0200)]
derive Hash for Invoice

20 months agoMerge pull request #1670 from TheBlueMatt/2022-08-mon-size-guidelines
Matt Corallo [Thu, 18 Aug 2022 16:33:20 +0000 (16:33 +0000)]
Merge pull request #1670 from TheBlueMatt/2022-08-mon-size-guidelines

Provide guidance on ChannelMonitorUpdate serialized size

20 months agoMerge pull request #1495 from TheBlueMatt/2022-04-all-claimables
Matt Corallo [Wed, 17 Aug 2022 22:50:49 +0000 (22:50 +0000)]
Merge pull request #1495 from TheBlueMatt/2022-04-all-claimables

Expose counterparty-revoked-outputs in `get_claimable_balance`

20 months agoProvide guidance on ChannelMonitorUpdate serialized size 2022-08-mon-size-guidelines
Matt Corallo [Mon, 15 Aug 2022 19:30:32 +0000 (19:30 +0000)]
Provide guidance on ChannelMonitorUpdate serialized size

Users need to make decisions about storage sizing and we need to
have advice on the maximum size of various things users need to
store. ChannelMonitorUpdates are likely the worst case of this,
they're usually at max a few KB, but can get up to a few hundred
KB for commitment transactions that have 400+ HTLCs pending.

We had one user report an update (likely) going over 400 KiB, which
isn't immediately obvious to me is practical, but its within a few
multiples of trivially-reachable sizes, so its likely that did
occur. To be on the safe side, we simply recommend users ensure
they can support "upwards of 1 MiB" here.

20 months agoMerge pull request #1648 from valentinewallace/2022-08-fuzz-onion-msgs
valentinewallace [Wed, 17 Aug 2022 19:48:29 +0000 (15:48 -0400)]
Merge pull request #1648 from valentinewallace/2022-08-fuzz-onion-msgs

Onion messages: add fuzz testing

20 months agoMerge pull request #1666 from TheBlueMatt/2022-08-fix-script-check
Matt Corallo [Wed, 17 Aug 2022 19:34:26 +0000 (19:34 +0000)]
Merge pull request #1666 from TheBlueMatt/2022-08-fix-script-check

Correct the on-chain script checked in gossip verification

20 months agoCorrect the on-chain script checked in gossip verification 2022-08-fix-script-check
Matt Corallo [Sat, 13 Aug 2022 17:29:06 +0000 (17:29 +0000)]
Correct the on-chain script checked in gossip verification

The `bitcoin_key_1` and `bitcoin_key_2` fields in
`channel_announcement` messages are sorted according to node_ids
rather than the keys themselves, however the on-chain funding
script is sorted according to the bitcoin keys themselves. Thus,
with some probability, we end up checking that the on-chain script
matches the wrong script and rejecting the channel announcement.

The correct solution is to use our existing channel funding script
generation function which ensure we always match what we generate.

This was found in testing the Java bindings, where a test checks
that retunring the generated funding script in `chain::Access`
results in the constructed channel ending up in our network graph.

20 months agoFuzz test onion messages
Valentine Wallace [Sun, 24 Jul 2022 18:47:31 +0000 (14:47 -0400)]
Fuzz test onion messages

Also update the fuzz ChaCha20Poly1305 to not mark as finished after a single
encrypt_in_place.  This is because more bytes may still need to be encrypted,
causing us to panic at the assertion that finished == false when we go to
encrypt more.

Also fix unused_mut warning in messenger + add log on OM forward for testing

20 months agoMerge pull request #1660 from TheBlueMatt/2022-08-cleanup-ratelimits
Matt Corallo [Tue, 16 Aug 2022 04:43:02 +0000 (04:43 +0000)]
Merge pull request #1660 from TheBlueMatt/2022-08-cleanup-ratelimits

Backfill gossip without buffering directly in LDK

20 months agoMove per-HTLC logic out of get_claimable_balances into a helper 2022-04-all-claimables
Matt Corallo [Sat, 16 Jul 2022 20:41:45 +0000 (20:41 +0000)]
Move per-HTLC logic out of get_claimable_balances into a helper

Val suggested this as an obvious cleanup to separate per_HTLC logic
from the total commitment transaction logic, separating the large
function into two.

20 months agoExpose counterparty-revoked-outputs in `get_claimable_balance`
Matt Corallo [Tue, 24 May 2022 23:57:56 +0000 (23:57 +0000)]
Expose counterparty-revoked-outputs in `get_claimable_balance`

This uses the various new tracking added in the prior commits to
expose a new `Balance` type - `CounterpartyRevokedOutputClaimable`.

Some nontrivial work is required, however, as we now have to track
HTLC outputs as spendable in a transaction that comes *after* an
HTLC-Success/HTLC-Timeout transaction, which we previously didn't
need to do. Thus, we have to check if an
`onchain_events_awaiting_threshold_conf` event spends a commitment
transaction's HTLC output while walking events. Further, because
we now need to track HTLC outputs after the
HTLC-Success/HTLC-Timeout confirms, and because we have to track
the counterparty's `to_self` output as a contentious output which
could be claimed by either party, we have to examine the
`OnchainTxHandler`'s set of outputs to spend when determining if
certain outputs are still spendable.

Two new tests are added which test various different transaction
formats, and hopefully provide good test coverage of the various
revoked output paths.

20 months agoDrop uneccessary `if {...; bool}` pattern in PeerManager 2022-08-cleanup-ratelimits
Matt Corallo [Mon, 15 Aug 2022 19:38:45 +0000 (19:38 +0000)]
Drop uneccessary `if {...; bool}` pattern in PeerManager

20 months agoReplace manual iteration with for loops in outbound gossip sync
Matt Corallo [Mon, 15 Aug 2022 18:08:13 +0000 (18:08 +0000)]
Replace manual iteration with for loops in outbound gossip sync

20 months agoSimplify claimable balance trivially with consistent accessors
Matt Corallo [Wed, 13 Jul 2022 01:20:09 +0000 (01:20 +0000)]
Simplify claimable balance trivially with consistent accessors

20 months agoScan `onchain_events_awaiting_threshold_conf` once in balance calc
Matt Corallo [Tue, 17 May 2022 20:45:17 +0000 (20:45 +0000)]
Scan `onchain_events_awaiting_threshold_conf` once in balance calc

Instead of a series of different
`onchain_events_awaiting_threshold_conf.iter()...` calls to scan
for HTLC status in balance calculation, pull them all out into one
`for ... { match ... }` to do it once and simplify the code
somewhat.

20 months agoTrack the txid that resolves HTLCs even after resolution completes
Matt Corallo [Sat, 21 May 2022 01:11:52 +0000 (01:11 +0000)]
Track the txid that resolves HTLCs even after resolution completes

We need this information when we look up if we still need to spend
a revoked output from an HTLC-Success/HTLC-Timeout transaction for
balance calculation.

20 months agoTrack HTLC-Success/HTLC-Timeout claims of revoked outputs
Matt Corallo [Thu, 19 May 2022 01:50:37 +0000 (01:50 +0000)]
Track HTLC-Success/HTLC-Timeout claims of revoked outputs

When a counterparty broadcasts a revoked commitment transaction,
followed immediately by HTLC-Success/-Timeout spends thereof, we'd
like to have an `onchain_events_awaiting_threshold_conf` entry
for them.

This does so using the `HTLCSpendConfirmation` entry, giving it
(slightly) new meaning. Because all existing uses of
`HTLCSpendConfirmation` already check if the relevant commitment
transaction is revoked first, this should be trivially backwards
compatible.

We will ultimately figure out if something is being spent via the
`OnchainTxHandler`, but to do so we need to look up the output via
the HTLC transaction txid, which this allows us to do.

20 months agoFix off-by-one in test_onchain_htlc_claim_reorg_remote_commitment
Matt Corallo [Tue, 17 May 2022 23:57:52 +0000 (23:57 +0000)]
Fix off-by-one in test_onchain_htlc_claim_reorg_remote_commitment

The test intended to disconnect a transaction previously connected
but didn't disconnect enough blocks to do so, leading to it
confirming two conflicting transactions.

In the next few commits this will become an assertion failure.

20 months agoClean up nesting in `get_counterparty_output_claim_info`
Matt Corallo [Thu, 14 Jul 2022 21:23:39 +0000 (21:23 +0000)]
Clean up nesting in `get_counterparty_output_claim_info`

20 months agoTrack counterparty payout info in counterparty commitment txn
Matt Corallo [Sat, 30 Apr 2022 20:29:31 +0000 (20:29 +0000)]
Track counterparty payout info in counterparty commitment txn

When handling a revoked counterparty commitment transaction which
was broadcast on-chain, we occasionally need to look up which
output (and its value) was to the counterparty (the `to_self`
output). This will allow us to generate `Balance`s for the user for
the revoked output.

20 months agoStore the full event transaction in `OnchainEvent` structs
Matt Corallo [Fri, 13 May 2022 05:11:14 +0000 (05:11 +0000)]
Store the full event transaction in `OnchainEvent` structs

When we see a transaction which generates some `OnchainEvent`, its
useful to have the full transaction around for later analysis.
Specifically, it lets us check the list of outputs which were spent
in the transaction, allowing us to look up, e.g. which HTLC
outpoint was spent in a transaction.

This will be used in a few commits to do exactly that - figure out
which HTLC a given `OnchainEvent` corresponds with.

20 months agoMerge pull request #1663 from tnull/2022-08-drop-register-output-return
Matt Corallo [Mon, 15 Aug 2022 23:10:32 +0000 (23:10 +0000)]
Merge pull request #1663 from tnull/2022-08-drop-register-output-return

Drop return value from `Filter::register_output`

20 months agoBackfill gossip without buffering directly in LDK
Matt Corallo [Tue, 9 Aug 2022 21:26:16 +0000 (21:26 +0000)]
Backfill gossip without buffering directly in LDK

Instead of backfilling gossip by buffering (up to) ten messages at
a time, only buffer one message at a time, as the peers' outbound
socket buffer drains. This moves the outbound backfill messages out
of `PeerHandler` and into the operating system buffer, where it
arguably belongs.

Not buffering causes us to walk the gossip B-Trees somewhat more
often, but avoids allocating vecs for the responses. While its
probably (without having benchmarked it) a net performance loss, it
simplifies buffer tracking and leaves us with more room to play
with the buffer sizing constants as we add onion message forwarding
which is an important win.

Note that because we change how often we check if we're out of
messages to send before pinging, we slightly change how many
messages are exchanged at once, impacting the
`test_do_attempt_write_data` constants.

20 months agoClarify 'should' vs 'will' in `get_relevant_txids`
Elias Rohrer [Thu, 11 Aug 2022 12:33:22 +0000 (14:33 +0200)]
Clarify 'should' vs 'will' in `get_relevant_txids`

20 months agoDrop return value from `Filter::register_output`
Elias Rohrer [Thu, 11 Aug 2022 12:27:45 +0000 (14:27 +0200)]
Drop return value from `Filter::register_output`

This commit removes the return value from `Filter::register_output` as
creating a suitable value almost always entails blocking operations
(e.g., lookups via network request), which however conflicts with the
requirement that user calls should avoid blocking calls at all cost.

Removing the return value also rendered quite a bit of test code for
dependent transaction handling superfluous, which is therefore also
removed with this commit.

20 months agoMerge pull request #1659 from valentinewallace/2022-08-fix-payload-decode
valentinewallace [Mon, 15 Aug 2022 18:32:47 +0000 (14:32 -0400)]
Merge pull request #1659 from valentinewallace/2022-08-fix-payload-decode

Fix payment onion payload decode

20 months agoFix fuzzer-found underflow
Valentine Wallace [Fri, 5 Aug 2022 17:15:57 +0000 (13:15 -0400)]
Fix fuzzer-found underflow

20 months agoRename HighZeroBytesDroppedVarInt to HighZeroBytesDroppedBigSize
Valentine Wallace [Sun, 7 Aug 2022 03:06:19 +0000 (23:06 -0400)]
Rename HighZeroBytesDroppedVarInt to HighZeroBytesDroppedBigSize

As observed by @wpaulino, this struct encodes its bytes as big-endian,
therefore it's a BigSize, not a VarInt.

20 months agoFix bug in onion payment payload decode
Valentine Wallace [Sat, 6 Aug 2022 02:19:50 +0000 (22:19 -0400)]
Fix bug in onion payment payload decode

Prior to this change, we could have failed to decode a valid payload of size
>253. This is because we were decoding the length (a BigSize, big-endian) as a
VarInt (little-endian).

Found in #1652.

20 months agoMerge pull request #1658 from lightning-signer/2022-08-bitcoin-0-29
Matt Corallo [Fri, 12 Aug 2022 23:51:06 +0000 (23:51 +0000)]
Merge pull request #1658 from lightning-signer/2022-08-bitcoin-0-29

Update bitcoin crate to 0.29.0

20 months agoModify ecdh to take Scalar
Devrandom [Wed, 10 Aug 2022 16:04:59 +0000 (18:04 +0200)]
Modify ecdh to take Scalar

20 months agoUpdate bitcoin crate to 0.29.0
Devrandom [Tue, 9 Aug 2022 15:39:51 +0000 (17:39 +0200)]
Update bitcoin crate to 0.29.0

20 months agoClarify comment on BUFFER_DRAIN_MSGS_PER_TICK.
Matt Corallo [Tue, 9 Aug 2022 21:45:19 +0000 (21:45 +0000)]
Clarify comment on BUFFER_DRAIN_MSGS_PER_TICK.

20 months agoUse util methods in `Peer` to decide when to forward
Valentine Wallace [Tue, 9 Aug 2022 21:20:56 +0000 (21:20 +0000)]
Use util methods in `Peer` to decide when to forward

This consolidates our various checks on peer buffer space into the
`Peer` impl itself, making the thresholds at which we stop taking
various actions on a peer more readable as a whole.

This commit was primarily authored by `Valentine Wallace
<vwallace@protonmail.com>` with some amendments by `Matt Corallo
<git@bluematt.me>`.

20 months agoMerge pull request #1655 from valentinewallace/2022-08-fix-ci-doc-links-check
valentinewallace [Tue, 9 Aug 2022 16:49:40 +0000 (12:49 -0400)]
Merge pull request #1655 from valentinewallace/2022-08-fix-ci-doc-links-check

Fix CI to error on doc links to private items

20 months agoMerge pull request #1651 from TheBlueMatt/2022-08-export-chan-list
Matt Corallo [Mon, 8 Aug 2022 16:59:53 +0000 (16:59 +0000)]
Merge pull request #1651 from TheBlueMatt/2022-08-export-chan-list

[C Bindings] Expose channel and nodes list in `ReadOnlyNetworkGraph`

20 months agoMerge pull request #1654 from TheBlueMatt/2022-08-update-libfuzzer
valentinewallace [Mon, 8 Aug 2022 15:37:42 +0000 (11:37 -0400)]
Merge pull request #1654 from TheBlueMatt/2022-08-update-libfuzzer

Update libfuzzer-sys to new upstream inclusion method

20 months agoUpdate libfuzzer-sys to new upstream inclusion method 2022-08-update-libfuzzer
Matt Corallo [Sun, 7 Aug 2022 19:02:33 +0000 (19:02 +0000)]
Update libfuzzer-sys to new upstream inclusion method

Dunno why they changed it, but the old "depend directly on git"
thing that cargo-fuzz used forever is now deprecated that that
repo is archived, they've now moved to another repo and publish
properly on crates.io.

20 months agoFix CI to error on doc links to private items
Valentine Wallace [Sun, 7 Aug 2022 17:49:10 +0000 (13:49 -0400)]
Fix CI to error on doc links to private items

Somehow we weren't doing this.

21 months agoMinor msgs::OnionHopData cleanups
Valentine Wallace [Sat, 6 Aug 2022 02:18:27 +0000 (22:18 -0400)]
Minor msgs::OnionHopData cleanups

21 months ago[C Bindings] Expose channel and nodes list in `ReadOnlyNetworkGraph` 2022-08-export-chan-list
Matt Corallo [Fri, 5 Aug 2022 03:20:53 +0000 (03:20 +0000)]
[C Bindings] Expose channel and nodes list in `ReadOnlyNetworkGraph`

21 months agoMerge pull request #1638 from ViktorTigerstrom/2022-07-update-decode-update-add-htlc...
Matt Corallo [Wed, 3 Aug 2022 17:44:46 +0000 (17:44 +0000)]
Merge pull request #1638 from ViktorTigerstrom/2022-07-update-decode-update-add-htlc-onion-return-parameters

Don't return `channel_state` from `decode_update_add_htlc_onion`

21 months agoMerge pull request #1619 from G8XSU/main
Matt Corallo [Wed, 3 Aug 2022 17:37:51 +0000 (17:37 +0000)]
Merge pull request #1619 from G8XSU/main

Add config support for 'their_channel_reserve_proportional_millionths' [#1498]

21 months agoMerge pull request #1503 from valentinewallace/2022-05-onion-msgs
Matt Corallo [Wed, 3 Aug 2022 04:39:56 +0000 (04:39 +0000)]
Merge pull request #1503 from valentinewallace/2022-05-onion-msgs

Onion messages v1

21 months agoFix possible incomplete read bug on onion packet decode
Valentine Wallace [Tue, 12 Jul 2022 20:04:42 +0000 (16:04 -0400)]
Fix possible incomplete read bug on onion packet decode

Pre-existing to this PR, we were reading next packet bytes with io::Read::read,
which is not guaranteed to read all the bytes we need, only guaranteed to read
*some* bytes.

We fix this to be read_exact, which is guaranteed to read all the next hop
packet bytes.

21 months agoError when attempting to send an OM to a blinded route with 0 hops
Valentine Wallace [Thu, 23 Jun 2022 19:51:43 +0000 (15:51 -0400)]
Error when attempting to send an OM to a blinded route with 0 hops

21 months agoAdd SendError enum for onion messages and error on too-big packets
Valentine Wallace [Thu, 23 Jun 2022 19:47:25 +0000 (15:47 -0400)]
Add SendError enum for onion messages and error on too-big packets

21 months agoAdd test utilities and integration tests for onion messages
Valentine Wallace [Sat, 4 Jun 2022 20:22:20 +0000 (13:22 -0700)]
Add test utilities and integration tests for onion messages

21 months agoSignificantly expand onion message documentation
Valentine Wallace [Thu, 23 Jun 2022 19:45:33 +0000 (15:45 -0400)]
Significantly expand onion message documentation

21 months agoImplement receiving and forwarding onion messages
Valentine Wallace [Sat, 28 May 2022 01:39:56 +0000 (18:39 -0700)]
Implement receiving and forwarding onion messages

This required adapting `onion_utils::decode_next_hop` to work for both payments
and onion messages.

Currently we just print out the path_id of any onion messages we receive. In
the future, these received onion messages will be redirected to their
respective handlers: i.e. an invoice_request will go to an InvoiceHandler,
custom onion messages will go to a custom handler, etc.

21 months agoSupport sending onion messages
Valentine Wallace [Sat, 28 May 2022 01:31:27 +0000 (18:31 -0700)]
Support sending onion messages

This adds several utilities in service of then adding
OnionMessenger::send_onion_message, which can send to either an unblinded
pubkey or a blinded route. Sending custom TLVs and sending an onion message
containing a reply path are not yet supported.

We also need to split the construct_keys_callback macro into two macros to
avoid an unused assignment warning.

21 months agoAdd baseline OnionMessenger and msgs::OnionMessage and its serialization
Valentine Wallace [Wed, 22 Jun 2022 21:03:06 +0000 (17:03 -0400)]
Add baseline OnionMessenger and msgs::OnionMessage and its serialization

OnionMessenger will be hooked up to the PeerManager to send and receive OMs in
a follow-up PR.

21 months agoKeysInterface: add new ecdh method
Valentine Wallace [Mon, 11 Jul 2022 20:27:10 +0000 (16:27 -0400)]
KeysInterface: add new ecdh method

This method will help us avoid retrieving our node secret, something we want to
get rid of entirely.  It will be used in upcoming commits when decoding the
onion message packet, and in future PRs to help us get rid of
KeysInterface::get_node_secret usages across the codebase

21 months agoAdd onion_message::Packet and adapt construct_onion_packet_with_init_noise for it
Valentine Wallace [Sat, 28 May 2022 00:47:15 +0000 (17:47 -0700)]
Add onion_message::Packet and adapt construct_onion_packet_with_init_noise for it

We need to add a new Packet struct because onion message packet hop_data fields
can be of variable length, whereas regular payment packets are always 1366
bytes.

Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
21 months agoAdd config support for 'their_channel_reserve_proportional_millionths' [#1498]
Gursharan Singh [Mon, 18 Jul 2022 23:58:10 +0000 (16:58 -0700)]
Add config support for 'their_channel_reserve_proportional_millionths' [#1498]

It is proportion of the channel value to configure as the
`their_channel_reserve_satoshis` for both outbound and inbound channels.
It decides the minimum balance that the other node has to maintain on their
side, at all times.

21 months agoDon't return `channel_state` from `decode_update_add_htlc_onion`
Viktor Tigerström [Sat, 23 Jul 2022 22:10:48 +0000 (00:10 +0200)]
Don't return `channel_state` from `decode_update_add_htlc_onion`

Currently `decode_update_add_htlc_onion` returns the `channel_state`
lock to ensure that `internal_update_add_htlc` holds a single
`channel_state` lock in when the entire function execution. This is
unnecessary, and since we are moving the channel storage to the
`per_peer_state`, this no longer achieves the goal it was intended for.

We therefore avoid returning the `channel_state` from
`decode_update_add_htlc_onion`, and just retake the lock in
`internal_update_add_htlc` instead.

21 months agoMerge pull request #1637 from tnull/2022-07-contrib-remove-slack
Matt Corallo [Tue, 2 Aug 2022 19:19:12 +0000 (19:19 +0000)]
Merge pull request #1637 from tnull/2022-07-contrib-remove-slack

Remove Slack and update `CONTRIBUTING`

21 months agoRemove Slack and update `CONTRIBUTING`
Elias Rohrer [Thu, 28 Jul 2022 07:26:02 +0000 (09:26 +0200)]
Remove Slack and update `CONTRIBUTING`

21 months agoAdd onion messages module + enable the construction of blinded routes
Valentine Wallace [Fri, 27 May 2022 23:25:15 +0000 (16:25 -0700)]
Add onion messages module + enable the construction of blinded routes

Blinded routes can be provided as destinations for onion messages, when the
recipient prefers to remain anonymous.

We also add supporting utilities for constructing blinded path keys, and
control TLVs structs representing blinded payloads prior to being
encoded/encrypted. These utilities and struct will be re-used in upcoming
commits for sending and receiving/forwarding onion messages.

Finally, add utilities for reading the padding from an onion message's
encrypted TLVs without an intermediate Vec.

21 months agoMerge pull request #1628 from tnull/2022-07-readme-remove-slack
Matt Corallo [Wed, 27 Jul 2022 19:10:04 +0000 (19:10 +0000)]
Merge pull request #1628 from tnull/2022-07-readme-remove-slack

Remove Slack link and other updates to `README`

21 months agoMerge pull request #1635 from TheBlueMatt/2022-07-accessor-pub
Matt Corallo [Wed, 27 Jul 2022 18:46:52 +0000 (18:46 +0000)]
Merge pull request #1635 from TheBlueMatt/2022-07-accessor-pub

Expose `ChannelMonitor::get_counterparty_node_id`

21 months agoMerge pull request #1633 from TheBlueMatt/2022-07-110
valentinewallace [Wed, 27 Jul 2022 18:03:44 +0000 (14:03 -0400)]
Merge pull request #1633 from TheBlueMatt/2022-07-110

Set release date on 0.0.110 release

21 months agoMerge pull request #1632 from TheBlueMatt/2022-07-warnings
Matt Corallo [Wed, 27 Jul 2022 16:29:09 +0000 (16:29 +0000)]
Merge pull request #1632 from TheBlueMatt/2022-07-warnings

Fix compilation warnings

21 months agoRemove 'slack' (and other things)
Elias Rohrer [Fri, 22 Jul 2022 16:28:31 +0000 (18:28 +0200)]
Remove 'slack' (and other things)

21 months agoExpose `ChannelMonitor::get_counterparty_node_id` 2022-07-accessor-pub
Matt Corallo [Wed, 27 Jul 2022 03:53:47 +0000 (03:53 +0000)]
Expose `ChannelMonitor::get_counterparty_node_id`

This fixes an oversight in ac842ed9dd7a36a4a26eb6b856d80ab04eecf750
namely that it left users unable to implement their own
`ChainMonitor` from outside of the `rust-lightning` crate.

21 months agoSet release date on 0.0.110 release 2022-07-110
Matt Corallo [Tue, 26 Jul 2022 23:43:58 +0000 (23:43 +0000)]
Set release date on 0.0.110 release

21 months agoMerge pull request #1629 from TheBlueMatt/2022-07-110 v0.0.110
Matt Corallo [Tue, 26 Jul 2022 23:40:45 +0000 (23:40 +0000)]
Merge pull request #1629 from TheBlueMatt/2022-07-110

Cut 0.0.110

21 months agoBump crate versions to 0.0.110/invoice 0.18
Matt Corallo [Mon, 25 Jul 2022 23:50:50 +0000 (23:50 +0000)]
Bump crate versions to 0.0.110/invoice 0.18

21 months agoAdd CHANGELOG entry for 0.0.110
Matt Corallo [Mon, 25 Jul 2022 23:49:24 +0000 (23:49 +0000)]
Add CHANGELOG entry for 0.0.110

21 months agoDrop unused test code in `lightning-invoice::payment` 2022-07-warnings
Matt Corallo [Tue, 26 Jul 2022 20:31:17 +0000 (20:31 +0000)]
Drop unused test code in `lightning-invoice::payment`

21 months agoFix new compilation warnings in `debug_sync` module
Matt Corallo [Tue, 26 Jul 2022 20:29:36 +0000 (20:29 +0000)]
Fix new compilation warnings in `debug_sync` module

21 months agoMerge pull request #1631 from dunxen/2022-07-disabledflags
Matt Corallo [Tue, 26 Jul 2022 15:53:34 +0000 (15:53 +0000)]
Merge pull request #1631 from dunxen/2022-07-disabledflags

Specify why flags for `channel_disabled` error are zero

21 months agoSpecify why flags for `channel_disabled` error are zero
Duncan Dean [Tue, 26 Jul 2022 07:54:09 +0000 (09:54 +0200)]
Specify why flags for `channel_disabled` error are zero

We can remove the TODO for this and specify why the flags are zero
as it's now fully specified in BOLT 4.

See https://github.com/lightning/bolts/blob/341ec84/04-onion-routing.md?plain=1#L1008

21 months agoMerge pull request #1403 from jurvis/jurvis/add-paymentforwardingfailed-event
Jeffrey Czyz [Tue, 26 Jul 2022 00:23:53 +0000 (19:23 -0500)]
Merge pull request #1403 from jurvis/jurvis/add-paymentforwardingfailed-event

Add HTLCHandlingFailed event

21 months agoMerge pull request #1617 from TheBlueMatt/2022-07-base-ppm
Matt Corallo [Mon, 25 Jul 2022 22:02:10 +0000 (22:02 +0000)]
Merge pull request #1617 from TheBlueMatt/2022-07-base-ppm

Add a per-amount base penalty in the ProbabilisticScorer

21 months agoMerge pull request #1626 from TheBlueMatt/2022-07-fix-pm-docs
Matt Corallo [Mon, 25 Jul 2022 21:56:40 +0000 (21:56 +0000)]
Merge pull request #1626 from TheBlueMatt/2022-07-fix-pm-docs

Remove scary disconenct warnings on PeerManager new connection fns

21 months agoMerge pull request #1611 from TheBlueMatt/2022-07-lower-bounded-estimator-nit
Matt Corallo [Mon, 25 Jul 2022 21:11:07 +0000 (21:11 +0000)]
Merge pull request #1611 from TheBlueMatt/2022-07-lower-bounded-estimator-nit

Use a separate (non-trait) fee-estimation fn in LowerBoundedEstimator

21 months agoMerge pull request #1519 from tnull/2022-06-require-htlc-max
Matt Corallo [Mon, 25 Jul 2022 21:04:54 +0000 (21:04 +0000)]
Merge pull request #1519 from tnull/2022-06-require-htlc-max

Make `htlc_maximum_msat` a required field.

21 months agoRename amount penalty to `liquidity_penalty_amount_multiplier_msat` 2022-07-base-ppm
Matt Corallo [Thu, 21 Jul 2022 17:47:19 +0000 (17:47 +0000)]
Rename amount penalty to `liquidity_penalty_amount_multiplier_msat`

This makes our `ProbabilisticScorer` field names more consistent,
as we add more types of penalties, referring to a penalty as only
the "amount penalty" no longer makes sense - we not have several
amount multiplier penalties.

21 months agoAdd a per-amount base penalty in the `ProbabilisticScorer`
Matt Corallo [Thu, 14 Jul 2022 01:06:10 +0000 (01:06 +0000)]
Add a per-amount base penalty in the `ProbabilisticScorer`

There's not much reason to not have a per-hop-per-amount penalty in
the `ProbabilisticScorer` to go along with the per-hop penalty to
let it scale up to larger amounts, so we add one here.

Notably, we use a divisor of 2^30 instead of 2^20 (like the
equivalent liquidity penalty) as it allows for more flexibility,
and there's not really any reason to worry about us not being able
to create high enough penalties.

Closes #1616

21 months agoTest serialization of `ChannelInfo` and `NodeInfo`
Elias Rohrer [Mon, 25 Jul 2022 18:39:06 +0000 (20:39 +0200)]
Test serialization of `ChannelInfo` and `NodeInfo`

21 months agoDon't fail read `NodeInfo` for inv. `NetAddress`
Elias Rohrer [Mon, 25 Jul 2022 18:38:18 +0000 (20:38 +0200)]
Don't fail read `NodeInfo` for inv. `NetAddress`

Fixes a deserialization incompatibility introduced with #1553.

21 months agoMake `htlc_maximum_msat` a required field.
Elias Rohrer [Mon, 25 Jul 2022 18:35:51 +0000 (20:35 +0200)]
Make `htlc_maximum_msat` a required field.

21 months agoChange `LowerBoundedFeeEstimator` fn name to make it hard to swap 2022-07-lower-bounded-estimator-nit
Matt Corallo [Mon, 25 Jul 2022 18:08:44 +0000 (18:08 +0000)]
Change `LowerBoundedFeeEstimator` fn name to make it hard to swap

This change the method name on `LowerBoundedFeeEstimator` to
further differentiate it from the generic `FeeEstimator` trait.

21 months agoAvoid blanket implementing FeeEstimator for Deref<FeeEstimator>
Matt Corallo [Thu, 21 Jul 2022 21:38:00 +0000 (21:38 +0000)]
Avoid blanket implementing FeeEstimator for Deref<FeeEstimator>

This simplifies things for bindings (and, to some extent,
downstream users) by exploiting the fact that we can always "clone"
a reference to a struct by dereferencing and then creating a new
reference.

21 months agoUse a separate (non-trait) fee-estimation fn in LowerBoundedEstimator
Matt Corallo [Wed, 13 Jul 2022 16:52:27 +0000 (16:52 +0000)]
Use a separate (non-trait) fee-estimation fn in LowerBoundedEstimator

This should make it somewhat more difficult to accidentally use a
straight fee estimator when we actually want a
LowerBoundedFeeEstimator by not having the types be exchangeable at
all.

21 months agoSend failure event if we fail to handle a HTLC
jurvis [Mon, 25 Jul 2022 18:28:51 +0000 (11:28 -0700)]
Send failure event if we fail to handle a HTLC

In `ChannelManager::fail_htlc_backwards_internal`, we push a `HTLCHandlingFailed`
containing some information about the HTLC

21 months agoRemove scary disconenct warnings on PeerManager new connection fns 2022-07-fix-pm-docs
Matt Corallo [Fri, 22 Jul 2022 00:32:17 +0000 (00:32 +0000)]
Remove scary disconenct warnings on PeerManager new connection fns

In 4703d4e72565ddfd150b9368ea036f4973fd7590 we changed
PeerManager::socket_disconnected to no longer require that sockets
which the PeerManager decided to disconnect not be disconnected.
However, we forgot to remove the scary warnings on the
`new_{inbound,outbound}_connection` functions which warned of the
old behavior.

We do so here.

21 months agoAdd utils to handle HTLC handling failure reason
jurvis [Tue, 19 Jul 2022 01:32:05 +0000 (20:32 -0500)]
Add utils to handle HTLC handling failure reason

We add `HTLCHandlingFailedConditions` to express the failure parameters,
that will be enforced by a new macro, `expect_pending_htlcs_forwardable_conditions`.

21 months agoAdd HTLCHandlingFailed event
jurvis [Tue, 19 Jul 2022 01:29:40 +0000 (20:29 -0500)]
Add HTLCHandlingFailed event

Adds a HTLCHandlingFailed that expresses failure by our node to process
a specific HTLC. A HTLCDestination enum is defined to express the
possible cases that causes the handling to fail.

21 months agoMerge pull request #1627 from dunxen/2022-07-reusevalidatepowblockhash
Matt Corallo [Fri, 22 Jul 2022 15:36:25 +0000 (15:36 +0000)]
Merge pull request #1627 from dunxen/2022-07-reusevalidatepowblockhash

Reuse `BlockHash` from `validate_pow()`

21 months agoReuse `BlockHash` from `validate_pow()`
Duncan Dean [Fri, 22 Jul 2022 09:34:25 +0000 (11:34 +0200)]
Reuse `BlockHash` from `validate_pow()`

The `validate_pow()` method now returns the BlockHash since rust-bitcoin
v0.26.2 thanks to jkczyz's PR (rust-bitcoin/rust-bitcoin/pull/572).

21 months agoMerge pull request #1420 from TheBlueMatt/2022-04-moar-lockorder
Matt Corallo [Thu, 21 Jul 2022 02:29:16 +0000 (02:29 +0000)]
Merge pull request #1420 from TheBlueMatt/2022-04-moar-lockorder

Expand lockorder testing to look at mutexes, not specific instances

21 months agoSwap `HashSet`s with custom `Hash` in debug_sync for `HashMap`s 2022-04-moar-lockorder
Matt Corallo [Tue, 19 Jul 2022 17:51:45 +0000 (17:51 +0000)]
Swap `HashSet`s with custom `Hash` in debug_sync for `HashMap`s

21 months agoExpand lockorder testing to look at mutexes, not specific instances
Matt Corallo [Tue, 12 Apr 2022 17:32:35 +0000 (17:32 +0000)]
Expand lockorder testing to look at mutexes, not specific instances

Our existing lockorder inversion checks look at specific instances
of mutexes rather than the general mutex itself. This changes that
behavior to look at the instruction pointer at which a mutex was
created and treat all mutexes which were created at the same
location as equivalent.

This allows us to detect lockorder inversions which occur across
tests, though it does substantially reduce parallelism during test
runs.

21 months agoConstruct all ChannelMonitor mutexes in the same function
Matt Corallo [Fri, 15 Jul 2022 16:18:42 +0000 (16:18 +0000)]
Construct all ChannelMonitor mutexes in the same function

When we add lockorder detection based on mutex construction site
rather than mutex instance in the next commit, ChannelMonitor's
PartialEq implementation causes spurious failures. This is caused
by the lockorder detection logic considering the ChannelMonitor
inner mutex to be two distinct mutexes - one when monitors are
deserialized and one when monitors are created fresh. Instead, we
attempt to tell the lockorder detection logic that they are the
same by ensuring they're constructed in the same place - in this
case a util method.