mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 12:51:05 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -21,13 +21,8 @@
|
||||
//! Keeps only recent extrinsic and discard the ones kept for a significant amount of time.
|
||||
//! Discarded extrinsics are banned so that they don't get re-imported again.
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
hash,
|
||||
iter,
|
||||
time::Duration,
|
||||
};
|
||||
use parking_lot::RwLock;
|
||||
use std::{collections::HashMap, hash, iter, time::Duration};
|
||||
use wasm_timer::Instant;
|
||||
|
||||
use super::base_pool::Transaction;
|
||||
@@ -48,10 +43,7 @@ pub struct PoolRotator<Hash> {
|
||||
|
||||
impl<Hash: hash::Hash + Eq> Default for PoolRotator<Hash> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
ban_time: Duration::from_secs(60 * 30),
|
||||
banned_until: Default::default(),
|
||||
}
|
||||
Self { ban_time: Duration::from_secs(60 * 30), banned_until: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +54,7 @@ impl<Hash: hash::Hash + Eq + Clone> PoolRotator<Hash> {
|
||||
}
|
||||
|
||||
/// Bans given set of hashes.
|
||||
pub fn ban(&self, now: &Instant, hashes: impl IntoIterator<Item=Hash>) {
|
||||
pub fn ban(&self, now: &Instant, hashes: impl IntoIterator<Item = Hash>) {
|
||||
let mut banned = self.banned_until.write();
|
||||
|
||||
for hash in hashes {
|
||||
@@ -81,9 +73,14 @@ impl<Hash: hash::Hash + Eq + Clone> PoolRotator<Hash> {
|
||||
/// Bans extrinsic if it's stale.
|
||||
///
|
||||
/// Returns `true` if extrinsic is stale and got banned.
|
||||
pub fn ban_if_stale<Ex>(&self, now: &Instant, current_block: u64, xt: &Transaction<Hash, Ex>) -> bool {
|
||||
pub fn ban_if_stale<Ex>(
|
||||
&self,
|
||||
now: &Instant,
|
||||
current_block: u64,
|
||||
xt: &Transaction<Hash, Ex>,
|
||||
) -> bool {
|
||||
if xt.valid_till > current_block {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
self.ban(now, iter::once(xt.hash.clone()));
|
||||
@@ -107,10 +104,7 @@ mod tests {
|
||||
type Ex = ();
|
||||
|
||||
fn rotator() -> PoolRotator<Hash> {
|
||||
PoolRotator {
|
||||
ban_time: Duration::from_millis(10),
|
||||
..Default::default()
|
||||
}
|
||||
PoolRotator { ban_time: Duration::from_millis(10), ..Default::default() }
|
||||
}
|
||||
|
||||
fn tx() -> (Hash, Transaction<Hash, Ex>) {
|
||||
@@ -160,7 +154,6 @@ mod tests {
|
||||
assert!(rotator.is_banned(&hash));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn should_clear_banned() {
|
||||
// given
|
||||
@@ -201,14 +194,14 @@ mod tests {
|
||||
let past_block = 0;
|
||||
|
||||
// when
|
||||
for i in 0..2*EXPECTED_SIZE {
|
||||
for i in 0..2 * EXPECTED_SIZE {
|
||||
let tx = tx_with(i as u64, past_block);
|
||||
assert!(rotator.ban_if_stale(&now, past_block, &tx));
|
||||
}
|
||||
assert_eq!(rotator.banned_until.read().len(), 2*EXPECTED_SIZE);
|
||||
assert_eq!(rotator.banned_until.read().len(), 2 * EXPECTED_SIZE);
|
||||
|
||||
// then
|
||||
let tx = tx_with(2*EXPECTED_SIZE as u64, past_block);
|
||||
let tx = tx_with(2 * EXPECTED_SIZE as u64, past_block);
|
||||
// trigger a garbage collection
|
||||
assert!(rotator.ban_if_stale(&now, past_block, &tx));
|
||||
assert_eq!(rotator.banned_until.read().len(), EXPECTED_SIZE);
|
||||
|
||||
Reference in New Issue
Block a user