Skip to content

Commit

Permalink
[Trivial] Use 'into_inner' for WeakBoundedVec (paritytech#1664)
Browse files Browse the repository at this point in the history
Prevents authority set clone
  • Loading branch information
davxy committed Sep 21, 2023
1 parent f4add01 commit cc461ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
9 changes: 4 additions & 5 deletions substrate/frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ impl<T: Config> Pallet<T> {

if authorities.is_empty() {
log::warn!(target: LOG_TARGET, "Ignoring empty epoch change.");

return
}

Expand Down Expand Up @@ -664,7 +663,7 @@ impl<T: Config> Pallet<T> {
let next_randomness = NextRandomness::<T>::get();

let next_epoch = NextEpochDescriptor {
authorities: next_authorities.to_vec(),
authorities: next_authorities.into_inner(),
randomness: next_randomness,
};
Self::deposit_consensus(ConsensusLog::NextEpochData(next_epoch));
Expand Down Expand Up @@ -700,7 +699,7 @@ impl<T: Config> Pallet<T> {
epoch_index: EpochIndex::<T>::get(),
start_slot: Self::current_epoch_start(),
duration: T::EpochDuration::get(),
authorities: Self::authorities().to_vec(),
authorities: Self::authorities().into_inner(),
randomness: Self::randomness(),
config: EpochConfig::<T>::get()
.expect("EpochConfig is initialized in genesis; we never `take` or `kill` it; qed"),
Expand All @@ -725,7 +724,7 @@ impl<T: Config> Pallet<T> {
epoch_index: next_epoch_index,
start_slot,
duration: T::EpochDuration::get(),
authorities: NextAuthorities::<T>::get().to_vec(),
authorities: NextAuthorities::<T>::get().into_inner(),
randomness: NextRandomness::<T>::get(),
config: NextEpochConfig::<T>::get().unwrap_or_else(|| {
EpochConfig::<T>::get().expect(
Expand Down Expand Up @@ -778,7 +777,7 @@ impl<T: Config> Pallet<T> {
// we use the same values as genesis because we haven't collected any
// randomness yet.
let next = NextEpochDescriptor {
authorities: Self::authorities().to_vec(),
authorities: Self::authorities().into_inner(),
randomness: Self::randomness(),
};

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn first_block_epoch_zero_start() {

let consensus_log = sp_consensus_babe::ConsensusLog::NextEpochData(
sp_consensus_babe::digests::NextEpochDescriptor {
authorities: Babe::authorities().to_vec(),
authorities: Babe::authorities().into_inner(),
randomness: Babe::randomness(),
},
);
Expand Down
10 changes: 4 additions & 6 deletions substrate/frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,16 @@ pub mod pallet {
if let Some(pending_change) = <PendingChange<T>>::get() {
// emit signal if we're at the block that scheduled the change
if block_number == pending_change.scheduled_at {
let next_authorities = pending_change.next_authorities.to_vec();
if let Some(median) = pending_change.forced {
Self::deposit_log(ConsensusLog::ForcedChange(
median,
ScheduledChange {
delay: pending_change.delay,
next_authorities: pending_change.next_authorities.to_vec(),
},
ScheduledChange { delay: pending_change.delay, next_authorities },
))
} else {
Self::deposit_log(ConsensusLog::ScheduledChange(ScheduledChange {
delay: pending_change.delay,
next_authorities: pending_change.next_authorities.to_vec(),
next_authorities,
}));
}
}
Expand All @@ -149,7 +147,7 @@ pub mod pallet {
if block_number == pending_change.scheduled_at + pending_change.delay {
Self::set_grandpa_authorities(&pending_change.next_authorities);
Self::deposit_event(Event::NewAuthorities {
authority_set: pending_change.next_authorities.to_vec(),
authority_set: pending_change.next_authorities.into_inner(),
});
<PendingChange<T>>::kill();
}
Expand Down

0 comments on commit cc461ad

Please sign in to comment.