mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Further expand clippy workspace lints
Achieves a notable amount of reduced async and clones.
This commit is contained in:
@@ -24,7 +24,7 @@ use crate::common::{tx::publish_tx, validator_sets::set_keys};
|
||||
pub async fn provide_batch(serai: &Serai, batch: Batch) -> [u8; 32] {
|
||||
// TODO: Get the latest session
|
||||
let set = ValidatorSet { session: Session(0), network: batch.network };
|
||||
let pair = insecure_pair_from_name(&format!("ValidatorSet {:?}", set));
|
||||
let pair = insecure_pair_from_name(&format!("ValidatorSet {set:?}"));
|
||||
let keys = if let Some(keys) =
|
||||
serai.as_of_latest_finalized_block().await.unwrap().validator_sets().keys(set).await.unwrap()
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ pub async fn set_keys(serai: &Serai, set: ValidatorSet, key_pair: KeyPair) -> [u
|
||||
&mut OsRng,
|
||||
frost::tests::algorithm_machines(
|
||||
&mut OsRng,
|
||||
Schnorrkel::new(b"substrate"),
|
||||
&Schnorrkel::new(b"substrate"),
|
||||
&HashMap::from([(threshold_keys.params().i(), threshold_keys.into())]),
|
||||
),
|
||||
&set_keys_message(&set, &[], &key_pair),
|
||||
|
||||
@@ -12,7 +12,8 @@ impl AllowMint for () {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)] // TODO: Investigate why Substrate generates this
|
||||
// TODO: Investigate why Substrate generates this
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
@@ -94,7 +94,8 @@ use sp_std::prelude::*;
|
||||
pub use types::*;
|
||||
pub use weights::WeightInfo;
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)] // TODO: Investigate why Substrate generates this
|
||||
// TODO: Investigate why Substrate generates these
|
||||
#[allow(clippy::cast_possible_truncation, clippy::no_effect_underscore_binding)]
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
@@ -74,7 +74,7 @@ fn check_pool_accounts_dont_collide() {
|
||||
for coin in coins() {
|
||||
let account = Dex::get_pool_account(coin);
|
||||
if map.contains(&account) {
|
||||
panic!("Collision at {:?}", coin);
|
||||
panic!("Collision at {coin:?}");
|
||||
}
|
||||
map.insert(account);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ use serai_primitives::{BlockHash, NetworkId};
|
||||
pub use in_instructions_primitives as primitives;
|
||||
use primitives::*;
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)] // TODO: Investigate why Substrate generates this
|
||||
// TODO: Investigate why Substrate generates these
|
||||
#[allow(clippy::cast_possible_truncation, clippy::no_effect_underscore_binding)]
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use sp_std::vec;
|
||||
|
||||
@@ -100,7 +100,7 @@ pub fn run() -> sc_cli::Result<()> {
|
||||
if config.role.is_authority() {
|
||||
config.state_pruning = Some(PruningMode::ArchiveAll);
|
||||
}
|
||||
service::new_full(config).await.map_err(sc_cli::Error::Service)
|
||||
service::new_full(config).map_err(sc_cli::Error::Service)
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ pub fn new_partial(config: &Configuration) -> Result<PartialComponents, ServiceE
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
|
||||
pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
|
||||
let sc_service::PartialComponents {
|
||||
client,
|
||||
backend,
|
||||
|
||||
@@ -65,8 +65,7 @@ impl Coin {
|
||||
match self {
|
||||
Coin::Serai => NetworkId::Serai,
|
||||
Coin::Bitcoin => NetworkId::Bitcoin,
|
||||
Coin::Ether => NetworkId::Ethereum,
|
||||
Coin::Dai => NetworkId::Ethereum,
|
||||
Coin::Ether | Coin::Dai => NetworkId::Ethereum,
|
||||
Coin::Monero => NetworkId::Monero,
|
||||
}
|
||||
}
|
||||
@@ -93,11 +92,8 @@ impl Coin {
|
||||
|
||||
pub fn decimals(&self) -> u32 {
|
||||
match self {
|
||||
Coin::Serai => 8,
|
||||
Coin::Bitcoin => 8,
|
||||
// Ether and DAI have 18 decimals, yet we only track 8 in order to fit them within u64s
|
||||
Coin::Ether => 8,
|
||||
Coin::Dai => 8,
|
||||
Coin::Serai | Coin::Bitcoin | Coin::Ether | Coin::Dai => 8,
|
||||
Coin::Monero => 12,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ mod _serde {
|
||||
fn deserialize<D: Deserializer<'a>>(de: D) -> Result<Self, D::Error> {
|
||||
let bytes = sp_core::bytes::deserialize(de)?;
|
||||
scale::Decode::decode(&mut &bytes[..])
|
||||
.map_err(|e| serde::de::Error::custom(format!("invalid transaction: {}", e)))
|
||||
.map_err(|e| serde::de::Error::custom(format!("invalid transaction: {e}")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,10 +159,8 @@ impl Contains<RuntimeCall> for CallFilter {
|
||||
// All of these pallets are our own, and all of their written calls are intended to be called
|
||||
RuntimeCall::Coins(call) => !matches!(call, coins::Call::__Ignore(_, _)),
|
||||
RuntimeCall::LiquidityTokens(call) => match call {
|
||||
coins::Call::transfer { .. } => true,
|
||||
coins::Call::burn { .. } => true,
|
||||
coins::Call::burn_with_instruction { .. } => false,
|
||||
coins::Call::__Ignore(_, _) => false,
|
||||
coins::Call::transfer { .. } | coins::Call::burn { .. } => true,
|
||||
coins::Call::burn_with_instruction { .. } | coins::Call::__Ignore(_, _) => false,
|
||||
},
|
||||
RuntimeCall::Dex(call) => !matches!(call, dex::Call::__Ignore(_, _)),
|
||||
RuntimeCall::ValidatorSets(call) => !matches!(call, validator_sets::Call::__Ignore(_, _)),
|
||||
@@ -170,17 +168,15 @@ impl Contains<RuntimeCall> for CallFilter {
|
||||
RuntimeCall::Signals(call) => !matches!(call, signals::Call::__Ignore(_, _)),
|
||||
|
||||
RuntimeCall::Babe(call) => match call {
|
||||
babe::Call::report_equivocation { .. } => true,
|
||||
babe::Call::report_equivocation { .. } |
|
||||
babe::Call::report_equivocation_unsigned { .. } => true,
|
||||
babe::Call::plan_config_change { .. } => false,
|
||||
babe::Call::__Ignore(_, _) => false,
|
||||
babe::Call::plan_config_change { .. } | babe::Call::__Ignore(_, _) => false,
|
||||
},
|
||||
|
||||
RuntimeCall::Grandpa(call) => match call {
|
||||
grandpa::Call::report_equivocation { .. } => true,
|
||||
grandpa::Call::report_equivocation { .. } |
|
||||
grandpa::Call::report_equivocation_unsigned { .. } => true,
|
||||
grandpa::Call::note_stalled { .. } => false,
|
||||
grandpa::Call::__Ignore(_, _) => false,
|
||||
grandpa::Call::note_stalled { .. } | grandpa::Call::__Ignore(_, _) => false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ pub mod pallet {
|
||||
// Returns true if this network's current set is in favor of the signal.
|
||||
//
|
||||
// Must only be called for networks which have a set decided.
|
||||
fn tally_for_network(signal_id: SignalId, network: NetworkId) -> Result<bool, Error<T>> {
|
||||
fn tally_for_network(signal_id: SignalId, network: NetworkId) -> bool {
|
||||
let this_network_session = VsPallet::<T>::latest_decided_session(network).unwrap();
|
||||
let this_set = ValidatorSet { network, session: this_network_session };
|
||||
|
||||
@@ -197,18 +197,18 @@ pub mod pallet {
|
||||
SetsInFavor::<T>::set((signal_id, this_set), Some(()));
|
||||
Self::deposit_event(Event::SetInFavor { signal_id, set: this_set });
|
||||
}
|
||||
Ok(true)
|
||||
true
|
||||
} else {
|
||||
if SetsInFavor::<T>::contains_key((signal_id, this_set)) {
|
||||
// This should no longer be under the current tally
|
||||
SetsInFavor::<T>::remove((signal_id, this_set));
|
||||
Self::deposit_event(Event::SetNoLongerInFavor { signal_id, set: this_set });
|
||||
}
|
||||
Ok(false)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn tally_for_all_networks(signal_id: SignalId) -> Result<bool, Error<T>> {
|
||||
fn tally_for_all_networks(signal_id: SignalId) -> bool {
|
||||
let mut total_in_favor_stake = 0;
|
||||
let mut total_allocated_stake = 0;
|
||||
for network in serai_primitives::NETWORKS {
|
||||
@@ -226,10 +226,8 @@ pub mod pallet {
|
||||
total_allocated_stake += network_stake.0;
|
||||
}
|
||||
|
||||
Ok(
|
||||
total_in_favor_stake >=
|
||||
(total_allocated_stake * REQUIREMENT_NUMERATOR).div_ceil(REQUIREMENT_DIVISOR),
|
||||
)
|
||||
total_in_favor_stake >=
|
||||
(total_allocated_stake * REQUIREMENT_NUMERATOR).div_ceil(REQUIREMENT_DIVISOR)
|
||||
}
|
||||
|
||||
fn revoke_favor_internal(
|
||||
@@ -247,7 +245,7 @@ pub mod pallet {
|
||||
// Technically, this tally may make the network in favor and justify re-tallying for all
|
||||
// networks
|
||||
// Its assumed not to
|
||||
Self::tally_for_network(signal_id, for_network)?;
|
||||
Self::tally_for_network(signal_id, for_network);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -378,7 +376,7 @@ pub mod pallet {
|
||||
// Check if the network is in favor
|
||||
// tally_for_network expects the network to be active, which is implied by being in the
|
||||
// latest decided set
|
||||
let network_in_favor = Self::tally_for_network(signal_id, for_network)?;
|
||||
let network_in_favor = Self::tally_for_network(signal_id, for_network);
|
||||
|
||||
// If this network is in favor, check if enough networks are
|
||||
// We could optimize this by only running the following code when the network is *newly* in
|
||||
@@ -387,7 +385,7 @@ pub mod pallet {
|
||||
// to each other, any new votes will cause a re-tally
|
||||
if network_in_favor {
|
||||
// If enough are, lock in the signal
|
||||
if Self::tally_for_all_networks(signal_id)? {
|
||||
if Self::tally_for_all_networks(signal_id) {
|
||||
match signal_id {
|
||||
SignalId::Retirement(signal_id) => {
|
||||
LockedInRetirement::<T>::set(Some((
|
||||
|
||||
@@ -351,9 +351,8 @@ pub mod pallet {
|
||||
|
||||
// Update CurrentSession
|
||||
let session = {
|
||||
let new_session = CurrentSession::<T>::get(network)
|
||||
.map(|session| Session(session.0 + 1))
|
||||
.unwrap_or(Session(0));
|
||||
let new_session =
|
||||
CurrentSession::<T>::get(network).map_or(Session(0), |session| Session(session.0 + 1));
|
||||
CurrentSession::<T>::set(network, Some(new_session));
|
||||
new_session
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user