]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
2 years agoSupport building `cfg=c_bindings` with `no-std` 2022-01-bindings-no-std-104
Matt Corallo [Tue, 4 Jan 2022 22:34:15 +0000 (22:34 +0000)]
Support building `cfg=c_bindings` with `no-std`

This will be needed for JavaScript bindings eventually.

2 years agoMerge pull request #1219 from TheBlueMatt/2021-12-0.0.104-bindings 2021-12-0.0.104-bindings
Matt Corallo [Sun, 19 Dec 2021 23:56:34 +0000 (23:56 +0000)]
Merge pull request #1219 from TheBlueMatt/2021-12-0.0.104-bindings

0.0.104 bindings

2 years ago(Bindings Only) Concretize LockableScore as MultiThreadedLockableScore
Matt Corallo [Fri, 17 Dec 2021 22:32:24 +0000 (22:32 +0000)]
(Bindings Only) Concretize LockableScore as MultiThreadedLockableScore

We don't really care about more than this in bindings - calling
into a custom `Score` is likely too slow to be practical anyway,
so this is also a performance improvement.

Works around https://github.com/rust-lang/rust/issues/90448

2 years agoSwap around generic argument ordering in InvoicePayer for bindings 2021-12-minor-bindings-tweaks
Matt Corallo [Sat, 18 Dec 2021 19:52:11 +0000 (19:52 +0000)]
Swap around generic argument ordering in InvoicePayer for bindings

The bindings generation really should support generic bounds other
than Deref::Target in where clauses, but currently does not. To
avoid needing to add support during the current release process,
we simply swap around the arguments to move them to the first <>
instead of the where.

2 years agoAdd a C-not exported tag to `NetGraphMsgHandler.network_graph`
Matt Corallo [Sat, 18 Dec 2021 03:43:34 +0000 (03:43 +0000)]
Add a C-not exported tag to `NetGraphMsgHandler.network_graph`

2 years agoAdd a constructor to MultiThreadedLockableScore
Matt Corallo [Sat, 18 Dec 2021 03:38:15 +0000 (03:38 +0000)]
Add a constructor to MultiThreadedLockableScore

...as otherwise the struct is rather useless.

2 years agoMerge pull request #1217 from TheBlueMatt/2021-12-0.0.104 v0.0.104
Matt Corallo [Fri, 17 Dec 2021 23:30:54 +0000 (23:30 +0000)]
Merge pull request #1217 from TheBlueMatt/2021-12-0.0.104

Cut 0.0.104

2 years agoSwap around generic argument ordering in DefaultRouter for bindings 2021-12-0.0.104
Matt Corallo [Fri, 17 Dec 2021 22:38:46 +0000 (22:38 +0000)]
Swap around generic argument ordering in DefaultRouter for bindings

The bindings generation really should support default generic types
in where clauses, but currently does not. To avoid needing to add
support during the current release process, we simply swap around
the arguments to move them to the first <> instead of the where.

2 years agoBump versions to 0.0.104/invoice 0.12
Matt Corallo [Fri, 17 Dec 2021 21:28:24 +0000 (21:28 +0000)]
Bump versions to 0.0.104/invoice 0.12

2 years agoUpdate CHANGELOG for 0.0.104
Matt Corallo [Fri, 17 Dec 2021 01:49:39 +0000 (01:49 +0000)]
Update CHANGELOG for 0.0.104

2 years agoMerge pull request #1216 from valentinewallace/2021-12-preimage-getter
Matt Corallo [Fri, 17 Dec 2021 17:34:47 +0000 (17:34 +0000)]
Merge pull request #1216 from valentinewallace/2021-12-preimage-getter

Add utility for retrieving an LDK payment preimage

2 years agoRemove trailing whitespace in the FeeEstimator interface
Matt Corallo [Fri, 17 Dec 2021 00:32:28 +0000 (00:32 +0000)]
Remove trailing whitespace in the FeeEstimator interface

2 years agoinbound_payment: Add utility to get payment preimage given hash/secret
Valentine Wallace [Mon, 13 Dec 2021 23:40:16 +0000 (18:40 -0500)]
inbound_payment: Add utility to get payment preimage given hash/secret

User-requested feature

2 years agoinbound_payment: DRY verify method for use in getting preimage
Valentine Wallace [Mon, 13 Dec 2021 22:36:09 +0000 (17:36 -0500)]
inbound_payment: DRY verify method for use in getting preimage

in the next commit(s)

2 years agocreate_inbound_payment: warn about dup hashes
Valentine Wallace [Fri, 17 Dec 2021 00:27:13 +0000 (16:27 -0800)]
create_inbound_payment: warn about dup hashes

Leftover feedback from #1177

2 years agoSalt inbound payment ExpandedKey
Valentine Wallace [Fri, 17 Dec 2021 00:24:24 +0000 (16:24 -0800)]
Salt inbound payment ExpandedKey

