rust-lightning
2 years agoMerge pull request #1095 from TheBlueMatt/2021-09-0.0.101 v0.0.101
Matt Corallo [Thu, 23 Sep 2021 18:43:25 +0000 (18:43 +0000)]
Merge pull request #1095 from TheBlueMatt/2021-09-0.0.101

Bump Crate versions to 0.0.101 (and invoice to 0.9)

2 years agoBump Crate versions to 0.0.101 (and invoice to 0.9) 2021-09-0.0.101
Matt Corallo [Thu, 23 Sep 2021 18:22:29 +0000 (18:22 +0000)]
Bump Crate versions to 0.0.101 (and invoice to 0.9)

2 years agoMerge pull request #1085 from TheBlueMatt/2021-09-0.0.101
Matt Corallo [Thu, 23 Sep 2021 18:12:02 +0000 (18:12 +0000)]
Merge pull request #1085 from TheBlueMatt/2021-09-0.0.101

Cut 0.0.101

2 years agoUpdate CHANGELOG for 0.0.101
Matt Corallo [Mon, 20 Sep 2021 22:07:03 +0000 (22:07 +0000)]
Update CHANGELOG for 0.0.101

2 years agoMerge pull request #1094 from TheBlueMatt/2021-09-type-explicit-bounds
Matt Corallo [Thu, 23 Sep 2021 16:59:36 +0000 (16:59 +0000)]
Merge pull request #1094 from TheBlueMatt/2021-09-type-explicit-bounds

Use Infallible for the unconstructable default custom message type

2 years agoMake method time on trait impl explitit to help bindings generator 2021-09-type-explicit-bounds
Matt Corallo [Thu, 23 Sep 2021 04:02:58 +0000 (04:02 +0000)]
Make method time on trait impl explitit to help bindings generator

Associated types in C bindings is somewhat of a misnomer - we
concretize each trait to a single struct. Thus, different trait
implementations must still have the same type, which defeats the
point of associated types.

In this particular case, however, we can reasonably special-case
the `Infallible` type, as an instance of it existing implies
something has gone horribly wrong.

In order to help our bindings code figure out how to do so when
referencing a parent trait's associated type, we specify the
explicit type in the implementation method signature.

2 years agoDrop redundant generic bounds when the trait requires the bounds
Matt Corallo [Wed, 22 Sep 2021 23:45:27 +0000 (23:45 +0000)]
Drop redundant generic bounds when the trait requires the bounds

2 years agoUse Infallible for the unconstructable default custom message type
Matt Corallo [Wed, 22 Sep 2021 19:00:30 +0000 (19:00 +0000)]
Use Infallible for the unconstructable default custom message type

When we landed custom messages, we used the empty tuple for the
custom message type for `IgnoringMessageHandler`. This was fine,
except that we also implemented `Writeable` to panic when writing
a `()`. Later, we added support for anchor output construction in
CommitmentTransaction, signified by setting a field to `Some(())`,
which is serialized as-is.

This causes us to panic when writing a `CommitmentTransaction`
with `opt_anchors` set. Note that we never set it inside of LDK,
but downstream users may.

Instead, we implement `Writeable` to write nothing for `()` and use
`core::convert::Infallible` for the default custom message type as
it is, appropriately, unconstructable.

This also makes it easier to implement various things in bindings,
as we can always assume `Infallible`-conversion logic is
unreachable.

2 years agoMerge pull request #1093 from TheBlueMatt/2021-09-type-explicit-bounds
Matt Corallo [Wed, 22 Sep 2021 16:49:02 +0000 (16:49 +0000)]
Merge pull request #1093 from TheBlueMatt/2021-09-type-explicit-bounds

Make `ChainMonitor::get_claimable_balances` take a slice of refs

2 years agoMake `ChainMonitor::get_claimable_balances` take a slice of refs
Matt Corallo [Wed, 22 Sep 2021 03:57:53 +0000 (03:57 +0000)]
Make `ChainMonitor::get_claimable_balances` take a slice of refs

For the same reason as `get_route`, a slice of objects isn't
practical to map to bindings - the objects in the bindings space
are structs with a pointer and some additional metadata. Thus, to
create a slice of them, we'd need to take ownership of the objects
behind the pointer, place them into a slace, and then restore them
to the pointer.

This would be a lot of memory copying and marshalling, not to
mention wouldn't be thread-safe, which the same function otherwise
would be if we used a slice of references instead of a slice of
objects.

2 years agoMerge pull request #1092 from TheBlueMatt/2021-09-type-explicit-bounds
Matt Corallo [Wed, 22 Sep 2021 02:46:25 +0000 (02:46 +0000)]
Merge pull request #1092 from TheBlueMatt/2021-09-type-explicit-bounds

