mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Add workspace lints
This commit is contained in:
@@ -13,6 +13,9 @@ publish = false
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
async-trait = { version = "0.1", default-features = false }
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ impl<D: Db> CosignEvaluator<D> {
|
||||
// If we haven't gotten the stake data yet, return
|
||||
let Some(stakes) = stakes_lock.as_ref() else { return };
|
||||
|
||||
let total_stake = stakes.values().cloned().sum::<u64>();
|
||||
let total_stake = stakes.values().copied().sum::<u64>();
|
||||
|
||||
let latest_cosigns = self.latest_cosigns.read().await;
|
||||
let mut highest_block = 0;
|
||||
@@ -319,7 +319,7 @@ impl<D: Db> CosignEvaluator<D> {
|
||||
tokio::spawn({
|
||||
async move {
|
||||
loop {
|
||||
let cosigns = evaluator.latest_cosigns.read().await.values().cloned().collect::<Vec<_>>();
|
||||
let cosigns = evaluator.latest_cosigns.read().await.values().copied().collect::<Vec<_>>();
|
||||
for cosign in cosigns {
|
||||
let mut buf = vec![];
|
||||
cosign.serialize(&mut buf).unwrap();
|
||||
|
||||
@@ -410,7 +410,7 @@ impl LibP2p {
|
||||
// If we are sending heartbeats, we should've sent one after 60s of no finalized blocks
|
||||
// (where a finalized block only occurs due to network activity), meaning this won't be
|
||||
// run
|
||||
_ = tokio::time::sleep(Duration::from_secs(80).saturating_sub(time_since_last)) => {
|
||||
() = tokio::time::sleep(Duration::from_secs(80).saturating_sub(time_since_last)) => {
|
||||
broadcast_raw(
|
||||
&mut swarm,
|
||||
&mut time_of_last_p2p_message,
|
||||
|
||||
@@ -95,7 +95,7 @@ pub async fn run_tributaries(
|
||||
mut tributaries: Vec<(LocalP2p, Tributary<MemDb, Transaction, LocalP2p>)>,
|
||||
) {
|
||||
loop {
|
||||
for (p2p, tributary) in tributaries.iter_mut() {
|
||||
for (p2p, tributary) in &mut tributaries {
|
||||
while let Poll::Ready(msg) = poll!(p2p.receive()) {
|
||||
match msg.kind {
|
||||
P2pMessageKind::Tributary(genesis) => {
|
||||
@@ -170,7 +170,7 @@ async fn tributary_test() {
|
||||
// run_tributaries will run them ad infinitum
|
||||
let timeout = SystemTime::now() + Duration::from_secs(65);
|
||||
while (blocks < 10) && (SystemTime::now().duration_since(timeout).is_err()) {
|
||||
for (p2p, tributary) in tributaries.iter_mut() {
|
||||
for (p2p, tributary) in &mut tributaries {
|
||||
while let Poll::Ready(msg) = poll!(p2p.receive()) {
|
||||
match msg.kind {
|
||||
P2pMessageKind::Tributary(genesis) => {
|
||||
@@ -196,7 +196,7 @@ async fn tributary_test() {
|
||||
}
|
||||
|
||||
// Handle all existing messages
|
||||
for (p2p, tributary) in tributaries.iter_mut() {
|
||||
for (p2p, tributary) in &mut tributaries {
|
||||
while let Poll::Ready(msg) = poll!(p2p.receive()) {
|
||||
match msg.kind {
|
||||
P2pMessageKind::Tributary(genesis) => {
|
||||
@@ -220,7 +220,7 @@ async fn tributary_test() {
|
||||
}
|
||||
assert!(tips.len() <= 2);
|
||||
if tips.len() == 2 {
|
||||
for tip in tips.iter() {
|
||||
for tip in &tips {
|
||||
// Find a Tributary where this isn't the tip
|
||||
for (_, tributary) in &tributaries {
|
||||
let Some(after) = tributary.reader().block_after(tip) else { continue };
|
||||
|
||||
@@ -337,7 +337,7 @@ async fn dkg_test() {
|
||||
for (i, tx) in txs.iter().enumerate() {
|
||||
assert_eq!(tributaries[i].1.add_transaction(tx.clone()).await, Ok(true));
|
||||
}
|
||||
for tx in txs.iter() {
|
||||
for tx in &txs {
|
||||
wait_for_tx_inclusion(&tributaries[0].1, block_before_tx, tx.hash()).await;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,14 +127,12 @@ impl ReattemptDb {
|
||||
.min(3);
|
||||
let upon_block = current_block_number + reattempt_delay;
|
||||
|
||||
#[allow(clippy::unwrap_or_default)]
|
||||
let mut reattempts = Self::get(txn, genesis, upon_block).unwrap_or(vec![]);
|
||||
reattempts.push(topic);
|
||||
Self::set(txn, genesis, upon_block, &reattempts);
|
||||
}
|
||||
|
||||
pub fn take(txn: &mut impl DbTxn, genesis: [u8; 32], block_number: u32) -> Vec<Topic> {
|
||||
#[allow(clippy::unwrap_or_default)]
|
||||
let res = Self::get(txn, genesis, block_number).unwrap_or(vec![]);
|
||||
if !res.is_empty() {
|
||||
Self::del(txn, genesis, block_number);
|
||||
|
||||
@@ -314,7 +314,7 @@ impl<
|
||||
.await;
|
||||
return;
|
||||
};
|
||||
let Ok(_) = self.check_sign_data_len(&removed, signed.signer, commitments.len()).await
|
||||
let Ok(()) = self.check_sign_data_len(&removed, signed.signer, commitments.len()).await
|
||||
else {
|
||||
return;
|
||||
};
|
||||
@@ -348,7 +348,7 @@ impl<
|
||||
.await;
|
||||
return;
|
||||
};
|
||||
let Ok(_) = self.check_sign_data_len(&removed, signed.signer, shares.len()).await else {
|
||||
let Ok(()) = self.check_sign_data_len(&removed, signed.signer, shares.len()).await else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -626,7 +626,7 @@ impl<
|
||||
despite us not providing that transaction",
|
||||
);
|
||||
|
||||
for id in plan_ids.into_iter() {
|
||||
for id in plan_ids {
|
||||
AttemptDb::recognize_topic(self.txn, genesis, Topic::Sign(id));
|
||||
self
|
||||
.recognized_id
|
||||
@@ -650,7 +650,7 @@ impl<
|
||||
return;
|
||||
};
|
||||
let signer = data.signed.signer;
|
||||
let Ok(_) = self.check_sign_data_len(&removed, signer, data.data.len()).await else {
|
||||
let Ok(()) = self.check_sign_data_len(&removed, signer, data.data.len()).await else {
|
||||
return;
|
||||
};
|
||||
let expected_len = match data.label {
|
||||
@@ -711,7 +711,7 @@ impl<
|
||||
.await;
|
||||
return;
|
||||
};
|
||||
let Ok(_) = self.check_sign_data_len(&removed, data.signed.signer, data.data.len()).await
|
||||
let Ok(()) = self.check_sign_data_len(&removed, data.signed.signer, data.data.len()).await
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -39,7 +39,6 @@ pub fn removed_as_of_dkg_attempt(
|
||||
}
|
||||
|
||||
pub fn latest_removed(getter: &impl Get, genesis: [u8; 32]) -> Vec<<Ristretto as Ciphersuite>::G> {
|
||||
#[allow(clippy::unwrap_or_default)]
|
||||
FatalSlashes::get(getter, genesis)
|
||||
.unwrap_or(vec![])
|
||||
.iter()
|
||||
|
||||
@@ -136,7 +136,7 @@ mod impl_pst_for_serai {
|
||||
signature: Signature,
|
||||
) {
|
||||
let tx = SeraiValidatorSets::set_keys(set.network, removed, key_pair, signature);
|
||||
async fn check(serai: SeraiValidatorSets<'_>, set: ValidatorSet, _: ()) -> bool {
|
||||
async fn check(serai: SeraiValidatorSets<'_>, set: ValidatorSet, (): ()) -> bool {
|
||||
if matches!(serai.keys(set).await, Ok(Some(_))) {
|
||||
log::info!("another coordinator set key pair for {:?}", set);
|
||||
return true;
|
||||
@@ -293,7 +293,6 @@ impl<
|
||||
*/
|
||||
match topic {
|
||||
Topic::Dkg => {
|
||||
#[allow(clippy::unwrap_or_default)]
|
||||
FatalSlashesAsOfDkgAttempt::set(
|
||||
self.txn,
|
||||
genesis,
|
||||
|
||||
@@ -158,7 +158,7 @@ impl<T: DbTxn, C: Encode> SigningProtocol<'_, T, C> {
|
||||
) -> Result<(AlgorithmSignatureMachine<Ristretto, Schnorrkel>, [u8; 32]), Participant> {
|
||||
let machine = self.preprocess_internal(participants).0;
|
||||
|
||||
let mut participants = serialized_preprocesses.keys().cloned().collect::<Vec<_>>();
|
||||
let mut participants = serialized_preprocesses.keys().copied().collect::<Vec<_>>();
|
||||
participants.sort();
|
||||
let mut preprocesses = HashMap::new();
|
||||
for participant in participants {
|
||||
@@ -231,7 +231,7 @@ fn threshold_i_map_to_keys_and_musig_i_map(
|
||||
};
|
||||
|
||||
let mut sorted = vec![];
|
||||
let mut threshold_is = map.keys().cloned().collect::<Vec<_>>();
|
||||
let mut threshold_is = map.keys().copied().collect::<Vec<_>>();
|
||||
threshold_is.sort();
|
||||
for threshold_i in threshold_is {
|
||||
sorted.push((key_from_threshold_i(threshold_i), map.remove(&threshold_i).unwrap()));
|
||||
|
||||
@@ -7,6 +7,13 @@ repository = "https://github.com/serai-dex/serai/tree/develop/coordinator/tribut
|
||||
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
|
||||
edition = "2021"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
async-trait = { version = "0.1", default-features = false }
|
||||
thiserror = { version = "1", default-features = false }
|
||||
|
||||
@@ -207,7 +207,7 @@ impl<T: TransactionTrait> Block<T> {
|
||||
let mut last_tx_order = Order::Provided;
|
||||
let mut included_in_block = HashSet::new();
|
||||
let mut txs = Vec::with_capacity(self.transactions.len());
|
||||
for tx in self.transactions.iter() {
|
||||
for tx in &self.transactions {
|
||||
let tx_hash = tx.hash();
|
||||
txs.push(tx_hash);
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ impl<D: Db, T: TransactionTrait> Blockchain<D, T> {
|
||||
let mut res = Self {
|
||||
db: Some(db.clone()),
|
||||
genesis,
|
||||
participants: participants.iter().cloned().collect(),
|
||||
participants: participants.iter().copied().collect(),
|
||||
|
||||
block_number: 0,
|
||||
tip: genesis,
|
||||
|
||||
@@ -38,7 +38,6 @@ impl<D: Db, T: TransactionTrait> Mempool<D, T> {
|
||||
let tx_hash = tx.hash();
|
||||
let transaction_key = self.transaction_key(&tx_hash);
|
||||
let current_mempool_key = self.current_mempool_key();
|
||||
#[allow(clippy::unwrap_or_default)]
|
||||
let mut current_mempool = self.db.get(¤t_mempool_key).unwrap_or(vec![]);
|
||||
|
||||
let mut txn = self.db.txn();
|
||||
@@ -182,14 +181,14 @@ impl<D: Db, T: TransactionTrait> Mempool<D, T> {
|
||||
signer: &<Ristretto as Ciphersuite>::G,
|
||||
order: Vec<u8>,
|
||||
) -> Option<u32> {
|
||||
self.last_nonce_in_mempool.get(&(*signer, order)).cloned().map(|nonce| nonce + 1)
|
||||
self.last_nonce_in_mempool.get(&(*signer, order)).copied().map(|nonce| nonce + 1)
|
||||
}
|
||||
|
||||
/// Get transactions to include in a block.
|
||||
pub(crate) fn block(&mut self) -> Vec<Transaction<T>> {
|
||||
let mut unsigned = vec![];
|
||||
let mut signed = vec![];
|
||||
for hash in self.txs.keys().cloned().collect::<Vec<_>>() {
|
||||
for hash in self.txs.keys().copied().collect::<Vec<_>>() {
|
||||
let tx = &self.txs[&hash];
|
||||
|
||||
match tx.kind() {
|
||||
@@ -222,7 +221,6 @@ impl<D: Db, T: TransactionTrait> Mempool<D, T> {
|
||||
pub(crate) fn remove(&mut self, tx: &[u8; 32]) {
|
||||
let transaction_key = self.transaction_key(tx);
|
||||
let current_mempool_key = self.current_mempool_key();
|
||||
#[allow(clippy::unwrap_or_default)]
|
||||
let current_mempool = self.db.get(¤t_mempool_key).unwrap_or(vec![]);
|
||||
|
||||
let mut i = 0;
|
||||
|
||||
@@ -136,7 +136,6 @@ impl<D: Db, T: Transaction> ProvidedTransactions<D, T> {
|
||||
}
|
||||
txn.commit();
|
||||
} else {
|
||||
#[allow(clippy::unwrap_or_default)]
|
||||
let mut currently_provided = txn.get(¤t_provided_key).unwrap_or(vec![]);
|
||||
currently_provided.extend(tx_hash);
|
||||
txn.put(current_provided_key, currently_provided);
|
||||
|
||||
@@ -7,6 +7,13 @@ repository = "https://github.com/serai-dex/serai/tree/develop/coordinator/tender
|
||||
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
|
||||
edition = "2021"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
async-trait = { version = "0.1", default-features = false }
|
||||
thiserror = { version = "1", default-features = false }
|
||||
|
||||
@@ -30,7 +30,7 @@ pub mod ext;
|
||||
use ext::*;
|
||||
|
||||
pub fn commit_msg(end_time: u64, id: &[u8]) -> Vec<u8> {
|
||||
[&end_time.to_le_bytes(), id].concat().to_vec()
|
||||
[&end_time.to_le_bytes(), id].concat()
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode)]
|
||||
@@ -398,7 +398,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
||||
},
|
||||
|
||||
// Handle our messages
|
||||
_ = queue_future => {
|
||||
() = queue_future => {
|
||||
Some((true, self.queue.pop_front().unwrap(), None))
|
||||
},
|
||||
|
||||
@@ -752,7 +752,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
||||
if self.block.round().step == Step::Propose {
|
||||
// Delay error handling (triggering a slash) until after we vote.
|
||||
let (valid, err) = match self.network.validate(block).await {
|
||||
Ok(_) => (true, Ok(None)),
|
||||
Ok(()) => (true, Ok(None)),
|
||||
Err(BlockError::Temporal) => (false, Ok(None)),
|
||||
Err(BlockError::Fatal) => (false, {
|
||||
log::warn!(target: "tendermint", "Validator proposed a fatally invalid block");
|
||||
@@ -812,7 +812,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
||||
|
||||
if self.block.log.has_consensus(self.block.round().number, Data::Prevote(Some(block.id()))) {
|
||||
match self.network.validate(block).await {
|
||||
Ok(_) => (),
|
||||
Ok(()) => (),
|
||||
// BlockError::Temporal is due to a temporal error we have, yet a supermajority of the
|
||||
// network does not, Because we do not believe this block to be fatally invalid, and
|
||||
// because a supermajority deems it valid, accept it.
|
||||
|
||||
@@ -21,9 +21,7 @@ impl<N: Network> MessageLog<N> {
|
||||
pub(crate) fn log(&mut self, signed: SignedMessageFor<N>) -> Result<bool, TendermintError<N>> {
|
||||
let msg = &signed.msg;
|
||||
// Clarity, and safety around default != new edge cases
|
||||
#[allow(clippy::unwrap_or_default)]
|
||||
let round = self.log.entry(msg.round).or_insert_with(HashMap::new);
|
||||
#[allow(clippy::unwrap_or_default)]
|
||||
let msgs = round.entry(msg.sender).or_insert_with(HashMap::new);
|
||||
|
||||
// Handle message replays without issue. It's only multiple messages which is malicious
|
||||
|
||||
Reference in New Issue
Block a user