Leftover feedback from #1177

2 years agoMerge pull request #1177 from valentinewallace/2021-11-derivable-payment-secret
Matt Corallo [Fri, 17 Dec 2021 00:15:24 +0000 (00:15 +0000)]
Merge pull request #1177 from valentinewallace/2021-11-derivable-payment-secret

Stop storing pending inbound payment data; instead make it derivable on receive

2 years agoAdd new invoice CreationError::InvalidAmount for use in checking `create_inbound_payment`
Valentine Wallace [Thu, 9 Dec 2021 22:41:33 +0000 (17:41 -0500)]
Add new invoice CreationError::InvalidAmount for use in checking `create_inbound_payment`

in an invoice creation utility. Note that if the error type of `create_inbound_payment` ever
changed, we'd be forced to update the invoice utility's callsite to handle the new error

2 years agoDrop need to store pending inbound payments
Valentine Wallace [Tue, 30 Nov 2021 00:59:18 +0000 (19:59 -0500)]
Drop need to store pending inbound payments

and replace payment_secret with encrypted metadata

See docs on `inbound_payment::verify` for details

Also add min_value checks to all create_inbound_payment* methods

2 years agoAdd get_single_block to chacha20 module
Valentine Wallace [Tue, 30 Nov 2021 00:36:59 +0000 (19:36 -0500)]
Add get_single_block to chacha20 module

In the next commit, we'll want to get a single block from a chacha stream that
takes a 16-byte nonce.

2 years agoMacro-ize checking that the total value of an MPP's parts is sane
Valentine Wallace [Mon, 22 Nov 2021 21:53:18 +0000 (16:53 -0500)]
Macro-ize checking that the total value of an MPP's parts is sane

This DRY-ed code will be used in upcoming commits when we stop storing inbound
payment data

2 years agoAdd get_inbound_payment_key_material to KeysInterface
Valentine Wallace [Mon, 29 Nov 2021 17:50:47 +0000 (12:50 -0500)]
Add get_inbound_payment_key_material to KeysInterface

This will allow us to retrieve key material for encrypting/decrypting inbound
payment info, in upcoming commits

2 years agoMerge pull request #1212 from TheBlueMatt/2021-12-timeout-graph
Matt Corallo [Thu, 16 Dec 2021 23:04:00 +0000 (23:04 +0000)]
Merge pull request #1212 from TheBlueMatt/2021-12-timeout-graph

Add a method to prune stale channels from NetworkGraph

2 years agoAutomatically prune NetworkGraph of stale channels hourly in BP 2021-12-timeout-graph
Matt Corallo [Wed, 15 Dec 2021 18:59:15 +0000 (18:59 +0000)]
Automatically prune NetworkGraph of stale channels hourly in BP

2 years agoReject channel_update messages with timestamps too old or new
Matt Corallo [Tue, 14 Dec 2021 01:33:37 +0000 (01:33 +0000)]
Reject channel_update messages with timestamps too old or new

Because we time out channel info that is older than two weeks now,
we should also reject new channel info that is older than two
weeks, in addition to rejecting future channel info.

2 years agoAdd a method to prune stale channels from `NetworkGraph`
Matt Corallo [Fri, 10 Dec 2021 06:46:29 +0000 (06:46 +0000)]
Add a method to prune stale channels from `NetworkGraph`

We define "stale" as "haven't heard an updated channel_update in
two weeks", as described in BOLT 7.

We also filter out stale channels at write-time for `std` users, as
we can look up the current time.

2 years agoDrop `allow_wallclock_use` feature in favor of simply using `std`
Matt Corallo [Fri, 10 Dec 2021 05:57:30 +0000 (05:57 +0000)]
Drop `allow_wallclock_use` feature in favor of simply using `std`

Fixes #1147.

2 years agoDRY up network_graph tests substantially with message creation fns
Matt Corallo [Wed, 15 Dec 2021 22:38:13 +0000 (22:38 +0000)]
DRY up network_graph tests substantially with message creation fns

2 years agoMerge pull request #1214 from TheBlueMatt/2021-12-fix-tokio-msrv-bump
Matt Corallo [Thu, 16 Dec 2021 17:44:21 +0000 (17:44 +0000)]
Merge pull request #1214 from TheBlueMatt/2021-12-fix-tokio-msrv-bump

2 years agoBuild no-std on 1.47 now that core2 supports it 2021-12-fix-tokio-msrv-bump
Matt Corallo [Thu, 16 Dec 2021 02:21:48 +0000 (02:21 +0000)]
Build no-std on 1.47 now that core2 supports it

2 years agoPin tokio to 1.14.0 in CI for older rustc's
Matt Corallo [Thu, 16 Dec 2021 02:10:09 +0000 (02:10 +0000)]
Pin tokio to 1.14.0 in CI for older rustc's

