Skip to content

Commit c8f9623

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 ea0baaa commit c8f9623

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
}
@@ -429,12 +429,15 @@ impl RoutingMessageHandler for Router {
429429
match network.nodes.get_mut(&msg.contents.node_id) {
430430
None => Err(LightningError{err: "No existing channels for node_announcement", action: ErrorAction::IgnoreError}),
431431
Some(node) => {
432-
if node.last_update >= msg.contents.timestamp {
433-
return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
432+
match node.last_update {
433+
Some(last_update) => if last_update >= msg.contents.timestamp {
434+
return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
435+
},
436+
None => {},
434437
}
435438

436439
node.features = msg.contents.features.clone();
437-
node.last_update = msg.contents.timestamp;
440+
node.last_update = Some(msg.contents.timestamp);
438441
node.rgb = msg.contents.rgb;
439442
node.alias = msg.contents.alias;
440443
node.addresses = msg.contents.addresses.clone();
@@ -550,7 +553,7 @@ impl RoutingMessageHandler for Router {
550553
lowest_inbound_channel_fee_base_msat: u32::max_value(),
551554
lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
552555
features: NodeFeatures::empty(),
553-
last_update: 0,
556+
last_update: None,
554557
rgb: [0; 3],
555558
alias: [0; 32],
556559
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(),
@@ -1168,7 +1171,7 @@ mod tests {
11681171
lowest_inbound_channel_fee_base_msat: 100,
11691172
lowest_inbound_channel_fee_proportional_millionths: 0,
11701173
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(1)),
1171-
last_update: 1,
1174+
last_update: Some(1),
11721175
rgb: [0; 3],
11731176
alias: [0; 32],
11741177
addresses: Vec::new(),
@@ -1202,7 +1205,7 @@ mod tests {
12021205
lowest_inbound_channel_fee_base_msat: 0,
12031206
lowest_inbound_channel_fee_proportional_millionths: 0,
12041207
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(2)),
1205-
last_update: 1,
1208+
last_update: Some(1),
12061209
rgb: [0; 3],
12071210
alias: [0; 32],
12081211
addresses: Vec::new(),
@@ -1236,7 +1239,7 @@ mod tests {
12361239
lowest_inbound_channel_fee_base_msat: 0,
12371240
lowest_inbound_channel_fee_proportional_millionths: 0,
12381241
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(8)),
1239-
last_update: 1,
1242+
last_update: Some(1),
12401243
rgb: [0; 3],
12411244
alias: [0; 32],
12421245
addresses: Vec::new(),
@@ -1276,7 +1279,7 @@ mod tests {
12761279
lowest_inbound_channel_fee_base_msat: 0,
12771280
lowest_inbound_channel_fee_proportional_millionths: 0,
12781281
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(3)),
1279-
last_update: 1,
1282+
last_update: Some(1),
12801283
rgb: [0; 3],
12811284
alias: [0; 32],
12821285
addresses: Vec::new(),
@@ -1356,7 +1359,7 @@ mod tests {
13561359
lowest_inbound_channel_fee_base_msat: 0,
13571360
lowest_inbound_channel_fee_proportional_millionths: 0,
13581361
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(4)),
1359-
last_update: 1,
1362+
last_update: Some(1),
13601363
rgb: [0; 3],
13611364
alias: [0; 32],
13621365
addresses: Vec::new(),
@@ -1390,7 +1393,7 @@ mod tests {
13901393
lowest_inbound_channel_fee_base_msat: 0,
13911394
lowest_inbound_channel_fee_proportional_millionths: 0,
13921395
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(5)),
1393-
last_update: 1,
1396+
last_update: Some(1),
13941397
rgb: [0; 3],
13951398
alias: [0; 32],
13961399
addresses: Vec::new(),
@@ -1447,7 +1450,7 @@ mod tests {
14471450
lowest_inbound_channel_fee_base_msat: 0,
14481451
lowest_inbound_channel_fee_proportional_millionths: 0,
14491452
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(6)),
1450-
last_update: 1,
1453+
last_update: Some(1),
14511454
rgb: [0; 3],
14521455
alias: [0; 32],
14531456
addresses: Vec::new(),

0 commit comments

Comments
 (0)