Move trait bounds on `wire::Type` from use to the trait itself

2 years agoMove trait bounds on `wire::Type` from use to the trait itself
Matt Corallo [Wed, 22 Sep 2021 01:04:35 +0000 (01:04 +0000)]
Move trait bounds on `wire::Type` from use to the trait itself

`wire::Type` is only (publicly) used as the `CustomMessage`
associated type in `CustomMessageReader`, where it has additional
trait bounds on `Debug` and `Writeable`. The documentation for
`Type` even mentions that you need to implement `Writeable` because
this is the one place it is used.

To make this more clear, we move the type bounds onto the trait
itself and not on the associated type.

This is also the only practical way to build C bindings for `Type`
as we cannot have a concrete, single, `Type` struct in C which only
optionally implements various subtraits, at least not without
runtime checking of the type bounds.

2 years agoMerge pull request #1091 from TheBlueMatt/2021-09-997-winblowz
Matt Corallo [Tue, 21 Sep 2021 22:34:00 +0000 (22:34 +0000)]
Merge pull request #1091 from TheBlueMatt/2021-09-997-winblowz

Fix windows-only test failure added in #997

2 years agoMerge pull request #1084 from valentinewallace/2021-09-rename-paymentfailed
Matt Corallo [Tue, 21 Sep 2021 22:14:42 +0000 (22:14 +0000)]
Merge pull request #1084 from valentinewallace/2021-09-rename-paymentfailed

Rename Event PaymentFailed -> PaymentPathFailed

2 years agoMerge pull request #1061 from sr-gi/add-transaction-convert
Matt Corallo [Tue, 21 Sep 2021 22:04:15 +0000 (22:04 +0000)]
Merge pull request #1061 from sr-gi/add-transaction-convert

Adds Transaction to lighting-block-sync::convert

2 years agoMerge pull request #1088 from TheBlueMatt/2021-09-1063-fixups
Matt Corallo [Tue, 21 Sep 2021 21:59:11 +0000 (21:59 +0000)]
Merge pull request #1088 from TheBlueMatt/2021-09-1063-fixups

Fix a panic in Route's new fee-calculation methods and clean up

2 years agoAdd path field to PaymentPathFailed event
Valentine Wallace [Mon, 20 Sep 2021 16:56:33 +0000 (12:56 -0400)]
Add path field to PaymentPathFailed event

2 years agoRename PaymentFailed -> PaymentPathFailed
Valentine Wallace [Mon, 20 Sep 2021 16:18:49 +0000 (12:18 -0400)]
Rename PaymentFailed -> PaymentPathFailed

Since we don't want to imply to users that a payment has
completely failed when it really has just partially
failed

2 years agoMerge pull request #1087 from TheBlueMatt/2021-09-event-backwards-compat-fix
Matt Corallo [Tue, 21 Sep 2021 21:37:32 +0000 (21:37 +0000)]
Merge pull request #1087 from TheBlueMatt/2021-09-event-backwards-compat-fix

Fix future unknown `Event` variant backwards compatibility

2 years agoFix windows-only test failure added in #997 2021-09-997-winblowz
Matt Corallo [Tue, 21 Sep 2021 20:31:16 +0000 (20:31 +0000)]
Fix windows-only test failure added in #997

This is a trivial bugfix to add a missing test updated required in
PR 997.

2 years agoMerge pull request #1090 from TheBlueMatt/2021-09-absurd-timeouts
Matt Corallo [Tue, 21 Sep 2021 21:12:34 +0000 (21:12 +0000)]
Merge pull request #1090 from TheBlueMatt/2021-09-absurd-timeouts

Bump HTTP read timeout to match reality of Bitcoin Core blocking

2 years agoAdds Transaction to lighting-block-sync::convert
Sergi Delgado Segura [Wed, 25 Aug 2021 14:26:19 +0000 (16:26 +0200)]
Adds Transaction to lighting-block-sync::convert

Includes disclaimer in docs, see https://github.com/rust-bitcoin/rust-lightning/pull/1061#issuecomment-911960862

2 years agoFix future unknown `Event` variant backwards compatibility 2021-09-event-backwards-compat-fix
Matt Corallo [Tue, 21 Sep 2021 17:48:40 +0000 (17:48 +0000)]
Fix future unknown `Event` variant backwards compatibility

In 8ffc2d1742ff1171a87b0410b21cbbd557ff8247, in 0.0.100, we added
a backwards compatibility feature to the reading of `Event`s - if
the type was unknown and odd, we'd simply ignore the event and
treat it as no event. However, we failed to read the
length-prefixed TLV stream when doing so, resulting in us reading
some of the skipped-event data as the next event or other data in
the ChannelManager.

We fix this by reading the varint length prefix written, then
skipping that many bytes when we come across an unknown odd event
type.

2 years agoMerge pull request #997 from ariard/2021-07-add-chan-closed
Matt Corallo [Tue, 21 Sep 2021 20:35:29 +0000 (20:35 +0000)]
Merge pull request #997 from ariard/2021-07-add-chan-closed

Add Event::ChannelClosed generation

2 years agoAdd `pending_events` deadlock detection in `handle_error`
Antoine Riard [Tue, 13 Jul 2021 16:59:39 +0000 (12:59 -0400)]
Add `pending_events` deadlock detection in `handle_error`

2 years agoAdd ChannelClosed generation at cooperative/force-close/error processing
Antoine Riard [Tue, 21 Sep 2021 16:25:38 +0000 (12:25 -0400)]
Add ChannelClosed generation at cooperative/force-close/error processing

When we detect a channel `is_shutdown()` or call on it
`force_shutdown()`, we notify the user with a Event::ChannelClosed
informing about the id and closure reason.

2 years agoExtend MsgHandleErrInternal with a new chan_id field Option<[u8; 32]>
Antoine Riard [Tue, 13 Jul 2021 16:55:32 +0000 (12:55 -0400)]
Extend MsgHandleErrInternal with a new chan_id field Option<[u8; 32]>

This field is used in next commit to generate appropriate
ChannelClosed event at `handle_error()` processing.

2 years agoRename MonitorEvent::CommitmentTxBroadcasted to CommitmentTxConfirmed
Antoine Riard [Tue, 21 Sep 2021 19:24:43 +0000 (15:24 -0400)]
Rename MonitorEvent::CommitmentTxBroadcasted to CommitmentTxConfirmed

2 years agoAdd Event::ChannelClosed generation at channel shutdown
Antoine Riard [Tue, 13 Jul 2021 17:04:54 +0000 (13:04 -0400)]
Add Event::ChannelClosed generation at channel shutdown

2 years agoBump HTTP read timeout to match reality of Bitcoin Core blocking 2021-09-absurd-timeouts
Matt Corallo [Tue, 21 Sep 2021 18:48:33 +0000 (18:48 +0000)]
Bump HTTP read timeout to match reality of Bitcoin Core blocking

2 years agoFix a panic in Route's new fee-calculation methods and clean up 2021-09-1063-fixups
Matt Corallo [Tue, 21 Sep 2021 18:09:15 +0000 (18:09 +0000)]
Fix a panic in Route's new fee-calculation methods and clean up

This addresses Val's feedback on the new Route fee- and
amount-calculation methods, including fixing the panic she
identified and cleaning up various docs and comments.

2 years agoMerge pull request #1082 from vss96/process_events_docs
Matt Corallo [Tue, 21 Sep 2021 18:54:19 +0000 (18:54 +0000)]
Merge pull request #1082 from vss96/process_events_docs

Update docs to specify where PeerManager::process_events is called

2 years agoMerge pull request #1063 from galderz/t_total_fee_999
Matt Corallo [Tue, 21 Sep 2021 18:09:12 +0000 (18:09 +0000)]
Merge pull request #1063 from galderz/t_total_fee_999

Add method to count total fees in a Route #999

2 years agoUpdate docs to specify where process events is called
vss96 [Mon, 20 Sep 2021 19:05:26 +0000 (00:35 +0530)]
Update docs to specify where process events is called

2 years agoAdd methods to count total fees and total amount in a Route #999
Galder Zamarreño [Fri, 27 Aug 2021 18:22:26 +0000 (19:22 +0100)]
Add methods to count total fees and total amount in a Route #999

* Added `get_total_fees` method to route,
to calculate all the fees paid accross each path.
* Added `get_total_amount` method to route,
to calculate the total of actual amounts paid in each path.

2 years agoMerge pull request #1068 from TheBlueMatt/2021-09-ser-cleanup
Matt Corallo [Sat, 18 Sep 2021 01:42:29 +0000 (01:42 +0000)]
Merge pull request #1068 from TheBlueMatt/2021-09-ser-cleanup

Simplify Message Serialization and Parse TLV Suffix

2 years agoConvert most P2P msg serialization to a new macro with TLV suffixes 2021-09-ser-cleanup
Matt Corallo [Sun, 29 Aug 2021 06:03:41 +0000 (06:03 +0000)]
Convert most P2P msg serialization to a new macro with TLV suffixes