2 years agoMerge pull request #1148 from dunxen/2021-11-new-onion-errors
Matt Corallo [Wed, 15 Dec 2021 23:32:30 +0000 (23:32 +0000)]
Merge pull request #1148 from dunxen/2021-11-new-onion-errors

Add mpp_timeout and invalid_onion_payload descriptions

2 years agoMerge pull request #1211 from ConorOkus/2021-11-add-max-conversion
Conor Okus [Wed, 15 Dec 2021 16:15:21 +0000 (16:15 +0000)]
Merge pull request #1211 from ConorOkus/2021-11-add-max-conversion

Update docs to add max return value to conversion list

2 years agoMerge pull request #1202 from TheBlueMatt/2021-12-fix-retries-races
Matt Corallo [Wed, 15 Dec 2021 04:58:46 +0000 (04:58 +0000)]
Merge pull request #1202 from TheBlueMatt/2021-12-fix-retries-races

Fix payment retry races and inform users when a payment fails

2 years agoMake attempting to retry a succeeded payment an APIError, not Route 2021-12-fix-retries-races
Matt Corallo [Mon, 13 Dec 2021 17:41:36 +0000 (17:41 +0000)]
Make attempting to retry a succeeded payment an APIError, not Route

This is symmetric with the new failure once a payment is abandoned.

2 years agoUse `Event::PaymentFailed` in `InvoicePayer` to remove retry count
Matt Corallo [Sat, 4 Dec 2021 23:41:37 +0000 (23:41 +0000)]
Use `Event::PaymentFailed` in `InvoicePayer` to remove retry count

This finally fixes the bug described in the previous commits where
we retry a payment after its retry count has expired due to early
removal of the payment from the retry count tracking map. A test is
also added which demonstrates the bug in previous versions and
which passes now.

Fixes #1164.

2 years agoExpose an event when a payment has failed and retries complete
Matt Corallo [Fri, 10 Dec 2021 00:28:24 +0000 (00:28 +0000)]
Expose an event when a payment has failed and retries complete

When a payment fails, a payer needs to know when they can consider
a payment as fully-failed, and when only some of the HTLCs in the
payment have failed. This isn't possible with the current event
scheme, as discovered recently and as described in the previous
commit.

This adds a new event which describes when a payment is fully and
irrevocably failed, generating it only after the payment has
expired or been marked as expired with
`ChannelManager::mark_retries_exceeded` *and* all HTLCs for it
have failed. With this, a payer can more simply deduce when a
payment has failed and use that to remove payment state or
finalize a payment failure.

2 years agoAdd a variant to `PendingOutboundPayment` for retries-exceeded
Matt Corallo [Fri, 3 Dec 2021 19:57:37 +0000 (19:57 +0000)]
Add a variant to `PendingOutboundPayment` for retries-exceeded

When a payer gives up trying to retry a payment, they don't know
for sure what the current state of the event queue is.
Specifically, they cannot be sure that there are not multiple
additional `PaymentPathFailed` or even `PaymentSuccess` events
pending which they will see later. Thus, they have a very hard
time identifying whether a payment has truly failed (and informing
the UI of that fact) or if it is still pending. See [1] for more
information.

In order to avoid this mess, we will resolve it here by having the
payer give `ChannelManager` a bit more information - when they
have given up on a payment - and using that to generate a
`PaymentFailed` event when all paths have failed.

This commit adds the neccessary storage and changes for the new
state inside `ChannelManager` and a public method to mark a payment
as failed, the next few commits will add the new `Event` and use
the new features in our `PaymentRetrier`.

[1] https://github.com/lightningdevkit/rust-lightning/issues/1164

2 years agoDRY up payment failure macros in functional_test_utils
Matt Corallo [Sat, 4 Dec 2021 23:41:01 +0000 (23:41 +0000)]
DRY up payment failure macros in functional_test_utils

... with a more extensible expectation-checking framework for them.

2 years agoAdd mpp_timeout and invalid_onion_payload descriptions & handling
Duncan Dean [Sat, 30 Oct 2021 08:25:44 +0000 (10:25 +0200)]
Add mpp_timeout and invalid_onion_payload descriptions & handling

2 years agoUpdates Fee estimator docs to include a max return value for get_est_sat_per_1000_weight
Conor Okus [Wed, 8 Dec 2021 17:15:57 +0000 (17:15 +0000)]
Updates Fee estimator docs to include a max return value for get_est_sat_per_1000_weight

Updates docs to include a max return value for get_est_sat_per_1000_weight

Adds max to both conversions

Additional detail

