Skip to content

Commit ab89dd9

Browse files
ignore updates for unknown channels
1 parent d10e645 commit ab89dd9

File tree

1 file changed

+42
-47
lines changed

1 file changed

+42
-47
lines changed

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

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
7272

7373
let node_id_1_index: BigSize = Readable::read(read_cursor)?;
7474
let node_id_2_index: BigSize = Readable::read(read_cursor)?;
75+
76+
// Is this only because we truncate max node ids read? Why not do a >0 bounds check as well :shrug:
7577
if max(node_id_1_index.0, node_id_2_index.0) >= node_id_count as u64 {
7678
return Err(DecodeError::InvalidValue.into());
7779
};
@@ -120,49 +122,43 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
120122
// flags are always sent in full, and hence always need updating
121123
let standard_channel_flags = channel_flags & 0b_0000_0011;
122124

123-
let mut synthetic_update = if channel_flags & 0b_1000_0000 == 0 {
124-
// full update, field flags will indicate deviations from the default
125-
UnsignedChannelUpdate {
126-
chain_hash,
127-
short_channel_id,
128-
timestamp: backdated_timestamp,
129-
flags: standard_channel_flags,
130-
cltv_expiry_delta: default_cltv_expiry_delta,
131-
htlc_minimum_msat: default_htlc_minimum_msat,
132-
htlc_maximum_msat: default_htlc_maximum_msat,
133-
fee_base_msat: default_fee_base_msat,
134-
fee_proportional_millionths: default_fee_proportional_millionths,
135-
excess_data: Vec::new(),
136-
}
137-
} else {
125+
let mut synthetic_update = UnsignedChannelUpdate {
126+
chain_hash,
127+
short_channel_id,
128+
timestamp: backdated_timestamp,
129+
flags: standard_channel_flags,
130+
cltv_expiry_delta: default_cltv_expiry_delta,
131+
htlc_minimum_msat: default_htlc_minimum_msat,
132+
htlc_maximum_msat: default_htlc_maximum_msat,
133+
fee_base_msat: default_fee_base_msat,
134+
fee_proportional_millionths: default_fee_proportional_millionths,
135+
excess_data: Vec::new(),
136+
};
137+
138+
let mut skip_update_for_unknown_channel = false;
139+
140+
if (channel_flags & 0b_1000_0000) != 0 {
138141
// incremental update, field flags will indicate mutated values
139142
let read_only_network_graph = network_graph.read_only();
140-
let channel = read_only_network_graph
143+
if let Some(channel) = read_only_network_graph
141144
.channels()
142-
.get(&short_channel_id)
143-
.ok_or(LightningError {
144-
err: "Couldn't find channel for update".to_owned(),
145-
action: ErrorAction::IgnoreError,
146-
})?;
147-
148-
let directional_info = channel
149-
.get_directional_info(channel_flags)
150-
.ok_or(LightningError {
151-
err: "Couldn't find previous directional data for update".to_owned(),
152-
action: ErrorAction::IgnoreError,
153-
})?;
154-
155-
UnsignedChannelUpdate {
156-
chain_hash,
157-
short_channel_id,
158-
timestamp: backdated_timestamp,
159-
flags: standard_channel_flags,
160-
cltv_expiry_delta: directional_info.cltv_expiry_delta,
161-
htlc_minimum_msat: directional_info.htlc_minimum_msat,
162-
htlc_maximum_msat: directional_info.htlc_maximum_msat,
163-
fee_base_msat: directional_info.fees.base_msat,
164-
fee_proportional_millionths: directional_info.fees.proportional_millionths,
165-
excess_data: Vec::new(),
145+
.get(&short_channel_id) {
146+
147+
let directional_info = channel
148+
.get_directional_info(channel_flags)
149+
.ok_or(LightningError {
150+
err: "Couldn't find previous directional data for update".to_owned(),
151+
action: ErrorAction::IgnoreError,
152+
})?;
153+
154+
synthetic_update.cltv_expiry_delta = directional_info.cltv_expiry_delta;
155+
synthetic_update.htlc_minimum_msat = directional_info.htlc_minimum_msat;
156+
synthetic_update.htlc_maximum_msat = directional_info.htlc_maximum_msat;
157+
synthetic_update.fee_base_msat = directional_info.fees.base_msat;
158+
synthetic_update.fee_proportional_millionths = directional_info.fees.proportional_millionths;
159+
160+
} else {
161+
skip_update_for_unknown_channel = true;
166162
}
167163
};
168164

@@ -191,6 +187,10 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
191187
synthetic_update.htlc_maximum_msat = htlc_maximum_msat;
192188
}
193189

190+
if skip_update_for_unknown_channel {
191+
continue;
192+
}
193+
194194
match network_graph.update_channel_unsigned(&synthetic_update) {
195195
Ok(_) => {},
196196
Err(LightningError { action: ErrorAction::IgnoreDuplicateGossip, .. }) => {},
@@ -251,7 +251,7 @@ mod tests {
251251
}
252252

253253
#[test]
254-
fn incremental_only_update_fails_without_prior_announcements() {
254+
fn incremental_only_update_ignores_missing_channel() {
255255
let incremental_update_input = vec![
256256
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,
257257
79, 147, 30, 131, 101, 225, 90, 8, 156, 104, 214, 25, 0, 0, 0, 0, 0, 97, 229, 183, 167,
@@ -268,12 +268,7 @@ mod tests {
268268

269269
let rapid_sync = RapidGossipSync::new(&network_graph);
270270
let update_result = rapid_sync.update_network_graph(&incremental_update_input[..]);
271-
assert!(update_result.is_err());
272-
if let Err(GraphSyncError::LightningError(lightning_error)) = update_result {
273-
assert_eq!(lightning_error.err, "Couldn't find channel for update");
274-
} else {
275-
panic!("Unexpected update result: {:?}", update_result)
276-
}
271+
assert!(update_result.is_ok());
277272
}
278273

279274
#[test]

0 commit comments

Comments
 (0)