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:
parent
889e7c668e
commit
f6641eaaee
|
|
@ -35,7 +35,7 @@ use crate::{
|
||||||
gossip_mempool_transaction_id, unmined_transactions_in_blocks, Config as MempoolConfig,
|
gossip_mempool_transaction_id, unmined_transactions_in_blocks, Config as MempoolConfig,
|
||||||
Mempool, MempoolError, SameEffectsChainRejectionError, UnboxMempoolError,
|
Mempool, MempoolError, SameEffectsChainRejectionError, UnboxMempoolError,
|
||||||
},
|
},
|
||||||
sync::{self, BlockGossipError, SyncStatus, TIPS_RESPONSE_TIMEOUT},
|
sync::{self, BlockGossipError, SyncStatus, PEER_GOSSIP_DELAY},
|
||||||
},
|
},
|
||||||
BoxError,
|
BoxError,
|
||||||
};
|
};
|
||||||
|
|
@ -421,7 +421,7 @@ async fn mempool_transaction_expiration() -> Result<(), crate::BoxError> {
|
||||||
hs.insert(tx1_id);
|
hs.insert(tx1_id);
|
||||||
|
|
||||||
// Transaction and Block IDs are gossipped, in any order, after waiting for the gossip delay
|
// 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 [
|
let possible_requests = &mut [
|
||||||
Request::AdvertiseTransactionIds(hs),
|
Request::AdvertiseTransactionIds(hs),
|
||||||
Request::AdvertiseBlock(block_two.hash()),
|
Request::AdvertiseBlock(block_two.hash()),
|
||||||
|
|
@ -490,7 +490,7 @@ async fn mempool_transaction_expiration() -> Result<(), crate::BoxError> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Test the block is gossiped, after waiting for the multi-gossip delay
|
// 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
|
peer_set
|
||||||
.expect_request(Request::AdvertiseBlock(block_three.hash()))
|
.expect_request(Request::AdvertiseBlock(block_three.hash()))
|
||||||
.await
|
.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
|
// 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();
|
let mut hs = HashSet::new();
|
||||||
hs.insert(tx2_id);
|
hs.insert(tx2_id);
|
||||||
|
|
@ -598,7 +598,7 @@ async fn mempool_transaction_expiration() -> Result<(), crate::BoxError> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Test the block is gossiped, after waiting for the multi-gossip delay
|
// 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
|
peer_set
|
||||||
.expect_request(Request::AdvertiseBlock(block.hash()))
|
.expect_request(Request::AdvertiseBlock(block.hash()))
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@ use zebra_network::MAX_TX_INV_IN_SENT_MESSAGE;
|
||||||
|
|
||||||
use zebra_network as zn;
|
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.
|
/// The maximum number of channel messages we will combine into a single peer broadcast.
|
||||||
pub const MAX_CHANGES_BEFORE_SEND: usize = 10;
|
pub const MAX_CHANGES_BEFORE_SEND: usize = 10;
|
||||||
|
|
@ -96,6 +99,6 @@ where
|
||||||
//
|
//
|
||||||
// in practice, transactions arrive every 1-20 seconds,
|
// in practice, transactions arrive every 1-20 seconds,
|
||||||
// so waiting 6 seconds can delay transaction propagation, in order to reduce peer load
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,16 @@ pub const MAX_TIPS_RESPONSE_HASH_COUNT: usize = 500;
|
||||||
/// failure loop.
|
/// failure loop.
|
||||||
pub const TIPS_RESPONSE_TIMEOUT: Duration = Duration::from_secs(6);
|
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.
|
/// Controls how long we wait for a block download request to complete.
|
||||||
///
|
///
|
||||||
/// This timeout makes sure that the syncer doesn't hang when:
|
/// This timeout makes sure that the syncer doesn't hang when:
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,10 @@ use tower::{timeout::Timeout, Service, ServiceExt};
|
||||||
use zebra_network as zn;
|
use zebra_network as zn;
|
||||||
use zebra_state::ChainTipChange;
|
use zebra_state::ChainTipChange;
|
||||||
|
|
||||||
use crate::BoxError;
|
use crate::{
|
||||||
|
components::sync::{SyncStatus, PEER_GOSSIP_DELAY, TIPS_RESPONSE_TIMEOUT},
|
||||||
use super::{SyncStatus, TIPS_RESPONSE_TIMEOUT};
|
BoxError,
|
||||||
|
};
|
||||||
|
|
||||||
use BlockGossipError::*;
|
use BlockGossipError::*;
|
||||||
|
|
||||||
|
|
@ -90,6 +91,6 @@ where
|
||||||
//
|
//
|
||||||
// in practice, we expect blocks to arrive approximately every 75 seconds,
|
// in practice, we expect blocks to arrive approximately every 75 seconds,
|
||||||
// so waiting 6 seconds won't make much difference
|
// so waiting 6 seconds won't make much difference
|
||||||
tokio::time::sleep(TIPS_RESPONSE_TIMEOUT).await;
|
tokio::time::sleep(PEER_GOSSIP_DELAY).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue