zebrad 6.4.1

The Zcash Foundation's independent, consensus-compatible implementation of a Zcash node
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
//! Fixed test vectors for the inbound gossip block download stream.
//!
//! These are the inbound-gossip siblings of the sync-path tests in
//! `crate::components::sync::downloads::tests`: they cover GHSA-4f6v-mj46-gxg3, where a peer
//! answers a `BlocksByHash` request with a canonical header and a rewritten coinbase height. The
//! coinbase scriptSig is excluded from the V5 transaction ID (ZIP-244), so the block hash is
//! unchanged and the response passes the hash check, but the forged height is dropped as too far
//! ahead of the tip, or behind the finalized tip, before consensus validation. The supplying peer
//! must be scored only when the parent header Zebra holds proves the height was rewritten.

use std::{iter, sync::Arc, time::Duration};

use futures::stream::StreamExt;

use zebra_chain::{
    block::{Block, Height},
    chain_tip::mock::MockChainTip,
    serialization::ZcashDeserializeInto,
};
use zebra_network::{InventoryResponse, PeerSocketAddr};
use zebra_state::MAX_BLOCK_REORG_HEIGHT;
use zebra_test::mock_service::{MockService, PanicAssertion};

use zebra_network as zn;
use zebra_state as zs;

use super::{DownloadAction, Downloads, HeightLimitError, MIN_CONCURRENCY_LIMIT};

use InventoryResponse::*;

/// Maximum time to wait for a request to any test service.
///
/// These tests run the download task in parallel with the test, so machines under heavy load need a
/// longer delay.
const MAX_SERVICE_REQUEST_DELAY: Duration = Duration::from_millis(1000);

/// A peer address used to check whether the supplying peer can be scored.
const ADVERTISER: &str = "127.0.0.1:8233";

type MockNetwork = MockService<zn::Request, zn::Response, PanicAssertion>;
type MockVerifier = MockService<zebra_consensus::Request, zebra_chain::block::Hash, PanicAssertion>;
type MockState = MockService<zs::Request, zs::Response, PanicAssertion>;

/// Build an inbound gossip downloader whose state tip is at `tip_height`, returning the mock
/// network, verifier, and state services so a test can drive and assert on them.
#[allow(clippy::type_complexity)]
fn mock_downloads(
    tip_height: Height,
) -> (
    Downloads<MockNetwork, MockVerifier, MockState, MockChainTip>,
    MockNetwork,
    MockVerifier,
    MockState,
) {
    let network: MockNetwork = MockService::build()
        .with_max_request_delay(MAX_SERVICE_REQUEST_DELAY)
        .for_unit_tests();

    let verifier: MockVerifier = MockService::build()
        .with_max_request_delay(MAX_SERVICE_REQUEST_DELAY)
        .for_unit_tests();

    let state: MockState = MockService::build()
        .with_max_request_delay(MAX_SERVICE_REQUEST_DELAY)
        .for_unit_tests();

    let (latest_chain_tip, chain_tip_sender) = MockChainTip::new();
    chain_tip_sender.send_best_tip_height(tip_height);
    // Dropping the sender is fine: `watch::Receiver::borrow` keeps returning the height we just
    // sent, and no test changes the tip mid-run.

    let downloads = Downloads::new(
        MIN_CONCURRENCY_LIMIT,
        network.clone(),
        verifier.clone(),
        state.clone(),
        latest_chain_tip,
    );

    (downloads, network, verifier, state)
}

/// Load the mainnet block 1 vector, which these tests use as a low-height block body.
fn block_1() -> Arc<Block> {
    zebra_test::vectors::BLOCK_MAINNET_1_BYTES
        .zcash_deserialize_into()
        .expect("hard-coded block vector deserializes")
}

/// Load the mainnet block 2 vector.
fn block_2() -> Arc<Block> {
    zebra_test::vectors::BLOCK_MAINNET_2_BYTES
        .zcash_deserialize_into()
        .expect("hard-coded block vector deserializes")
}

/// Load the mainnet genesis block vector.
fn genesis() -> Arc<Block> {
    zebra_test::vectors::BLOCK_MAINNET_GENESIS_BYTES
        .zcash_deserialize_into()
        .expect("hard-coded block vector deserializes")
}

/// Load the mainnet block 10 vector, which the far-ahead tests use as a high-height block body.
fn block_10() -> Arc<Block> {
    zebra_test::vectors::BLOCK_MAINNET_10_BYTES
        .zcash_deserialize_into()
        .expect("hard-coded block vector deserializes")
}

