Skip to content

Commit e17765f

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 41ada11 commit e17765f

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
@@ -154,7 +154,7 @@ struct NodeInfo {
154154
lowest_inbound_channel_fee_proportional_millionths: u32,
155155

156156
features: Features<FeatureContextNode>,
157-
last_update: u32,
157+
last_update: Option<u32>,
158158
rgb: [u8; 3],
159159
alias: [u8; 32],
160160
addresses: Vec<NetAddress>,
@@ -165,7 +165,7 @@ struct NodeInfo {
165165

166166
impl std::fmt::Display for NodeInfo {
167167
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
168-
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[..])?;
168+
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[..])?;
169169
Ok(())
170170
}
171171
}
@@ -428,12 +428,15 @@ impl RoutingMessageHandler for Router {
428428
match network.nodes.get_mut(&msg.contents.node_id) {
429429
None => Err(LightningError{err: "No existing channels for node_announcement", action: ErrorAction::IgnoreError}),
430430
Some(node) => {
431-
if node.last_update >= msg.contents.timestamp {
432-
return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
431+
match node.last_update {
432+
Some(last_update) => if last_update >= msg.contents.timestamp {
433+
return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
434+
},
435+
None => {},
433436
}
434437

435438
node.features = msg.contents.features.clone();
436-
node.last_update = msg.contents.timestamp;
439+
node.last_update = Some(msg.contents.timestamp);
437440
node.rgb = msg.contents.rgb;
438441
node.alias = msg.contents.alias;
439442
node.addresses = msg.contents.addresses.clone();
@@ -549,7 +552,7 @@ impl RoutingMessageHandler for Router {
549552
lowest_inbound_channel_fee_base_msat: u32::max_value(),
550553
lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
551554
features: Features::<FeatureContextNode>::empty(),
552-
last_update: 0,
555+
last_update: None,
553556
rgb: [0; 3],
554557
alias: [0; 32],
555558
addresses: Vec::new(),
@@ -751,7 +754,7 @@ impl Router {
751754
lowest_inbound_channel_fee_base_msat: u32::max_value(),
752755
lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
753756
features: Features::<FeatureContextNode>::empty(),
754-
last_update: 0,
757+
last_update: None,
755758
rgb: [0; 3],
756759
alias: [0; 32],
757760
addresses: Vec::new(),
@@ -1164,7 +1167,7 @@ mod tests {
11641167
lowest_inbound_channel_fee_base_msat: 100,
11651168
lowest_inbound_channel_fee_proportional_millionths: 0,
11661169
features: Features { flags: id_to_feature_flags!(1), mark: ::std::marker::PhantomData },
1167-
last_update: 1,
1170+
last_update: Some(1),
11681171
rgb: [0; 3],
11691172
alias: [0; 32],
11701173
addresses: Vec::new(),
@@ -1198,7 +1201,7 @@ mod tests {
11981201
lowest_inbound_channel_fee_base_msat: 0,
11991202
lowest_inbound_channel_fee_proportional_millionths: 0,
12001203
features: Features { flags: id_to_feature_flags!(2), mark: ::std::marker::PhantomData },
1201-
last_update: 1,
1204+
last_update: Some(1),
12021205
rgb: [0; 3],
12031206
alias: [0; 32],
12041207
addresses: Vec::new(),
@@ -1232,7 +1235,7 @@ mod tests {
12321235
lowest_inbound_channel_fee_base_msat: 0,
12331236
lowest_inbound_channel_fee_proportional_millionths: 0,
12341237
features: Features { flags: id_to_feature_flags!(8), mark: ::std::marker::PhantomData },
1235-
last_update: 1,
1238+
last_update: Some(1),
12361239
rgb: [0; 3],
12371240
alias: [0; 32],
12381241
addresses: Vec::new(),
@@ -1272,7 +1275,7 @@ mod tests {
12721275
lowest_inbound_channel_fee_base_msat: 0,
12731276
lowest_inbound_channel_fee_proportional_millionths: 0,
12741277
features: Features { flags: id_to_feature_flags!(3), mark: ::std::marker::PhantomData },
1275-
last_update: 1,
1278+
last_update: Some(1),
12761279
rgb: [0; 3],
12771280
alias: [0; 32],
12781281
addresses: Vec::new(),
@@ -1352,7 +1355,7 @@ mod tests {
13521355
lowest_inbound_channel_fee_base_msat: 0,
13531356
lowest_inbound_channel_fee_proportional_millionths: 0,
13541357
features: Features { flags: id_to_feature_flags!(4), mark: ::std::marker::PhantomData },
1355-
last_update: 1,
1358+
last_update: Some(1),
13561359
rgb: [0; 3],
13571360
alias: [0; 32],
13581361
addresses: Vec::new(),
@@ -1386,7 +1389,7 @@ mod tests {
13861389
lowest_inbound_channel_fee_base_msat: 0,
13871390
lowest_inbound_channel_fee_proportional_millionths: 0,
13881391
features: Features { flags: id_to_feature_flags!(5), mark: ::std::marker::PhantomData },
1389-
last_update: 1,
1392+
last_update: Some(1),
13901393
rgb: [0; 3],
13911394
alias: [0; 32],
13921395
addresses: Vec::new(),
@@ -1443,7 +1446,7 @@ mod tests {
14431446
lowest_inbound_channel_fee_base_msat: 0,
14441447
lowest_inbound_channel_fee_proportional_millionths: 0,
14451448
features: Features { flags: id_to_feature_flags!(6), mark: ::std::marker::PhantomData },
1446-
last_update: 1,
1449+
last_update: Some(1),
14471450
rgb: [0; 3],
14481451
alias: [0; 32],
14491452
addresses: Vec::new(),

0 commit comments

Comments
 (0)