Commit graph

2875 commits

Author SHA1 Message Date
Matt Corallo
e9f1934e5b Move MonitorEvent serialization to TLV-enum-upgradable from custom 2021-10-18 22:04:56 +00:00
Matt Corallo
dda86a0cf2
Merge pull request #1112 from TheBlueMatt/2021-10-mon-refactors
Hide internals of ChainMonitor behind getter
2021-10-14 01:45:20 +00:00
Matt Corallo
1464671ae8 Use Persister to return errors in fuzzers not chain::Watch 2021-10-14 00:19:43 +00:00
Matt Corallo
c396dc6ee5 Use Persister to return errors in tests not chain::Watch
As ChainMonitor will need to see those errors in a coming PR,
we need to return errors via Persister so that our ChainMonitor
chain::Watch implementation sees them.
2021-10-14 00:19:42 +00:00
Matt Corallo
1b6a7c1314 Handle Persister returning TemporaryFailure for new channels
Previously, if a Persister returned a TemporaryFailure error when
we tried to persist a new channel, the ChainMonitor wouldn't track
the new ChannelMonitor at all, generating a PermanentFailure later
when the updating is restored.

This fixes that by correctly storing the ChannelMonitor on
TemporaryFailures, allowing later update restoration to happen
normally.

This is (indirectly) tested in the next commit where we use
Persister to return all monitor-update errors.
2021-10-14 00:19:12 +00:00
Matt Corallo
49dbabff27 Simplify channelmonitor tests which use chain::Watch and Persister
test_simple_monitor_permanent_update_fail and
test_simple_monitor_temporary_update_fail both have a mode where
they use either chain::Watch or persister to return errors.

As we won't be doing any returns directly from the chain::Watch
wrapper in a coming commit, the chain::Watch-return form of the
test will no longer make sense.
2021-10-14 00:19:12 +00:00
Matt Corallo
79541b11e8 Make ChainMonitor::monitors private and expose monitor via getter
Exposing a `RwLock<HashMap<>>` directly was always a bit strange,
and in upcoming changes we'd like to change the internal
datastructure in `ChainMonitor`.

Further, the use of `RwLock` and `HashMap` meant we weren't able
to expose the ChannelMonitors themselves to users in bindings,
leaving a bindings/rust API gap.

Thus, we take this opportunity go expose ChannelMonitors directly
via a wrapper, hiding the internals of `ChainMonitor` behind
getters. We also update tests to use the new API.
2021-10-14 00:17:31 +00:00
Matt Corallo
6a7c48b60d Move ChannelMonitorUpdateErr to chain as it is a chain::Watch val 2021-10-14 00:16:50 +00:00
Matt Corallo
0dfb24e661 Move Persist trait to chainmonitor as that's the only reference 2021-10-14 00:16:50 +00:00
Matt Corallo
da498d7974
Merge pull request #1120 from jkczyz/2021-10-test-refactors
Pre-scoring test clean-ups
2021-10-14 00:16:27 +00:00
Jeffrey Czyz
d4ec090bb8
Move mpp_failure test to payment_tests.rs 2021-10-13 18:37:05 -05:00
Jeffrey Czyz
0a5ccd1f13
Replace get_route with get_route_and_payment_hash
The interface for get_route will change to take a scorer. Using
get_route_and_payment_hash whenever possible allows for keeping the
scorer inside get_route_and_payment_hash rather than at every call site.

Replace get_route with get_route_and_payment_hash wherever possible.
Additionally, update get_route_and_payment_hash to use the known invoice
features and the sending node's logger.
2021-10-13 18:37:01 -05:00
Matt Corallo
2144166bc6
Merge pull request #1115 from TheBlueMatt/2021-10-expose-addr-vec
Expose ReadOnlyNetworkGraph::get_addresses to C by cloning result
2021-10-13 16:54:09 +00:00
Jeffrey Czyz
3fc035267c
Fix unused variable warnings in fuzzer 2021-10-13 10:26:32 -05:00
Jeffrey Czyz
d7c8c8c572
Speed up test_timer_tick_called 2021-10-13 10:25:18 -05:00
Matt Corallo
d2b7f6cc08 Expose ReadOnlyNetworkGraph::get_addresses to C by cloning result
We cannot expose ReadOnlyNetworkGraph::get_addresses as is in C as
it returns a list of references to an enum, which the bindings
dont support. Instead, we simply clone the result so that it
doesn't contain references.
2021-10-13 01:18:43 +00:00
Matt Corallo
fe8c10db95
Merge pull request #1077 from jkczyz/2021-09-failing-route-hop
Include short channel id in PaymentPathFailed
2021-10-13 01:13:41 +00:00
Jeffrey Czyz
202acd9e16
Add failing short channel id to PaymentPathFailed
This will be useful for scoring channels when a payment fails.
2021-10-12 18:40:06 -05:00
Matt Corallo
5a356cad69
Merge pull request #1116 from TheBlueMatt/2021-10-test-local-chan-routing
Use local channel state when constructing routes in test macro  + Fix compile-warning
2021-10-12 18:29:05 +00:00
Matt Corallo
00ffa4397d Fix loop label shadowing warning 2021-10-12 02:29:56 +00:00
Matt Corallo
74a9be6956 Use local channel state when constructing routes in test macro
This is a bit more realistic and needed to route over non-public
channels.
2021-10-12 02:29:01 +00:00
Jeffrey Czyz
1e2ca5233b
Clean up fee_insufficient computation 2021-10-11 13:47:04 -05:00
Matt Corallo
d66574803e
Merge pull request #1098 from 1nF0rmed/2021-09-adds-discard-funding-event
Add Event::DiscardFunding generation
2021-10-09 17:17:55 +00:00
1nF0rmed
1955008d6d Adds DiscardFunding event
During the event of a channel close, if the funding transaction
is yet to be broadcasted then a DiscardFunding event is issued
along with the ChannelClose event.
2021-10-09 16:43:50 +05:30
Matt Corallo
843d25d750
Merge pull request #1107 from dunxen/2021-10-swap-pubkey-for-bytearray
Replace PublicKey with [u8; 33] in NetworkGraph
2021-10-08 21:02:53 +00:00
Matt Corallo
e635db0da3
Merge pull request #1062 from galderz/t_payment_hash_999 2021-10-08 20:49:19 +00:00
Duncan Dean
fce631ca21
Replace PublicKey with [u8; 33] in NetworkGraph 2021-10-08 18:37:55 +02:00
Galder Zamarreño
204bfd260c Add payment_hash to PaymentSent #999 2021-10-08 06:53:10 +02:00
Matt Corallo
6582aaebae
Merge pull request #1109 from TheBlueMatt/2021-10-init-fail-payment-retry-leak
Move pending payment tracking to after the new HTLC flies
2021-10-07 23:14:06 +00:00
Matt Corallo
a58c617c42 Correct error returned when retry_payment doesn't have a payment 2021-10-07 22:27:58 +00:00
Matt Corallo
928bfb12d2 Move pending payment tracking to after the new HTLC flies
If we attempt to send a payment, but the HTLC cannot be send due to
local channel limits, we'll provide the user an error but end up
with an entry in our pending payment map. This will result in a
memory leak as we'll never reclaim the pending payment map entry.
2021-10-07 22:27:58 +00:00
Jeffrey Czyz
f5abc93978
Pass hop index in construct_onion_keys_callback
This simplifies failing route hop calculation, which will be useful for
later identifying the failing hop for PaymentFailed events.
2021-10-06 23:31:59 -05:00
Jeffrey Czyz
42bb0af11d
Remove special case for onion error expiry_too_far
With channel scoring and payment retries, it is no longer necessary to
have expiry_too_far imply a payment failure.
2021-10-06 23:31:27 -05:00
Matt Corallo
ab0739e3ea
Merge pull request #1079 from TheBlueMatt/2021-09-stale-docs
Update Event::PaymentReceived docs since we require payment secret
2021-10-05 23:16:20 +00:00
Matt Corallo
7478207d5c Update Event::PaymentReceived docs since we require payment secret
Users no longer need to verify the amounts of received payments as
the payment secret will protect us against the probing attacks such
verification was intended to fix.
2021-10-05 22:35:04 +00:00
Matt Corallo
bb4ff74da1 Move tests of payment retries into a new module 2021-10-05 19:26:45 +00:00
Matt Corallo
17d75a845a
Merge pull request #1100 from TheBlueMatt/2021-09-multihop-route-hint-fix
Consider many first-hop paths to the same counterparty in routing
2021-10-05 18:43:39 +00:00
Matt Corallo
7aa2caccd8
Merge pull request #1096 from valentinewallace/2021-09-mpp-retries 2021-09-30 01:19:04 +00:00
Valentine Wallace
3e6297a664
Expire outbound payments after 3 blocks if no parts are pending 2021-09-29 20:25:42 -04:00
Valentine Wallace
207479f32f
Don't remove failed payments when all paths fail
This is because we want the ability to retry completely failed
payments.

