Skip to content

Commit a087f75

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 6e86470 commit a087f75

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lightning/src/ln/router.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ struct NodeInfo {
156156
lowest_inbound_channel_fee_proportional_millionths: u32,
157157

158158
features: NodeFeatures,
159-
last_update: u32,
159+
/// Unlike for channels, we may have a NodeInfo entry before having received a node_update.
160+
/// Thus, we have to be able to capture "no update has been received", which we do with an
161+
/// Option here.
162+
last_update: Option<u32>,
160163
rgb: [u8; 3],
161164
alias: [u8; 32],
162165
addresses: Vec<NetAddress>,
@@ -167,7 +170,7 @@ struct NodeInfo {
167170

168171
impl std::fmt::Display for NodeInfo {
169172
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
170-
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[..])?;
173+
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[..])?;
171174
Ok(())
172175
}
173176
}
@@ -418,12 +421,15 @@ impl RoutingMessageHandler for Router {
418421
match network.nodes.get_mut(&msg.contents.node_id) {
419422
None => Err(LightningError{err: "No existing channels for node_announcement", action: ErrorAction::IgnoreError}),
420423
Some(node) => {
421-
if node.last_update >= msg.contents.timestamp {
422-
return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
424+
match node.last_update {
425+
Some(last_update) => if last_update >= msg.contents.timestamp {
426+
return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
427+
},
428+
None => {},
423429
}
424430

425431
node.features = msg.contents.features.clone();
426-
node.last_update = msg.contents.timestamp;
432+
node.last_update = Some(msg.contents.timestamp);
427433
node.rgb = msg.contents.rgb;
428434
node.alias = msg.contents.alias;
429435
node.addresses = msg.contents.addresses.clone();
@@ -539,7 +545,7 @@ impl RoutingMessageHandler for Router {
539545
lowest_inbound_channel_fee_base_msat: u32::max_value(),
540546
lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
541547
features: NodeFeatures::empty(),
542-
last_update: 0,
548+
last_update: None,
543549
rgb: [0; 3],
544550
alias: [0; 32],
545551
addresses: Vec::new(),
@@ -752,7 +758,7 @@ impl Router {
752758
lowest_inbound_channel_fee_base_msat: u32::max_value(),
753759
lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
754760
features: NodeFeatures::empty(),
755-
last_update: 0,
761+
last_update: None,
756762
rgb: [0; 3],
757763
alias: [0; 32],
758764
addresses: Vec::new(),
@@ -1175,7 +1181,7 @@ mod tests {
11751181
lowest_inbound_channel_fee_base_msat: 100,
11761182
lowest_inbound_channel_fee_proportional_millionths: 0,
11771183
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(1)),
1178-
last_update: 1,
1184+
last_update: Some(1),
11791185
rgb: [0; 3],
11801186
alias: [0; 32],
11811187
addresses: Vec::new(),
@@ -1209,7 +1215,7 @@ mod tests {
12091215
lowest_inbound_channel_fee_base_msat: 0,
12101216
lowest_inbound_channel_fee_proportional_millionths: 0,
12111217
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(2)),
1212-
last_update: 1,
1218+
last_update: Some(1),
12131219
rgb: [0; 3],
12141220
alias: [0; 32],
12151221
addresses: Vec::new(),
@@ -1243,7 +1249,7 @@ mod tests {
12431249
lowest_inbound_channel_fee_base_msat: 0,
12441250
lowest_inbound_channel_fee_proportional_millionths: 0,
12451251
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(8)),
1246-
last_update: 1,
1252+
last_update: Some(1),
12471253
rgb: [0; 3],
12481254
alias: [0; 32],
12491255
addresses: Vec::new(),
@@ -1283,7 +1289,7 @@ mod tests {
12831289
lowest_inbound_channel_fee_base_msat: 0,
12841290
lowest_inbound_channel_fee_proportional_millionths: 0,
12851291
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(3)),
1286-
last_update: 1,
1292+
last_update: Some(1),
12871293
rgb: [0; 3],
12881294
alias: [0; 32],
12891295
addresses: Vec::new(),
@@ -1363,7 +1369,7 @@ mod tests {
13631369
lowest_inbound_channel_fee_base_msat: 0,
13641370
lowest_inbound_channel_fee_proportional_millionths: 0,
13651371
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(4)),
1366-
last_update: 1,
1372+
last_update: Some(1),
13671373
rgb: [0; 3],
13681374
alias: [0; 32],
13691375
addresses: Vec::new(),
@@ -1397,7 +1403,7 @@ mod tests {
13971403
lowest_inbound_channel_fee_base_msat: 0,
13981404
lowest_inbound_channel_fee_proportional_millionths: 0,
13991405
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(5)),
1400-
last_update: 1,
1406+
last_update: Some(1),
14011407
rgb: [0; 3],
14021408
alias: [0; 32],
14031409
addresses: Vec::new(),
@@ -1454,7 +1460,7 @@ mod tests {
14541460
lowest_inbound_channel_fee_base_msat: 0,
14551461
lowest_inbound_channel_fee_proportional_millionths: 0,
14561462
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(6)),
1457-
last_update: 1,
1463+
last_update: Some(1),
14581464
rgb: [0; 3],
14591465
alias: [0; 32],
14601466
addresses: Vec::new(),

0 commit comments

Comments
 (0)