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
cab8fb5d
Commit
cab8fb5d
authored
5 years ago
by
Arkadiy Paronyan
Committed by
Bastian Köcher
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixed uncle pruning (#3491)
* Fixed uncle pruning * Version bump
parent
10b032bb
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/node/runtime/src/lib.rs
+2
-2
2 additions, 2 deletions
substrate/node/runtime/src/lib.rs
substrate/srml/authorship/src/lib.rs
+29
-26
29 additions, 26 deletions
substrate/srml/authorship/src/lib.rs
with
31 additions
and
28 deletions
substrate/node/runtime/src/lib.rs
+
2
−
2
View file @
cab8fb5d
...
...
@@ -79,8 +79,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to equal spec_version. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version
:
15
2
,
impl_version
:
15
2
,
spec_version
:
15
3
,
impl_version
:
15
3
,
apis
:
RUNTIME_API_VERSIONS
,
};
...
...
This diff is collapsed.
Click to expand it.
substrate/srml/authorship/src/lib.rs
+
29
−
26
View file @
cab8fb5d
...
...
@@ -27,7 +27,7 @@ use srml_support::traits::{FindAuthor, VerifySeal, Get};
use
srml_support
::
dispatch
::
Result
as
DispatchResult
;
use
codec
::{
Encode
,
Decode
};
use
system
::
ensure_none
;
use
sr_primitives
::
traits
::{
SimpleArithmetic
,
Header
as
HeaderT
,
One
,
Zero
};
use
sr_primitives
::
traits
::{
Header
as
HeaderT
,
One
,
Zero
};
use
sr_primitives
::
weights
::
SimpleDispatchInfo
;
use
inherents
::{
RuntimeString
,
InherentIdentifier
,
ProvideInherent
,
...
...
@@ -236,29 +236,14 @@ decl_storage! {
}
}
fn
prune_old_uncles
<
BlockNumber
,
Hash
,
Author
>
(
minimum_height
:
BlockNumber
,
uncles
:
&
mut
Vec
<
UncleEntryItem
<
BlockNumber
,
Hash
,
Author
>>
)
where
BlockNumber
:
SimpleArithmetic
{
let
prune_entries
=
uncles
.iter
()
.take_while
(|
item
|
match
item
{
UncleEntryItem
::
Uncle
(
_
,
_
)
=>
true
,
UncleEntryItem
::
InclusionHeight
(
height
)
=>
height
<
&
minimum_height
,
});
let
prune_index
=
prune_entries
.count
();
let
_
=
uncles
.drain
(
..
prune_index
);
}
decl_module!
{
pub
struct
Module
<
T
:
Trait
>
for
enum
Call
where
origin
:
T
::
Origin
{
fn
on_initialize
(
now
:
T
::
BlockNumber
)
{
let
uncle_generations
=
T
::
UncleGenerations
::
get
();
let
mut
uncles
=
<
Self
as
Store
>
::
Uncles
::
get
();
// prune uncles that are older than the allowed number of generations.
if
uncle_generations
<=
now
{
let
minimum_height
=
now
-
uncle_generations
;
prune_old_uncles
(
minimum_height
,
&
mut
uncles
)
Self
::
prune_old_uncles
(
minimum_height
)
}
<
Self
as
Store
>
::
DidSetUncles
::
put
(
false
);
...
...
@@ -387,6 +372,18 @@ impl<T: Trait> Module<T> {
// check uncle validity.
T
::
FilterUncle
::
filter_uncle
(
&
uncle
,
accumulator
)
}
fn
prune_old_uncles
(
minimum_height
:
T
::
BlockNumber
)
{
let
mut
uncles
=
<
Self
as
Store
>
::
Uncles
::
get
();
let
prune_entries
=
uncles
.iter
()
.take_while
(|
item
|
match
item
{
UncleEntryItem
::
Uncle
(
_
,
_
)
=>
true
,
UncleEntryItem
::
InclusionHeight
(
height
)
=>
height
<
&
minimum_height
,
});
let
prune_index
=
prune_entries
.count
();
let
_
=
uncles
.drain
(
..
prune_index
);
<
Self
as
Store
>
::
Uncles
::
put
(
uncles
);
}
}
impl
<
T
:
Trait
>
ProvideInherent
for
Module
<
T
>
{
...
...
@@ -569,15 +566,21 @@ mod tests {
#[test]
fn
prune_old_uncles_works
()
{
use
UncleEntryItem
::
*
;
let
mut
uncles
=
vec!
[
InclusionHeight
(
1u32
),
Uncle
((),
Some
(())),
Uncle
((),
None
),
Uncle
((),
None
),
InclusionHeight
(
2u32
),
Uncle
((),
None
),
InclusionHeight
(
3u32
),
Uncle
((),
None
),
];
prune_old_uncles
(
3
,
&
mut
uncles
);
assert_eq!
(
uncles
,
vec!
[
InclusionHeight
(
3
),
Uncle
((),
None
)]);
with_externalities
(
&
mut
new_test_ext
(),
||
{
let
hash
=
Default
::
default
();
let
author
=
Default
::
default
();
let
uncles
=
vec!
[
InclusionHeight
(
1u64
),
Uncle
(
hash
,
Some
(
author
)),
Uncle
(
hash
,
None
),
Uncle
(
hash
,
None
),
InclusionHeight
(
2u64
),
Uncle
(
hash
,
None
),
InclusionHeight
(
3u64
),
Uncle
(
hash
,
None
),
];
<
Authorship
as
Store
>
::
Uncles
::
put
(
uncles
);
Authorship
::
prune_old_uncles
(
3
);
let
uncles
=
<
Authorship
as
Store
>
::
Uncles
::
get
();
assert_eq!
(
uncles
,
vec!
[
InclusionHeight
(
3u64
),
Uncle
(
hash
,
None
)]);
})
}
#[test]
...
...
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