Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
substrate
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
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
Radu Popa
substrate
Commits
28ab7f50
Commit
28ab7f50
authored
5 years ago
by
André Silva
Browse files
Options
Downloads
Patches
Plain Diff
babe: make the epoch duration a parameter type
parent
53b5b1d4
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/test-runtime/src/lib.rs
+7
-1
7 additions, 1 deletion
core/test-runtime/src/lib.rs
srml/babe/src/lib.rs
+8
-10
8 additions, 10 deletions
srml/babe/src/lib.rs
with
15 additions
and
11 deletions
core/test-runtime/src/lib.rs
+
7
−
1
View file @
28ab7f50
...
...
@@ -356,7 +356,13 @@ impl srml_timestamp::Trait for Runtime {
type
MinimumPeriod
=
MinimumPeriod
;
}
impl
srml_babe
::
Trait
for
Runtime
{}
parameter_types!
{
pub
const
EpochDuration
:
u64
=
6
;
}
impl
srml_babe
::
Trait
for
Runtime
{
type
EpochDuration
=
EpochDuration
;
}
/// Adds one to the given input and returns the final result.
#[inline(never)]
...
...
This diff is collapsed.
Click to expand it.
srml/babe/src/lib.rs
+
8
−
10
View file @
28ab7f50
...
...
@@ -107,7 +107,9 @@ impl ProvideInherentData for InherentDataProvider {
}
}
pub
trait
Trait
:
timestamp
::
Trait
{}
pub
trait
Trait
:
timestamp
::
Trait
{
type
EpochDuration
:
Get
<
u64
>
;
}
/// The length of the BABE randomness
pub
const
RANDOMNESS_LENGTH
:
usize
=
32
;
...
...
@@ -206,10 +208,10 @@ impl<T: Trait> IsMember<AuthorityId> for Module<T> {
}
}
impl
<
T
:
Trait
+
Duration
>
session
::
ShouldEndSession
<
T
::
BlockNumber
>
for
Module
<
T
>
{
impl
<
T
:
Trait
>
session
::
ShouldEndSession
<
T
::
BlockNumber
>
for
Module
<
T
>
{
fn
should_end_session
(
_
:
T
::
BlockNumber
)
->
bool
{
let
diff
=
CurrentSlot
::
get
()
.saturating_sub
(
EpochStartSlot
::
get
());
diff
>=
T
::
babe_e
poch
_d
uration
()
diff
>=
<
T
::
E
poch
D
uration
>
::
get
()
}
}
...
...
@@ -260,11 +262,7 @@ impl<T: Trait> OnTimestampSet<T::Moment> for Module<T> {
fn
on_timestamp_set
(
_moment
:
T
::
Moment
)
{
}
}
pub
trait
Duration
{
fn
babe_epoch_duration
()
->
u64
;
}
impl
<
T
:
Trait
+
staking
::
Trait
+
Duration
>
session
::
OneSessionHandler
<
T
::
AccountId
>
for
Module
<
T
>
{
impl
<
T
:
Trait
+
staking
::
Trait
>
session
::
OneSessionHandler
<
T
::
AccountId
>
for
Module
<
T
>
{
type
Key
=
AuthorityId
;
fn
on_new_session
<
'a
,
I
:
'a
>
(
_changed
:
bool
,
_validators
:
I
,
queued_validators
:
I
)
where
I
:
Iterator
<
Item
=
(
&
'a
T
::
AccountId
,
AuthorityId
)
>
...
...
@@ -288,14 +286,14 @@ impl<T: Trait + staking::Trait + Duration> session::OneSessionHandler<T::Account
// What was the next epoch is now the current epoch
let
randomness
=
Self
::
randomness_change_epoch
(
epoch_index
);
EpochStartSlot
::
mutate
(|
previous
|
*
previous
+=
T
::
babe_e
poch
_d
uration
());
EpochStartSlot
::
mutate
(|
previous
|
*
previous
+=
<
T
::
E
poch
D
uration
>
::
get
());
let
start_slot
=
EpochStartSlot
::
get
();
Self
::
change_epoch
(
Epoch
{
epoch_index
,
start_slot
,
duration
:
T
::
babe_e
poch
_d
uration
(),
duration
:
<
T
::
E
poch
D
uration
>
::
get
(),
authorities
,
randomness
,
})
...
...
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