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

Conversation

@tomusdrw
Copy link
Contributor

@tomusdrw tomusdrw commented Sep 11, 2019

Resolves #3553

Currently im-online is using (indirectly) staking::current_elected_set to get the validators and report those who didn't send a Heartbeat.
That's incorrect, since session is buffering the keys (and validator set changes). In this PR we use Session::validators instead, which allows us to get rid of the extra associated type.

  • Add some simple tests to im-online module.
  • Remove dependency on staking
  • Relax crypto requirements (don't require AppKey).
  • Make UintAuthorityId more usable in tests.

Polkadot PR: #429

@tomusdrw tomusdrw added A0-please_review Pull request needs code review. M4-core labels Sep 11, 2019
}
}

impl PartialOrd for UintAuthorityId {
Copy link
Member

Choose a reason for hiding this comment

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

WHy not just auto derive it?

}
}

impl Ord for UintAuthorityId {
Copy link
Member

Choose a reason for hiding this comment

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

Same

};
let signature = id.sign(&heartbeat.encode()).unwrap();

// when
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// when

assert!(!ImOnline::is_online_in_current_session(0));

// when
heartbeat(block, 2, 0, 1.into());
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get how in block 1 session_index = 2

Copy link
Contributor

Choose a reason for hiding this comment

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

(I changed the code a bit but my question still holds)
(I am aware of the buffering and that we need one extra rotate_session to write the buffered validators)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Session rotations are independent of blocks. In regular node-runtime that would never happen though.


assert_eq!(Session::current_index(), 2);
// TODO: hmmm...
assert_eq!(Session::validators(), vec![1, 2, 3]);
Copy link
Contributor

Choose a reason for hiding this comment

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

why? I was expecting all 6 of them to get buffered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first time you call advance_session we switch to:
current(vec![]), queued(vec![1, 2, 3])
second time you call advance_session we switch to:
current(vec![1, 2, 3]), queued(vec![1,...6]))

Initially both current and queued are empty.

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.

Added another small test, one should probably add a LOT more in a separate PR; looks good as-is to be merged and fix a potentially critical issue.

@gavofyork gavofyork added A8-looksgood and removed A0-please_review Pull request needs code review. labels Sep 11, 2019
advance_session();

assert_eq!(Session::current_index(), 2);
// TODO: hmmm...
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this ToDo forgotten here? If not a follow-up ticket or a better explanation would be nice.

Copy link
Contributor Author

@tomusdrw tomusdrw Sep 12, 2019

Choose a reason for hiding this comment

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

Removed, it was addressed by this comment: #3596 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, my bad. I should have just asked the question. Writing to TODO was maybe too much :D

@tomusdrw
Copy link
Contributor Author

Everything fixed now, should be good to go.

@tomusdrw tomusdrw requested a review from gui1117 as a code owner September 13, 2019 12:00
@gavofyork gavofyork merged commit 1a59e8c into master Sep 13, 2019
@gavofyork gavofyork deleted the td-imonline-session branch September 13, 2019 12:55
svyatonik pushed a commit that referenced this pull request Sep 17, 2019
* Use session::validators instead of staking::current_elected

* Basic test framework.

* Initialize validators, attempt to heartbeat.

* Use dummy crypto for im-online testing.

* Remove printlns.

* Finish test, make it invalid.

* Add reporting test.

* Finalize the test.

* Remove dumbness.

* Updates.

* Update AuRa

* Update srml/im-online/src/tests.rs

Co-Authored-By: Bastian Köcher <[email protected]>

* Derive Ord

* Add some more tests.

* Remove stray todo.

* Bump runtime version.

* Bump impl-trait-for-tuples.

* Enforce new version of trait-for-tuples.
Demi-Marie pushed a commit to Demi-Marie/substrate that referenced this pull request Sep 17, 2019
* Use session::validators instead of staking::current_elected

* Basic test framework.

* Initialize validators, attempt to heartbeat.

* Use dummy crypto for im-online testing.

* Remove printlns.

* Finish test, make it invalid.

* Add reporting test.

* Finalize the test.

* Remove dumbness.

* Updates.

* Update AuRa

* Update srml/im-online/src/tests.rs

Co-Authored-By: Bastian Köcher <[email protected]>

* Derive Ord

* Add some more tests.

* Remove stray todo.

* Bump runtime version.

* Bump impl-trait-for-tuples.

* Enforce new version of trait-for-tuples.
en pushed a commit to en/substrate that referenced this pull request Sep 24, 2019
* Use session::validators instead of staking::current_elected

* Basic test framework.

* Initialize validators, attempt to heartbeat.

* Use dummy crypto for im-online testing.

* Remove printlns.

* Finish test, make it invalid.

* Add reporting test.

* Finalize the test.

* Remove dumbness.

* Updates.

* Update AuRa

* Update srml/im-online/src/tests.rs

Co-Authored-By: Bastian Köcher <[email protected]>

* Derive Ord

* Add some more tests.

* Remove stray todo.

* Bump runtime version.

* Bump impl-trait-for-tuples.

* Enforce new version of trait-for-tuples.
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.

Time gap for validators between srml/staking and srml/session will result in direct slash for new validators.

6 participants