The network serialization format for all messages was changed some
time ago to include a TLV suffix for all messages, however we never
bothered to implement it as there isn't a lot of use validating a
TLV stream with nothing to do with it. However, messages are
increasingly utilizing the TLV suffix feature, and there are some
compatibility concerns with messages written as a part of other
structs having their format changed (see previous commit).

Thus, here we go ahead and convert most message serialization to a
new macro which includes a TLV suffix after a series of fields,
simplifying several serialization implementations in the process.

2 years agoAdd forward-compat due serialization variants of HTLCFailureMsg
Matt Corallo [Sun, 29 Aug 2021 02:55:39 +0000 (02:55 +0000)]
Add forward-compat due serialization variants of HTLCFailureMsg

Going forward, all lightning messages have a TLV stream suffix,
allowing new fields to be added as needed. In the P2P protocol,
messages have an explicit length, so there is no implied length in
the TLV stream itself. HTLCFailureMsg enum variants have messages
in them, but without a size prefix or any explicit end. Thus, if a
HTLCFailureMsg is read as a part of a ChannelManager, with a TLV
stream at the end, there is no way to differentiate between the end
of the message and the next field(s) in the ChannelManager.

Here we add two new variant values for HTLCFailureMsg variants in
the read path, allowing us to switch to the new values if/when we
add new TLV fields in UpdateFailHTLC or UpdateFailMalformedHTLC so
that older versions can still read the new TLV fields.

2 years ago[fuzz] Swap mode on most messages to account for TLV suffix
Matt Corallo [Sat, 4 Sep 2021 06:37:36 +0000 (06:37 +0000)]
[fuzz] Swap mode on most messages to account for TLV suffix

2 years agoDrop writer size hinting/message vec preallocation
Matt Corallo [Sun, 29 Aug 2021 05:26:39 +0000 (05:26 +0000)]
Drop writer size hinting/message vec preallocation

In order to avoid significant malloc traffic, messages previously
explicitly stated their serialized length allowing for Vec
preallocation during the message serialization pipeline. This added
some amount of complexity in the serialization code, but did avoid
some realloc() calls.

Instead, here, we drop all the complexity in favor of a fixed 2KiB
buffer for all message serialization. This should not only be
simpler with a similar reduction in realloc() traffic, but also
may reduce heap fragmentation by allocating identically-sized
buffers more often.

2 years agoMerge pull request #1053 from valentinewallace/2021-08-dedup-payment-sent
Matt Corallo [Fri, 17 Sep 2021 20:59:29 +0000 (20:59 +0000)]
Merge pull request #1053 from valentinewallace/2021-08-dedup-payment-sent

Deduplicate PaymentSent events for MPP payments

2 years agoAdd all_paths_failed field to PaymentFailed
Valentine Wallace [Fri, 17 Sep 2021 01:09:46 +0000 (21:09 -0400)]
Add all_paths_failed field to PaymentFailed

see field docs for details

2 years agoPrevent duplicate PaymentSent events
Valentine Wallace [Fri, 20 Aug 2021 00:44:45 +0000 (20:44 -0400)]
Prevent duplicate PaymentSent events

by removing all pending outbound payments associated with the same
MPP payment after the preimage is received

2 years agoAdd MPP ID to pending_outbound_htlcs
Valentine Wallace [Thu, 19 Aug 2021 23:56:53 +0000 (19:56 -0400)]
Add MPP ID to pending_outbound_htlcs

We'll use this to correlate MPP shards in upcoming commits

2 years agoImplement Readable/Writeable for HashSet
Valentine Wallace [Mon, 13 Sep 2021 00:46:11 +0000 (20:46 -0400)]
Implement Readable/Writeable for HashSet

To be used in upcoming commits for MPP ID storage

2 years agoAdd MppId field to HTLCSource as a way to correlate mpp payment paths
Valentine Wallace [Thu, 19 Aug 2021 20:45:55 +0000 (16:45 -0400)]
Add MppId field to HTLCSource as a way to correlate mpp payment paths

2 years agotest utils: refactor fail_payment_along_route for mpp
Valentine Wallace [Wed, 1 Sep 2021 21:30:11 +0000 (17:30 -0400)]
test utils: refactor fail_payment_along_route for mpp

2 years agoMerge pull request #1070 from TheBlueMatt/2021-09-fix-bindings-ignore
Matt Corallo [Fri, 17 Sep 2021 17:26:54 +0000 (17:26 +0000)]
Merge pull request #1070 from TheBlueMatt/2021-09-fix-bindings-ignore

Move CounterpartyForwardingInfo from channel to channelmanager

