Skip to content

Commit 2340839

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 4502b48 commit 2340839

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
@@ -3154,6 +3154,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
31543154
}
31553155
if header.bitcoin_hash() != self.last_block_connected {
31563156
self.last_block_connected = header.bitcoin_hash();
3157+
self.channel_update_count = cmp::max(self.channel_update_count, header.time);
31573158
if let Some(channel_monitor) = self.channel_monitor.as_mut() {
31583159
channel_monitor.last_block_hash = self.last_block_connected;
31593160
}

lightning/src/ln/channelmanager.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,6 +2742,16 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send> Ch
27422742
}
27432743
self.latest_block_height.store(height as usize, Ordering::Release);
27442744
*self.last_block_hash.try_lock().expect("block_(dis)connected must not be called in parallel") = header_hash;
2745+
loop {
2746+
// Just in case we end up in a race, we loop until we either successfully update
2747+
// last_node_announcement_serial or decide we don't need to.
2748+
let old_serial = self.last_node_announcement_serial.load(Ordering::Acquire);
2749+
if old_serial < header.time as usize {
2750+
if self.last_node_announcement_serial.compare_exchange(old_serial, header.time as usize, Ordering::AcqRel, Ordering::Relaxed).is_ok() {
2751+
break;
2752+
}
2753+
} else { break; }
2754+
}
27452755
}
27462756

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

0 commit comments

Comments
 (0)