2 years agoMerge pull request #1169 from TheBlueMatt/2021-11-fix-update-announcements
Matt Corallo [Thu, 9 Dec 2021 18:21:55 +0000 (18:21 +0000)]
Merge pull request #1169 from TheBlueMatt/2021-11-fix-update-announcements

Fix announcements of our own gossip

2 years agoAdd a comment describing the timestamp field's use 2021-11-fix-update-announcements
Matt Corallo [Thu, 9 Dec 2021 03:49:50 +0000 (03:49 +0000)]
Add a comment describing the timestamp field's use

2 years agoMerge pull request #1203 from lightning-signer/2021-12-value-to-self
Matt Corallo [Wed, 8 Dec 2021 02:24:32 +0000 (02:24 +0000)]
Merge pull request #1203 from lightning-signer/2021-12-value-to-self

Getter for the total channel balance

2 years agoMerge pull request #1210 from TheBlueMatt/2021-12-new-codecod-upload
Matt Corallo [Wed, 8 Dec 2021 01:01:34 +0000 (01:01 +0000)]
Merge pull request #1210 from TheBlueMatt/2021-12-new-codecod-upload

Upgrade to codecov uploader v2

2 years agoUpgrade to codecov uploader v2 2021-12-new-codecod-upload
Matt Corallo [Tue, 7 Dec 2021 19:17:57 +0000 (19:17 +0000)]
Upgrade to codecov uploader v2

Some time ago codecov stopped supporting their old v1 uploader, and
it seems they've now finally turned it off, so we aren't getting
any coverage reports anymore. Hopefully upgrading is pretty trivial.

2 years agoMerge pull request #1208 from TheBlueMatt/2021-12-less-force-close
Matt Corallo [Tue, 7 Dec 2021 20:11:47 +0000 (20:11 +0000)]
Merge pull request #1208 from TheBlueMatt/2021-12-less-force-close

Reduce force-closures with user fee estimators which round poorly

2 years agoMerge pull request #1205 from TheBlueMatt/2021-12-new-feature-bit
Matt Corallo [Tue, 7 Dec 2021 19:28:29 +0000 (19:28 +0000)]
Merge pull request #1205 from TheBlueMatt/2021-12-new-feature-bit

Support the channel_type feature bit.

2 years agoReduce force-closures with user fee estimators which round poorly 2021-12-less-force-close
Matt Corallo [Tue, 7 Dec 2021 17:23:42 +0000 (17:23 +0000)]
Reduce force-closures with user fee estimators which round poorly

See comment for more

2 years agoSupport the `channel_type` feature bit. 2021-12-new-feature-bit
Matt Corallo [Mon, 6 Dec 2021 00:18:59 +0000 (00:18 +0000)]
Support the `channel_type` feature bit.

Note that this feature bit does absolutely nothing. We signal it
(as we already support channel type negotiation), but do not bother
to look to see if peers support it, as we don't care - we simply
look for the TLV entry and deduce if a peer supports channel type
negotiation from that.

The only behavioral change at all here is that we don't barf if a
peer sets channel type negotiation to required via the feature bit
(instead of failing the channel at open-time), but of course no
implementations do this, and likely won't for some time (if ever -
you can simply fail channels with unknown types later, and there's
no reason to refuse connections, really).

As defined in https://github.com/lightning/bolts/pull/906

2 years agoGetter for the total channel balance
Devrandom [Sun, 5 Dec 2021 11:42:25 +0000 (12:42 +0100)]
Getter for the total channel balance

The existing balance getters subtract reserve, this one does not.

2 years agoMerge pull request #1201 from jkczyz/2021-12-idempotent-channelmanager
Matt Corallo [Tue, 7 Dec 2021 00:42:02 +0000 (00:42 +0000)]
Merge pull request #1201 from jkczyz/2021-12-idempotent-channelmanager

Ensure ChannelManager methods are idempotent

2 years agoEnsure ChannelManager methods are idempotent
Jeffrey Czyz [Fri, 3 Dec 2021 19:04:58 +0000 (13:04 -0600)]
Ensure ChannelManager methods are idempotent

During event handling, ChannelManager methods may need to be called as
indicated in the Event documentation. Ensure that these calls are
idempotent for the same event rather than panicking. This allows users
to persist events for later handling without needing to worry about
processing the same event twice (e.g., if ChannelManager is not
persisted but the events were, the restarted ChannelManager would return
some of the same events).

2 years agoMerge pull request #1204 from TheBlueMatt/2021-12-no-torv2
Matt Corallo [Mon, 6 Dec 2021 22:49:18 +0000 (22:49 +0000)]
Merge pull request #1204 from TheBlueMatt/2021-12-no-torv2

Remove OnionV2 parsing support

2 years agoMerge pull request #1130 from TheBlueMatt/2021-10-mon-fail-after-conf
Matt Corallo [Mon, 6 Dec 2021 19:35:58 +0000 (19:35 +0000)]
Merge pull request #1130 from TheBlueMatt/2021-10-mon-fail-after-conf

