Skip to content

Commit b727baf

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 846c123 commit b727baf

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,6 +2757,16 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
27572757
}
27582758
self.latest_block_height.store(height as usize, Ordering::Release);
27592759
*self.last_block_hash.try_lock().expect("block_(dis)connected must not be called in parallel") = header_hash;
2760+
loop {
2761+
// Just in case we end up in a race, we loop until we either successfully update
2762+
// last_node_announcement_serial or decide we don't need to.
2763+
let old_serial = self.last_node_announcement_serial.load(Ordering::Acquire);
2764+
if old_serial < header.time as usize {
2765+
if self.last_node_announcement_serial.compare_exchange(old_serial, header.time as usize, Ordering::AcqRel, Ordering::Relaxed).is_ok() {
2766+
break;
2767+
}
2768+
} else { break; }
2769+
}
27602770
}
27612771

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

0 commit comments

Comments
 (0)