diff --git a/api/bin/chainflip-elections-tracker/src/elections.rs b/api/bin/chainflip-elections-tracker/src/elections.rs index 34bdb93cbc..a26019bda3 100644 --- a/api/bin/chainflip-elections-tracker/src/elections.rs +++ b/api/bin/chainflip-elections-tracker/src/elections.rs @@ -11,6 +11,7 @@ use pallet_cf_elections::{ pub struct ElectionData { pub height: u32, + #[allow(clippy::type_complexity)] pub bitmaps: BTreeMap< UniqueMonotonicIdentifier, Vec<(BitmapComponentOf, BitVec)>, @@ -169,7 +170,7 @@ where // no votes for authority_id in 0..data.validators { - if votes.get(&(*identifier, authority_id)).is_none() { + if !votes.contains_key(&(*identifier, authority_id)) { trace.insert( cloned_vec([&key0, &key1, &key2, &Category(extra.clone(), NoVote)]), start.clone(), diff --git a/api/bin/chainflip-elections-tracker/src/main.rs b/api/bin/chainflip-elections-tracker/src/main.rs index b98795120d..b182dd7dba 100644 --- a/api/bin/chainflip-elections-tracker/src/main.rs +++ b/api/bin/chainflip-elections-tracker/src/main.rs @@ -65,7 +65,7 @@ async fn observe_elections( { task_scope::task_scope(|scope| async move { - let (_finalized_stream, unfinalized_stream, client) = StateChainClient::connect_without_account(&scope, &rpc_url).await.unwrap(); + let (_finalized_stream, unfinalized_stream, client) = StateChainClient::connect_without_account(scope, &rpc_url).await.unwrap(); unfinalized_stream.fold((client, (BTreeMap::new(), BTreeMap::new()), tracer), async |(client, (overview_trace, detailed_traces), tracer), block| { @@ -92,7 +92,7 @@ async fn observe_elections( .expect("could not get storage"); let mut individual_components = BTreeMap::new(); - for (key, _prop) in &all_properties { + for key in all_properties.keys() { for (validator_index, validator) in validators.iter().enumerate() { if let Some((_, comp)) = client.storage_double_map_entry::>(block_hash, key.unique_monotonic(), validator) @@ -117,7 +117,7 @@ async fn observe_elections( CompositeElectionProperties::EE(_) => "Liveness", CompositeElectionProperties::FF(_) => "Vaultswap", }; - (key.clone(), (name.into(), val.clone())) + (*key, (name.into(), val.clone())) }) .collect(); @@ -174,7 +174,7 @@ where let context = if let Some(Some(context)) = p { let key = get_key_name(k); - let mut span = tracer.start_with_context(key, &context); + let mut span = tracer.start_with_context(key, context); for (key, value) in values { span.set_attribute(KeyValue::new(key, value)); } @@ -205,10 +205,7 @@ where }, ) .into_iter() - .filter_map(|(k, v)| match v { - Some(v) => Some((k, v)), - None => None, - }) + .filter_map(|(k, v)| v.map(|v| (k,v))) .collect(); traces } diff --git a/api/bin/chainflip-elections-tracker/src/trace.rs b/api/bin/chainflip-elections-tracker/src/trace.rs index 33d0ce62a4..0840403f48 100644 --- a/api/bin/chainflip-elections-tracker/src/trace.rs +++ b/api/bin/chainflip-elections-tracker/src/trace.rs @@ -48,13 +48,12 @@ pub fn map_with_parent( let mut processed = BTreeMap::new(); for length in 0..10 { for (key, value) in this.extract_if(|k, _| k.len() == length) { - let p; - if key.len() > 0 { + let p = if !key.is_empty() { let parent_key = &key[0..key.len() - 1]; - p = processed.get(parent_key); + processed.get(parent_key) } else { - p = None; - } + None + }; let v = f(&key, p, value); processed.insert(key, v); } @@ -62,7 +61,7 @@ pub fn map_with_parent( processed } -pub fn get_key_name<'a, K: std::fmt::Display>(key: &'a Vec) -> String { +pub fn get_key_name(key: &[K]) -> String { key.last().map(|x| format!("{x}")).unwrap_or("root".into()) }