-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose voter state #114
Expose voter state #114
Conversation
It looks like @octol hasn't signed our Contributor License Agreement, yet.
You can read and sign our full Contributor License Agreement at the following URL: https://cla.parity.io Once you've signed, please reply to this thread with Many thanks, Parity Technologies CLA Bot |
[clabot:check] |
It looks like @octol signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
2fe5d65
to
e8b45e5
Compare
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.
overall lgtm. could you try adding a test where we spin up a set of voters and check the voter state afterwards? have a look at this test: https://github.com/paritytech/finality-grandpa/blob/master/src/voter/mod.rs#L948
@@ -286,6 +290,13 @@ impl<H, N, E: Environment<H, N>> PastRounds<H, N, E> where | |||
} | |||
} | |||
|
|||
pub(super) fn voting_rounds(&self) -> impl Iterator<Item = &VotingRound<H, N, E>> { |
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.
needs docs
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.
Agree!
src/voter/mod.rs
Outdated
@@ -420,6 +423,76 @@ fn instantiate_last_round<H, N, E: Environment<H, N>>( | |||
} | |||
} | |||
|
|||
pub trait VoterState<Id> { |
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.
These and the types below need docs :)
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.
Good catch!
src/testing.rs
Outdated
@@ -198,11 +199,19 @@ pub mod environment { | |||
} | |||
|
|||
impl crate::voter::Environment<&'static str, u32> for Environment { | |||
type Timer = BoxFuture<'static, Result<(),Error>>; | |||
type Timer = Pin<Box<dyn Future<Output = Result<(), Error>> + Unpin + Send + Sync>>; |
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.
I need to double check why we need to pin this and the stream/sink below.
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.
Removed in latest
I updated the tests so that now the check for |
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.
lgtm. @rphmeier do you want to give this a look?
src/voter/mod.rs
Outdated
inner.best_round.round_number(), | ||
inner.best_round.round_number() + 1, |
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.
inner.best_round.round_number(), | |
inner.best_round.round_number() + 1, | |
inner.best_round.round_number(), | |
inner.best_round.round_number() + 1, |
src/voter/mod.rs
Outdated
#[cfg_attr(test, derive(Debug))] | ||
pub struct RoundState<Id: Eq + std::hash::Hash> { | ||
pub total_weight: VoterWeight, | ||
pub threshold_weight: VoterWeight, |
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.
missing docs on these fields, VoterState
fields, and the mod report
, and fn voter_state
. There are even more missing docs - remember the guideline that all public items should be documented.
(yes, I know it's a PITA but it makes the code much more maintainable and readable)
src/voter/mod.rs
Outdated
} | ||
} | ||
|
||
pub struct Inner<H, N, E> where |
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.
Exposing a struct Inner
from voter.rs
seems a little ambiguous. Likewise, implementation on Arc<RwLock<...>>
directly seems difficult from a backwards-compatibility perspective. Could you elaborate on the goal of the trait VoterState
rather than having a simple struct?
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.
It's used in struct Voter
as well, but it's called inner
although there are other fields. This would not have to be exposed as public with a wrapper struct, meaning it could gain a more descriptive name than Inner
.
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.
The first approach Jon tried used a struct, the problem was that this struct had to be typed on H, N, E
, and we'd have to propagate these types throughout the substrate codebase, it was especially hairy because types like Environment
are currently not explicitly typed anywhere but would have to be due to the RPC initialization process. In substrate this trait is used as a trait object to avoid the type proliferation.
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.
OK, I assumed something like that. Still, the API could be improved substantially with a wrapping struct.
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.
Thanks for the feedback @rphmeier :)
I think we can actually remove the pub
from Inner
if I'm not mistaken? I'll add the missing docs
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.
IMO I think it's better to keep the struct anyway (although not exported) to be able to lock inner as a whole for correctness (rather than best and background distinctly).
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.
Updated the docs and removed the pub
from Inner
.
OK, I assumed something like that. Still, the API could be improved substantially with a wrapping struct.
Sorry, do you mean that the API could have been improved if using a simple struct instead of the trait would have been practical? Or that the API could be improved by creating a struct wrapping Arc<RwLock<...>>
just so that we don't have to impl
directly on Arc<RwLock<...>>
?
I started sketching on the latter but I got stuck on finding a good name ... :/
Probably VoterState
would be appropriate for such a struct, but then the trait would need to be renamed ... VoterStateQueryable
? Doesn't roll of the tongue very well ...
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.
struct SharedVoterState<...>(Arc<RwLock<Inner<...>>>);
and then you implement VoterState
for SharedVoterState
.
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.
Added the SharedVoterState
to wrap Arc<RwLock<Inner>>
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.
Looks fine except for grumbles
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.
thanks for adding all the missing docs to this crate, just some last minor nits.
Co-Authored-By: Joshy Orndorff <[email protected]>
Implement #55 and support paritytech/substrate#4921 / paritytech/substrate#5375
Expose voter state to the outside world. Useful for querying diagnostics
Left to do:
background_rounds
https://github.com/paritytech/finality-grandpa/pull/114/files#diff-7dbd927baa51274d73fc2a7cb663e166R484