Speed up getLeaderSchedule

This commit is contained in:
Michael Vines
2021-02-24 08:38:29 -08:00
parent eddb7f98f5
commit 5b54aed1c0

View File

@ -2405,15 +2405,23 @@ impl RpcSol for RpcSolImpl {
Ok( Ok(
solana_ledger::leader_schedule_utils::leader_schedule(epoch, &bank).map( solana_ledger::leader_schedule_utils::leader_schedule(epoch, &bank).map(
|leader_schedule| { |leader_schedule| {
let mut map = HashMap::new(); let mut leader_schedule_by_identity = HashMap::new();
for (slot_index, pubkey) in for (slot_index, identity_pubkey) in
leader_schedule.get_slot_leaders().iter().enumerate() leader_schedule.get_slot_leaders().iter().enumerate()
{ {
let pubkey = pubkey.to_string(); leader_schedule_by_identity
map.entry(pubkey).or_insert_with(Vec::new).push(slot_index); .entry(identity_pubkey)
.or_insert_with(Vec::new)
.push(slot_index);
} }
map
leader_schedule_by_identity
.into_iter()
.map(|(identity_pubkey, slot_indices)| {
(identity_pubkey.to_string(), slot_indices)
})
.collect()
}, },
), ),
) )