Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Phragmen solution should submit for current era and be checked against current era #5583

Merged
merged 6 commits into from
Apr 14, 2020

Conversation

gui1117
Copy link
Contributor

@gui1117 gui1117 commented Apr 8, 2020

phragmen solution should be submitted for the current era. the pallet-session can decide to delay by one or multiple era and dynamically. The active era should only be used for rewards stuff.

Phragmen solution submittion submit solution for the next current era so they should be submitted in the current_era, regardless of the active_era.

@@ -3006,7 +3060,7 @@ mod offchain_phragmen {
winners,
compact,
score,
active_era(),
current_era(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that for all those test current_era == active_era anyway.

Copy link
Contributor

@kianenigma kianenigma Apr 8, 2020

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

frame/staking/src/tests.rs Outdated Show resolved Hide resolved
@gui1117 gui1117 added the A0-please_review Pull request needs code review. label Apr 8, 2020
@gui1117 gui1117 added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Apr 9, 2020
Comment on lines 615 to 618
// This start and activate the era given.
// Because the mock use pallet-session which delays session by one, this will be one session after
// the election happened, not the first session after the election has happened.
pub fn start_era(era_index: EraIndex) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the test to use current_era instead of active_era but actually the tests generally as you pointed in #5244 the tests doesn't test this difference.

Also start_era is ambiguous and used to both start the current era or the active era.
But in the implementation it actually starts the active_era (without taking into account any Forced stuff, maybe would be better to change it with a while loop.

Comment on lines +116 to +117
// defensive-only: current era can never be none except genesis.
let current_era = <Module<T>>::current_era().unwrap_or_default();
Copy link
Contributor Author

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

@gui1117
Copy link
Contributor Author

gui1117 commented Apr 9, 2020

I updated the tests but they still doesn't cover this change indeed. should #5244 be part of this PR or should we merge this as is ?

@gui1117 gui1117 added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Apr 9, 2020
@@ -3780,7 +3780,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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure this is correct and the eras_stakers should be indexed by active era here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does fix the phragmen issue so approve for now, but long term i'd really like to see a revamp of staking tests so that:
1- active_era and current_era are actually different.
2- sessions is actually queuing the receiving validators (same as all of our real chains).

@kianenigma kianenigma added A3-needsresolving and removed A0-please_review Pull request needs code review. labels Apr 14, 2020
@gnunicorn gnunicorn merged commit ae62c56 into master Apr 14, 2020
@gnunicorn gnunicorn deleted the gui-fix-submit-solution-for-current-era branch April 14, 2020 14:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants