Use block timestamps as the min for generated update messages.
authorMatt Corallo <git@bluematt.me>
Tue, 25 Feb 2020 18:32:13 +0000 (13:32 -0500)
committerMatt Corallo <git@bluematt.me>
Sun, 1 Mar 2020 04:26:16 +0000 (23:26 -0500)
Fixes issue #493 and should resolve some issues where other nodes
(incorrectly) reject channel_update/node_announcement messages
which have a serial number that is not a relatively recent
timestamp.

lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs

index f155a0bd295051f87c8b69a308774e4e13e53eb0..b0f54450395eaabc42372d0cf3d3fdfa7b79fe98 100644 (file)
@@ -3175,6 +3175,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                }
                if header.bitcoin_hash() != self.last_block_connected {
                        self.last_block_connected = header.bitcoin_hash();
+                       self.channel_update_count = cmp::max(self.channel_update_count, header.time);
                        if let Some(channel_monitor) = self.channel_monitor.as_mut() {
                                channel_monitor.last_block_hash = self.last_block_connected;
                        }
index 784173e13aad9d6360883f12093cec96ad0b58de..3a53c3f4a6eecbc5cdca73738c5afb1c19c4a9cf 100644 (file)
@@ -2758,6 +2758,16 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
                }
                self.latest_block_height.store(height as usize, Ordering::Release);
                *self.last_block_hash.try_lock().expect("block_(dis)connected must not be called in parallel") = header_hash;
+               loop {
+                       // Just in case we end up in a race, we loop until we either successfully update
+                       // last_node_announcement_serial or decide we don't need to.
+                       let old_serial = self.last_node_announcement_serial.load(Ordering::Acquire);
+                       if old_serial < header.time as usize {
+                               if self.last_node_announcement_serial.compare_exchange(old_serial, header.time as usize, Ordering::AcqRel, Ordering::Relaxed).is_ok() {
+                                       break;
+                               }
+                       } else { break; }
+               }
        }
 
        /// We force-close the channel without letting our counterparty participate in the shutdown