Skip to content

Commit

Permalink
Use block timestamps as the min for generated update messages.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheBlueMatt committed Mar 5, 2020
1 parent 01a5d33 commit 4334755
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lightning/src/ln/channel.rs
Expand Up @@ -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;
}
Expand Down
13 changes: 13 additions & 0 deletions lightning/src/ln/channelmanager.rs
Expand Up @@ -2759,6 +2759,19 @@ 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 {
// Update last_node_announcement_serial to be the max of its current value and the
// block timestamp. This should keep us close to the current time without relying on
// having an explicit local time source.
// 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
Expand Down

0 comments on commit 4334755

Please sign in to comment.