/// The tip height that puts block 2 exactly on the lookahead limit.
///
/// The downloader accepts blocks up to `MIN_CONCURRENCY_LIMIT` above the tip, so block 10 is far
/// ahead of this tip, and block 2 is the highest block it still verifies.
fn lookahead_boundary_tip() -> Height {
    Height(2 - u32::try_from(MIN_CONCURRENCY_LIMIT).expect("small constant fits in u32"))
}

/// Regression test for GHSA-4f6v-mj46-gxg3: a gossiped body whose claimed height contradicts the
/// parent we already hold is attributed to the peer that supplied it, and never reaches consensus.
///
/// A peer can answer with a canonical header and rewritten coinbase height because the initial hash
/// check does not recompute the header's commitment to the body's authorizing data. The parent is
/// the proof: a block's height is one more than its parent's.
#[tokio::test]
async fn contradicted_behind_tip_height_is_attributed_and_never_verified() {
    let _init_guard = zebra_test::init();

    // The tip is far enough ahead that a claimed height of 1 is behind the reorg limit.
    let (mut downloads, mut network, mut verifier, mut state) =
        mock_downloads(Height(2 * MAX_BLOCK_REORG_HEIGHT));

    // Block 2's header with block 1's body: the hash and parent are block 2's, because the hash
    // covers only the header, but the coinbase now claims height 1 instead of 2. This is the shape
    // of the reported attack, without reproducing the hash-preserving rewrite itself.
    let block_1 = block_1();
    let block_2 = block_2();
    let block = Arc::new(Block {
        header: block_2.header.clone(),
        transactions: block_1.transactions.clone(),
    });
    let hash = block.hash();
    assert_eq!(
        hash,
        block_2.hash(),
        "the block hash covers only the header"
    );
    assert_eq!(
        block.coinbase_height(),
        Some(Height(1)),
        "the body must claim the height the downloader reads"
    );

    let advertiser: PeerSocketAddr = ADVERTISER.parse().expect("hard-coded address is valid");

    assert!(
        matches!(
            downloads.download_and_verify(hash, Some(advertiser)),
            DownloadAction::AddedToQueue
        ),
        "download is queued"
    );

    // The block is not already in the state.
    state
        .expect_request(zs::Request::KnownBlock(hash))
        .await
        .respond(zs::Response::KnownBlock(None));

    network
        .expect_request(zn::Request::BlocksByHash(iter::once(hash).collect()))
        .await
        .respond(zn::Response::Blocks(vec![Available((
            block.clone(),
            Some(advertiser),
        ))]));

    // We hold the real parent, block 1, so the body's real height is 2, not the 1 it claims.
    state
        .expect_request(zs::Request::BlockHeader(
            block.header.previous_block_hash.into(),
        ))
        .await
        .respond(zs::Response::BlockHeader {
            header: block_1.header.clone(),
            hash: block_1.hash(),
            height: Height(1),
            next_block_hash: Some(hash),
        });

    let (error, advertiser_addr) = downloads
        .next()
        .await
        .expect("downloads is non-empty")
        .expect_err("block behind the reorg limit is dropped");

    assert!(
        matches!(
            error.downcast_ref::<HeightLimitError>(),
            Some(HeightLimitError::BehindTip { .. })
        ),
        "a contradicted behind-tip height must be a scoreable typed error, but was: {error:?}"
    );
    assert_eq!(
        advertiser_addr,
        Some(advertiser),
        "a contradicted behind-tip height must attribute the drop to the supplying peer"
    );

    // The rewritten body is dropped before consensus validation, which is why the peer must be
    // scored on this path instead.
    verifier.expect_no_requests().await;
}

