mirror of
https://github.com/MAGICGrants/cuprate-for-explorer.git
synced 2026-01-08 03:13:50 -05:00
lints: enable wildcard_enum_match_arm (#367)
* apply * fixes * clippy * fmt * fix * review fix
This commit is contained in:
@@ -433,7 +433,7 @@ allow_attributes = "deny"
|
||||
undocumented_unsafe_blocks = "deny"
|
||||
# multiple_unsafe_ops_per_block = "deny"
|
||||
# single_char_lifetime_names = "deny"
|
||||
# wildcard_enum_match_arm = "deny"
|
||||
wildcard_enum_match_arm = "deny"
|
||||
|
||||
[workspace.lints.rust]
|
||||
# Cold
|
||||
|
||||
@@ -26,6 +26,10 @@ impl<N: NetworkZone> Service<ChainSvcRequest<N>> for ChainService {
|
||||
}
|
||||
|
||||
fn call(&mut self, req: ChainSvcRequest<N>) -> Self::Future {
|
||||
#[expect(
|
||||
clippy::wildcard_enum_match_arm,
|
||||
reason = "other requests should be unreachable"
|
||||
)]
|
||||
let map_res = |res: BlockchainResponse| match res {
|
||||
BlockchainResponse::CompactChainHistory {
|
||||
block_ids,
|
||||
|
||||
@@ -122,7 +122,7 @@ const fn check_time_lock(time_lock: &Timelock, chain_height: usize) -> Result<()
|
||||
Err(MinerTxError::InvalidLockTime)
|
||||
}
|
||||
}
|
||||
_ => Err(MinerTxError::InvalidLockTime),
|
||||
Timelock::None | Timelock::Time(_) => Err(MinerTxError::InvalidLockTime),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use curve25519_dalek::EdwardsPoint;
|
||||
use monero_serai::{
|
||||
io::decompress_point,
|
||||
@@ -400,9 +398,8 @@ fn check_inputs_sorted(inputs: &[Input], hf: HardFork) -> Result<(), Transaction
|
||||
|
||||
if hf >= HardFork::V7 {
|
||||
for inps in inputs.windows(2) {
|
||||
match get_ki(&inps[0])?.cmp(&get_ki(&inps[1])?) {
|
||||
Ordering::Greater => (),
|
||||
_ => return Err(TransactionError::InputsAreNotOrdered),
|
||||
if get_ki(&inps[0])? <= get_ki(&inps[1])? {
|
||||
return Err(TransactionError::InputsAreNotOrdered);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,13 @@ fn check_rct_type(ty: RctType, hf: HardFork, tx_hash: &[u8; 32]) -> Result<(), R
|
||||
T::MlsagBulletproofsCompactAmount if GRANDFATHERED_TRANSACTIONS.contains(tx_hash) => Ok(()),
|
||||
T::ClsagBulletproof if hf >= F::V13 && hf < F::V16 => Ok(()),
|
||||
T::ClsagBulletproofPlus if hf >= F::V15 => Ok(()),
|
||||
_ => Err(RingCTError::TypeNotAllowed),
|
||||
|
||||
T::AggregateMlsagBorromean
|
||||
| T::MlsagBorromean
|
||||
| T::MlsagBulletproofs
|
||||
| T::MlsagBulletproofsCompactAmount
|
||||
| T::ClsagBulletproof
|
||||
| T::ClsagBulletproofPlus => Err(RingCTError::TypeNotAllowed),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +141,10 @@ impl Service<BlockchainReadRequest> for DummyDatabase {
|
||||
let dummy_height = self.dummy_height;
|
||||
|
||||
async move {
|
||||
#[expect(
|
||||
clippy::wildcard_enum_match_arm,
|
||||
reason = "the context svc should not need other requests"
|
||||
)]
|
||||
Ok(match req {
|
||||
BlockchainReadRequest::BlockExtendedHeader(id) => {
|
||||
let mut id = id;
|
||||
|
||||
@@ -554,7 +554,7 @@ where
|
||||
.iter()
|
||||
.filter_map(|lock| match lock {
|
||||
Timelock::Time(time) => Some(time),
|
||||
_ => None,
|
||||
Timelock::None | Timelock::Block(_) => None,
|
||||
})
|
||||
.min();
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ pub fn new_ring_member_info(
|
||||
.iter()
|
||||
.filter_map(|out| match out.time_lock {
|
||||
Timelock::None => None,
|
||||
lock => Some(lock),
|
||||
Timelock::Block(_) | Timelock::Time(_) => Some(out.time_lock),
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
|
||||
@@ -26,6 +26,10 @@ use cuprate_test_utils::data::TX_E2D393;
|
||||
fn dummy_database(outputs: BTreeMap<u64, OutputOnChain>) -> impl Database + Clone {
|
||||
let outputs = Arc::new(outputs);
|
||||
|
||||
#[expect(
|
||||
clippy::wildcard_enum_match_arm,
|
||||
reason = "Other database requests are not needed for this test"
|
||||
)]
|
||||
service_fn(move |req: BlockchainReadRequest| {
|
||||
ready(Ok(match req {
|
||||
BlockchainReadRequest::NumberOutputsWithAmount(_) => {
|
||||
@@ -48,7 +52,7 @@ fn dummy_database(outputs: BTreeMap<u64, OutputOnChain>) -> impl Database + Clon
|
||||
BlockchainResponse::Outputs(ret)
|
||||
}
|
||||
BlockchainReadRequest::KeyImagesSpent(_) => BlockchainResponse::KeyImagesSpent(false),
|
||||
_ => panic!("Database request not needed for this test"),
|
||||
_ => panic!(),
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ impl_path_lazylock! {
|
||||
fn path_with_network(path: &Path, network: Network) -> PathBuf {
|
||||
match network {
|
||||
Network::Mainnet => path.to_path_buf(),
|
||||
network => path.join(network.to_string()),
|
||||
Network::Testnet | Network::Stagenet => path.join(network.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ impl AllFieldsNetworkAddress {
|
||||
NetworkAddress::from(OnionAddr::new(self.host?.as_str(), self.port?).ok()?)
|
||||
}
|
||||
// Invalid
|
||||
_ => return None,
|
||||
AddressType::Invalid | AddressType::I2p => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,10 @@ impl ProtocolMessage {
|
||||
decode_message(ProtocolMessage::FluffyMissingTransactionsRequest, buf)?
|
||||
}
|
||||
C::GetTxPoolCompliment => decode_message(ProtocolMessage::GetTxPoolCompliment, buf)?,
|
||||
_ => return Err(BucketError::UnknownCommand),
|
||||
|
||||
C::Handshake | C::TimedSync | C::Ping | C::SupportFlags | C::Unknown(_) => {
|
||||
return Err(BucketError::UnknownCommand);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -296,7 +299,17 @@ impl AdminRequestMessage {
|
||||
|
||||
Self::SupportFlags
|
||||
}
|
||||
_ => return Err(BucketError::UnknownCommand),
|
||||
|
||||
C::NewBlock
|
||||
| C::NewTransactions
|
||||
| C::GetObjectsRequest
|
||||
| C::GetObjectsResponse
|
||||
| C::ChainRequest
|
||||
| C::ChainResponse
|
||||
| C::NewFluffyBlock
|
||||
| C::FluffyMissingTxsRequest
|
||||
| C::GetTxPoolCompliment
|
||||
| C::Unknown(_) => return Err(BucketError::UnknownCommand),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -343,7 +356,17 @@ impl AdminResponseMessage {
|
||||
C::TimedSync => decode_message(AdminResponseMessage::TimedSync, buf)?,
|
||||
C::Ping => decode_message(AdminResponseMessage::Ping, buf)?,
|
||||
C::SupportFlags => decode_message(AdminResponseMessage::SupportFlags, buf)?,
|
||||
_ => return Err(BucketError::UnknownCommand),
|
||||
|
||||
C::NewBlock
|
||||
| C::NewTransactions
|
||||
| C::GetObjectsRequest
|
||||
| C::GetObjectsResponse
|
||||
| C::ChainRequest
|
||||
| C::ChainResponse
|
||||
| C::NewFluffyBlock
|
||||
| C::FluffyMissingTxsRequest
|
||||
| C::GetTxPoolCompliment
|
||||
| C::Unknown(_) => return Err(BucketError::UnknownCommand),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -694,7 +694,7 @@ where
|
||||
allow_ping = false;
|
||||
continue;
|
||||
}
|
||||
_ => {
|
||||
AdminRequestMessage::Handshake(_) | AdminRequestMessage::TimedSync(_) => {
|
||||
return Err(HandshakeError::PeerSentInvalidMessage(
|
||||
"Peer sent an admin request before responding to the handshake",
|
||||
));
|
||||
|
||||
@@ -131,7 +131,7 @@ impl TryFrom<PeerRequest> for BroadcastMessage {
|
||||
PeerRequest::Protocol(ProtocolRequest::NewFluffyBlock(block)) => {
|
||||
Ok(Self::NewFluffyBlock(block))
|
||||
}
|
||||
_ => Err(MessageConversionError),
|
||||
PeerRequest::Admin(_) | PeerRequest::Protocol(_) => Err(MessageConversionError),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,9 @@ impl Encoder<LevinMessage<Message>> for FragmentCodec {
|
||||
self.0.encode(frag.into(), dst)?;
|
||||
}
|
||||
}
|
||||
_ => unreachable!("Handshakes should only send bucket bodys"),
|
||||
LevinMessage::Bucket(_) | LevinMessage::Dummy(_) => {
|
||||
unreachable!("Handshakes should only send bucket bodys");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -148,6 +148,7 @@ impl Transport<Tor> for Arti {
|
||||
.unwrap();
|
||||
|
||||
// Accept all rendez-vous and await correct stream request
|
||||
#[expect(clippy::wildcard_enum_match_arm)]
|
||||
let req_stream = handle_rend_requests(rdv_stream).then(move |sreq| async move {
|
||||
match sreq.request() {
|
||||
// As specified in: <https://spec.torproject.org/rend-spec/managing-streams.html>
|
||||
|
||||
@@ -243,7 +243,7 @@ fn mock_block_downloader_client(blockchain: Arc<MockBlockchain>) -> Client<Clear
|
||||
},
|
||||
)))
|
||||
}
|
||||
_ => panic!(),
|
||||
PeerRequest::Admin(_) | PeerRequest::Protocol(_) => panic!(),
|
||||
}
|
||||
}
|
||||
.boxed()
|
||||
|
||||
@@ -231,6 +231,7 @@ impl Ord for DecompressedPruningSeed {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
// Compare the `log_stripes` first so peers which store more blocks are greater than peers
|
||||
// storing less.
|
||||
#[expect(clippy::wildcard_enum_match_arm)]
|
||||
match self.log_stripes.cmp(&other.log_stripes) {
|
||||
Ordering::Equal => self.stripe.cmp(&other.stripe),
|
||||
ord => ord,
|
||||
|
||||
@@ -88,7 +88,7 @@ impl Id {
|
||||
pub const fn as_u64(&self) -> Option<u64> {
|
||||
match self {
|
||||
Self::Num(n) => Some(*n),
|
||||
_ => None,
|
||||
Self::Null | Self::Str(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ impl Id {
|
||||
pub fn as_str(&self) -> Option<&str> {
|
||||
match self {
|
||||
Self::Str(s) => Some(s.as_ref()),
|
||||
_ => None,
|
||||
Self::Null | Self::Num(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -246,16 +246,14 @@ pub fn fixed_bytes(current_size_bytes: usize, add_bytes: usize) -> NonZeroUsize
|
||||
/// ```
|
||||
pub fn percent(current_size_bytes: usize, percent: f32) -> NonZeroUsize {
|
||||
// Guard against bad floats.
|
||||
use std::num::FpCategory;
|
||||
let percent = match percent.classify() {
|
||||
FpCategory::Normal => {
|
||||
if percent <= 1.0 {
|
||||
1.0
|
||||
} else {
|
||||
percent
|
||||
}
|
||||
let percent = if percent.classify() == std::num::FpCategory::Normal {
|
||||
if percent <= 1.0 {
|
||||
1.0
|
||||
} else {
|
||||
percent
|
||||
}
|
||||
_ => 1.0,
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
|
||||
let page_size = *PAGE_SIZE;
|
||||
|
||||
@@ -96,7 +96,16 @@ impl TransactionBlobs {
|
||||
match marker.inner_marker {
|
||||
InnerMarker::Object => Ok(Self::Pruned(Vec::read(b, &marker)?)),
|
||||
InnerMarker::String => Ok(Self::Normal(Vec::read(b, &marker)?)),
|
||||
_ => Err(cuprate_epee_encoding::Error::Value(
|
||||
InnerMarker::I64
|
||||
| InnerMarker::I32
|
||||
| InnerMarker::I16
|
||||
| InnerMarker::I8
|
||||
| InnerMarker::U64
|
||||
| InnerMarker::U32
|
||||
| InnerMarker::U16
|
||||
| InnerMarker::U8
|
||||
| InnerMarker::F64
|
||||
| InnerMarker::Bool => Err(cuprate_epee_encoding::Error::Value(
|
||||
"Invalid marker for tx blobs".to_string(),
|
||||
)),
|
||||
}
|
||||
|
||||
@@ -181,7 +181,21 @@ impl HardFork {
|
||||
pub const fn block_time(self) -> Duration {
|
||||
match self {
|
||||
Self::V1 => BLOCK_TIME_V1,
|
||||
_ => BLOCK_TIME_V2,
|
||||
Self::V2
|
||||
| Self::V3
|
||||
| Self::V4
|
||||
| Self::V5
|
||||
| Self::V6
|
||||
| Self::V7
|
||||
| Self::V8
|
||||
| Self::V9
|
||||
| Self::V10
|
||||
| Self::V11
|
||||
| Self::V12
|
||||
| Self::V13
|
||||
| Self::V14
|
||||
| Self::V15
|
||||
| Self::V16 => BLOCK_TIME_V2,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user