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
7ea85cb9
Commit
7ea85cb9
authored
2 years ago
by
Davide Galassi
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Prevent epochs pruning while finalizing blocks on epoch 0 (#12758)
* Prevent epochs pruning while on epoch 0
parent
e429ef1d
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/client/consensus/epochs/src/lib.rs
+85
-3
85 additions, 3 deletions
substrate/client/consensus/epochs/src/lib.rs
with
85 additions
and
3 deletions
substrate/client/consensus/epochs/src/lib.rs
+
85
−
3
View file @
7ea85cb9
...
...
@@ -518,13 +518,13 @@ where
let
is_descendent_of
=
descendent_of_builder
.build_is_descendent_of
(
None
);
let
predicate
=
|
epoch
:
&
PersistedEpochHeader
<
E
>
|
match
*
epoch
{
PersistedEpochHeader
::
Genesis
(
ref
epoch_
0
,
_
)
=>
epoch_
0
.start_slot
<=
slot
,
PersistedEpochHeader
::
Genesis
(
_
,
ref
epoch_
1
)
=>
epoch_
1
.start_slot
<=
slot
,
PersistedEpochHeader
::
Regular
(
ref
epoch_n
)
=>
epoch_n
.start_slot
<=
slot
,
};
//
p
rune any epochs which could not be _live_ as of the children of the
//
P
rune any epochs which could not be _live_ as of the children of the
// finalized block, i.e. re-root the fork tree to the oldest ancestor of
// (hash, number) where epoch.
end
_slot()
>
= finalized_slot
// (hash, number) where
`
epoch.
start
_slot()
<
= finalized_slot
`.
let
removed
=
self
.inner
.prune
(
hash
,
&
number
,
&
is_descendent_of
,
&
predicate
)
?
;
for
(
hash
,
number
,
_
)
in
removed
{
...
...
@@ -1197,6 +1197,88 @@ mod tests {
assert_eq!
(
nodes
,
vec!
[
b"B"
,
b"C"
,
b"F"
,
b"G"
]);
}
#[test]
fn
near_genesis_prune_works
()
{
// [X]: announces next epoch change (i.e. adds a node in the epoch changes tree)
//
// 0--[A]--B--C--D--E--[G]--H--I--J--K--[L]
// +
// \--[F]
let
is_descendent_of
=
|
base
:
&
Hash
,
block
:
&
Hash
|
->
Result
<
bool
,
TestError
>
{
match
(
block
,
base
)
{
|
(
b"A"
,
b"0"
)
|
(
b"B"
,
b"0"
|
b"A"
)
|
(
b"C"
,
b"0"
|
b"A"
|
b"B"
)
|
(
b"D"
,
b"0"
|
b"A"
|
b"B"
|
b"C"
)
|
(
b"E"
,
b"0"
|
b"A"
|
b"B"
|
b"C"
|
b"D"
)
|
(
b"F"
,
b"0"
|
b"A"
|
b"B"
|
b"C"
|
b"D"
|
b"E"
)
|
(
b"G"
,
b"0"
|
b"A"
|
b"B"
|
b"C"
|
b"D"
|
b"E"
)
|
(
b"H"
,
b"0"
|
b"A"
|
b"B"
|
b"C"
|
b"D"
|
b"E"
|
b"G"
)
|
(
b"I"
,
b"0"
|
b"A"
|
b"B"
|
b"C"
|
b"D"
|
b"E"
|
b"G"
|
b"H"
)
|
(
b"J"
,
b"0"
|
b"A"
|
b"B"
|
b"C"
|
b"D"
|
b"E"
|
b"G"
|
b"H"
|
b"I"
)
|
(
b"K"
,
b"0"
|
b"A"
|
b"B"
|
b"C"
|
b"D"
|
b"E"
|
b"G"
|
b"H"
|
b"I"
|
b"J"
)
|
(
b"L"
,
b"0"
|
b"A"
|
b"B"
|
b"C"
|
b"D"
|
b"E"
|
b"G"
|
b"H"
|
b"I"
|
b"J"
|
b"K"
,
)
=>
Ok
(
true
),
_
=>
Ok
(
false
),
}
};
let
mut
epoch_changes
=
EpochChanges
::
new
();
let
epoch
=
Epoch
{
start_slot
:
278183811
,
duration
:
5
};
let
epoch
=
PersistedEpoch
::
Genesis
(
epoch
.clone
(),
epoch
.increment
(()));
epoch_changes
.import
(
&
is_descendent_of
,
*
b"A"
,
1
,
Default
::
default
(),
IncrementedEpoch
(
epoch
))
.unwrap
();
let
import_at
=
|
epoch_changes
:
&
mut
EpochChanges
<
_
,
_
,
Epoch
>
,
slot
,
hash
:
&
Hash
,
number
,
parent_hash
,
parent_number
|
{
let
make_genesis
=
|
slot
|
Epoch
{
start_slot
:
slot
,
duration
:
5
};
// Get epoch descriptor valid for 'slot'
let
epoch_descriptor
=
epoch_changes
.epoch_descriptor_for_child_of
(
&
is_descendent_of
,
parent_hash
,
parent_number
,
slot
)
.unwrap
()
.unwrap
();
// Increment it
let
next_epoch_desc
=
epoch_changes
.viable_epoch
(
&
epoch_descriptor
,
&
make_genesis
)
.unwrap
()
.increment
(());
// Assign it to hash/number
epoch_changes
.import
(
&
is_descendent_of
,
*
hash
,
number
,
*
parent_hash
,
next_epoch_desc
)
.unwrap
();
};
// Should not prune anything
epoch_changes
.prune_finalized
(
&
is_descendent_of
,
b"C"
,
3
,
278183813
)
.unwrap
();
import_at
(
&
mut
epoch_changes
,
278183816
,
b"G"
,
6
,
b"E"
,
5
);
import_at
(
&
mut
epoch_changes
,
278183816
,
b"F"
,
6
,
b"E"
,
5
);
// Should not prune anything since we are on epoch0
epoch_changes
.prune_finalized
(
&
is_descendent_of
,
b"C"
,
3
,
278183813
)
.unwrap
();
let
mut
list
:
Vec
<
_
>
=
epoch_changes
.inner
.iter
()
.map
(|
e
|
e
.0
)
.collect
();
list
.sort
();
assert_eq!
(
list
,
vec!
[
b"A"
,
b"F"
,
b"G"
]);
import_at
(
&
mut
epoch_changes
,
278183821
,
b"L"
,
11
,
b"K"
,
10
);
// Should prune any fork of our ancestor not in the canonical chain (i.e. "F")
epoch_changes
.prune_finalized
(
&
is_descendent_of
,
b"J"
,
9
,
278183819
)
.unwrap
();
let
mut
list
:
Vec
<
_
>
=
epoch_changes
.inner
.iter
()
.map
(|
e
|
e
.0
)
.collect
();
list
.sort
();
assert_eq!
(
list
,
vec!
[
b"A"
,
b"G"
,
b"L"
]);
}
/// Test that ensures that the gap is not enabled when we import multiple genesis blocks.
#[test]
fn
gap_is_not_enabled_when_multiple_genesis_epochs_are_imported
()
{
...
...
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