2 years agoMerge pull request #1066 from valentinewallace/2021-08-fix-double-temp-failure
Matt Corallo [Wed, 15 Sep 2021 20:51:37 +0000 (20:51 +0000)]
Merge pull request #1066 from valentinewallace/2021-08-fix-double-temp-failure

Allow multiple calls to `monitor_update_failed`

2 years agoAllow multiple monitor_update_failed calls
Valentine Wallace [Fri, 3 Sep 2021 21:24:01 +0000 (17:24 -0400)]
Allow multiple monitor_update_failed calls

without requiring calls to channel_monitor_updated in between.

Found by the fuzzer

2 years agoUpdate fuzz README with latest instructions
Valentine Wallace [Thu, 26 Aug 2021 19:03:09 +0000 (15:03 -0400)]
Update fuzz README with latest instructions

2 years agoMerge pull request #1074 from p2pderivatives/add-node-id-to-custom-msg-cb
Matt Corallo [Wed, 15 Sep 2021 18:54:15 +0000 (18:54 +0000)]
Merge pull request #1074 from p2pderivatives/add-node-id-to-custom-msg-cb

Add node id to custom message callback

2 years agoMerge pull request #1034 from TheBlueMatt/2021-07-maturing-claims
Matt Corallo [Wed, 15 Sep 2021 18:44:04 +0000 (18:44 +0000)]
Merge pull request #1034 from TheBlueMatt/2021-07-maturing-claims

Expose in-flight claim balances

2 years agoMerge pull request #1043 from jkczyz/2021-07-network-update-handler
Matt Corallo [Wed, 15 Sep 2021 18:13:20 +0000 (18:13 +0000)]
Merge pull request #1043 from jkczyz/2021-07-network-update-handler

Handle network updates from failed payments in BackgroundProcessor

2 years agoExpand `ANTI_REORG_DELAY` docs to say its a library-wide assumption 2021-07-maturing-claims
Matt Corallo [Sun, 29 Aug 2021 19:01:05 +0000 (19:01 +0000)]
Expand `ANTI_REORG_DELAY` docs to say its a library-wide assumption

2 years agoAdd an accessor to `ChainMonitor` to get the claimable balances
Matt Corallo [Wed, 25 Aug 2021 20:13:01 +0000 (20:13 +0000)]
Add an accessor to `ChainMonitor` to get the claimable balances

The common user desire is to get the set of claimable balances for
all non-closed channels. In order to do so, they really want to
just ask their `ChainMonitor` for the set of balances, which they
can do here by passing the `ChannelManager::list_channels` output
to `ChainMonitor::get_claimable_balances`.

2 years agoExpose the amount of funds available for claim in ChannelMonitor
Matt Corallo [Wed, 4 Aug 2021 16:10:38 +0000 (16:10 +0000)]
Expose the amount of funds available for claim in ChannelMonitor

In general, we should always allow users to query for how much is
currently in-flight being claimed on-chain at any time.

This does so by examining the confirmed claims on-chain and
breaking down what is left to be claimed into a new
`ClaimableBalance` enum.

Fixes #995.

2 years agoFix indentation in ChannelMonitor
Matt Corallo [Wed, 25 Aug 2021 19:36:43 +0000 (19:36 +0000)]
Fix indentation in ChannelMonitor

2 years agoTrack how our HTLCs are resolved on-chain persistently
Matt Corallo [Wed, 4 Aug 2021 15:16:43 +0000 (15:16 +0000)]
Track how our HTLCs are resolved on-chain persistently

This tracks how any HTLC outputs in broadcast commitment
transactions are resolved on-chain, storing the result of the HTLC
resolution persistently in the ChannelMonitor.

This can be used to determine which outputs may still be available
for claiming on-chain.

2 years agoTrack the tx which spends our funding output in ChannelMonitor
Matt Corallo [Wed, 4 Aug 2021 15:14:56 +0000 (15:14 +0000)]
Track the tx which spends our funding output in ChannelMonitor

This allows us to easily look up how our channel was closed and
track which balances may be spendable on-chain.

2 years agoRename CounterpartyCommitmentTransaction to Params as it is static
Matt Corallo [Tue, 27 Jul 2021 19:30:27 +0000 (19:30 +0000)]
Rename CounterpartyCommitmentTransaction to Params as it is static

2 years agoDrop unused CounterpartyCommitmentTransaction::per_htlc HashMap
Matt Corallo [Tue, 27 Jul 2021 19:27:43 +0000 (19:27 +0000)]
Drop unused CounterpartyCommitmentTransaction::per_htlc HashMap

2 years agoStore to-self value in the current commitment tx in ChannelMonitor
Matt Corallo [Tue, 27 Jul 2021 15:52:21 +0000 (15:52 +0000)]
Store to-self value in the current commitment tx in ChannelMonitor

