Skip to content

Commit 4334755

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 01a5d33 commit 4334755

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
@@ -2759,6 +2759,19 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
27592759
}
27602760
self.latest_block_height.store(height as usize, Ordering::Release);
27612761
*self.last_block_hash.try_lock().expect("block_(dis)connected must not be called in parallel") = header_hash;
2762+
loop {
2763+
// Update last_node_announcement_serial to be the max of its current value and the
2764+
// block timestamp. This should keep us close to the current time without relying on
2765+
// having an explicit local time source.
2766+
// Just in case we end up in a race, we loop until we either successfully update
2767+
// last_node_announcement_serial or decide we don't need to.
2768+
let old_serial = self.last_node_announcement_serial.load(Ordering::Acquire);
2769+
if old_serial < header.time as usize {
2770+
if self.last_node_announcement_serial.compare_exchange(old_serial, header.time as usize, Ordering::AcqRel, Ordering::Relaxed).is_ok() {
2771+
break;
2772+
}
2773+
} else { break; }
2774+
}
27622775
}
27632776

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

0 commit comments

Comments
 (0)