@@ -72,6 +72,8 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
72
72
73
73
let node_id_1_index: BigSize = Readable :: read ( read_cursor) ?;
74
74
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:
75
77
if max ( node_id_1_index. 0 , node_id_2_index. 0 ) >= node_id_count as u64 {
76
78
return Err ( DecodeError :: InvalidValue . into ( ) ) ;
77
79
} ;
@@ -120,49 +122,43 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
120
122
// flags are always sent in full, and hence always need updating
121
123
let standard_channel_flags = channel_flags & 0b_0000_0011 ;
122
124
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 {
138
141
// incremental update, field flags will indicate mutated values
139
142
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
141
144
. 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 ;
166
162
}
167
163
} ;
168
164
@@ -191,6 +187,10 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
191
187
synthetic_update. htlc_maximum_msat = htlc_maximum_msat;
192
188
}
193
189
190
+ if skip_update_for_unknown_channel {
191
+ continue ;
192
+ }
193
+
194
194
match network_graph. update_channel_unsigned ( & synthetic_update) {
195
195
Ok ( _) => { } ,
196
196
Err ( LightningError { action : ErrorAction :: IgnoreDuplicateGossip , .. } ) => { } ,
@@ -251,7 +251,7 @@ mod tests {
251
251
}
252
252
253
253
#[ test]
254
- fn incremental_only_update_fails_without_prior_announcements ( ) {
254
+ fn incremental_only_update_ignores_missing_channel ( ) {
255
255
let incremental_update_input = vec ! [
256
256
76 , 68 , 75 , 1 , 111 , 226 , 140 , 10 , 182 , 241 , 179 , 114 , 193 , 166 , 162 , 70 , 174 , 99 , 247 ,
257
257
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 {
268
268
269
269
let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
270
270
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( ) ) ;
277
272
}
278
273
279
274
#[ test]
0 commit comments