Skip to content

Commit

Permalink
Respond to suggestions on the pull request, no longer using reference…
Browse files Browse the repository at this point in the history
…s for Instant and Duration
  • Loading branch information
NotGyro committed Apr 8, 2023
1 parent dfece1e commit 1a6bc0b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions consensus/service/src/api/client_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ impl ClientSessionTracking {
/// of an individual tx proposal failure incident for? Any records which
/// have existed for longer than this value will be dropped when this
/// method is called.
pub fn fail_tx_proposal(&mut self, now: &Instant, tracking_window: &Duration) -> usize {
pub fn fail_tx_proposal(&mut self, now: Instant, tracking_window: Duration) -> usize {
self.tx_proposal_failures.retain(|past_failure| {
now.saturating_duration_since(*past_failure) <= *tracking_window
now.saturating_duration_since(*past_failure) <= tracking_window
});
self.tx_proposal_failures.push_back(*now);
self.tx_proposal_failures.push_back(now);
self.tx_proposal_failures.len()
}
}
Expand Down Expand Up @@ -140,7 +140,9 @@ impl ClientApiService {
if let TxManagerError::TransactionValidation(cause) = &err {
counters::TX_VALIDATION_ERROR_COUNTER.inc(&format!("{cause:?}"));

let tracking_window = Duration::from_secs(5); // TODO, placeholder before draft PR gets published.
// This will become a proper config option, already implemented
// in pull request #3296 "Failure limit on tx proposals"
let tracking_window = Duration::from_secs(60);
let mut tracker = self.tracked_sessions.lock().expect("Mutex poisoned");
if !tracker.contains(&session_id) {
tracker.put(session_id.clone(), ClientSessionTracking::new());
Expand All @@ -149,9 +151,9 @@ impl ClientApiService {
tracker.get_mut(&session_id).expect("Session id {session_id} should be tracked.");

let _recent_failure_count =
record.fail_tx_proposal(&Instant::now(), &tracking_window);
// TODO: drop session when recent_failure_count reaches some
// number
record.fail_tx_proposal(Instant::now(), tracking_window);
// Dropping the client after a limit has been reached will be
// implemented in a future pull request.
}
err
})?;
Expand Down

0 comments on commit 1a6bc0b

Please sign in to comment.