Skip to content

Commit

Permalink
refactor: improve readability of get_tracked_shards_view() (#10225)
Browse files Browse the repository at this point in the history
Previously the function created a vector of tuples just to deconstruct
it right away. This change hopefully makes it easier to digest the
function.
  • Loading branch information
akhi3030 authored Nov 20, 2023
1 parent debc26a commit 3387460
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions chain/client/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,28 +334,23 @@ impl ClientActor {
let epoch_id = self.client.chain.header_head()?.epoch_id;
let fetch_hash = self.client.chain.header_head()?.last_block_hash;
let me = self.client.validator_signer.as_ref().map(|x| x.validator_id().clone());

let tracked_shards: Vec<(bool, bool)> = (0..self
.client
.epoch_manager
.num_shards(&epoch_id)
.unwrap())
.map(|x| {
(
self.client.shard_tracker.care_about_shard(me.as_ref(), &fetch_hash, x, true),
self.client.shard_tracker.will_care_about_shard(
me.as_ref(),
&fetch_hash,
x,
true,
),
let num_shards = self.client.epoch_manager.num_shards(&epoch_id).unwrap();
let shards_tracked_this_epoch = (0..num_shards)
.map(|shard_id| {
self.client.shard_tracker.care_about_shard(me.as_ref(), &fetch_hash, shard_id, true)
})
.collect();
let shards_tracked_next_epoch = (0..num_shards)
.map(|shard_id| {
self.client.shard_tracker.will_care_about_shard(
me.as_ref(),
&fetch_hash,
shard_id,
true,
)
})
.collect();
Ok(TrackedShardsView {
shards_tracked_this_epoch: tracked_shards.iter().map(|x| x.0).collect(),
shards_tracked_next_epoch: tracked_shards.iter().map(|x| x.1).collect(),
})
Ok(TrackedShardsView { shards_tracked_this_epoch, shards_tracked_next_epoch })
}

fn get_recent_epoch_info(
Expand Down

0 comments on commit 3387460

Please sign in to comment.