@@ -374,28 +374,18 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
374
374
let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
375
375
let batch_count = batches. len ( ) ;
376
376
for ( batch_index, batch) in batches. into_iter ( ) . enumerate ( ) {
377
- // Per spec, the initial first_blocknum needs to be <= the query's first_blocknum.
378
- // Use the query's values since we don't use pre-processed reply ranges.
379
- let first_blocknum = if batch_index == 0 {
380
- msg. first_blocknum
381
- }
382
- // Subsequent replies must be >= the last sent first_blocknum. Use the first block
383
- // in the new batch. Batches beyond the first one cannot be empty.
384
- else {
385
- block_from_scid ( batch. first ( ) . unwrap ( ) )
386
- } ;
387
-
388
- // Per spec, the last end_blocknum needs to be >= the query's end_blocknum. Last
389
- // reply calculates difference between the query's end_blocknum and the start of the reply.
390
- // Overflow safe since end_blocknum=msg.first_block_num+msg.number_of_blocks and first_blocknum
391
- // will be either msg.first_blocknum or a higher block height.
377
+ // Per spec, the initial first_blocknum needs to be <= the query's first_blocknum and subsequent
378
+ // must be >= the prior reply. We'll simplify this by using zero since its still spec compliant and
379
+ // sequence completion is now explicitly.
380
+ let first_blocknum = 0 ;
381
+
382
+ // Per spec, the final end_blocknum needs to be >= the query's end_blocknum, so we'll use the
383
+ // query's value. Prior batches must use the number of blocks that fit into the message. We'll
384
+ // base this off the last SCID in the batch since we've somewhat abusing first_blocknum.
392
385
let number_of_blocks = if batch_index == batch_count-1 {
393
- msg. end_blocknum ( ) - first_blocknum
394
- }
395
- // Prior replies should use the number of blocks that fit into the reply. Overflow
396
- // safe since first_blocknum is always <= last SCID's block.
397
- else {
398
- block_from_scid ( batch. last ( ) . unwrap ( ) ) - first_blocknum + 1
386
+ msg. end_blocknum ( )
387
+ } else {
388
+ block_from_scid ( batch. last ( ) . unwrap ( ) ) + 1
399
389
} ;
400
390
401
391
// Only true for the last message in a sequence
@@ -2209,7 +2199,6 @@ mod tests {
2209
2199
2210
2200
// used for testing resumption on same block
2211
2201
scids. push ( scid_from_parts ( 108001 , 1 , 0 ) . unwrap ( ) ) ;
2212
- scids. push ( scid_from_parts ( 108001 , 2 , 0 ) . unwrap ( ) ) ;
2213
2202
2214
2203
for scid in scids {
2215
2204
let unsigned_announcement = UnsignedChannelAnnouncement {
@@ -2307,8 +2296,8 @@ mod tests {
2307
2296
vec ! [
2308
2297
ReplyChannelRange {
2309
2298
chain_hash: chain_hash. clone( ) ,
2310
- first_blocknum: 0xffffff ,
2311
- number_of_blocks: 1 ,
2299
+ first_blocknum: 0 ,
2300
+ number_of_blocks: 0x01000000 ,
2312
2301
sync_complete: true ,
2313
2302
short_channel_ids: vec![ ]
2314
2303
} ,
@@ -2321,15 +2310,15 @@ mod tests {
2321
2310
& node_id_2,
2322
2311
QueryChannelRange {
2323
2312
chain_hash : chain_hash. clone ( ) ,
2324
- first_blocknum : 0x00800000 ,
2313
+ first_blocknum : 1000 ,
2325
2314
number_of_blocks : 1000 ,
2326
2315
} ,
2327
2316
true ,
2328
2317
vec ! [
2329
2318
ReplyChannelRange {
2330
2319
chain_hash: chain_hash. clone( ) ,
2331
- first_blocknum: 0x00800000 ,
2332
- number_of_blocks: 1000 ,
2320
+ first_blocknum: 0 ,
2321
+ number_of_blocks: 2000 ,
2333
2322
sync_complete: true ,
2334
2323
short_channel_ids: vec![ ] ,
2335
2324
}
@@ -2349,8 +2338,8 @@ mod tests {
2349
2338
vec ! [
2350
2339
ReplyChannelRange {
2351
2340
chain_hash: chain_hash. clone( ) ,
2352
- first_blocknum: 0xfe0000 ,
2353
- number_of_blocks: 0xffffffff - 0xfe0000 ,
2341
+ first_blocknum: 0 ,
2342
+ number_of_blocks: 0xffffffff ,
2354
2343
sync_complete: true ,
2355
2344
short_channel_ids: vec![
2356
2345
0xfffffe_ffffff_ffff , // max
@@ -2372,8 +2361,8 @@ mod tests {
2372
2361
vec ! [
2373
2362
ReplyChannelRange {
2374
2363
chain_hash: chain_hash. clone( ) ,
2375
- first_blocknum: 100000 ,
2376
- number_of_blocks: 8000 ,
2364
+ first_blocknum: 0 ,
2365
+ number_of_blocks: 108000 ,
2377
2366
sync_complete: true ,
2378
2367
short_channel_ids: ( 100000 ..=107999 )
2379
2368
. map( |block| scid_from_parts( block, 0 , 0 ) . unwrap( ) )
@@ -2395,17 +2384,17 @@ mod tests {
2395
2384
vec ! [
2396
2385
ReplyChannelRange {
2397
2386
chain_hash: chain_hash. clone( ) ,
2398
- first_blocknum: 100000 ,
2399
- number_of_blocks: 8000 ,
2387
+ first_blocknum: 0 ,
2388
+ number_of_blocks: 108000 ,
2400
2389
sync_complete: false ,
2401
2390
short_channel_ids: ( 100000 ..=107999 )
2402
2391
. map( |block| scid_from_parts( block, 0 , 0 ) . unwrap( ) )
2403
2392
. collect( ) ,
2404
2393
} ,
2405
2394
ReplyChannelRange {
2406
2395
chain_hash: chain_hash. clone( ) ,
2407
- first_blocknum: 108000 ,
2408
- number_of_blocks: 1 ,
2396
+ first_blocknum: 0 ,
2397
+ number_of_blocks: 108001 ,
2409
2398
sync_complete: true ,
2410
2399
short_channel_ids: vec![
2411
2400
scid_from_parts( 108000 , 0 , 0 ) . unwrap( ) ,
@@ -2427,21 +2416,20 @@ mod tests {
2427
2416
vec ! [
2428
2417
ReplyChannelRange {
2429
2418
chain_hash: chain_hash. clone( ) ,
2430
- first_blocknum: 100002 ,
2431
- number_of_blocks: 8000 ,
2419
+ first_blocknum: 0 ,
2420
+ number_of_blocks: 108002 ,
2432
2421
sync_complete: false ,
2433
2422
short_channel_ids: ( 100002 ..=108001 )
2434
2423
. map( |block| scid_from_parts( block, 0 , 0 ) . unwrap( ) )
2435
2424
. collect( ) ,
2436
2425
} ,
2437
2426
ReplyChannelRange {
2438
2427
chain_hash: chain_hash. clone( ) ,
2439
- first_blocknum: 108001 ,
2440
- number_of_blocks: 1 ,
2428
+ first_blocknum: 0 ,
2429
+ number_of_blocks: 108002 ,
2441
2430
sync_complete: true ,
2442
2431
short_channel_ids: vec![
2443
2432
scid_from_parts( 108001 , 1 , 0 ) . unwrap( ) ,
2444
- scid_from_parts( 108001 , 2 , 0 ) . unwrap( ) ,
2445
2433
] ,
2446
2434
}
2447
2435
]
0 commit comments