cleanup(clippy): Remove unnecessary `try_into()` with `cargo clippy --fix` (#7940)
* Remove unnecessary try_into() with cargo clippy --fix * Manually remove some unnecessary try_from()s * impl From<Diversifier> for pallas::Affine instead of TryFrom * Remove unused imports * cargo fmt --all * Remove redundant comma
This commit is contained in:
parent
dee10983c1
commit
af82a76d18
|
|
@ -87,17 +87,12 @@ impl PartialEq<[u8; 11]> for Diversifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Diversifier> for pallas::Affine {
|
impl From<Diversifier> for pallas::Affine {
|
||||||
type Error = &'static str;
|
|
||||||
|
|
||||||
/// Get a diversified base point from a diversifier value in affine
|
/// Get a diversified base point from a diversifier value in affine
|
||||||
/// representation.
|
/// representation.
|
||||||
fn try_from(d: Diversifier) -> Result<Self, Self::Error> {
|
fn from(d: Diversifier) -> Self {
|
||||||
if let Ok(projective_point) = pallas::Point::try_from(d) {
|
let projective_point = pallas::Point::from(d);
|
||||||
Ok(projective_point.into())
|
projective_point.into()
|
||||||
} else {
|
|
||||||
Err("Invalid Diversifier -> pallas::Affine")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,9 +84,7 @@ impl Arbitrary for Output {
|
||||||
.prop_map(|(enc_ciphertext, out_ciphertext, zkproof)| Self {
|
.prop_map(|(enc_ciphertext, out_ciphertext, zkproof)| Self {
|
||||||
cv: ExtendedPoint::generator().try_into().unwrap(),
|
cv: ExtendedPoint::generator().try_into().unwrap(),
|
||||||
cm_u: NoteCommitment(AffinePoint::identity()).extract_u(),
|
cm_u: NoteCommitment(AffinePoint::identity()).extract_u(),
|
||||||
ephemeral_key: keys::EphemeralPublicKey(
|
ephemeral_key: keys::EphemeralPublicKey(ExtendedPoint::generator().into()),
|
||||||
ExtendedPoint::generator().try_into().unwrap(),
|
|
||||||
),
|
|
||||||
enc_ciphertext,
|
enc_ciphertext,
|
||||||
out_ciphertext,
|
out_ciphertext,
|
||||||
zkproof,
|
zkproof,
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ pub fn halving_divisor(height: Height, network: Network) -> Option<u64> {
|
||||||
Some(halving_div)
|
Some(halving_div)
|
||||||
} else {
|
} else {
|
||||||
let pre_blossom_height = blossom_height - SLOW_START_SHIFT;
|
let pre_blossom_height = blossom_height - SLOW_START_SHIFT;
|
||||||
let scaled_pre_blossom_height = pre_blossom_height
|
let scaled_pre_blossom_height =
|
||||||
* HeightDiff::try_from(BLOSSOM_POW_TARGET_SPACING_RATIO).expect("constant is positive");
|
pre_blossom_height * HeightDiff::from(BLOSSOM_POW_TARGET_SPACING_RATIO);
|
||||||
|
|
||||||
let post_blossom_height = height - blossom_height;
|
let post_blossom_height = height - blossom_height;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ fn generate_test_vectors() {
|
||||||
let action = zebra_chain::orchard::Action {
|
let action = zebra_chain::orchard::Action {
|
||||||
cv: a.cv_net().to_bytes().try_into().unwrap(),
|
cv: a.cv_net().to_bytes().try_into().unwrap(),
|
||||||
nullifier: a.nullifier().to_bytes().try_into().unwrap(),
|
nullifier: a.nullifier().to_bytes().try_into().unwrap(),
|
||||||
rk: <[u8; 32]>::from(a.rk()).try_into().unwrap(),
|
rk: <[u8; 32]>::from(a.rk()).into(),
|
||||||
cm_x: pallas::Base::from_repr(a.cmx().into()).unwrap(),
|
cm_x: pallas::Base::from_repr(a.cmx().into()).unwrap(),
|
||||||
ephemeral_key: a.encrypted_note().epk_bytes.try_into().unwrap(),
|
ephemeral_key: a.encrypted_note().epk_bytes.try_into().unwrap(),
|
||||||
enc_ciphertext: a.encrypted_note().enc_ciphertext.into(),
|
enc_ciphertext: a.encrypted_note().enc_ciphertext.into(),
|
||||||
|
|
@ -89,9 +89,7 @@ fn generate_test_vectors() {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
binding_sig: <[u8; 64]>::from(bundle.authorization().binding_signature())
|
binding_sig: <[u8; 64]>::from(bundle.authorization().binding_signature()).into(),
|
||||||
.try_into()
|
|
||||||
.unwrap(),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
||||||
|
|
@ -523,11 +523,7 @@ mod tests {
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
INVENTORY_ROTATION_INTERVAL
|
INVENTORY_ROTATION_INTERVAL
|
||||||
< Duration::from_secs(
|
< Duration::from_secs(POST_BLOSSOM_POW_TARGET_SPACING.into()),
|
||||||
POST_BLOSSOM_POW_TARGET_SPACING
|
|
||||||
.try_into()
|
|
||||||
.expect("non-negative"),
|
|
||||||
),
|
|
||||||
"we should expire inventory every time 1-2 new blocks get generated"
|
"we should expire inventory every time 1-2 new blocks get generated"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ impl CachedFfiTransaction {
|
||||||
};
|
};
|
||||||
|
|
||||||
if err == zcash_script_error_t_zcash_script_ERR_OK {
|
if err == zcash_script_error_t_zcash_script_ERR_OK {
|
||||||
let ret = ret.try_into().expect("c_uint fits in a u64");
|
let ret = ret.into();
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::from(err))
|
Err(Error::from(err))
|
||||||
|
|
|
||||||
|
|
@ -196,8 +196,7 @@ pub fn transparent_coinbase_spend(
|
||||||
|
|
||||||
match spend_restriction {
|
match spend_restriction {
|
||||||
OnlyShieldedOutputs { spend_height } => {
|
OnlyShieldedOutputs { spend_height } => {
|
||||||
let min_spend_height =
|
let min_spend_height = utxo.height + MIN_TRANSPARENT_COINBASE_MATURITY.into();
|
||||||
utxo.height + MIN_TRANSPARENT_COINBASE_MATURITY.try_into().unwrap();
|
|
||||||
let min_spend_height =
|
let min_spend_height =
|
||||||
min_spend_height.expect("valid UTXOs have coinbase heights far below Height::MAX");
|
min_spend_height.expect("valid UTXOs have coinbase heights far below Height::MAX");
|
||||||
if spend_height >= min_spend_height {
|
if spend_height >= min_spend_height {
|
||||||
|
|
|
||||||
|
|
@ -91,9 +91,7 @@ impl TransactionIndex {
|
||||||
|
|
||||||
/// Returns this index as a `usize`
|
/// Returns this index as a `usize`
|
||||||
pub fn as_usize(&self) -> usize {
|
pub fn as_usize(&self) -> usize {
|
||||||
self.0
|
self.0.into()
|
||||||
.try_into()
|
|
||||||
.expect("the maximum valid index fits in usize")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a transaction index from a `u64`.
|
/// Creates a transaction index from a `u64`.
|
||||||
|
|
@ -108,9 +106,7 @@ impl TransactionIndex {
|
||||||
/// Returns this index as a `u64`
|
/// Returns this index as a `u64`
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn as_u64(&self) -> u64 {
|
pub fn as_u64(&self) -> u64 {
|
||||||
self.0
|
self.0.into()
|
||||||
.try_into()
|
|
||||||
.expect("the maximum valid index fits in u64")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,8 +164,7 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
// Checkpoints must be on the main chain, so we skip blocks that are within the
|
// Checkpoints must be on the main chain, so we skip blocks that are within the
|
||||||
// Zcash reorg limit.
|
// Zcash reorg limit.
|
||||||
let height_limit = height_limit
|
let height_limit = height_limit - HeightDiff::from(MIN_TRANSPARENT_COINBASE_MATURITY);
|
||||||
- HeightDiff::try_from(MIN_TRANSPARENT_COINBASE_MATURITY).expect("constant fits in i32");
|
|
||||||
let height_limit = height_limit
|
let height_limit = height_limit
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
eyre!(
|
eyre!(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
//! Timing tests for the mempool crawler.
|
//! Timing tests for the mempool crawler.
|
||||||
|
|
||||||
use std::convert::TryInto;
|
|
||||||
|
|
||||||
use zebra_chain::parameters::POST_BLOSSOM_POW_TARGET_SPACING;
|
use zebra_chain::parameters::POST_BLOSSOM_POW_TARGET_SPACING;
|
||||||
use zebra_network::constants::{DEFAULT_CRAWL_NEW_PEER_INTERVAL, HANDSHAKE_TIMEOUT};
|
use zebra_network::constants::{DEFAULT_CRAWL_NEW_PEER_INTERVAL, HANDSHAKE_TIMEOUT};
|
||||||
|
|
||||||
|
|
@ -10,10 +8,7 @@ use crate::components::mempool::crawler::RATE_LIMIT_DELAY;
|
||||||
#[test]
|
#[test]
|
||||||
fn ensure_timing_consistent() {
|
fn ensure_timing_consistent() {
|
||||||
assert!(
|
assert!(
|
||||||
RATE_LIMIT_DELAY.as_secs()
|
RATE_LIMIT_DELAY.as_secs() < POST_BLOSSOM_POW_TARGET_SPACING.into(),
|
||||||
< POST_BLOSSOM_POW_TARGET_SPACING
|
|
||||||
.try_into()
|
|
||||||
.expect("not negative"),
|
|
||||||
"a mempool crawl should complete before most new blocks"
|
"a mempool crawl should complete before most new blocks"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
//! Check the relationship between various sync timeouts and delays.
|
//! Check the relationship between various sync timeouts and delays.
|
||||||
|
|
||||||
use std::{
|
use std::sync::{
|
||||||
convert::TryInto,
|
atomic::{AtomicU8, Ordering},
|
||||||
sync::{
|
Arc,
|
||||||
atomic::{AtomicU8, Ordering},
|
|
||||||
Arc,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use futures::future;
|
use futures::future;
|
||||||
|
|
@ -79,10 +76,7 @@ fn ensure_timeouts_consistent() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
SYNC_RESTART_DELAY.as_secs()
|
SYNC_RESTART_DELAY.as_secs() < POST_BLOSSOM_POW_TARGET_SPACING.into(),
|
||||||
< POST_BLOSSOM_POW_TARGET_SPACING
|
|
||||||
.try_into()
|
|
||||||
.expect("not negative"),
|
|
||||||
"a syncer tip crawl should complete before most new blocks"
|
"a syncer tip crawl should complete before most new blocks"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -396,8 +396,7 @@ pub fn wait_for_zebra_checkpoints_generation<
|
||||||
test_type: TestType,
|
test_type: TestType,
|
||||||
show_zebrad_logs: bool,
|
show_zebrad_logs: bool,
|
||||||
) -> Result<(TestChild<TempDir>, TestChild<P>)> {
|
) -> Result<(TestChild<TempDir>, TestChild<P>)> {
|
||||||
let last_checkpoint_gap = HeightDiff::try_from(MIN_TRANSPARENT_COINBASE_MATURITY)
|
let last_checkpoint_gap = HeightDiff::from(MIN_TRANSPARENT_COINBASE_MATURITY)
|
||||||
.expect("constant fits in HeightDiff")
|
|
||||||
+ HeightDiff::try_from(MAX_CHECKPOINT_HEIGHT_GAP).expect("constant fits in HeightDiff");
|
+ HeightDiff::try_from(MAX_CHECKPOINT_HEIGHT_GAP).expect("constant fits in HeightDiff");
|
||||||
let expected_final_checkpoint_height =
|
let expected_final_checkpoint_height =
|
||||||
(zebra_tip_height - last_checkpoint_gap).expect("network tip is high enough");
|
(zebra_tip_height - last_checkpoint_gap).expect("network tip is high enough");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue