Skip to content

Commit

Permalink
chore: clippy fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
MxmUrw committed Feb 14, 2025
1 parent cfc2a21 commit 11fb67a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
3 changes: 2 additions & 1 deletion api/bin/chainflip-elections-tracker/src/elections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use pallet_cf_elections::{
pub struct ElectionData<ES: ElectoralSystemTypes> {
pub height: u32,

#[allow(clippy::type_complexity)]
pub bitmaps: BTreeMap<
UniqueMonotonicIdentifier,
Vec<(BitmapComponentOf<ES>, BitVec<u8, bitvec::order::Lsb0>)>,
Expand Down Expand Up @@ -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(),
Expand Down
13 changes: 5 additions & 8 deletions api/bin/chainflip-elections-tracker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn observe_elections<T: Tracer + Send>(
{
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| {

Expand All @@ -92,7 +92,7 @@ async fn observe_elections<T: Tracer + Send>(
.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::<pallet_cf_elections::IndividualComponents::<Runtime, SolanaInstance>>(block_hash, key.unique_monotonic(), validator)
Expand All @@ -117,7 +117,7 @@ async fn observe_elections<T: Tracer + Send>(
CompositeElectionProperties::EE(_) => "Liveness",
CompositeElectionProperties::FF(_) => "Vaultswap",
};
(key.clone(), (name.into(), val.clone()))
(*key, (name.into(), val.clone()))
})
.collect();

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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
}
11 changes: 5 additions & 6 deletions api/bin/chainflip-elections-tracker/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,20 @@ pub fn map_with_parent<K: Ord, V, W>(
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);
}
}
processed
}

pub fn get_key_name<'a, K: std::fmt::Display>(key: &'a Vec<K>) -> String {
pub fn get_key_name<K: std::fmt::Display>(key: &[K]) -> String {
key.last().map(|x| format!("{x}")).unwrap_or("root".into())
}

Expand Down

0 comments on commit 11fb67a

Please sign in to comment.