Upcoming commits will remove these payments on timeout to prevent
DoS issues

Also test that this removal allows retrying single-path payments
2021-09-29 20:25:42 -04:00
Valentine Wallace
8db9c50b8b
Add method to retry payments 2021-09-29 20:25:39 -04:00
Matt Corallo
730d5639a4
Merge pull request #1080 from valentinewallace/2021-09-dup-chan-outpoint
Fix fuzzer-found panic from duplicate channel outpoint
2021-09-30 00:01:35 +00:00
Matt Corallo
cc704465c3 f readability improvements from val 2021-09-29 23:16:22 +00:00
Matt Corallo
2352587811
Merge pull request #1076 from TheBlueMatt/2021-09-forwardable-regen 2021-09-29 20:24:37 +00:00
Matt Corallo
0fcc34b9b5 Regenerate PendingHTLCsForwardable on reload instead of serializing
When we are prepared to forward HTLCs, we generate a
PendingHTLCsForwardable event with a time in the future when the
user should tell us to forward. This provides some basic batching
of forward events, improving privacy slightly.

After we generate the event, we expect users to spawn a timer in
the background and let us know when it finishes. However, if the
user shuts down before the timer fires, the user will restart and
have no idea that HTLCs are waiting to be forwarded/received.

To fix this, instead of serializing PendingHTLCsForwardable events
to disk while they're pending (before the user starts the timer),
we simply regenerate them when a ChannelManager is deserialized
with HTLCs pending.

Fixes #1042
2021-09-29 19:20:38 +00:00
Matt Corallo
56c75f0bac Consider many first-hop paths to the same counterparty in routing
Previously we'd simply overwritten "the" first hop path to each
counterparty when routing, however this results in us ignoring all
channels except the last one in the `ChannelDetails` list per
counterparty.
2021-09-29 19:15:16 +00:00
Matt Corallo
6edb4fe42f Correct step number in get_route 2021-09-29 18:51:14 +00:00
Valentine Wallace
bf527b0ddb
channelmanager: Add retry data to pending_outbound_payments 2021-09-28 19:39:37 -04:00
Valentine Wallace
72e1c91d46
Refactor send_payment internals for retries 2
Retrying a partial payment means send_payment_internal needs to be parameterized
by a total payment amount, else 'HTLC values do not match' errors
2021-09-28 19:39:37 -04:00
Valentine Wallace
5d316302df
Refactor send_payment internals for retries
We want to reuse send_payment internal functions for retries,
so some need to now be parameterized by PaymentId to avoid
generating a new PaymentId on retry
2021-09-28 19:39:37 -04:00