Skip to content

Commit b8a4c45

Browse files
committed
Use block timestamps as the min for generated update messages.
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.
1 parent abe15c0 commit b8a4c45

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,6 +3175,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
31753175
}
31763176
if header.bitcoin_hash() != self.last_block_connected {
31773177
self.last_block_connected = header.bitcoin_hash();
3178+
self.channel_update_count = cmp::max(self.channel_update_count, header.time);
31783179
if let Some(channel_monitor) = self.channel_monitor.as_mut() {
31793180
channel_monitor.last_block_hash = self.last_block_connected;
31803181
}

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,6 +2766,19 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
27662766
}
27672767
self.latest_block_height.store(height as usize, Ordering::Release);
27682768
*self.last_block_hash.try_lock().expect("block_(dis)connected must not be called in parallel") = header_hash;
2769+
loop {
2770+
// Update last_node_announcement_serial to be the max of its current value and the
2771+
// block timestamp. This should keep us close to the current time without relying on
2772+
// having an explicit local time source.
2773+
// Just in case we end up in a race, we loop until we either successfully update
2774+
// last_node_announcement_serial or decide we don't need to.
2775+
let old_serial = self.last_node_announcement_serial.load(Ordering::Acquire);
2776+
if old_serial < header.time as usize {
2777+
if self.last_node_announcement_serial.compare_exchange(old_serial, header.time as usize, Ordering::AcqRel, Ordering::Relaxed).is_ok() {
2778+
break;
2779+
}
2780+
} else { break; }
2781+
}
27692782
}
27702783

27712784
/// We force-close the channel without letting our counterparty participate in the shutdown

0 commit comments

Comments
 (0)