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
1e31b8d8
Commit
1e31b8d8
authored
6 years ago
by
Svyatoslav Nikolsky
Committed by
Gav Wood
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
log authorities change (#726)
parent
04e22cd7
Branches
gh-readonly-queue/master/pr-7640-9e75647c8cb0286f8d6b48f5e8acdcb386b10235
Branches containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
substrate/srml/consensus/src/lib.rs
+15
-4
15 additions, 4 deletions
substrate/srml/consensus/src/lib.rs
substrate/srml/consensus/src/mock.rs
+62
-0
62 additions, 0 deletions
substrate/srml/consensus/src/mock.rs
substrate/srml/consensus/src/tests.rs
+66
-0
66 additions, 0 deletions
substrate/srml/consensus/src/tests.rs
with
143 additions
and
4 deletions
substrate/srml/consensus/src/lib.rs
+
15
−
4
View file @
1e31b8d8
...
...
@@ -51,6 +51,9 @@ use primitives::bft::MisbehaviorReport;
use
substrate_primitives
::
storage
::
well_known_keys
;
use
system
::{
ensure_signed
,
ensure_inherent
};
mod
mock
;
mod
tests
;
struct
AuthorityStorageVec
<
S
:
codec
::
Codec
+
Default
>
(
rstd
::
marker
::
PhantomData
<
S
>
);
impl
<
S
:
codec
::
Codec
+
Default
>
StorageVec
for
AuthorityStorageVec
<
S
>
{
type
Item
=
S
;
...
...
@@ -90,13 +93,13 @@ impl<SessionKey: Member> RawLog<SessionKey> {
// Implementation for tests outside of this crate.
#[cfg(any(feature
=
"std"
,
test))]
impl
<
N
>
From
<
RawLog
<
N
>>
for
primitives
::
testing
::
DigestItem
{
impl
<
N
>
From
<
RawLog
<
N
>>
for
primitives
::
testing
::
DigestItem
where
N
:
Into
<
u64
>
{
fn
from
(
log
:
RawLog
<
N
>
)
->
primitives
::
testing
::
DigestItem
{
match
log
{
RawLog
::
AuthoritiesChange
(
authorities
)
=>
primitives
::
generic
::
DigestItem
::
AuthoritiesChange
::
<
substrate_primitives
::
H256
,
u64
>
(
authorities
.into_iter
()
.
enumerate
()
.map
(|(
i
,
_
)|
i
as
u64
)
.collect
()),
.
map
(
Into
::
into
)
.collect
()),
}
}
}
...
...
@@ -211,13 +214,21 @@ impl<T: Trait> Module<T> {
<
OriginalAuthorities
<
T
>>
::
put
(
current_authorities
.unwrap_or_else
(||
AuthorityStorageVec
::
<
T
::
SessionKey
>
::
items
()));
}
/// Deposit one of this module's logs.
fn
deposit_log
(
log
:
Log
<
T
>
)
{
<
system
::
Module
<
T
>>
::
deposit_log
(
<
T
as
Trait
>
::
Log
::
from
(
log
)
.into
());
}
}
/// Finalization hook for the consensus module.
impl
<
T
:
Trait
>
OnFinalise
<
T
::
BlockNumber
>
for
Module
<
T
>
{
fn
on_finalise
(
_n
:
T
::
BlockNumber
)
{
if
let
Some
(
_
)
=
<
OriginalAuthorities
<
T
>>
::
take
()
{
// TODO: call Self::deposit_log
if
let
Some
(
original_authorities
)
=
<
OriginalAuthorities
<
T
>>
::
take
()
{
let
current_authorities
=
AuthorityStorageVec
::
<
T
::
SessionKey
>
::
items
();
if
current_authorities
!=
original_authorities
{
Self
::
deposit_log
(
RawLog
::
AuthoritiesChange
(
current_authorities
));
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
substrate/srml/consensus/src/mock.rs
0 → 100644
+
62
−
0
View file @
1e31b8d8
// Copyright 2018 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Test utilities
#![cfg(test)]
use
primitives
::{
BuildStorage
,
testing
::{
Digest
,
DigestItem
,
Header
}};
use
runtime_io
;
use
substrate_primitives
::{
H256
,
Blake2Hasher
,
RlpCodec
};
use
{
GenesisConfig
,
Trait
,
Module
,
system
};
impl_outer_origin!
{
pub
enum
Origin
for
Test
{}
}
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone,
PartialEq,
Eq,
Debug,
Serialize,
Deserialize)]
pub
struct
Test
;
impl
Trait
for
Test
{
const
NOTE_OFFLINE_POSITION
:
u32
=
1
;
type
Log
=
DigestItem
;
type
SessionKey
=
u64
;
type
OnOfflineValidator
=
();
}
impl
system
::
Trait
for
Test
{
type
Origin
=
Origin
;
type
Index
=
u64
;
type
BlockNumber
=
u64
;
type
Hash
=
H256
;
type
Hashing
=
::
primitives
::
traits
::
BlakeTwo256
;
type
Digest
=
Digest
;
type
AccountId
=
u64
;
type
Header
=
Header
;
type
Event
=
();
type
Log
=
DigestItem
;
}
pub
fn
new_test_ext
(
authorities
:
Vec
<
u64
>
)
->
runtime_io
::
TestExternalities
<
Blake2Hasher
,
RlpCodec
>
{
let
mut
t
=
system
::
GenesisConfig
::
<
Test
>
::
default
()
.build_storage
()
.unwrap
();
t
.extend
(
GenesisConfig
::
<
Test
>
{
code
:
vec!
[],
authorities
,
}
.build_storage
()
.unwrap
());
t
.into
()
}
pub
type
System
=
system
::
Module
<
Test
>
;
pub
type
Consensus
=
Module
<
Test
>
;
This diff is collapsed.
Click to expand it.
substrate/srml/consensus/src/tests.rs
0 → 100644
+
66
−
0
View file @
1e31b8d8
// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Tests for the module.
#![cfg(test)]
use
super
::
*
;
use
primitives
::{
generic
,
testing
};
use
runtime_io
::
with_externalities
;
use
substrate_primitives
::
H256
;
use
mock
::{
Consensus
,
System
,
new_test_ext
};
#[test]
fn
authorities_change_logged
()
{
with_externalities
(
&
mut
new_test_ext
(
vec!
[
1
,
2
,
3
]),
||
{
System
::
initialise
(
&
1
,
&
Default
::
default
(),
&
Default
::
default
());
Consensus
::
set_authorities
(
&
[
4
,
5
,
6
]);
Consensus
::
on_finalise
(
1
);
let
header
=
System
::
finalise
();
assert_eq!
(
header
.digest
,
testing
::
Digest
{
logs
:
vec!
[
generic
::
DigestItem
::
AuthoritiesChange
::
<
H256
,
u64
>
(
vec!
[
4
,
5
,
6
]),
],
});
});
}
#[test]
fn
authorities_change_is_not_logged_when_not_changed
()
{
with_externalities
(
&
mut
new_test_ext
(
vec!
[
1
,
2
,
3
]),
||
{
System
::
initialise
(
&
1
,
&
Default
::
default
(),
&
Default
::
default
());
Consensus
::
on_finalise
(
1
);
let
header
=
System
::
finalise
();
assert_eq!
(
header
.digest
,
testing
::
Digest
{
logs
:
vec!
[],
});
});
}
#[test]
fn
authorities_change_is_not_logged_when_changed_back_to_original
()
{
with_externalities
(
&
mut
new_test_ext
(
vec!
[
1
,
2
,
3
]),
||
{
System
::
initialise
(
&
1
,
&
Default
::
default
(),
&
Default
::
default
());
Consensus
::
set_authorities
(
&
[
4
,
5
,
6
]);
Consensus
::
set_authorities
(
&
[
1
,
2
,
3
]);
Consensus
::
on_finalise
(
1
);
let
header
=
System
::
finalise
();
assert_eq!
(
header
.digest
,
testing
::
Digest
{
logs
:
vec!
[],
});
});
}
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