Always return failure in update_monitor after funding spend

2 years agoAdd trivial test of monitor update failure during block connection 2021-10-mon-fail-after-conf
Matt Corallo [Sun, 28 Nov 2021 17:13:38 +0000 (17:13 +0000)]
Add trivial test of monitor update failure during block connection

2 years agoAdd a test for MonitorEvent holding when they complete out-of-order
Matt Corallo [Tue, 19 Oct 2021 23:44:29 +0000 (23:44 +0000)]
Add a test for MonitorEvent holding when they complete out-of-order

2 years agoAdd a simple test for ChainMonitor MonitorUpdate-holding behavior
Matt Corallo [Sun, 17 Oct 2021 21:24:39 +0000 (21:24 +0000)]
Add a simple test for ChainMonitor MonitorUpdate-holding behavior

2 years agoMake APIError debug output more clear by including the variant
Matt Corallo [Sun, 17 Oct 2021 21:24:53 +0000 (21:24 +0000)]
Make APIError debug output more clear by including the variant

2 years agoDrop `MonitorUpdateErr` in favor of opaque errors.
Matt Corallo [Mon, 29 Nov 2021 21:36:12 +0000 (21:36 +0000)]
Drop `MonitorUpdateErr` in favor of opaque errors.

We don't expect users to ever change behavior based on the string
contained in a `MonitorUpdateErr`, except log it, so there's little
reason to not just log it ourselves and return a `()` for errors.

We do so here, simplifying the callsite in `ChainMonitor` as well.

2 years agoAlways return failure in `update_monitor` after funding spend
Matt Corallo [Sun, 17 Oct 2021 21:28:50 +0000 (21:28 +0000)]
Always return failure in `update_monitor` after funding spend

Previously, monitor updates were allowed freely even after a
funding-spend transaction confirmed. This would allow a race
condition where we could receive a payment (including the
counterparty revoking their broadcasted state!) and accept it
without recourse as long as the ChannelMonitor receives the block
first, the full commitment update dance occurs after the block is
connected, and before the ChannelManager receives the block.

Obviously this is an incredibly contrived race given the
counterparty would be risking their full channel balance for it,
but its worth fixing nonetheless as it makes the potential
ChannelMonitor states simpler to reason about.

The test in this commit also tests the behavior changed in the
previous commit.

2 years agoDefine public getters for all feature flags
Matt Corallo [Fri, 23 Jul 2021 15:49:24 +0000 (15:49 +0000)]
Define public getters for all feature flags

There's not a ton of reason not to do this, and moving it to the
macro removes some code.

2 years agoRemove OnionV2 parsing support 2021-12-no-torv2
Matt Corallo [Mon, 6 Dec 2021 00:12:35 +0000 (00:12 +0000)]
Remove OnionV2 parsing support

OnionV2s don't (really) work on Tor anymore anyway, and the field
is set for removal in the BOLTs [1]. Sadly because of the way
addresses are parsed we have to continue to understand that type 3
addresses are 12 bytes long. Thus, for simplicity we keep the
`OnionV2` enum variant around and just make it an opaque 12 bytes,
with the documentation updated to note the deprecation.

[1] https://github.com/lightning/bolts/pull/940

3 years agoMerge pull request #1197 from jkczyz/2021-11-score-successful-payment-path
Matt Corallo [Fri, 3 Dec 2021 21:04:41 +0000 (21:04 +0000)]
Merge pull request #1197 from jkczyz/2021-11-score-successful-payment-path

Score successful payment paths

3 years agoFix shift overflow in Scorer::channel_penalty_msat
Jeffrey Czyz [Wed, 1 Dec 2021 04:57:32 +0000 (22:57 -0600)]
Fix shift overflow in Scorer::channel_penalty_msat

An unchecked shift of more than 64 bits on u64 values causes a shift
overflow panic. This may happen if a channel is penalized only once and
(1) is not successfully routed through and (2) after 64 or more half
life decays. Use a checked shift to prevent this from happening.

3 years agoDecay channel failure penalty upon success
Jeffrey Czyz [Wed, 1 Dec 2021 00:27:08 +0000 (18:27 -0600)]
Decay channel failure penalty upon success

If a payment failed to route through a channel, a penalty is applied to
the channel in the future when finding a route. This penalty decays over
time. Immediately decay the penalty by one half life when a payment is
successfully routed through the channel.

3 years agoScore successful payment paths
Jeffrey Czyz [Tue, 30 Nov 2021 23:16:05 +0000 (17:16 -0600)]
Score successful payment paths

Expand the Score trait with a payment_path_successful function for
scoring successful payment paths. Called by InvoicePayer's EventHandler
implementation when processing PaymentPathSuccessful events. May be used
by Score implementations to revert any channel penalties that were
applied by calls to payment_path_failed.

