Skip to content

Commit 6b2276d

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 7afc683 commit 6b2276d

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
@@ -156,7 +156,7 @@ struct NodeInfo {
156156
lowest_inbound_channel_fee_proportional_millionths: u32,
157157

158158
features: NodeFeatures,
159-
last_update: u32,
159+
last_update: Option<u32>,
160160
rgb: [u8; 3],
161161
alias: [u8; 32],
162162
addresses: Vec<NetAddress>,
@@ -167,7 +167,7 @@ struct NodeInfo {
167167

168168
impl std::fmt::Display for NodeInfo {
169169
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[..])?;
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[..])?;
171171
Ok(())
172172
}
173173
}
@@ -418,12 +418,15 @@ impl RoutingMessageHandler for Router {
418418
match network.nodes.get_mut(&msg.contents.node_id) {
419419
None => Err(LightningError{err: "No existing channels for node_announcement", action: ErrorAction::IgnoreError}),
420420
Some(node) => {
421-
if node.last_update >= msg.contents.timestamp {
422-
return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
421+
match node.last_update {
422+
Some(last_update) => if last_update >= msg.contents.timestamp {
423+
return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
424+
},
425+
None => {},
423426
}
424427

425428
node.features = msg.contents.features.clone();
426-
node.last_update = msg.contents.timestamp;
429+
node.last_update = Some(msg.contents.timestamp);
427430
node.rgb = msg.contents.rgb;
428431
node.alias = msg.contents.alias;
429432
node.addresses = msg.contents.addresses.clone();
@@ -539,7 +542,7 @@ impl RoutingMessageHandler for Router {
539542
lowest_inbound_channel_fee_base_msat: u32::max_value(),
540543
lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
541544
features: NodeFeatures::empty(),
542-
last_update: 0,
545+
last_update: None,
543546
rgb: [0; 3],
544547
alias: [0; 32],
545548
addresses: Vec::new(),
@@ -752,7 +755,7 @@ impl Router {
752755
lowest_inbound_channel_fee_base_msat: u32::max_value(),
753756
lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
754757
features: NodeFeatures::empty(),
755-
last_update: 0,
758+
last_update: None,
756759
rgb: [0; 3],
757760
alias: [0; 32],
758761
addresses: Vec::new(),
@@ -1175,7 +1178,7 @@ mod tests {
11751178
lowest_inbound_channel_fee_base_msat: 100,
11761179
lowest_inbound_channel_fee_proportional_millionths: 0,
11771180
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(1)),
1178-
last_update: 1,
1181+
last_update: Some(1),
11791182
rgb: [0; 3],
11801183
alias: [0; 32],
11811184
addresses: Vec::new(),
@@ -1209,7 +1212,7 @@ mod tests {
12091212
lowest_inbound_channel_fee_base_msat: 0,
12101213
lowest_inbound_channel_fee_proportional_millionths: 0,
12111214
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(2)),
1212-
last_update: 1,
1215+
last_update: Some(1),
12131216
rgb: [0; 3],
12141217
alias: [0; 32],
12151218
addresses: Vec::new(),
@@ -1243,7 +1246,7 @@ mod tests {
12431246
lowest_inbound_channel_fee_base_msat: 0,
12441247
lowest_inbound_channel_fee_proportional_millionths: 0,
12451248
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(8)),
1246-
last_update: 1,
1249+
last_update: Some(1),
12471250
rgb: [0; 3],
12481251
alias: [0; 32],
12491252
addresses: Vec::new(),
@@ -1283,7 +1286,7 @@ mod tests {
12831286
lowest_inbound_channel_fee_base_msat: 0,
12841287
lowest_inbound_channel_fee_proportional_millionths: 0,
12851288
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(3)),
1286-
last_update: 1,
1289+
last_update: Some(1),
12871290
rgb: [0; 3],
12881291
alias: [0; 32],
12891292
addresses: Vec::new(),
@@ -1363,7 +1366,7 @@ mod tests {
13631366
lowest_inbound_channel_fee_base_msat: 0,
13641367
lowest_inbound_channel_fee_proportional_millionths: 0,
13651368
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(4)),
1366-
last_update: 1,
1369+
last_update: Some(1),
13671370
rgb: [0; 3],
13681371
alias: [0; 32],
13691372
addresses: Vec::new(),
@@ -1397,7 +1400,7 @@ mod tests {
13971400
lowest_inbound_channel_fee_base_msat: 0,
13981401
lowest_inbound_channel_fee_proportional_millionths: 0,
13991402
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(5)),
1400-
last_update: 1,
1403+
last_update: Some(1),
14011404
rgb: [0; 3],
14021405
alias: [0; 32],
14031406
addresses: Vec::new(),
@@ -1454,7 +1457,7 @@ mod tests {
14541457
lowest_inbound_channel_fee_base_msat: 0,
14551458
lowest_inbound_channel_fee_proportional_millionths: 0,
14561459
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(6)),
1457-
last_update: 1,
1460+
last_update: Some(1),
14581461
rgb: [0; 3],
14591462
alias: [0; 32],
14601463
addresses: Vec::new(),

0 commit comments

Comments
 (0)