/// A peer that serves a genuinely old block is not attributed, so it cannot be scored.
///
/// Its height agrees with its parent's, so there is no proof of misbehaviour and the drop must stay
/// anonymous.
#[tokio::test]
async fn genuinely_old_block_is_dropped_without_attribution() {
    let _init_guard = zebra_test::init();

    let (mut downloads, mut network, mut verifier, mut state) =
        mock_downloads(Height(2 * MAX_BLOCK_REORG_HEIGHT));

    let block = block_1();
    let hash = block.hash();
    let advertiser: PeerSocketAddr = ADVERTISER.parse().expect("hard-coded address is valid");

    assert!(
        matches!(
            downloads.download_and_verify(hash, Some(advertiser)),
            DownloadAction::AddedToQueue
        ),
        "download is queued"
    );

    state
        .expect_request(zs::Request::KnownBlock(hash))
        .await
        .respond(zs::Response::KnownBlock(None));

    network
        .expect_request(zn::Request::BlocksByHash(iter::once(hash).collect()))
        .await
        .respond(zn::Response::Blocks(vec![Available((
            block.clone(),
            Some(advertiser),
        ))]));

    // The parent is genesis, one below the height the body claims: the body is authentic.
    let genesis = genesis();
    assert_eq!(
        block.header.previous_block_hash,
        genesis.hash(),
        "block 1's parent is genesis"
    );
    state
        .expect_request(zs::Request::BlockHeader(
            block.header.previous_block_hash.into(),
        ))
        .await
        .respond(zs::Response::BlockHeader {
            header: genesis.header.clone(),
            hash: genesis.hash(),
            height: Height(0),
            next_block_hash: Some(hash),
        });

    let (error, advertiser_addr) = downloads
        .next()
        .await
        .expect("downloads is non-empty")
        .expect_err("block behind the reorg limit is dropped");

    assert!(
        matches!(
            error.downcast_ref::<HeightLimitError>(),
            Some(HeightLimitError::BehindTip { .. })
        ),
        "an old block must still be a typed behind-tip error, but was: {error:?}"
    );
    assert_eq!(
        advertiser_addr, None,
        "an authentic old block must not be attributed to its peer"
    );

    verifier.expect_no_requests().await;
}

/// A peer whose old block has a parent we do not hold is not attributed either: without the parent
/// there is no proof the height was rewritten.
#[tokio::test]
async fn behind_tip_block_with_unknown_parent_is_not_attributed() {
    let _init_guard = zebra_test::init();

    let (mut downloads, mut network, mut verifier, mut state) =
        mock_downloads(Height(2 * MAX_BLOCK_REORG_HEIGHT));

    let block = block_1();
    let hash = block.hash();
    let advertiser: PeerSocketAddr = ADVERTISER.parse().expect("hard-coded address is valid");

    assert!(
        matches!(
            downloads.download_and_verify(hash, Some(advertiser)),
            DownloadAction::AddedToQueue
        ),
        "download is queued"
    );

    state
        .expect_request(zs::Request::KnownBlock(hash))
        .await
        .respond(zs::Response::KnownBlock(None));

    network
        .expect_request(zn::Request::BlocksByHash(iter::once(hash).collect()))
        .await
        .respond(zn::Response::Blocks(vec![Available((
            block.clone(),
            Some(advertiser),
        ))]));

    state
        .expect_request(zs::Request::BlockHeader(
            block.header.previous_block_hash.into(),
        ))
        .await
        .respond(Err(zn::BoxError::from("block not found in any chain")));

    let (error, advertiser_addr) = downloads
        .next()
        .await
        .expect("downloads is non-empty")
        .expect_err("block behind the reorg limit is dropped");

    assert!(
        matches!(
            error.downcast_ref::<HeightLimitError>(),
            Some(HeightLimitError::BehindTip { .. })
        ),
        "a behind-tip drop must be a typed error, but was: {error:?}"
    );
    assert_eq!(
        advertiser_addr, None,
        "a block whose parent we do not hold must not be attributed"
    );

    verifier.expect_no_requests().await;
}

/// The parent lookup is bounded: when the state does not answer, the block is still dropped and the
/// peer is still not attributed.
///
/// Paused time lets the runtime advance past `PARENT_LOOKUP_TIMEOUT` as soon as the download task is
/// the only thing waiting, so the test does not sleep for real.
#[tokio::test(start_paused = true)]
async fn behind_tip_parent_lookup_timeout_is_not_attributed() {
    let _init_guard = zebra_test::init();

    let (mut downloads, mut network, mut verifier, mut state) =
        mock_downloads(Height(2 * MAX_BLOCK_REORG_HEIGHT));

    let block = block_1();
    let hash = block.hash();
    let advertiser: PeerSocketAddr = ADVERTISER.parse().expect("hard-coded address is valid");

    assert!(
        matches!(
            downloads.download_and_verify(hash, Some(advertiser)),
            DownloadAction::AddedToQueue
        ),
        "download is queued"
    );

    state
        .expect_request(zs::Request::KnownBlock(hash))
        .await
        .respond(zs::Response::KnownBlock(None));

    network
        .expect_request(zn::Request::BlocksByHash(iter::once(hash).collect()))
        .await
        .respond(zn::Response::Blocks(vec![Available((
            block.clone(),
            Some(advertiser),
        ))]));

    // The parent lookup is deliberately never answered, so it can only end by timing out.
    let (error, advertiser_addr) = downloads
        .next()
        .await
        .expect("downloads is non-empty")
        .expect_err("block behind the reorg limit is dropped");

    assert!(
        matches!(
            error.downcast_ref::<HeightLimitError>(),
            Some(HeightLimitError::BehindTip { .. })
        ),
        "a timed-out lookup must still drop with a typed error, but was: {error:?}"
    );
    assert_eq!(
        advertiser_addr, None,
        "a timed-out parent lookup must not attribute the drop"
    );

    verifier.expect_no_requests().await;
}

