Skip to content

Commit b7078d0

Browse files
committed
Allow node_announcement timestamps of 0 in accordance with BOLT 7
Unlike channel_update messages, node_announcement messages have no requirement that the timestamp is greater than 0.
1 parent 1ba81bc commit b7078d0

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

lightning/src/ln/router.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ struct NodeInfo {
155155
lowest_inbound_channel_fee_proportional_millionths: u32,
156156

157157
features: NodeFeatures,
158-
last_update: u32,
158+
last_update: Option<u32>,
159159
rgb: [u8; 3],
160160
alias: [u8; 32],
161161
addresses: Vec<NetAddress>,
@@ -166,7 +166,7 @@ struct NodeInfo {
166166

167167
impl std::fmt::Display for NodeInfo {
168168
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
169-
write!(f, "features: {}, last_update: {}, lowest_inbound_channel_fee_base_msat: {}, lowest_inbound_channel_fee_proportional_millionths: {}, channels: {:?}", log_bytes!(self.features.encode()), self.last_update, self.lowest_inbound_channel_fee_base_msat, self.lowest_inbound_channel_fee_proportional_millionths, &self.channels[..])?;
169+
write!(f, "features: {}, last_update: {:?}, lowest_inbound_channel_fee_base_msat: {}, lowest_inbound_channel_fee_proportional_millionths: {}, channels: {:?}", log_bytes!(self.features.encode()), self.last_update, self.lowest_inbound_channel_fee_base_msat, self.lowest_inbound_channel_fee_proportional_millionths, &self.channels[..])?;
170170
Ok(())
171171
}
172172
}
@@ -414,12 +414,15 @@ impl RoutingMessageHandler for Router {
414414
match network.nodes.get_mut(&msg.contents.node_id) {
415415
None => Err(LightningError{err: "No existing channels for node_announcement", action: ErrorAction::IgnoreError}),
416416
Some(node) => {
417-
if node.last_update >= msg.contents.timestamp {
418-
return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
417+
match node.last_update {
418+
Some(last_update) => if last_update >= msg.contents.timestamp {
419+
return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
420+
},
421+
None => {},
419422
}
420423

421424
node.features = msg.contents.features.clone();
422-
node.last_update = msg.contents.timestamp;
425+
node.last_update = Some(msg.contents.timestamp);
423426
node.rgb = msg.contents.rgb;
424427
node.alias = msg.contents.alias;
425428
node.addresses = msg.contents.addresses.clone();
@@ -535,7 +538,7 @@ impl RoutingMessageHandler for Router {
535538
lowest_inbound_channel_fee_base_msat: u32::max_value(),
536539
lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
537540
features: NodeFeatures::empty(),
538-
last_update: 0,
541+
last_update: None,
539542
rgb: [0; 3],
540543
alias: [0; 32],
541544
addresses: Vec::new(),
@@ -737,7 +740,7 @@ impl Router {
737740
lowest_inbound_channel_fee_base_msat: u32::max_value(),
738741
lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
739742
features: NodeFeatures::empty(),
740-
last_update: 0,
743+
last_update: None,
741744
rgb: [0; 3],
742745
alias: [0; 32],
743746
addresses: Vec::new(),
@@ -1153,7 +1156,7 @@ mod tests {
11531156
lowest_inbound_channel_fee_base_msat: 100,
11541157
lowest_inbound_channel_fee_proportional_millionths: 0,
11551158
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(1)),
1156-
last_update: 1,
1159+
last_update: Some(1),
11571160
rgb: [0; 3],
11581161
alias: [0; 32],
11591162
addresses: Vec::new(),
@@ -1187,7 +1190,7 @@ mod tests {
11871190
lowest_inbound_channel_fee_base_msat: 0,
11881191
lowest_inbound_channel_fee_proportional_millionths: 0,
11891192
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(2)),
1190-
last_update: 1,
1193+
last_update: Some(1),
11911194
rgb: [0; 3],
11921195
alias: [0; 32],
11931196
addresses: Vec::new(),
@@ -1221,7 +1224,7 @@ mod tests {
12211224
lowest_inbound_channel_fee_base_msat: 0,
12221225
lowest_inbound_channel_fee_proportional_millionths: 0,
12231226
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(8)),
1224-
last_update: 1,
1227+
last_update: Some(1),
12251228
rgb: [0; 3],
12261229
alias: [0; 32],
12271230
addresses: Vec::new(),
@@ -1261,7 +1264,7 @@ mod tests {
12611264
lowest_inbound_channel_fee_base_msat: 0,
12621265
lowest_inbound_channel_fee_proportional_millionths: 0,
12631266
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(3)),
1264-
last_update: 1,
1267+
last_update: Some(1),
12651268
rgb: [0; 3],
12661269
alias: [0; 32],
12671270
addresses: Vec::new(),
@@ -1341,7 +1344,7 @@ mod tests {
13411344
lowest_inbound_channel_fee_base_msat: 0,
13421345
lowest_inbound_channel_fee_proportional_millionths: 0,
13431346
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(4)),
1344-
last_update: 1,
1347+
last_update: Some(1),
13451348
rgb: [0; 3],
13461349
alias: [0; 32],
13471350
addresses: Vec::new(),
@@ -1375,7 +1378,7 @@ mod tests {
13751378
lowest_inbound_channel_fee_base_msat: 0,
13761379
lowest_inbound_channel_fee_proportional_millionths: 0,
13771380
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(5)),
1378-
last_update: 1,
1381+
last_update: Some(1),
13791382
rgb: [0; 3],
13801383
alias: [0; 32],
13811384
addresses: Vec::new(),
@@ -1432,7 +1435,7 @@ mod tests {
14321435
lowest_inbound_channel_fee_base_msat: 0,
14331436
lowest_inbound_channel_fee_proportional_millionths: 0,
14341437
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(6)),
1435-
last_update: 1,
1438+
last_update: Some(1),
14361439
rgb: [0; 3],
14371440
alias: [0; 32],
14381441
addresses: Vec::new(),

0 commit comments

Comments
 (0)