3 years agoMerge pull request #1196 from TheBlueMatt/2021-11-bad-rustdoc
Matt Corallo [Wed, 1 Dec 2021 20:14:14 +0000 (20:14 +0000)]
Merge pull request #1196 from TheBlueMatt/2021-11-bad-rustdoc

Fix compilation in `payment` rustdoc examples

3 years agoFix compilation in `payment` rustdoc examples 2021-11-bad-rustdoc
Matt Corallo [Tue, 30 Nov 2021 21:01:39 +0000 (21:01 +0000)]
Fix compilation in `payment` rustdoc examples

The samples were not valid rust, but previous versions of rustc had
a bug where they were accepted anyway. Latest rustc beta no longer
accepts these.

3 years agoMerge pull request #1195 from TheBlueMatt/2021-11-chanman-read-regression
Matt Corallo [Tue, 30 Nov 2021 15:35:27 +0000 (15:35 +0000)]
Merge pull request #1195 from TheBlueMatt/2021-11-chanman-read-regression

Fix regression when reading `Event::PaymentReceived` in some cases

3 years agoFix regression when reading `Event::PaymentReceived` in some cases 2021-11-chanman-read-regression
Matt Corallo [Mon, 29 Nov 2021 20:05:35 +0000 (20:05 +0000)]
Fix regression when reading `Event::PaymentReceived` in some cases

For some reason rustc was deciding on a type for the `Option` being
deserialized for us as `_user_payment_id`. This really, really,
absolutely should have been a compile failure - the type (with
methods called on it!) was ambiguous! Instead, rustc seems to have
been defaulting to `Option<()>`, causing us to read zero of the
eight bytes in the `user_payment_id` field, which returns an
`Err(InvalidValue)` error as TLVs must always be read fully.

This should likely be reported to rustc as its definitely a bug,
but I cannot seem to cause the same error on any kinda of
vaguely-minimized version of the same code.

Found by `chanmon_consistency` fuzz target.

3 years agoMerge pull request #1163 from TheBlueMatt/2021-11-support-insecure-counterparty
Matt Corallo [Mon, 29 Nov 2021 21:02:36 +0000 (21:02 +0000)]
Merge pull request #1163 from TheBlueMatt/2021-11-support-insecure-counterparty

Explicitly support counterparty setting 0 channel reserve

3 years agoExplicitly support counterparty setting 0 channel reserve 2021-11-support-insecure-counterparty
Matt Corallo [Tue, 9 Nov 2021 21:25:33 +0000 (21:25 +0000)]
Explicitly support counterparty setting 0 channel reserve

A peer providing a channel_reserve_satoshis of 0 (or less than our
dust limit) is insecure, but only for them. Because some LSPs do it
with some level of trust of the clients (for a substantial UX
improvement), we explicitly allow it. Because its unlikely to
happen often in normal testing, we test it explicitly here.

3 years agoMerge pull request #1189 from TheBlueMatt/2021-11-trivial-impls
Matt Corallo [Mon, 29 Nov 2021 16:56:23 +0000 (16:56 +0000)]
Merge pull request #1189 from TheBlueMatt/2021-11-trivial-impls

Derive `Clone` and friends on additional public structs

3 years agoImplement Clone for InvalidShutdownScript 2021-11-trivial-impls
Matt Corallo [Tue, 19 Oct 2021 06:20:12 +0000 (06:20 +0000)]
Implement Clone for InvalidShutdownScript

Users hopefully shouldn't have much of a reason to use this, but
the bindings may need it to ensure no leaking pointers over an ffi.

3 years agoImplement Clone, Hash, PartialEq for ClosingTransaction
Matt Corallo [Tue, 19 Oct 2021 06:19:28 +0000 (06:19 +0000)]
Implement Clone, Hash, PartialEq for ClosingTransaction

This is a public struct intended to be used as an object by users,
so it should likely have common implementations, given they're
trivial.

3 years agoContinue after a single failure in `ChannelMonitor::update_monitor`
Matt Corallo [Sun, 17 Oct 2021 21:26:04 +0000 (21:26 +0000)]
Continue after a single failure in `ChannelMonitor::update_monitor`

`ChannelMonitorUpdate`s may contain multiple updates, including, eg
a payment preimage after a commitment transaction update. While
such updates are generally not generated today, we shouldn't return
early out of the update loop, causing us to miss any updates after
an earlier update fails.

3 years agoPrefer fully-specified paths in test macros
Matt Corallo [Sun, 17 Oct 2021 21:23:51 +0000 (21:23 +0000)]
Prefer fully-specified paths in test macros

This avoids macros being context-specific use-dependent.