/// A block at the oldest height that is still within the reorg limit is verified, not dropped.
///
/// This is the guard against dropping and attributing honest near-boundary blocks:
/// `min_accepted_height` is the boundary, and the behind-tip comparison is strict, so a block
/// exactly on it is a normal download and the parent is never consulted.
#[tokio::test]
async fn block_at_reorg_boundary_is_verified_not_dropped() {
    let _init_guard = zebra_test::init();

    // `min_accepted_height` is `Height(1)`, so the height-1 block sits exactly on the boundary.
    let (mut downloads, mut network, mut verifier, mut state) =
        mock_downloads(Height(MAX_BLOCK_REORG_HEIGHT + 1));

    let block = block_1();
    let hash = block.hash();
    let advertiser: PeerSocketAddr = ADVERTISER.parse().expect("hard-coded address is valid");

    assert!(
        matches!(
            downloads.download_and_verify(hash, Some(advertiser)),
            DownloadAction::AddedToQueue
        ),
        "download is queued"
    );

    state
        .expect_request(zs::Request::KnownBlock(hash))
        .await
        .respond(zs::Response::KnownBlock(None));

    network
        .expect_request(zn::Request::BlocksByHash(iter::once(hash).collect()))
        .await
        .respond(zn::Response::Blocks(vec![Available((
            block.clone(),
            Some(advertiser),
        ))]));

    verifier
        .expect_request(zebra_consensus::Request::Commit(block))
        .await
        .respond(hash);

    assert_eq!(
        downloads
            .next()
            .await
            .expect("downloads is non-empty")
            .expect("block on the reorg boundary is verified"),
        hash,
        "a block at min_accepted_height must be verified, not dropped as behind the tip"
    );

    // The parent lookup only runs on the behind-tip drop path, so a boundary block must not trigger
    // one.
    state.expect_no_requests().await;
}

/// The far-ahead sibling of the regression test for GHSA-4f6v-mj46-gxg3: a gossiped body whose
/// claimed height is above the lookahead limit, and contradicts the parent we already hold, is
/// attributed to the peer that supplied it, and never reaches consensus.
///
/// The sync path deliberately leaves its far-ahead drops unscored (GHSA-qhr3-cvch-5fh2), because
/// the serving peer did not choose the height of a genuine block. Here the parent is the proof, so
/// scoring is safe: a genuine block whose parent we hold is at most one above the tip, so its real
/// height is never far ahead.
#[tokio::test]
async fn contradicted_far_ahead_height_is_attributed_and_never_verified() {
    let _init_guard = zebra_test::init();

    let (mut downloads, mut network, mut verifier, mut state) =
        mock_downloads(lookahead_boundary_tip());

    // Block 2's header with block 10's body: the hash and parent are block 2's, because the hash
    // covers only the header, but the coinbase now claims height 10 instead of 2.
    let block_2 = block_2();
    let block_10 = block_10();
    let block = Arc::new(Block {
        header: block_2.header.clone(),
        transactions: block_10.transactions.clone(),
    });
    let hash = block.hash();
    assert_eq!(
        hash,
        block_2.hash(),
        "the block hash covers only the header"
    );
    assert_eq!(
        block.coinbase_height(),
        Some(Height(10)),
        "the body must claim the height the downloader reads"
    );

    let advertiser: PeerSocketAddr = ADVERTISER.parse().expect("hard-coded address is valid");

    assert!(
        matches!(
            downloads.download_and_verify(hash, Some(advertiser)),
            DownloadAction::AddedToQueue
        ),
        "download is queued"
    );

    state
        .expect_request(zs::Request::KnownBlock(hash))
        .await
        .respond(zs::Response::KnownBlock(None));

    network
        .expect_request(zn::Request::BlocksByHash(iter::once(hash).collect()))
        .await
        .respond(zn::Response::Blocks(vec![Available((
            block.clone(),
            Some(advertiser),
        ))]));

    // We hold the real parent, block 1, so the body's real height is 2, not the 10 it claims.
    let block_1 = block_1();
    state
        .expect_request(zs::Request::BlockHeader(
            block.header.previous_block_hash.into(),
        ))
        .await
        .respond(zs::Response::BlockHeader {
            header: block_1.header.clone(),
            hash: block_1.hash(),
            height: Height(1),
            next_block_hash: Some(hash),
        });

    let (error, advertiser_addr) = downloads
        .next()
        .await
        .expect("downloads is non-empty")
        .expect_err("block above the lookahead limit is dropped");

    assert!(
        matches!(
            error.downcast_ref::<HeightLimitError>(),
            Some(HeightLimitError::AboveLookahead { .. })
        ),
        "a contradicted far-ahead height must be a scoreable typed error, but was: {error:?}"
    );
    assert_eq!(
        advertiser_addr,
        Some(advertiser),
        "a contradicted far-ahead height must attribute the drop to the supplying peer"
    );

    verifier.expect_no_requests().await;
}

