Skip to content

Commit f009fa0

Browse files
committed
Do not fail to apply RGS updates for removed channels
If we receive a Rapid Gossip Sync update for channels where we are missing the existing channel data, we should ignore the missing channel. This can happen in a number of cases, whether because we received updated channel information via an onion error from an HTLC failure or because we've partially synced the graph from a peer over the standard lightning P2P protocol.
1 parent 96c8507 commit f009fa0

File tree

1 file changed

+6
-32
lines changed

1 file changed

+6
-32
lines changed

lightning-rapid-gossip-sync/src/processing.rs

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,15 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
169169
if (channel_flags & 0b_1000_0000) != 0 {
170170
// incremental update, field flags will indicate mutated values
171171
let read_only_network_graph = network_graph.read_only();
172-
if let Some(channel) = read_only_network_graph
173-
.channels()
174-
.get(&short_channel_id) {
175-
176-
let directional_info = channel
177-
.get_directional_info(channel_flags)
178-
.ok_or(LightningError {
179-
err: "Couldn't find previous directional data for update".to_owned(),
180-
action: ErrorAction::IgnoreError,
181-
})?;
182-
172+
if let Some(directional_info) =
173+
read_only_network_graph.channels().get(&short_channel_id)
174+
.map(|channel| channel.get_directional_info(channel_flags)).unwrap_or(None)
175+
{
183176
synthetic_update.cltv_expiry_delta = directional_info.cltv_expiry_delta;
184177
synthetic_update.htlc_minimum_msat = directional_info.htlc_minimum_msat;
185178
synthetic_update.htlc_maximum_msat = directional_info.htlc_maximum_msat;
186179
synthetic_update.fee_base_msat = directional_info.fees.base_msat;
187180
synthetic_update.fee_proportional_millionths = directional_info.fees.proportional_millionths;
188-
189181
} else {
190182
skip_update_for_unknown_channel = true;
191183
}
@@ -345,16 +337,7 @@ mod tests {
345337
assert_eq!(network_graph.read_only().channels().len(), 0);
346338

347339
let rapid_sync = RapidGossipSync::new(&network_graph);
348-
let update_result = rapid_sync.update_network_graph(&announced_update_input[..]);
349-
assert!(update_result.is_err());
350-
if let Err(GraphSyncError::LightningError(lightning_error)) = update_result {
351-
assert_eq!(
352-
lightning_error.err,
353-
"Couldn't find previous directional data for update"
354-
);
355-
} else {
356-
panic!("Unexpected update result: {:?}", update_result)
357-
}
340+
rapid_sync.update_network_graph(&announced_update_input[..]).unwrap();
358341
}
359342

360343
#[test]
@@ -410,16 +393,7 @@ mod tests {
410393
0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 8, 153, 192, 0, 2, 27, 0, 0, 136, 0, 0, 0, 221, 255, 2,
411394
68, 226, 0, 6, 11, 0, 1, 128,
412395
];
413-
let update_result = rapid_sync.update_network_graph(&opposite_direction_incremental_update_input[..]);
414-
assert!(update_result.is_err());
415-
if let Err(GraphSyncError::LightningError(lightning_error)) = update_result {
416-
assert_eq!(
417-
lightning_error.err,
418-
"Couldn't find previous directional data for update"
419-
);
420-
} else {
421-
panic!("Unexpected update result: {:?}", update_result)
422-
}
396+
rapid_sync.update_network_graph(&opposite_direction_incremental_update_input[..]).unwrap();
423397
}
424398

425399
#[test]

0 commit comments

Comments
 (0)