2 years agoUpdate NetworkGraph in BackgroundProcessor
Jeffrey Czyz [Wed, 15 Sep 2021 02:38:00 +0000 (21:38 -0500)]
Update NetworkGraph in BackgroundProcessor

Decorate the user-supplied EventHandler with NetGraphMsgHandler in
the BackgroundProcessor. The resulting handler will intercept
PaymentFailed events in order to update the NetworkGraph in the
background before delegating to the user's event handler.

2 years agoExpand and format BackgroundProcessor docs
Jeffrey Czyz [Thu, 19 Aug 2021 16:21:42 +0000 (11:21 -0500)]
Expand and format BackgroundProcessor docs

2 years agoEventHandler for applying NetworkUpdate
Jeffrey Czyz [Thu, 12 Aug 2021 21:02:42 +0000 (16:02 -0500)]
EventHandler for applying NetworkUpdate

PaymentFailed events contain an optional NetworkUpdate describing
changes to the NetworkGraph as conveyed by a node along a failed payment
path according to BOLT 4. An EventHandler should apply the update to the
graph so that future routing decisions can account for it.

Implement EventHandler for NetGraphMsgHandler to update NetworkGraph.
Previously, NetGraphMsgHandler::handle_htlc_fail_channel_update
implemented this behavior.

2 years agoRefactor PaymentFailureNetworkUpdate event
Jeffrey Czyz [Thu, 12 Aug 2021 20:30:53 +0000 (15:30 -0500)]
Refactor PaymentFailureNetworkUpdate event

MessageSendEvent::PaymentFailureNetworkUpdate served as a hack to pass
an HTLCFailChannelUpdate from ChannelManager to NetGraphMsgHandler via
PeerManager. Instead, remove the event entirely and move the contained
data (renamed NetworkUpdate) to Event::PaymentFailed to be processed by
an event handler.

2 years agoAdd node id to custom message callback
Tibo-lg [Tue, 14 Sep 2021 06:40:10 +0000 (15:40 +0900)]
Add node id to custom message callback

2 years agoMove CounterpartyForwardingInfo from channel to channelmanager 2021-09-fix-bindings-ignore
Matt Corallo [Mon, 6 Sep 2021 03:25:27 +0000 (03:25 +0000)]
Move CounterpartyForwardingInfo from channel to channelmanager

CounterpartyForwardingInfo is public (previously exposed with a
`pub use`), and used inside of ChannelCounterparty in
channelmanager.rs. However, it is defined in channel.rs, away from
where it is used.

This would be fine, except that the bindings generator is somewhat
confused by this - it doesn't currently support interpreting
`pub use` as a struct to expose, instead ignoring it.

Fixes https://github.com/lightningdevkit/ldk-garbagecollected/issues/44

2 years agoMerge pull request #1072 from TheBlueMatt/2021-09-tighter-max_fee-constant
Matt Corallo [Mon, 13 Sep 2021 16:42:36 +0000 (16:42 +0000)]
Merge pull request #1072 from TheBlueMatt/2021-09-tighter-max_fee-constant

Reduce our stated max closing-transaction fee to be the true value

2 years agoMerge pull request #1073 from gilescope/less-deps
Matt Corallo [Mon, 13 Sep 2021 04:22:26 +0000 (04:22 +0000)]
Merge pull request #1073 from gilescope/less-deps

2 years agoNot needed now. We refer to std::futures.
Giles Cope [Sat, 11 Sep 2021 19:11:10 +0000 (20:11 +0100)]
Not needed now. We refer to std::futures.

2 years agoFail with PERM|8 (permanent_channel_failure)
Jeffrey Czyz [Wed, 25 Aug 2021 01:24:23 +0000 (20:24 -0500)]
Fail with PERM|8 (permanent_channel_failure)

This affects the htlc_fail_async_shutdown test.

2 years agoRemove test_invalid_channel_announcement
Jeffrey Czyz [Wed, 25 Aug 2021 00:41:35 +0000 (19:41 -0500)]
Remove test_invalid_channel_announcement

It doesn't seem to be testing anything useful that isn't covered
elsewhere.

2 years agoAdd a read-only view of NetworkGraph
Jeffrey Czyz [Mon, 16 Aug 2021 23:40:19 +0000 (18:40 -0500)]
Add a read-only view of NetworkGraph

Hide the internal locking of NetworkGraph by providing a read-only
view. This way the locking order is handled internally.

