-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Phragmen solution should submit for current era and be checked against current era #5583
Changes from all commits
28ae548
576efef
e2ff7bc
e8f1aac
a066fe8
29aba71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1847,20 +1847,20 @@ fn era_is_always_same_length() { | |
let session_per_era = <SessionsPerEra as Get<SessionIndex>>::get(); | ||
|
||
mock::start_era(1); | ||
assert_eq!(Staking::eras_start_session_index(active_era()).unwrap(), session_per_era); | ||
assert_eq!(Staking::eras_start_session_index(current_era()).unwrap(), session_per_era); | ||
|
||
mock::start_era(2); | ||
assert_eq!(Staking::eras_start_session_index(active_era()).unwrap(), session_per_era * 2u32); | ||
assert_eq!(Staking::eras_start_session_index(current_era()).unwrap(), session_per_era * 2u32); | ||
|
||
let session = Session::current_index(); | ||
ForceEra::put(Forcing::ForceNew); | ||
advance_session(); | ||
advance_session(); | ||
assert_eq!(Staking::active_era().unwrap().index, 3); | ||
assert_eq!(Staking::eras_start_session_index(active_era()).unwrap(), session + 2); | ||
assert_eq!(current_era(), 3); | ||
assert_eq!(Staking::eras_start_session_index(current_era()).unwrap(), session + 2); | ||
|
||
mock::start_era(4); | ||
assert_eq!(Staking::eras_start_session_index(active_era()).unwrap(), session + 2u32 + session_per_era); | ||
assert_eq!(Staking::eras_start_session_index(current_era()).unwrap(), session + 2u32 + session_per_era); | ||
}); | ||
} | ||
|
||
|
@@ -2912,7 +2912,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
)); | ||
|
||
let queued_result = Staking::queued_elected().unwrap(); | ||
|
@@ -2955,7 +2955,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note that for all those test current_era == active_era anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would be substantially better is to change the test setup to also have this one session drift. This is probably a lot of work, but I think a good step forward. In that case, I would expect active_era and current_era difference to matter. Also related #5244 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed if we want that we need to use a different session-pallet which have more than one session delay. |
||
)); | ||
|
||
let queued_result = Staking::queued_elected().unwrap(); | ||
|
@@ -3005,7 +3005,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenEarlySubmission, | ||
); | ||
|
@@ -3031,7 +3031,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
)); | ||
|
||
// a bad solution | ||
|
@@ -3042,7 +3042,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenWeakSubmission, | ||
); | ||
|
@@ -3068,7 +3068,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
)); | ||
|
||
// a better solution | ||
|
@@ -3078,7 +3078,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
)); | ||
}) | ||
} | ||
|
@@ -3116,7 +3116,7 @@ mod offchain_phragmen { | |
TransactionValidity::Ok(ValidTransaction { | ||
priority: (1 << 20) + 1125, // the proposed slot stake. | ||
requires: vec![], | ||
provides: vec![("StakingOffchain", active_era()).encode()], | ||
provides: vec![("StakingOffchain", current_era()).encode()], | ||
longevity: 3, | ||
propagate: false, | ||
}) | ||
|
@@ -3140,7 +3140,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
),); | ||
|
||
// now run the offchain worker in the same chain state. | ||
|
@@ -3191,7 +3191,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenBogusWinnerCount, | ||
); | ||
|
@@ -3222,7 +3222,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenBogusWinnerCount, | ||
); | ||
|
@@ -3251,7 +3251,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
),); | ||
}) | ||
} | ||
|
@@ -3282,7 +3282,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenBogusCompact, | ||
); | ||
|
@@ -3315,7 +3315,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenBogusCompact, | ||
); | ||
|
@@ -3347,7 +3347,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenBogusWinner, | ||
); | ||
|
@@ -3383,7 +3383,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenBogusEdge, | ||
); | ||
|
@@ -3419,7 +3419,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenBogusSelfVote, | ||
); | ||
|
@@ -3455,7 +3455,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenBogusSelfVote, | ||
); | ||
|
@@ -3490,7 +3490,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenBogusCompact, | ||
); | ||
|
@@ -3532,7 +3532,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenBogusNomination, | ||
); | ||
|
@@ -3560,7 +3560,7 @@ mod offchain_phragmen { | |
run_to_block(20); | ||
|
||
// slash 10. This must happen outside of the election window. | ||
let offender_expo = Staking::eras_stakers(active_era(), 11); | ||
let offender_expo = Staking::eras_stakers(Staking::active_era().unwrap().index, 11); | ||
on_offence_now( | ||
&[OffenceDetails { | ||
offender: (11, offender_expo.clone()), | ||
|
@@ -3595,7 +3595,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
)); | ||
|
||
// a wrong solution. | ||
|
@@ -3614,7 +3614,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenSlashedNomination, | ||
); | ||
|
@@ -3642,7 +3642,7 @@ mod offchain_phragmen { | |
winners, | ||
compact, | ||
score, | ||
active_era(), | ||
current_era(), | ||
), | ||
Error::<Test>::PhragmenBogusScore, | ||
); | ||
|
@@ -3729,7 +3729,7 @@ mod offchain_phragmen { | |
run_to_block(12); | ||
assert_eq!(Staking::era_election_status(), ElectionStatus::Open(12)); | ||
|
||
let offender_expo = Staking::eras_stakers(active_era(), 10); | ||
let offender_expo = Staking::eras_stakers(Staking::active_era().unwrap().index, 10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we sure this is correct and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. offence can come from active era or previous era (i.e. a validator must be validating or having been validating in order to commit an offence), it reports the exposures of the era of the offence. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it depends on this: pub(crate) fn on_offence_now(
offenders: &[OffenceDetails<AccountId, pallet_session::historical::IdentificationTuple<Test>>],
slash_fraction: &[Perbill],
) {
let now = Staking::active_era().unwrap().index;
on_offence_in_era(offenders, slash_fraction, now)
} it is fine for now. |
||
|
||
// panic from the impl in mock | ||
on_offence_now( | ||
|
@@ -3754,8 +3754,8 @@ fn slash_kicks_validators_not_nominators_and_disables_nominator_for_kicked_valid | |
assert_eq!(Balances::free_balance(101), 2000); | ||
|
||
// 11 and 21 both have the support of 100 | ||
let exposure_11 = Staking::eras_stakers(active_era(), &11); | ||
let exposure_21 = Staking::eras_stakers(active_era(), &21); | ||
let exposure_11 = Staking::eras_stakers(Staking::active_era().unwrap().index, &11); | ||
let exposure_21 = Staking::eras_stakers(Staking::active_era().unwrap().index, &21); | ||
|
||
assert_eq!(exposure_11.total, 1000 + 125); | ||
assert_eq!(exposure_21.total, 1000 + 375); | ||
|
@@ -3795,8 +3795,8 @@ fn slash_kicks_validators_not_nominators_and_disables_nominator_for_kicked_valid | |
assert_ok!(Staking::validate(Origin::signed(10), Default::default())); | ||
|
||
mock::start_era(2); | ||
let exposure_11 = Staking::eras_stakers(active_era(), &11); | ||
let exposure_21 = Staking::eras_stakers(active_era(), &21); | ||
let exposure_11 = Staking::eras_stakers(Staking::active_era().unwrap().index, &11); | ||
let exposure_21 = Staking::eras_stakers(Staking::active_era().unwrap().index, &21); | ||
|
||
// 10 is re-elected, but without the support of 100 | ||
assert_eq!(exposure_11.total, 900); | ||
|
@@ -3897,7 +3897,7 @@ fn zero_slash_keeps_nominators() { | |
|
||
assert_eq!(Balances::free_balance(11), 1000); | ||
|
||
let exposure = Staking::eras_stakers(active_era(), 11); | ||
let exposure = Staking::eras_stakers(Staking::active_era().unwrap().index, 11); | ||
assert_eq!(Balances::free_balance(101), 2000); | ||
|
||
on_offence_now( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I don't think this is defensive, if current_era is none it means there is no current_era, maybe the staking module hasn't started yet, but anyway I think it should return OffchainElectionError, but this is out of scope of the PR