/// Returns true if the next transaction should be throttled due to high
/// load on the ledger.
Returns true if the next transaction should be throttled due to high
load on the ledger.
Returns true if the next transaction should be throttled due to high load on the ledger .
fn throttle(&self, now: TimeStamp) -> bool {
        let num_in_window = self.transactions_by_height.len();
        // We admit the first half of max_transactions_in_window freely.
        // After that we start throttling on per-second basis.
        // This way we guarantee that at most max_transactions_in_window will
        // get through within the transaction window.
        if num_in_window >= self.max_transactions_in_window / 2 {
            // max num of transactions allowed per second
            let max_rate = (0.5 * self.max_transactions_in_window as f64
                / self.transaction_window.as_secs_f64())
            .ceil() as usize;
            if self
                .transactions_by_height
                .get(num_in_window.saturating_sub(max_rate))
                .map(|x| x.block_timestamp)
                .unwrap_or_else(|| TimeStamp::from_nanos_since_unix_epoch(0))
                + Duration::from_secs(1)
                > now
            {
                return true;
            }
        }
        false
    }
fn throttle ( & self , now : TimeStamp ) -> bool { let num_in_window = self . transactions_by_height . len ( ) ; // We admit the first half of max_transactions_in_window freely. // After that we start throttling on per-second basis. // This way we guarantee that at most max_transactions_in_window will // get through within the transaction window. if num_in_window >= self . max_transactions_in_window / 2 { // max num of transactions allowed per second let max_rate = ( 0.5 * self . max_transactions_in_window as f64 / self . transaction_window . as_secs_f64 ( ) ) . ceil ( ) as usize ; if self . transactions_by_height . get ( num_in_window . saturating_sub ( max_rate ) ) . map ( | x | x . block_timestamp ) . unwrap_or_else ( | | TimeStamp :: from_nanos_since_unix_epoch ( 0 ) ) + Duration :: from_secs ( 1 ) > now { return true ; } } false }
Returns true if the next transaction should be throttled due to high
load on the ledger.
Returns true if the next transaction should be throttled due to high load on the ledger .
&self
now
TimeStamp