]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Generate PendingHTLCsForwardable event on deserialization 2018-12-forward-event
authorMatt Corallo <git@bluematt.me>
Fri, 21 Dec 2018 16:54:44 +0000 (11:54 -0500)
committerMatt Corallo <git@bluematt.me>
Sat, 22 Dec 2018 12:04:50 +0000 (07:04 -0500)
src/ln/channelmanager.rs

index 6f3dbdabed12ea827cf8506c05639ee418399c99..7884fa8f6f4290d030f6a8196ad875acaafbde5f 100644 (file)
@@ -2956,7 +2956,21 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
                        }
                }
 
+               let mut pending_events = Vec::new();
+
                let forward_htlcs_count: u64 = Readable::read(reader)?;
+               let next_forward = if forward_htlcs_count == 0 {
+                       Instant::now()
+               } else {
+                       // Wait five seconds to forward things we got off disk to give them a chance to
+                       // reconnect to their peers. Probably all the HTLCs have timed out by now, but try
+                       // anyway.
+                       let now_plus_five = Instant::now() + Duration::from_secs(5);
+                       pending_events.push(events::Event::PendingHTLCsForwardable {
+                               time_forwardable: now_plus_five,
+                       });
+                       now_plus_five
+               };
                let mut forward_htlcs = HashMap::with_capacity(cmp::min(forward_htlcs_count as usize, 128));
                for _ in 0..forward_htlcs_count {
                        let short_channel_id = Readable::read(reader)?;
@@ -2994,14 +3008,14 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
                        channel_state: Mutex::new(ChannelHolder {
                                by_id,
                                short_to_id,
-                               next_forward: Instant::now(),
+                               next_forward,
                                forward_htlcs,
                                claimable_htlcs,
                                pending_msg_events: Vec::new(),
                        }),
                        our_network_key: args.keys_manager.get_node_secret(),
 
-                       pending_events: Mutex::new(Vec::new()),
+                       pending_events: Mutex::new(pending_events),
                        total_consistency_lock: RwLock::new(()),
                        keys_manager: args.keys_manager,
                        logger: args.logger,