Skip to content

Commit 5691099

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 596ef3b commit 5691099

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
}
@@ -341,16 +333,7 @@ mod tests {
341333
assert_eq!(network_graph.read_only().channels().len(), 0);
342334

343335
let rapid_sync = RapidGossipSync::new(&network_graph);
344-
let update_result = rapid_sync.update_network_graph(&announced_update_input[..]);
345-
assert!(update_result.is_err());
346-
if let Err(GraphSyncError::LightningError(lightning_error)) = update_result {
347-
assert_eq!(
348-
lightning_error.err,
349-
"Couldn't find previous directional data for update"
350-
);
351-
} else {
352-
panic!("Unexpected update result: {:?}", update_result)
353-
}
336+
rapid_sync.update_network_graph(&announced_update_input[..]).unwrap();
354337
}
355338

356339
#[test]
@@ -405,16 +388,7 @@ mod tests {
405388
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,
406389
68, 226, 0, 6, 11, 0, 1, 128,
407390
];
408-
let update_result = rapid_sync.update_network_graph(&opposite_direction_incremental_update_input[..]);
409-
assert!(update_result.is_err());
410-
if let Err(GraphSyncError::LightningError(lightning_error)) = update_result {
411-
assert_eq!(
412-
lightning_error.err,
413-
"Couldn't find previous directional data for update"
414-
);
415-
} else {
416-
panic!("Unexpected update result: {:?}", update_result)
417-
}
391+
rapid_sync.update_network_graph(&opposite_direction_incremental_update_input[..]).unwrap();
418392
}
419393

420394
#[test]

0 commit comments

Comments
 (0)