2 years agoRemove RwLock from around NetworkGraph
Jeffrey Czyz [Tue, 10 Aug 2021 14:47:27 +0000 (09:47 -0500)]
Remove RwLock from around NetworkGraph

Now that NetworkGraph uses interior mutability, the RwLock used around
it in NetGraphMsgHandler is no longer needed. This allows for shared
ownership without a lock.

2 years agoIndividually lock NetworkGraph fields
Jeffrey Czyz [Tue, 10 Aug 2021 03:24:41 +0000 (22:24 -0500)]
Individually lock NetworkGraph fields

In preparation for giving NetworkGraph shared ownership, wrap individual
fields in RwLock. This allows removing the outer RwLock used in
NetGraphMsgHandler.

2 years agoPass Event by reference to EventHandler
Jeffrey Czyz [Tue, 17 Aug 2021 16:12:18 +0000 (11:12 -0500)]
Pass Event by reference to EventHandler

Passing an Event by reference rather and by move gives more flexibility
for composing event handlers without needing to clone events.

2 years agoReduce our stated max closing-transaction fee to be the true value 2021-09-tighter-max_fee-constant
Matt Corallo [Thu, 9 Sep 2021 01:09:41 +0000 (01:09 +0000)]
Reduce our stated max closing-transaction fee to be the true value

When communicating the maximum fee we're willing to accept on a
cooperative closing transaction to our peer, we currently tell them
we'll accept `u64::max_value()` if they're the ones who have to pay
it. Spec-wise this is fine - they aren't allowed to try to claim
our balance, and we don't care how much of their own funds they
want to spend on transaction fees.

However, the Eclair folks prefer to check all values on the wire
do not exceed 21 million BTC, which seems like generally good
practice to avoid overflows and such issues. Thus, our close
messages are rejected by Eclair.

Here we simply relax our stated maximum to be the real value - our
counterparty's current balance in satoshis.

Fixes #1071

2 years agoMerge pull request #1064 from lightning-signer/2021-08-closing-tx-phase2
Matt Corallo [Thu, 9 Sep 2021 19:31:47 +0000 (19:31 +0000)]
Merge pull request #1064 from lightning-signer/2021-08-closing-tx-phase2

2 years agoUse ClosingTransaction in BaseSign
Devrandom [Wed, 1 Sep 2021 12:56:50 +0000 (14:56 +0200)]
Use ClosingTransaction in BaseSign

2 years agoIntroduce ClosingTransaction
Devrandom [Wed, 1 Sep 2021 12:38:01 +0000 (14:38 +0200)]
Introduce ClosingTransaction

2 years agoMerge pull request #1047 from TheBlueMatt/2021-08-985-followups
Matt Corallo [Thu, 9 Sep 2021 09:23:08 +0000 (09:23 +0000)]
Merge pull request #1047 from TheBlueMatt/2021-08-985-followups

2 years agoAdd further comments around fee update handling in channel 2021-08-985-followups
Matt Corallo [Mon, 16 Aug 2021 18:02:59 +0000 (18:02 +0000)]
Add further comments around fee update handling in channel

These were suggested to clarify behavior in post-merge review of #985.

2 years agoUpdate docs for pending_update_fee and holding_cell_update_fee
Matt Corallo [Mon, 16 Aug 2021 17:47:36 +0000 (17:47 +0000)]
Update docs for pending_update_fee and holding_cell_update_fee

The docs were left stale after the logic was updated in #985 as
pointed out in post-merge review.

2 years agoFactor out low-level build_closing_transaction
Devrandom [Tue, 31 Aug 2021 13:23:48 +0000 (15:23 +0200)]
Factor out low-level build_closing_transaction

2 years agoMerge pull request #1055 from lightning-signer/2021-08-anchor-tx
Matt Corallo [Thu, 2 Sep 2021 21:54:11 +0000 (21:54 +0000)]
Merge pull request #1055 from lightning-signer/2021-08-anchor-tx

2 years agoAdd anchor outputs pair in CommitmentTransaction
Devrandom [Sun, 22 Aug 2021 09:08:28 +0000 (11:08 +0200)]
Add anchor outputs pair in CommitmentTransaction

The anchor ouputs pair is added if there are pending HTLCs. Or a
a per-party anchor is added if the party has a pending balance.

2 years agoMerge pull request #1057 from TheBlueMatt/2021-08-invoice-fails
Matt Corallo [Tue, 31 Aug 2021 22:11:22 +0000 (22:11 +0000)]
Merge pull request #1057 from TheBlueMatt/2021-08-invoice-fails

Fix and modernize lightning-invoice API

2 years agoRequire payment secrets when building and reading invoices 2021-08-invoice-fails
Matt Corallo [Fri, 27 Aug 2021 02:21:32 +0000 (02:21 +0000)]
Require payment secrets when building and reading invoices

2 years agoUse new BOLT 11 test vectors with payment_secrets and feature flags
Matt Corallo [Tue, 24 Aug 2021 23:22:55 +0000 (23:22 +0000)]
Use new BOLT 11 test vectors with payment_secrets and feature flags

This pulls the BOLT 11 test vectors from
https://github.com/lightningnetwork/lightning-rfc/pull/898,
tweaking our tests to properly handle them.

2 years ago[invoice] Ignore InvalidLength fields
Matt Corallo [Tue, 24 Aug 2021 23:15:07 +0000 (23:15 +0000)]
[invoice] Ignore InvalidLength fields

BOLT 11 states that a reader "MUST skip over...`p`, `h`, `s` or `n`
fields that do NOT have data_lengths of 52, 52, 52 or 53,
respectively." Here we do so by simply ignoring any invalid-length
field.

2 years agoImplement core::hash::Hash more incl invoice::RawTaggedField
Matt Corallo [Tue, 24 Aug 2021 21:00:17 +0000 (21:00 +0000)]
Implement core::hash::Hash more incl invoice::RawTaggedField

2 years agoCheck if invoices contain unknown required features
Matt Corallo [Sun, 22 Aug 2021 19:54:08 +0000 (19:54 +0000)]
Check if invoices contain unknown required features

This adds the final missing BOLT 11 failure test, checking for
unknown required feature flags before accepting an invoice.

2 years agoConvert the invoice creation API to millisats and req it for parse
Matt Corallo [Sun, 22 Aug 2021 19:42:29 +0000 (19:42 +0000)]
Convert the invoice creation API to millisats and req it for parse

The BOLT 11 invalid invoice test vectors suggest failing to parse
invoices which have an amount which is not a whole number of
millisatoshis. lightning-invoice, however, happily parses such
invoices. While we could continue to parse them, failing them makes
for one less check on the user code side, so we might as well.

In order to keep the invoice creation less likely to fail, we also
switch the Builder amount-setting function to use millisatoshis.

2 years ago[invoice] Fix non-recoverable sig handling and bogus SI prefix err
Matt Corallo [Sun, 22 Aug 2021 19:36:01 +0000 (19:36 +0000)]
[invoice] Fix non-recoverable sig handling and bogus SI prefix err

This adds two additional tests from the BOLT 11 invalid invoice
tests, fixing the two errors that broke them. It fixes a panic on
the "nonrecoverable signature" test and makes the error variant
more sensible on the bogus SI prefix test.

2 years ago[invoice] Add the BOLT 11 failure unit tests that we already pass
Matt Corallo [Sun, 22 Aug 2021 19:35:15 +0000 (19:35 +0000)]
[invoice] Add the BOLT 11 failure unit tests that we already pass

2 years agoMerge pull request #1040 from abhik-99/Issue#945
Matt Corallo [Tue, 31 Aug 2021 17:50:14 +0000 (17:50 +0000)]
Merge pull request #1040 from abhik-99/Issue#945

Multi-Hop Route Hint now considered. Added in unit tests for same.

2 years agoMulti-Hop Route Hint as per Bolt 12 now considered
abhik-99 [Mon, 9 Aug 2021 15:06:51 +0000 (20:36 +0530)]
Multi-Hop Route Hint as per Bolt 12 now considered

Bolt 12 details the process of picking up route hints from payee
using the lightning invoice. This PR brings the changes to use
multiple route hints from payee picked from the invoice.

The route hints are processed in the following manner:-
 - `get_route()` receives the hints in `last_hops`.
 - Every `RouteHintHop` in `RouteHint` is processed based on
   feasiblity of channel capacity and fees.
 - If a `RouteHintHop` then preceeding `RouteHintHop`s are not
   processed.
 - A direct route is checked from `first_hops_targets` to the
   first `RouteHintHop` if the respective `RouteHint` is
   processed from the payee's end till the first `RouteHintHop`.

`partial_route_hint_test`, `ignores_empty_last_hops_test`,
`multi_hint_last_hops_test` and `last_hops_with_public_channel_test`
test usage of partial route hints for building optimal route,
processing empty route hint hops, complete usage of private route
hints and presence of public channels in route hints respectively.

Resolves: #945

2 years agoMerge pull request #1039 from lightning-signer/2021-08-more-enforcement
Matt Corallo [Mon, 30 Aug 2021 02:43:01 +0000 (02:43 +0000)]
Merge pull request #1039 from lightning-signer/2021-08-more-enforcement

Introduce EnforcementState, validate release of revocation secret