/// A peer that serves a genuinely far-ahead block is not attributed, so it cannot be scored.
///
/// This is the common case while Zebra is catching up: the block's parent is not in the state yet,
/// so there is no proof of misbehaviour and the drop must stay anonymous.
#[tokio::test]
async fn genuinely_far_ahead_block_is_dropped_without_attribution() {
    let _init_guard = zebra_test::init();

    let (mut downloads, mut network, mut verifier, mut state) =
        mock_downloads(lookahead_boundary_tip());

    let block = block_10();
    let hash = block.hash();
    let advertiser: PeerSocketAddr = ADVERTISER.parse().expect("hard-coded address is valid");

    assert!(
        matches!(
            downloads.download_and_verify(hash, Some(advertiser)),
            DownloadAction::AddedToQueue
        ),
        "download is queued"
    );

    state
        .expect_request(zs::Request::KnownBlock(hash))
        .await
        .respond(zs::Response::KnownBlock(None));

    network
        .expect_request(zn::Request::BlocksByHash(iter::once(hash).collect()))
        .await
        .respond(zn::Response::Blocks(vec![Available((
            block.clone(),
            Some(advertiser),
        ))]));

    // The parent, block 9, is far ahead too, so we do not hold it.
    state
        .expect_request(zs::Request::BlockHeader(
            block.header.previous_block_hash.into(),
        ))
        .await
        .respond(Err(zn::BoxError::from("block hash or height not found")));

    let (error, advertiser_addr) = downloads
        .next()
        .await
        .expect("downloads is non-empty")
        .expect_err("block above the lookahead limit is dropped");

    assert!(
        matches!(
            error.downcast_ref::<HeightLimitError>(),
            Some(HeightLimitError::AboveLookahead { .. })
        ),
        "a far-ahead drop must be a typed error, but was: {error:?}"
    );
    assert_eq!(
        advertiser_addr, None,
        "a genuinely far-ahead block must not be attributed to its peer"
    );

    verifier.expect_no_requests().await;
}

/// A block at the highest height that is still within the lookahead limit is verified, not dropped.
///
/// This is the guard against dropping and attributing honest near-boundary blocks:
/// `max_lookahead_height` is the boundary, and the far-ahead comparison is strict, so a block exactly
/// on it is a normal download and the parent is never consulted.
#[tokio::test]
async fn block_at_lookahead_boundary_is_verified_not_dropped() {
    let _init_guard = zebra_test::init();

    let (mut downloads, mut network, mut verifier, mut state) =
        mock_downloads(lookahead_boundary_tip());

    let block = block_2();
    let hash = block.hash();
    let advertiser: PeerSocketAddr = ADVERTISER.parse().expect("hard-coded address is valid");

    assert!(
        matches!(
            downloads.download_and_verify(hash, Some(advertiser)),
            DownloadAction::AddedToQueue
        ),
        "download is queued"
    );

    state
        .expect_request(zs::Request::KnownBlock(hash))
        .await
        .respond(zs::Response::KnownBlock(None));

    network
        .expect_request(zn::Request::BlocksByHash(iter::once(hash).collect()))
        .await
        .respond(zn::Response::Blocks(vec![Available((
            block.clone(),
            Some(advertiser),
        ))]));

    verifier
        .expect_request(zebra_consensus::Request::Commit(block))
        .await
        .respond(hash);

    assert_eq!(
        downloads
            .next()
            .await
            .expect("downloads is non-empty")
            .expect("block on the lookahead boundary is verified"),
        hash,
        "a block at max_lookahead_height must be verified, not dropped as far ahead"
    );

    // The parent lookup only runs on the height limit drop paths, so a boundary block must not
    // trigger one.
    state.expect_no_requests().await;
}