Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Martin Pugh
polkadot
Commits
35cb5630
Unverified
Commit
35cb5630
authored
Nov 23, 2020
by
Andronik Ordian
Browse files
fix off-by-one error
parent
612c170e
Changes
1
Hide whitespace changes
Inline
Side-by-side
runtime/parachains/src/session_info.rs
View file @
35cb5630
...
...
@@ -25,7 +25,7 @@ use frame_support::{
weights
::
Weight
,
};
use
crate
::{
configuration
,
paras
,
scheduler
};
use
sp_std
::
vec
::
Vec
;
use
sp_std
::
{
cmp
,
vec
::
Vec
}
;
pub
trait
Trait
:
frame_system
::
Trait
...
...
@@ -94,8 +94,9 @@ impl<T: Trait> Module<T> {
let
new_session_index
=
notification
.session_index
;
let
old_earliest_stored_session
=
EarliestStoredSession
::
get
();
let
new_earliest_stored_session
=
new_session_index
.checked_sub
(
dispute_period
)
.unwrap_or
(
0
);
let
new_earliest_stored_session
=
core
::
cmp
::
max
(
new_earliest_stored_session
,
old_earliest_stored_session
);
let
dispute_period
=
cmp
::
max
(
1
,
dispute_period
);
let
new_earliest_stored_session
=
new_session_index
.checked_sub
(
dispute_period
-
1
)
.unwrap_or
(
0
);
let
new_earliest_stored_session
=
cmp
::
max
(
new_earliest_stored_session
,
old_earliest_stored_session
);
// update `EarliestStoredSession` based on `config.dispute_period`
EarliestStoredSession
::
set
(
new_earliest_stored_session
);
// remove all entries from `Sessions` from the previous value up to the new value
...
...
@@ -217,23 +218,23 @@ mod tests {
fn
session_pruning_is_based_on_dispute_deriod
()
{
new_test_ext
(
genesis_config
())
.execute_with
(||
{
run_to_block
(
100
,
session_changes
);
assert_eq!
(
EarliestStoredSession
::
get
(),
10
-
2
);
assert_eq!
(
EarliestStoredSession
::
get
(),
9
);
// changing dispute_period works
let
dispute_period
=
5
;
Configuration
::
set_dispute_period
(
Origin
::
root
(),
dispute_period
)
.unwrap
();
run_to_block
(
200
,
session_changes
);
assert_eq!
(
EarliestStoredSession
::
get
(),
20
-
dispute_period
);
assert_eq!
(
EarliestStoredSession
::
get
(),
20
-
dispute_period
+
1
);
// we don't have that many sessions stored
let
new_dispute_period
=
16
;
Configuration
::
set_dispute_period
(
Origin
::
root
(),
new_dispute_period
)
.unwrap
();
run_to_block
(
300
,
session_changes
);
assert_eq!
(
EarliestStoredSession
::
get
(),
20
-
dispute_period
);
assert_eq!
(
EarliestStoredSession
::
get
(),
20
-
dispute_period
+
1
);
// now we do
run_to_block
(
400
,
session_changes
);
assert_eq!
(
EarliestStoredSession
::
get
(),
40
-
new_dispute_period
);
assert_eq!
(
EarliestStoredSession
::
get
(),
40
-
new_dispute_period
+
1
);
})
}
...
...
Write
Preview
Supports
Markdown
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!
Cancel
Please
register
or
sign in
to comment