3 years agoAllow missing-docs on test-only macros
Matt Corallo [Wed, 20 Oct 2021 01:35:01 +0000 (01:35 +0000)]
Allow missing-docs on test-only macros

3 years agoMerge pull request #1184 from TheBlueMatt/2021-11-c-bindings-tweaks
Matt Corallo [Wed, 24 Nov 2021 20:03:14 +0000 (20:03 +0000)]
Merge pull request #1184 from TheBlueMatt/2021-11-c-bindings-tweaks

C Bindings Compatibility Tweaks

3 years agoSeal `scoring::Time` and only use `Instant` or `Eternity` publicly 2021-11-c-bindings-tweaks
Matt Corallo [Mon, 22 Nov 2021 18:00:08 +0000 (18:00 +0000)]
Seal `scoring::Time` and only use `Instant` or `Eternity` publicly

`scoring::Time` exists in part to make testing the passage of time
in `Scorer` practical. To allow no-std users to provide a time
source it was exposed as a trait as well. However, it seems
somewhat unlikely that a no-std user is going to have a use for
providing their own time source (otherwise they wouldn't be a
no-std user), and likely they won't have a graph in memory either.

`scoring::Time` as currently written is also exceptionally hard to
write C bindings for - the C bindings trait mappings relies on the
ability to construct trait implementations at runtime with function
pointers (i.e. `dyn Trait`s). `scoring::Time`, on the other hand,
is a supertrait of `core::ops::Sub` which requires a `sub` method
which takes a type parameter and returns a type parameter. Both of
which aren't practical in bindings, especially given the
`Sub::Output` associated type is not bound by any trait bounds at
all (implying we cannot simply map the `sub` function to return an
opaque trait object).

Thus, for simplicity, we here simply seal `scoring::Time` and make
it effectively-private, ensuring the bindings don't need to bother
with it.

3 years agoMake `Score : Writeable` in c_bindings and impl on `LockedScore`
Matt Corallo [Mon, 22 Nov 2021 03:27:17 +0000 (03:27 +0000)]
Make `Score : Writeable` in c_bindings and impl on `LockedScore`

Ultimately we likely need to wrap the locked `Score` in a struct
that exposes writeable somehow, but because all traits have to be
fully concretized for C bindings we'll still need `Writeable` on
all `Score` in order to expose `Writeable` on the locked score.
Otherwise, we'll only have a `LockedScore` with a `Score` visible
that only has the `Score` methods, never the original type.

3 years agoMerge pull request #1186 from TheBlueMatt/2021-11-fix-log-select
Matt Corallo [Wed, 24 Nov 2021 16:31:32 +0000 (16:31 +0000)]
Merge pull request #1186 from TheBlueMatt/2021-11-fix-log-select

Fix the `max_level_trace` feature

3 years agoTest all log-limiting features in CI 2021-11-fix-log-select
Matt Corallo [Tue, 23 Nov 2021 23:03:34 +0000 (23:03 +0000)]
Test all log-limiting features in CI

3 years agoFix compilation with the max_level_trace feature
Matt Corallo [Tue, 23 Nov 2021 23:03:13 +0000 (23:03 +0000)]
Fix compilation with the max_level_trace feature

3 years agoAdd a comment describing `update_time_counter` and when its updated
Matt Corallo [Tue, 16 Nov 2021 20:55:10 +0000 (20:55 +0000)]
Add a comment describing `update_time_counter` and when its updated

3 years agoRe-broadcast our own gossip even if its same as the last broadcast
Matt Corallo [Sat, 13 Nov 2021 01:54:54 +0000 (01:54 +0000)]
Re-broadcast our own gossip even if its same as the last broadcast

Even if our gossip hasn't changed, we should be willing to
re-broadcast it to our peers. All our peers may have been
disconnected the last time we broadcasted it.

3 years agoUpdate `ChannelUpdate::timestamp` when channels are dis-/en-abled
Matt Corallo [Sat, 13 Nov 2021 01:06:09 +0000 (01:06 +0000)]
Update `ChannelUpdate::timestamp` when channels are dis-/en-abled

We update the `Channel::update_time_counter` field (which is copied
into `ChannelUpdate::timestamp`) only when the channel is
initialized or closes, and when a new block is connected. However,
if a peer disconnects or reconnects, we may wish to generate
`ChannelUpdate` updates in between new blocks. In such a case, we
need to make sure the `timestamp` field is newer than any previous
updates' `timestamp` fields, which we do here by simply
incrementing it when the channel status is changed.

As a side effect of this we have to update
`test_background_processor` to ensure it eventually succeeds even
if the serialization of the `ChannelManager` changes after the test
begins.

3 years agoSeparate ChannelAnnouncement and ChannelUpdate broadcast conditions
Matt Corallo [Sat, 13 Nov 2021 00:27:05 +0000 (00:27 +0000)]
Separate ChannelAnnouncement and ChannelUpdate broadcast conditions

When a `ChannelUpdate` message is generated for broadcast as a part
of a `BroadcastChannelAnnouncement` event, it may be newer than our
previous `ChannelUpdate` and need to be broadcast. However, if the
`ChannelAnnouncement` had already been seen we wouldn't
re-broadcast either message as the `handle_channel_announcement`
call would fail, short-circuiting the condition to broadcast both.

Instead, we split the broadcast of each message as well as the
conditional so that we always attempt to handle each message and
update our local graph state, then broadcast the message if its
update was processed successfully.

3 years agoStore holder channel reserve and max-htlc-in-flight explicitly
Matt Corallo [Tue, 9 Nov 2021 21:12:30 +0000 (21:12 +0000)]
Store holder channel reserve and max-htlc-in-flight explicitly

Previously, `holder_selected_channel_reserve_satoshis` and
`holder_max_htlc_value_in_flight_msat` were constant functions
of the channel value satoshis. However, in the future we may allow
allow users to specify it. In order to do so, we'll need to track
them explicitly, including serializing them as appropriate.

We go ahead and do so here, in part as it will make testing
different counterparty-selected channel reserve values easier.

3 years agoMerge pull request #1162 from TheBlueMatt/2021-11-fix-accept-chan-checks
Matt Corallo [Tue, 23 Nov 2021 20:46:38 +0000 (20:46 +0000)]
Merge pull request #1162 from TheBlueMatt/2021-11-fix-accept-chan-checks

Correct initial commitment tx fee affordability checks on open

3 years agoMerge pull request #1178 from jkczyz/2021-11-payment-path-successful
Matt Corallo [Tue, 23 Nov 2021 20:39:28 +0000 (20:39 +0000)]
Merge pull request #1178 from jkczyz/2021-11-payment-path-successful

Generate PaymentPathSuccessful event for each path

3 years agoMerge pull request #1176 from lightning-signer/2021-11-htlc-anchors
Matt Corallo [Tue, 23 Nov 2021 19:37:09 +0000 (19:37 +0000)]
Merge pull request #1176 from lightning-signer/2021-11-htlc-anchors

Add anchors support for HTLCs

3 years agoGenerate PaymentPathSuccessful event for each path
Jeffrey Czyz [Thu, 18 Nov 2021 22:24:14 +0000 (16:24 -0600)]
Generate PaymentPathSuccessful event for each path

A single PaymentSent event is generated when a payment is fulfilled.
This is occurs when the preimage is revealed on the first claimed HTLC.
For subsequent HTLCs, the event is not generated.

In order to score channels involved with a successful payments, the
scorer must be notified of each successful path involved in the payment.
Add a PaymentPathSuccessful event for this purpose. Generate it whenever
a part is removed from a pending outbound payment. This avoids duplicate
events when reconnecting to a peer.

3 years agoAdd test vectors for get_htlc_redeemscript wrt anchors
Ken Sedgwick [Tue, 16 Nov 2021 19:40:27 +0000 (11:40 -0800)]
Add test vectors for get_htlc_redeemscript wrt anchors

3 years agoAdjust HTLC_{SUCCESS,TIMEOUT}_TX_WEIGHT when anchors used
Ken Sedgwick [Tue, 16 Nov 2021 17:27:33 +0000 (09:27 -0800)]
Adjust HTLC_{SUCCESS,TIMEOUT}_TX_WEIGHT when anchors used

3 years agoAdd anchor support to build_htlc_transaction
Ken Sedgwick [Tue, 16 Nov 2021 03:39:39 +0000 (19:39 -0800)]
Add anchor support to build_htlc_transaction

3 years agoIncrease visibility of anchor related methods
Ken Sedgwick [Tue, 16 Nov 2021 02:50:57 +0000 (18:50 -0800)]
Increase visibility of anchor related methods

3 years agoAdd anchor support to commitment HTLC outputs
Ken Sedgwick [Tue, 16 Nov 2021 02:03:46 +0000 (18:03 -0800)]
Add anchor support to commitment HTLC outputs

3 years agoSupport `logger::Record` in C by String-ing the fmt::Arguments
Matt Corallo [Sun, 21 Nov 2021 22:29:48 +0000 (22:29 +0000)]
Support `logger::Record` in C by String-ing the fmt::Arguments

This adds a new (non-feature) cfg argument `c_bindings` which will
be set when building C bindings. With this, we can (slightly) tweak
behavior and API based on whether we are being built for Rust or C
users.

Ideally we'd never need this, but as long as we can keep the API
consistent-enough to avoid material code drift, this gives us a
cheap way of doing the "right" thing for both C and Rust when the
two are in tension.

We also move lightning-background-processor to support the same
MSRV as the main lightning crate, instead of only
lightning-net-tokio's MSRV.