Skip to content

Commit da0d858

Browse files
committed
Switch jail function by CommonParams
1 parent 21586fd commit da0d858

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

core/src/consensus/stake/mod.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,16 @@ pub fn on_term_close(
392392
let current_term = metadata.current_term_id();
393393
ctrace!(ENGINE, "on_term_close. current_term: {}", current_term);
394394

395+
let metadata = metadata.params().expect(
396+
"Term close events can be called after the ChangeParams called, \
397+
so the metadata always has CommonParams",
398+
);
399+
let custody_period = metadata.custody_period();
400+
let release_period = metadata.release_period();
401+
395402
let (nomination_expiration, custody_until, kick_at) = {
396-
let metadata = metadata.params().expect(
397-
"Term close events can be called after the ChangeParams called, \
398-
so the metadata always has CommonParams",
399-
);
400403
let nomination_expiration = metadata.nomination_expiration();
401404
assert_ne!(0, nomination_expiration);
402-
let custody_period = metadata.custody_period();
403-
assert_ne!(0, custody_period);
404-
let release_period = metadata.release_period();
405-
assert_ne!(0, release_period);
406405
(nomination_expiration, current_term + custody_period, current_term + release_period)
407406
};
408407

@@ -412,7 +411,10 @@ pub fn on_term_close(
412411
let reverted: Vec<_> = expired.into_iter().chain(released).collect();
413412
revert_delegations(state, &reverted)?;
414413

415-
jail(state, inactive_validators, custody_until, kick_at)?;
414+
let jail_enabled = custody_period != 0 || release_period != 0;
415+
if jail_enabled {
416+
jail(state, inactive_validators, custody_until, kick_at)?;
417+
}
416418

417419
let validators = Validators::elect(state)?;
418420
validators.save_to_state(state)?;

types/src/common_params.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,6 @@ impl CommonParams {
181181
if self.nomination_expiration == 0 {
182182
return Err("You should set the nomination expiration".to_string())
183183
}
184-
if self.custody_period == 0 {
185-
return Err("You should set the custody period".to_string())
186-
}
187-
if self.release_period == 0 {
188-
return Err("You should set the release period".to_string())
189-
}
190184
if self.max_num_of_validators == 0 {
191185
return Err("You should set the maximum number of validators".to_string())
192186
}
@@ -205,7 +199,7 @@ impl CommonParams {
205199
self.min_num_of_validators, self.max_num_of_validators
206200
))
207201
}
208-
if self.custody_period >= self.release_period {
202+
if self.custody_period > self.release_period {
209203
return Err(format!(
210204
"The release period({}) should be longer than the custody period({})",
211205
self.release_period, self.custody_period

0 commit comments

Comments
 (0)