Skip to content

Commit

Permalink
Renames and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
coderofstuff committed Jan 7, 2024
1 parent 8b168cd commit 77b1952
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion protocol/flows/src/flowcontext/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ impl TransactionsSpread {

async fn broadcast(&self, msg: KaspadMessage, should_throttle: bool) {
if should_throttle {
self.hub.broadcast_some(msg, 0.5).await
// Broadcast to only half of the peers
// TODO: Figure out the better percentage
self.hub.broadcast_to_some_peers(msg, 0.5).await
} else {
self.hub.broadcast(msg).await
}
Expand Down
6 changes: 3 additions & 3 deletions protocol/flows/src/v5/txrelay/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ impl RelayTransactionsFlow {

if snapshot_delta.low_priority_tx_counts > 0 {
let tps = snapshot_delta.low_priority_tx_counts / 10;
if tps > MAX_TPS_THRESHOLD {
if !should_throttle && tps > MAX_TPS_THRESHOLD {
warn!("P2P tx relay threshold exceeded. Throttling relay. Current: {}, Max: {}", tps, MAX_TPS_THRESHOLD);
should_throttle = true;
} else if tps < MAX_TPS_THRESHOLD / 2 && should_throttle {
} else if should_throttle && tps < MAX_TPS_THRESHOLD / 2 {
warn!("P2P tx relay threshold back to normal. Current: {}, Max: {}", tps, MAX_TPS_THRESHOLD);
should_throttle = false;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ impl RelayTransactionsFlow {
// To reduce the P2P TPS to below the threshold, we need to request up to a max of
// whatever the balances overage. If MAX_TPS_THRESHOLD is 3000 and the current TPS is 4000,
// then we can only request up to 2000 (MAX - (4000 - 3000)) to average out into the threshold.
let curr_p2p_tps = snapshot_delta.low_priority_tx_counts / (snapshot_delta.elapsed_time.as_millis().max(1) as u64);
let curr_p2p_tps = 1000 * snapshot_delta.low_priority_tx_counts / (snapshot_delta.elapsed_time.as_millis().max(1) as u64);
let overage = if should_throttle && curr_p2p_tps > MAX_TPS_THRESHOLD { curr_p2p_tps - MAX_TPS_THRESHOLD } else { 0 };

let limit = MAX_TPS_THRESHOLD - overage;
Expand Down
2 changes: 1 addition & 1 deletion protocol/p2p/src/core/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Hub {
}

/// Broadcast a message to some peers given a percentage
pub async fn broadcast_some(&self, msg: KaspadMessage, percentage: f64) {
pub async fn broadcast_to_some_peers(&self, msg: KaspadMessage, percentage: f64) {
let percentage = percentage.clamp(0.0, 1.0);

let peers = self.peers.read().values().cloned().collect::<Vec<_>>();
Expand Down

0 comments on commit 77b1952

Please sign in to comment.