@@ -375,17 +375,20 @@ impl<C: Deref , L: Deref > RoutingMessageHandler for NetGraphMsgHandler<C, L> wh
375
375
let batch_count = batches. len ( ) ;
376
376
for ( batch_index, batch) in batches. into_iter ( ) . enumerate ( ) {
377
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 ;
378
+ // must be >= the prior reply. We'll simplify this by using the query's first_blocknum since its
379
+ // still spec compliant and sequence completion is now explicit .
380
+ let first_blocknum = msg . first_blocknum ;
381
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 .
382
+ // Per spec, the last end_block needs to be >= the query's end_blocknum. Last
383
+ // reply calculates difference between the query's end_blocknum and the start of the reply.
384
+ // Overflow safe since end_blocknum must be >= msg.first_block_num .
385
385
let number_of_blocks = if batch_index == batch_count-1 {
386
- msg. end_blocknum ( )
387
- } else {
388
- block_from_scid ( batch. last ( ) . unwrap ( ) ) + 1
386
+ msg. end_blocknum ( ) - first_blocknum
387
+ }
388
+ // Prior replies should use the number of blocks that fit into the reply. Overflow
389
+ // safe since first_blocknum is always <= last SCID's block.
390
+ else {
391
+ block_from_scid ( batch. last ( ) . unwrap ( ) ) - first_blocknum + 1
389
392
} ;
390
393
391
394
// Only true for the last message in a sequence
@@ -2235,8 +2238,8 @@ mod tests {
2235
2238
vec ! [
2236
2239
ReplyChannelRange {
2237
2240
chain_hash: chain_hash. clone( ) ,
2238
- first_blocknum: 0 ,
2239
- number_of_blocks: 0x01000000 ,
2241
+ first_blocknum: 0xffffff ,
2242
+ number_of_blocks: 1 ,
2240
2243
sync_complete: true ,
2241
2244
short_channel_ids: vec![ ]
2242
2245
} ,
@@ -2256,8 +2259,8 @@ mod tests {
2256
2259
vec ! [
2257
2260
ReplyChannelRange {
2258
2261
chain_hash: chain_hash. clone( ) ,
2259
- first_blocknum: 0 ,
2260
- number_of_blocks: 2000 ,
2262
+ first_blocknum: 1000 ,
2263
+ number_of_blocks: 1000 ,
2261
2264
sync_complete: true ,
2262
2265
short_channel_ids: vec![ ] ,
2263
2266
}
@@ -2277,8 +2280,8 @@ mod tests {
2277
2280
vec ! [
2278
2281
ReplyChannelRange {
2279
2282
chain_hash: chain_hash. clone( ) ,
2280
- first_blocknum: 0 ,
2281
- number_of_blocks: 0xffffffff ,
2283
+ first_blocknum: 0xfe0000 ,
2284
+ number_of_blocks: 0xffffffff - 0xfe0000 ,
2282
2285
sync_complete: true ,
2283
2286
short_channel_ids: vec![
2284
2287
0xfffffe_ffffff_ffff , // max
@@ -2300,8 +2303,8 @@ mod tests {
2300
2303
vec ! [
2301
2304
ReplyChannelRange {
2302
2305
chain_hash: chain_hash. clone( ) ,
2303
- first_blocknum: 0 ,
2304
- number_of_blocks: 108000 ,
2306
+ first_blocknum: 100000 ,
2307
+ number_of_blocks: 8000 ,
2305
2308
sync_complete: true ,
2306
2309
short_channel_ids: ( 100000 ..=107999 )
2307
2310
. map( |block| scid_from_parts( block, 0 , 0 ) . unwrap( ) )
@@ -2323,17 +2326,17 @@ mod tests {
2323
2326
vec ! [
2324
2327
ReplyChannelRange {
2325
2328
chain_hash: chain_hash. clone( ) ,
2326
- first_blocknum: 0 ,
2327
- number_of_blocks: 108000 ,
2329
+ first_blocknum: 100000 ,
2330
+ number_of_blocks: 8000 ,
2328
2331
sync_complete: false ,
2329
2332
short_channel_ids: ( 100000 ..=107999 )
2330
2333
. map( |block| scid_from_parts( block, 0 , 0 ) . unwrap( ) )
2331
2334
. collect( ) ,
2332
2335
} ,
2333
2336
ReplyChannelRange {
2334
2337
chain_hash: chain_hash. clone( ) ,
2335
- first_blocknum: 0 ,
2336
- number_of_blocks: 108001 ,
2338
+ first_blocknum: 100000 ,
2339
+ number_of_blocks: 8001 ,
2337
2340
sync_complete: true ,
2338
2341
short_channel_ids: vec![
2339
2342
scid_from_parts( 108000 , 0 , 0 ) . unwrap( ) ,
@@ -2355,17 +2358,17 @@ mod tests {
2355
2358
vec ! [
2356
2359
ReplyChannelRange {
2357
2360
chain_hash: chain_hash. clone( ) ,
2358
- first_blocknum: 0 ,
2359
- number_of_blocks: 108002 ,
2361
+ first_blocknum: 100002 ,
2362
+ number_of_blocks: 8000 ,
2360
2363
sync_complete: false ,
2361
2364
short_channel_ids: ( 100002 ..=108001 )
2362
2365
. map( |block| scid_from_parts( block, 0 , 0 ) . unwrap( ) )
2363
2366
. collect( ) ,
2364
2367
} ,
2365
2368
ReplyChannelRange {
2366
2369
chain_hash: chain_hash. clone( ) ,
2367
- first_blocknum: 0 ,
2368
- number_of_blocks: 108002 ,
2370
+ first_blocknum: 100002 ,
2371
+ number_of_blocks: 8000 ,
2369
2372
sync_complete: true ,
2370
2373
short_channel_ids: vec![
2371
2374
scid_from_parts( 108001 , 1 , 0 ) . unwrap( ) ,
0 commit comments