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

Conversation

@mxinden
Copy link
Contributor

@mxinden mxinden commented Apr 7, 2020

When run as a sentry node, the authority discovery module does not
publish any addresses to the dht, but still discovers validators and
sentry nodes of validators.

polkadot companion: paritytech/polkadot#984

When run as a sentry node, the authority discovery module does not
publish any addresses to the dht, but still discovers validators and
sentry nodes of validators.
@mxinden mxinden added A0-please_review Pull request needs code review. B1-clientnoteworthy labels Apr 7, 2020
Copy link
Contributor

@tomaka tomaka left a comment

Choose a reason for hiding this comment

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

Looks good to me

use sp_core::traits::BareCryptoStorePtr;
use sp_runtime::{traits::Block as BlockT, generic::BlockId};
use sp_api::ProvideRuntimeApi;
// TODO: Needed?
Copy link
Contributor

@tomaka tomaka Apr 14, 2020

Choose a reason for hiding this comment

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

Suggested change
// TODO: Needed?

There is an unused import, but it's not this one.

@bkchr
Copy link
Member

bkchr commented Apr 16, 2020

Does not compile.

Copy link
Contributor

@andresilva andresilva left a comment

Choose a reason for hiding this comment

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

minor nits. overall lgtm.

Comment on lines 181 to 196
let sentries;
let authority_discovery_role;

match role {
sc_service::config::Role::Authority { ref sentry_nodes } => {
sentries = sentry_nodes.clone();
authority_discovery_role = sc_authority_discovery::Role::Authority (
service.keystore(),
);
}
sc_service::config::Role::Sentry {..} => {
sentries = vec![];
authority_discovery_role = sc_authority_discovery::Role::Sentry;
}
_ => unreachable!("Due to outer matches! constraint; qed.")
}
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
let sentries;
let authority_discovery_role;
match role {
sc_service::config::Role::Authority { ref sentry_nodes } => {
sentries = sentry_nodes.clone();
authority_discovery_role = sc_authority_discovery::Role::Authority (
service.keystore(),
);
}
sc_service::config::Role::Sentry {..} => {
sentries = vec![];
authority_discovery_role = sc_authority_discovery::Role::Sentry;
}
_ => unreachable!("Due to outer matches! constraint; qed.")
}
let (sentries, authority_discovery_role) = match role {
sc_service::config::Role::Authority { ref sentry_nodes } => (
sentry_nodes.clone(),
sc_authority_discovery::Role::Authority(service.keystore()),
),
sc_service::config::Role::Sentry { .. } => (
vec![],
sc_authority_discovery::Role::Sentry,
),
_ => unreachable!("Due to outer matches! constraint; qed."),
};

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should move this code into some method in authority discovery so that we can re-use it in polkadot service. Do you think it would make sense for the AuthorityDiscovery::new to take sc_service::config::Role? Or maybe add a new constructor that takes it.

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 did have AuthorityDiscovery::new not take sc_service::config::Role for two reasons:

  • Make the authority discovery module independent of the underlying network.

  • Make it impossible at compile time to pass a key store as a sentry or to not pass a key store as a validator.

Does the above sound reasonable @andresilva ? If you think the additional code in cli/service is not worth the benefits above I can move it into the authority discovery module.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I didn't think of the sc_service dependency and also appreciate that keystore requirement is validated statically. Let's keep it in cli/service then.
I still prefer the code as written in my suggestion (I didn't test it, just wrote it in Github), mainly because I prefer expressions over statements. 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, sorry I that I oversaw your suggestion @andresilva. Indeed a lot better. 57d141d.

fn get_own_public_keys_within_authority_set(
key_store: &BareCryptoStorePtr,
client: &Client,
) -> Result<HashSet<AuthorityId>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we just kept this method as is and made it return an empty HashSet instead for sentries, couldn't we keep the rest of the logic above unchanged? I guess we could still keep the early exit in the method above.

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 am not sure returning an empty HashSet for sentry nodes would be more expressive. This reminds me of C code returning -1 on error.

Do you think the changes above are intrusive?

Copy link
Contributor Author

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

@andresilva thanks for the review! Would you mind taking another look?

Comment on lines 181 to 196
let sentries;
let authority_discovery_role;

match role {
sc_service::config::Role::Authority { ref sentry_nodes } => {
sentries = sentry_nodes.clone();
authority_discovery_role = sc_authority_discovery::Role::Authority (
service.keystore(),
);
}
sc_service::config::Role::Sentry {..} => {
sentries = vec![];
authority_discovery_role = sc_authority_discovery::Role::Sentry;
}
_ => unreachable!("Due to outer matches! constraint; qed.")
}
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 did have AuthorityDiscovery::new not take sc_service::config::Role for two reasons:

  • Make the authority discovery module independent of the underlying network.

  • Make it impossible at compile time to pass a key store as a sentry or to not pass a key store as a validator.

Does the above sound reasonable @andresilva ? If you think the additional code in cli/service is not worth the benefits above I can move it into the authority discovery module.

fn get_own_public_keys_within_authority_set(
key_store: &BareCryptoStorePtr,
client: &Client,
) -> Result<HashSet<AuthorityId>> {
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 am not sure returning an empty HashSet for sentry nodes would be more expressive. This reminds me of C code returning -1 on error.

Do you think the changes above are intrusive?

@andresilva
Copy link
Contributor

Needs merge with master to fix conflicts.

@andresilva andresilva merged commit 75134a2 into master Apr 16, 2020
@andresilva andresilva deleted the mxinden-authority-discovery-sentry branch April 16, 2020 17:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_review Pull request needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants