cleanup(gossip): Use a separate named constant for the gossip interval (#6704)

* Use a named consttant for the gossip interval

* Update tests

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
teor 2023-05-23 05:21:53 +10:00 committed by GitHub
parent 889e7c668e
commit f6641eaaee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 11 deletions

View File

@ -35,7 +35,7 @@ use crate::{
gossip_mempool_transaction_id, unmined_transactions_in_blocks, Config as MempoolConfig,
Mempool, MempoolError, SameEffectsChainRejectionError, UnboxMempoolError,
},
sync::{self, BlockGossipError, SyncStatus, TIPS_RESPONSE_TIMEOUT},
sync::{self, BlockGossipError, SyncStatus, PEER_GOSSIP_DELAY},
},
BoxError,
};
@ -421,7 +421,7 @@ async fn mempool_transaction_expiration() -> Result<(), crate::BoxError> {
hs.insert(tx1_id);
// Transaction and Block IDs are gossipped, in any order, after waiting for the gossip delay
tokio::time::sleep(TIPS_RESPONSE_TIMEOUT).await;
tokio::time::sleep(PEER_GOSSIP_DELAY).await;
let possible_requests = &mut [
Request::AdvertiseTransactionIds(hs),
Request::AdvertiseBlock(block_two.hash()),
@ -490,7 +490,7 @@ async fn mempool_transaction_expiration() -> Result<(), crate::BoxError> {
.unwrap();
// Test the block is gossiped, after waiting for the multi-gossip delay
tokio::time::sleep(TIPS_RESPONSE_TIMEOUT).await;
tokio::time::sleep(PEER_GOSSIP_DELAY).await;
peer_set
.expect_request(Request::AdvertiseBlock(block_three.hash()))
.await
@ -567,7 +567,7 @@ async fn mempool_transaction_expiration() -> Result<(), crate::BoxError> {
);
// Test transaction 2 is gossiped, after waiting for the multi-gossip delay
tokio::time::sleep(TIPS_RESPONSE_TIMEOUT).await;
tokio::time::sleep(PEER_GOSSIP_DELAY).await;
let mut hs = HashSet::new();
hs.insert(tx2_id);
@ -598,7 +598,7 @@ async fn mempool_transaction_expiration() -> Result<(), crate::BoxError> {
.unwrap();
// Test the block is gossiped, after waiting for the multi-gossip delay
tokio::time::sleep(TIPS_RESPONSE_TIMEOUT).await;
tokio::time::sleep(PEER_GOSSIP_DELAY).await;
peer_set
.expect_request(Request::AdvertiseBlock(block.hash()))
.await

View File

@ -16,7 +16,10 @@ use zebra_network::MAX_TX_INV_IN_SENT_MESSAGE;
use zebra_network as zn;
use crate::{components::sync::TIPS_RESPONSE_TIMEOUT, BoxError};
use crate::{
components::sync::{PEER_GOSSIP_DELAY, TIPS_RESPONSE_TIMEOUT},
BoxError,
};
/// The maximum number of channel messages we will combine into a single peer broadcast.
pub const MAX_CHANGES_BEFORE_SEND: usize = 10;
@ -96,6 +99,6 @@ where
//
// in practice, transactions arrive every 1-20 seconds,
// so waiting 6 seconds can delay transaction propagation, in order to reduce peer load
tokio::time::sleep(TIPS_RESPONSE_TIMEOUT).await;
tokio::time::sleep(PEER_GOSSIP_DELAY).await;
}
}

View File

@ -107,6 +107,16 @@ pub const MAX_TIPS_RESPONSE_HASH_COUNT: usize = 500;
/// failure loop.
pub const TIPS_RESPONSE_TIMEOUT: Duration = Duration::from_secs(6);
/// Controls how long we wait between gossiping successive blocks or transactions.
///
/// ## Correctness
///
/// If this timeout is set too high, blocks and transactions won't propagate through
/// the network efficiently.
///
/// If this timeout is set too low, the peer set and remote peers can get overloaded.
pub const PEER_GOSSIP_DELAY: Duration = Duration::from_secs(7);
/// Controls how long we wait for a block download request to complete.
///
/// This timeout makes sure that the syncer doesn't hang when:

View File

@ -9,9 +9,10 @@ use tower::{timeout::Timeout, Service, ServiceExt};
use zebra_network as zn;
use zebra_state::ChainTipChange;
use crate::BoxError;
use super::{SyncStatus, TIPS_RESPONSE_TIMEOUT};
use crate::{
components::sync::{SyncStatus, PEER_GOSSIP_DELAY, TIPS_RESPONSE_TIMEOUT},
BoxError,
};
use BlockGossipError::*;
@ -90,6 +91,6 @@ where
//
// in practice, we expect blocks to arrive approximately every 75 seconds,
// so waiting 6 seconds won't make much difference
tokio::time::sleep(TIPS_RESPONSE_TIMEOUT).await;
tokio::time::sleep(PEER_GOSSIP_DELAY).await;
}
}