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

client/authority-discovery: Allow to be run by sentry node#5568

Merged
andresilva merged 8 commits into
masterfrom
mxinden-authority-discovery-sentry
Apr 16, 2020
Merged

client/authority-discovery: Allow to be run by sentry node#5568
andresilva merged 8 commits into
masterfrom
mxinden-authority-discovery-sentry

Conversation

@mxinden

@mxinden mxinden commented Apr 7, 2020

Copy link
Copy Markdown
Contributor

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

@tomaka tomaka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me

Comment thread client/authority-discovery/src/lib.rs Outdated
use sp_core::traits::BareCryptoStorePtr;
use sp_runtime::{traits::Block as BlockT, generic::BlockId};
use sp_api::ProvideRuntimeApi;
// TODO: Needed?

@tomaka tomaka Apr 14, 2020

Copy link
Copy Markdown
Contributor

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

bkchr commented Apr 16, 2020

Copy link
Copy Markdown
Member

Does not compile.

@andresilva andresilva left a comment

Copy link
Copy Markdown
Contributor

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 thread client/authority-discovery/src/lib.rs Outdated
Comment thread bin/node/cli/src/service.rs Outdated
Comment thread bin/node/cli/src/service.rs Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread client/authority-discovery/src/lib.rs Outdated
fn get_own_public_keys_within_authority_set(
key_store: &BareCryptoStorePtr,
client: &Client,
) -> Result<HashSet<AuthorityId>> {

Copy link
Copy Markdown
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
Copy Markdown
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?

Co-Authored-By: André Silva <123550+andresilva@users.noreply.github.com>

@mxinden mxinden left a comment

Copy link
Copy Markdown
Contributor Author

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 thread bin/node/cli/src/service.rs Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

4 participants