From 9a1065de5527e1c682c8cfc1bd07c3384a43ff0f Mon Sep 17 00:00:00 2001 From: arya2 Date: Wed, 30 Nov 2022 21:04:54 -0500 Subject: [PATCH 1/2] moves mempool.enable below peer_set.expect_request --- .../components/inbound/tests/fake_peer_set.rs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/zebrad/src/components/inbound/tests/fake_peer_set.rs b/zebrad/src/components/inbound/tests/fake_peer_set.rs index e50484870f2..53ef3e68e58 100644 --- a/zebrad/src/components/inbound/tests/fake_peer_set.rs +++ b/zebrad/src/components/inbound/tests/fake_peer_set.rs @@ -78,13 +78,11 @@ async fn mempool_requests_for_transactions() { .await; match response { Ok(Response::TransactionIds(response)) => assert_eq!(response, added_transaction_ids), - Ok(Response::Nil) => if !added_transaction_ids.is_empty() { - info!( - "response {response:?} to `MempoolTransactionIds` request \ - should match added_transaction_ids {added_transaction_ids:?}, \ - ignoring test failure because this test is unreliable due to timing issues", - ); - } + Ok(Response::Nil) => assert!( + added_transaction_ids.is_empty(), + "`MempoolTransactionIds` request should match added_transaction_ids {:?}, got Ok(Nil)", + added_transaction_ids + ), _ => unreachable!( "`MempoolTransactionIds` requests should always respond `Ok(Vec | Nil)`, got {:?}", response @@ -869,9 +867,6 @@ async fn setup( chain_tip_change.clone(), ); - // Enable the mempool - mempool_service.enable(&mut recent_syncs).await; - let sync_gossip_task_handle = tokio::spawn(sync::gossip_best_tip_block_hashes( sync_status.clone(), chain_tip_change.clone(), @@ -894,6 +889,13 @@ async fn setup( .respond(Response::Nil); } + // Enable the mempool + // Note: this needs to be done after the mock peer set service has received the AdvertiseBlock + // request to ensure that the call to `last_tip_change` returns the chain tip block for block_one + // and not the genesis block, or else the transactions from the genesis block will be added to + // the mempool storage's rejection list and tests will fail. + mempool_service.enable(&mut recent_syncs).await; + // Add transactions to the mempool, skipping verification and broadcast let mut added_transactions = Vec::new(); if add_transactions { From fb0d312e8a1daf1b842813db36cf31e3fe17baef Mon Sep 17 00:00:00 2001 From: arya2 Date: Wed, 30 Nov 2022 22:12:39 -0500 Subject: [PATCH 2/2] adds `sync_close_to_tip` call before starting gossip_best_tip_block_hashes task --- zebrad/src/components/inbound/tests/fake_peer_set.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zebrad/src/components/inbound/tests/fake_peer_set.rs b/zebrad/src/components/inbound/tests/fake_peer_set.rs index 53ef3e68e58..337e674405d 100644 --- a/zebrad/src/components/inbound/tests/fake_peer_set.rs +++ b/zebrad/src/components/inbound/tests/fake_peer_set.rs @@ -855,7 +855,8 @@ async fn setup( .unwrap(); committed_blocks.push(block_one); - // Don't wait for the chain tip update here, we wait for AdvertiseBlock below. + // Don't wait for the chain tip update here, we wait for expect_request(AdvertiseBlock) below, + // which is called by the gossip_best_tip_block_hashes task once the chain tip changes. let (mut mempool_service, transaction_receiver) = Mempool::new( &MempoolConfig::default(), @@ -867,6 +868,9 @@ async fn setup( chain_tip_change.clone(), ); + // Pretend we're close to tip + SyncStatus::sync_close_to_tip(&mut recent_syncs); + let sync_gossip_task_handle = tokio::spawn(sync::gossip_best_tip_block_hashes( sync_status.clone(), chain_tip_change.clone(),