Skip to content

Commit 785e912

Browse files
committed
Do not enforce network key presence for collators
Because of https://github.com/paritytech/polkadot-sdk/blob/299aacb56f4f11127b194d12692b00066e91ac92/cumulus/client/cli/src/lib.rs#L318 #3852 wrongly enforces that the network key is present for collators started with polkadot-parachain binary, instead of generating it on the fly. That is not necessary and created some small friction for collators, since they have to pass `--unsafe-force-node-key-generation` or generate the key with the `generate-node-key` command. This PR fixes that since the change was intended to apply only for relaychain authorithies. Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
1 parent 18ed309 commit 785e912

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

polkadot/cli/src/command.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ impl SubstrateCli for Cli {
153153
},
154154
})
155155
}
156+
157+
// Enforce the presence of a network key if the node is started as an authorithy.
158+
fn enforce_network_key_exists_when_authority(&self) -> bool {
159+
true
160+
}
156161
}
157162

158163
fn set_default_ss58_version(spec: &Box<dyn polkadot_service::ChainSpec>) {

substrate/client/cli/src/config.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,15 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
437437
///
438438
/// By default this is retrieved from `NodeKeyParams` if it is available. Otherwise its
439439
/// `NodeKeyConfig::default()`.
440-
fn node_key(&self, net_config_dir: &PathBuf) -> Result<NodeKeyConfig> {
440+
fn node_key(
441+
&self,
442+
net_config_dir: &PathBuf,
443+
require_key_for_authority: bool,
444+
) -> Result<NodeKeyConfig> {
441445
let is_dev = self.is_dev()?;
442446
let role = self.role(is_dev)?;
443447
self.node_key_params()
444-
.map(|x| x.node_key(net_config_dir, role, is_dev))
448+
.map(|x| x.node_key(net_config_dir, role, is_dev, require_key_for_authority))
445449
.unwrap_or_else(|| Ok(Default::default()))
446450
}
447451

@@ -490,7 +494,8 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
490494
Database::ParityDb
491495
},
492496
);
493-
let node_key = self.node_key(&net_config_dir)?;
497+
let node_key =
498+
self.node_key(&net_config_dir, cli.enforce_network_key_exists_when_authority())?;
494499
let role = self.role(is_dev)?;
495500
let max_runtime_instances = self.max_runtime_instances()?.unwrap_or(8);
496501
let is_validator = role.is_authority();

substrate/client/cli/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,9 @@ pub trait SubstrateCli: Sized {
250250
command.init(&Self::support_url(), &Self::impl_version(), logger_hook, &config)?;
251251
Runner::new(config, tokio_runtime, signals)
252252
}
253+
254+
/// Returns if a node should enforce the presence of a node key for authorities.
255+
fn enforce_network_key_exists_when_authority(&self) -> bool {
256+
false
257+
}
253258
}

substrate/client/cli/src/params/node_key_params.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl NodeKeyParams {
105105
net_config_dir: &PathBuf,
106106
role: Role,
107107
is_dev: bool,
108+
require_key_for_authority: bool,
108109
) -> error::Result<NodeKeyConfig> {
109110
Ok(match self.node_key_type {
110111
NodeKeyType::Ed25519 => {
@@ -116,8 +117,9 @@ impl NodeKeyParams {
116117
.clone()
117118
.unwrap_or_else(|| net_config_dir.join(NODE_KEY_ED25519_FILE));
118119
if !self.unsafe_force_node_key_generation &&
119-
role.is_authority() && !is_dev &&
120-
!key_path.exists()
120+
require_key_for_authority &&
121+
role.is_authority() &&
122+
!is_dev && !key_path.exists()
121123
{
122124
return Err(Error::NetworkKeyNotFound(key_path))
123125
}
@@ -166,12 +168,14 @@ mod tests {
166168
node_key_file: None,
167169
unsafe_force_node_key_generation: false,
168170
};
169-
params.node_key(net_config_dir, Role::Authority, false).and_then(|c| match c {
170-
NodeKeyConfig::Ed25519(sc_network::config::Secret::Input(ref ski))
171-
if node_key_type == NodeKeyType::Ed25519 && &sk[..] == ski.as_ref() =>
172-
Ok(()),
173-
_ => Err(error::Error::Input("Unexpected node key config".into())),
174-
})
171+
params.node_key(net_config_dir, Role::Authority, false, true).and_then(
172+
|c| match c {
173+
NodeKeyConfig::Ed25519(sc_network::config::Secret::Input(ref ski))
174+
if node_key_type == NodeKeyType::Ed25519 && &sk[..] == ski.as_ref() =>
175+
Ok(()),
176+
_ => Err(error::Error::Input("Unexpected node key config".into())),
177+
},
178+
)
175179
})
176180
}
177181

@@ -189,7 +193,7 @@ mod tests {
189193
};
190194

191195
let node_key = params
192-
.node_key(&PathBuf::from("not-used"), Role::Authority, false)
196+
.node_key(&PathBuf::from("not-used"), Role::Authority, false, true)
193197
.expect("Creates node key config")
194198
.into_keypair()
195199
.expect("Creates node key pair");
@@ -238,7 +242,7 @@ mod tests {
238242
let dir = PathBuf::from(net_config_dir.clone());
239243
let typ = params.node_key_type;
240244
let role = role.clone();
241-
params.node_key(net_config_dir, role, is_dev).and_then(move |c| match c {
245+
params.node_key(net_config_dir, role, is_dev, true).and_then(move |c| match c {
242246
NodeKeyConfig::Ed25519(sc_network::config::Secret::File(ref f))
243247
if typ == NodeKeyType::Ed25519 &&
244248
f == &dir.join(NODE_KEY_ED25519_FILE) =>

0 commit comments

Comments
 (0)