Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
09b5def9
Commit
09b5def9
authored
2 years ago
by
Keith Yeung
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Use BoundedVec in aura pallet (#11617)
* Use BoundedVec in aura pallet * cargo fmt
parent
e0e34ad4
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/frame/aura/src/lib.rs
+12
-7
12 additions, 7 deletions
substrate/frame/aura/src/lib.rs
with
12 additions
and
7 deletions
substrate/frame/aura/src/lib.rs
+
12
−
7
View file @
09b5def9
...
...
@@ -40,8 +40,9 @@
use
codec
::{
Decode
,
Encode
,
MaxEncodedLen
};
use
frame_support
::{
log
,
traits
::{
DisabledValidators
,
FindAuthor
,
Get
,
OnTimestampSet
,
OneSessionHandler
},
BoundedSlice
,
ConsensusEngineId
,
Parameter
,
WeakBoundedVec
,
BoundedSlice
,
BoundedVec
,
ConsensusEngineId
,
Parameter
,
};
use
sp_consensus_aura
::{
AuthorityIndex
,
ConsensusLog
,
Slot
,
AURA_ENGINE_ID
};
use
sp_runtime
::{
...
...
@@ -116,7 +117,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn
authorities)]
pub
(
super
)
type
Authorities
<
T
:
Config
>
=
StorageValue
<
_
,
Weak
BoundedVec
<
T
::
AuthorityId
,
T
::
MaxAuthorities
>
,
ValueQuery
>
;
StorageValue
<
_
,
BoundedVec
<
T
::
AuthorityId
,
T
::
MaxAuthorities
>
,
ValueQuery
>
;
/// The current slot of this block.
///
...
...
@@ -150,7 +151,7 @@ impl<T: Config> Pallet<T> {
///
/// The storage will be applied immediately.
/// And aura consensus log will be appended to block's log.
pub
fn
change_authorities
(
new
:
Weak
BoundedVec
<
T
::
AuthorityId
,
T
::
MaxAuthorities
>
)
{
pub
fn
change_authorities
(
new
:
BoundedVec
<
T
::
AuthorityId
,
T
::
MaxAuthorities
>
)
{
<
Authorities
<
T
>>
::
put
(
&
new
);
let
log
=
DigestItem
::
Consensus
(
...
...
@@ -219,10 +220,14 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
let
next_authorities
=
validators
.map
(|(
_
,
k
)|
k
)
.collect
::
<
Vec
<
_
>>
();
let
last_authorities
=
Self
::
authorities
();
if
last_authorities
!=
next_authorities
{
let
bounded
=
<
WeakBoundedVec
<
_
,
T
::
MaxAuthorities
>>
::
force_from
(
next_authorities
,
Some
(
"AuRa new session"
),
);
if
next_authorities
.len
()
as
u32
>
T
::
MaxAuthorities
::
get
()
{
log
::
warn!
(
target
:
"runtime::aura"
,
"next authorities list larger than {}, truncating"
,
T
::
MaxAuthorities
::
get
(),
);
}
let
bounded
=
<
BoundedVec
<
_
,
T
::
MaxAuthorities
>>
::
truncate_from
(
next_authorities
);
Self
::
change_authorities
(
bounded
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment