Merge pull request #1702 from TheBlueMatt/2022-09-one-hop-retryable
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Thu, 8 Sep 2022 17:34:04 +0000 (17:34 +0000)
committerGitHub <noreply@github.com>
Thu, 8 Sep 2022 17:34:04 +0000 (17:34 +0000)
Mark failed one-hop HTLCs as retrably

CHANGELOG.md
lightning/src/ln/channelmanager.rs
lightning/src/util/events.rs

index 4618446397540439cd43357a794da30bcadcdf5d..efc6218e7adf5898ada3f87e49a7821c52b82ac3 100644 (file)
@@ -1,4 +1,4 @@
-# 0.0.110 - 2022-07-26
+# 0.0.110 - 2022-07-26 - "Routing, With a Vengeance"
 
 ## API Updates
  * `ChannelManager::send_probe` and `Score::probe_{failed,successful}` have
@@ -55,7 +55,7 @@ deletions in 52 commits from 9 authors, in alphabetical order:
  * Wilmer Paulino
  * jurvis
 
-# 0.0.109 - 2022-07-01
+# 0.0.109 - 2022-07-01 - "The Kitchen Sink"
 
 ## API Updates
  * `ChannelManager::update_channel_config` has been added to allow the fields
@@ -128,7 +128,7 @@ deletions in 33 commits from 9 authors, in alphabetical order:
  * Wilmer Paulino
 
 
-# 0.0.108 - 2022-06-10
+# 0.0.108 - 2022-06-10 - "You Wanted It To Build?! Why Didn't You Say So?"
 
 ## Bug Fixes
  * Fixed `lightning-background-processor` build in release mode.
@@ -140,7 +140,7 @@ deletions in 5 commits from 4 authors, in alphabetical order:
  * Max Fang
  * Viktor Tigerström
 
-# 0.0.107 - 2022-06-08
+# 0.0.107 - 2022-06-08 - "BlueWallet's Wishlist"
 
 ## API Updates
  * Channels larger than 16777215 sats (Wumbo!) are now supported and can be
@@ -864,7 +864,7 @@ deletions in 89 commits from 12 authors, in alphabetical order:
  * vss96
 
 
-# 0.0.100 - 2021-08-17
+# 0.0.100 - 2021-08-17 - "Oh, so *that's* what's going on inside the box"
 
 ## API Updates
  * The `lightning` crate can now be built in no_std mode, making it easy to
@@ -957,7 +957,7 @@ In total, this release features 59 files changed, 5861 insertions, and 2082
 deletions in 95 commits from 6 authors.
 
 
-# 0.0.99 - 2021-07-09
+# 0.0.99 - 2021-07-09 - "It's a Bugz Life"
 
 ## API Updates
 
@@ -1028,7 +1028,7 @@ deletions in 95 commits from 6 authors.
    versions. If you have such a `ChannelManager` available, a simple patch will
    allow it to deserialize. Please file an issue if you need assistance (#973).
 
-# 0.0.98 - 2021-06-11
+# 0.0.98 - 2021-06-11 - "It's ALIVVVVEEEEEEE"
 
 0.0.98 should be considered a release candidate to the first alpha release of
 Rust-Lightning and the broader LDK. It represents several years of work
index 2d1a3c7efdc30a1913bd2819ee32010a161eeb74..80d0fea5b6ca12d5d1db9185560cff11709735c1 100644 (file)
@@ -5671,10 +5671,6 @@ where
        ///
        /// An [`EventHandler`] may safely call back to the provider in order to handle an event.
        /// However, it must not call [`Writeable::write`] as doing so would result in a deadlock.
-       ///
-       /// Pending events are persisted as part of [`ChannelManager`]. While these events are cleared
-       /// when processed, an [`EventHandler`] must be able to handle previously seen events when
-       /// restarting from an old state.
        fn process_pending_events<H: Deref>(&self, handler: H) where H::Target: EventHandler {
                PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.persistence_notifier, || {
                        let mut result = NotifyOption::SkipPersist;
index 47e0c88f549f6f882f310c220d5cc94736dc4f41..be1979c77c93cfb6739ae01ef2da78ba25e75b75 100644 (file)
@@ -1002,7 +1002,7 @@ impl MaybeReadable for Event {
                                                (4, path, vec_type),
                                                (6, short_channel_id, option),
                                        });
-                                       Ok(Some(Event::ProbeFailed{
+                                       Ok(Some(Event::ProbeFailed {
                                                payment_id,
                                                payment_hash,
                                                path: path.unwrap(),
@@ -1011,6 +1011,28 @@ impl MaybeReadable for Event {
                                };
                                f()
                        },
+                       25u8 => {
+                               let f = || {
+                                       let mut prev_channel_id = [0; 32];
+                                       let mut failed_next_destination_opt = None;
+                                       read_tlv_fields!(reader, {
+                                               (0, prev_channel_id, required),
+                                               (2, failed_next_destination_opt, ignorable),
+                                       });
+                                       if let Some(failed_next_destination) = failed_next_destination_opt {
+                                               Ok(Some(Event::HTLCHandlingFailed {
+                                                       prev_channel_id,
+                                                       failed_next_destination,
+                                               }))
+                                       } else {
+                                               // If we fail to read a `failed_next_destination` assume it's because
+                                               // `MaybeReadable::read` returned `Ok(None)`, though it's also possible we
+                                               // were simply missing the field.
+                                               Ok(None)
+                                       }
+                               };
+                               f()
+                       },
                        // Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
                        // Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
                        // reads.
@@ -1207,11 +1229,17 @@ pub trait OnionMessageProvider {
 ///
 /// # Requirements
 ///
-/// See [`process_pending_events`] for requirements around event processing.
-///
 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
-/// event since the last invocation. The handler must either act upon the event immediately
-/// or preserve it for later handling.
+/// event since the last invocation.
+///
+/// In order to ensure no [`Event`]s are lost, implementors of this trait will persist [`Event`]s
+/// and replay any unhandled events on startup. An [`Event`] is considered handled when
+/// [`process_pending_events`] returns, thus handlers MUST fully handle [`Event`]s and persist any
+/// relevant changes to disk *before* returning.
+///
+/// Further, because an application may crash between an [`Event`] being handled and the
+/// implementor of this trait being re-serialized, [`Event`] handling must be idempotent - in
+/// effect, [`Event`]s may be replayed.
 ///
 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
 /// consult the provider's documentation on the implication of processing events and how a handler
@@ -1228,9 +1256,7 @@ pub trait OnionMessageProvider {
 pub trait EventsProvider {
        /// Processes any events generated since the last call using the given event handler.
        ///
-       /// Subsequent calls must only process new events. However, handlers must be capable of handling
-       /// duplicate events across process restarts. This may occur if the provider was recovered from
-       /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
+       /// See the trait-level documentation for requirements.
        fn process_pending_events<H: Deref>(&self, handler: H) where H::Target: EventHandler;
 }