Skip to content

Commit

Permalink
use Arc to avoid cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
alindima committed Feb 22, 2024
1 parent 9c3dd5c commit af1cd82
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions polkadot/node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ struct PerRelayParentState {
/// The core states for all cores.
cores: Vec<CoreState>,
/// The validator index -> group mapping at this relay parent.
validator_to_group: IndexedVec<ValidatorIndex, Option<GroupIndex>>,
validator_to_group: Arc<IndexedVec<ValidatorIndex, Option<GroupIndex>>>,
/// The associated group rotation information.
group_rotation_info: GroupRotationInfo,
}
Expand Down Expand Up @@ -290,7 +290,8 @@ struct State {
/// or explicit view for which a `Seconded` statement has been successfully imported.
per_candidate: HashMap<CandidateHash, PerCandidateState>,
/// Cache the per-session Validator->Group mapping.
validator_to_group_cache: LruMap<SessionIndex, IndexedVec<ValidatorIndex, Option<GroupIndex>>>,
validator_to_group_cache:
LruMap<SessionIndex, Arc<IndexedVec<ValidatorIndex, Option<GroupIndex>>>>,
/// A cloneable sender which is dispatched to background candidate validation tasks to inform
/// the main task of the result.
background_validation_tx: mpsc::Sender<(Hash, ValidatedCandidateCommand)>,
Expand Down Expand Up @@ -1110,7 +1111,7 @@ async fn construct_per_relay_parent_state<Context>(
keystore: &KeystorePtr,
validator_to_group_cache: &mut LruMap<
SessionIndex,
IndexedVec<ValidatorIndex, Option<GroupIndex>>,
Arc<IndexedVec<ValidatorIndex, Option<GroupIndex>>>,
>,
mode: ProspectiveParachainsMode,
) -> Result<Option<PerRelayParentState>, Error> {
Expand Down Expand Up @@ -1219,7 +1220,7 @@ async fn construct_per_relay_parent_state<Context>(
}
}

IndexedVec::<_, _>::from(vector)
Arc::new(IndexedVec::<_, _>::from(vector))
})
.expect("Just inserted");

Expand Down

0 comments on commit af1cd82

Please sign in to comment.