Further expand clippy workspace lints

Achieves a notable amount of reduced async and clones.
This commit is contained in:
Luke Parker
2023-12-17 00:01:41 -05:00
parent ea3af28139
commit 065d314e2a
113 changed files with 596 additions and 724 deletions

View File

@@ -102,7 +102,7 @@ impl ResolvedDb {
txn: &mut impl DbTxn,
key: &[u8],
plan: [u8; 32],
resolution: <N::Transaction as Transaction<N>>::Id,
resolution: &<N::Transaction as Transaction<N>>::Id,
) {
let mut signing = SigningDb::get(txn, key).unwrap_or_default();
assert_eq!(signing.len() % 32, 0);
@@ -160,7 +160,7 @@ impl PlansFromScanningDb {
}
impl ForwardedOutputDb {
pub fn save_forwarded_output(txn: &mut impl DbTxn, instruction: InInstructionWithBalance) {
pub fn save_forwarded_output(txn: &mut impl DbTxn, instruction: &InInstructionWithBalance) {
let mut existing = Self::get(txn, instruction.balance).unwrap_or_default();
existing.extend(instruction.encode());
Self::set(txn, instruction.balance, &existing);
@@ -184,7 +184,7 @@ impl ForwardedOutputDb {
}
impl DelayedOutputDb {
pub fn save_delayed_output(txn: &mut impl DbTxn, instruction: InInstructionWithBalance) {
pub fn save_delayed_output(txn: &mut impl DbTxn, instruction: &InInstructionWithBalance) {
let mut existing = Self::get(txn).unwrap_or_default();
existing.extend(instruction.encode());
Self::set(txn, &existing);

View File

@@ -7,7 +7,7 @@ use scale::{Encode, Decode};
use messages::SubstrateContext;
use serai_client::{
primitives::{MAX_DATA_LEN, NetworkId, Coin, ExternalAddress, BlockHash},
primitives::{MAX_DATA_LEN, NetworkId, Coin, ExternalAddress, BlockHash, Data},
in_instructions::primitives::{
InInstructionWithBalance, Batch, RefundableInInstruction, Shorthand, MAX_BATCH_SIZE,
},
@@ -316,7 +316,7 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
assert_eq!(balance.coin.network(), N::NETWORK);
if let Ok(address) = N::Address::try_from(address.consume()) {
payments.push(Payment { address, data: data.map(|data| data.consume()), balance });
payments.push(Payment { address, data: data.map(Data::consume), balance });
}
}
@@ -513,7 +513,7 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
let mut plans = vec![];
existing_outputs.retain(|output| {
match output.kind() {
OutputType::External => false,
OutputType::External | OutputType::Forwarded => false,
OutputType::Branch => {
let scheduler = &mut self.existing.as_mut().unwrap().scheduler;
// There *would* be a race condition here due to the fact we only mark a `Branch` output
@@ -576,7 +576,6 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
}
false
}
OutputType::Forwarded => false,
}
});
plans
@@ -873,7 +872,7 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
// letting it die out
if let Some(tx) = &tx {
instruction.balance.amount.0 -= tx.0.fee();
ForwardedOutputDb::save_forwarded_output(txn, instruction);
ForwardedOutputDb::save_forwarded_output(txn, &instruction);
}
} else if let Some(refund_to) = refund_to {
if let Ok(refund_to) = refund_to.consume().try_into() {
@@ -907,9 +906,7 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
}
let (refund_to, instruction) = instruction_from_output::<N>(&output);
let instruction = if let Some(instruction) = instruction {
instruction
} else {
let Some(instruction) = instruction else {
if let Some(refund_to) = refund_to {
if let Ok(refund_to) = refund_to.consume().try_into() {
plans.push(Self::refund_plan(output.clone(), refund_to));
@@ -922,7 +919,7 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
if Some(output.key()) == self.new.as_ref().map(|new| new.key) {
match step {
RotationStep::UseExisting => {
DelayedOutputDb::save_delayed_output(txn, instruction);
DelayedOutputDb::save_delayed_output(txn, &instruction);
continue;
}
RotationStep::NewAsChange |
@@ -1003,7 +1000,7 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
// within the block. Unknown Eventualities may have their Completed events emitted after
// ScannerEvent::Block however.
ScannerEvent::Completed(key, block_number, id, tx) => {
ResolvedDb::resolve_plan::<N>(txn, &key, id, tx.id());
ResolvedDb::resolve_plan::<N>(txn, &key, id, &tx.id());
(block_number, MultisigEvent::Completed(key, id, tx))
}
};

View File

@@ -415,7 +415,7 @@ impl<N: Network, D: Db> Scanner<N, D> {
)
}
async fn emit(&mut self, event: ScannerEvent<N>) -> bool {
fn emit(&mut self, event: ScannerEvent<N>) -> bool {
if self.events.send(event).is_err() {
info!("Scanner handler was dropped. Shutting down?");
return false;
@@ -496,12 +496,9 @@ impl<N: Network, D: Db> Scanner<N, D> {
}
}
let block = match network.get_block(block_being_scanned).await {
Ok(block) => block,
Err(_) => {
warn!("couldn't get block {block_being_scanned}");
break;
}
let Ok(block) = network.get_block(block_being_scanned).await else {
warn!("couldn't get block {block_being_scanned}");
break;
};
let block_id = block.id();
@@ -570,7 +567,7 @@ impl<N: Network, D: Db> Scanner<N, D> {
completion_block_numbers.push(block_number);
// This must be before the mission of ScannerEvent::Block, per commentary in mod.rs
if !scanner.emit(ScannerEvent::Completed(key_vec.clone(), block_number, id, tx)).await {
if !scanner.emit(ScannerEvent::Completed(key_vec.clone(), block_number, id, tx)) {
return;
}
}
@@ -687,10 +684,7 @@ impl<N: Network, D: Db> Scanner<N, D> {
txn.commit();
// Send all outputs
if !scanner
.emit(ScannerEvent::Block { is_retirement_block, block: block_id, outputs })
.await
{
if !scanner.emit(ScannerEvent::Block { is_retirement_block, block: block_id, outputs }) {
return;
}

View File

@@ -335,7 +335,7 @@ impl<N: Network> Scheduler<N> {
// Since we do multiple aggregation TXs at once, this will execute in logarithmic time
let utxos = self.utxos.drain(..).collect::<Vec<_>>();
let mut utxo_chunks =
utxos.chunks(N::MAX_INPUTS).map(|chunk| chunk.to_vec()).collect::<Vec<_>>();
utxos.chunks(N::MAX_INPUTS).map(<[<N as Network>::Output]>::to_vec).collect::<Vec<_>>();
// Use the first chunk for any scheduled payments, since it has the most value
let utxos = utxo_chunks.remove(0);
@@ -456,10 +456,7 @@ impl<N: Network> Scheduler<N> {
}
// If we didn't actually create this output, return, dropping the child payments
let actual = match actual {
Some(actual) => actual,
None => return,
};
let Some(actual) = actual else { return };
// Amortize the fee amongst all payments underneath this branch
{