Skip to content

Commit

Permalink
[PICA-149] Ensure backwards compatibility with ed25519_verify (#3192)
Browse files Browse the repository at this point in the history
  • Loading branch information
vimukthi-git authored Feb 15, 2023
1 parent f42c9c3 commit 7692fb8
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 39 deletions.
1 change: 1 addition & 0 deletions code/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions code/parachain/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ sp-storage = { git = "https://github.com/paritytech/substrate", branch = "polkad
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }

# Cumulus dependencies
cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" }
Expand Down
4 changes: 4 additions & 0 deletions code/parachain/node/src/chain_spec/composable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use composable_runtime::GenesisConfig;

use super::{Extensions, ParaId};

// The block number until ed25519-dalek should be used for signature verification. Decided at
// 1_393_300
pub const DALEK_END_BLOCK: u32 = 1_681_300;

/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, Extensions>;

Expand Down
4 changes: 4 additions & 0 deletions code/parachain/node/src/chain_spec/picasso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use picasso_runtime::GenesisConfig;

use super::{Extensions, ParaId};

// The block number until ed25519-dalek should be used for signature verification. Decided at
// 1_788_000
pub const DALEK_END_BLOCK: u32 = 2_076_000;

/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, Extensions>;

Expand Down
19 changes: 11 additions & 8 deletions code/parachain/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,23 @@ pub fn run() -> Result<()> {
let partials = new_partial::<
picasso_runtime::RuntimeApi,
PicassoExecutor,
>(&config)?;
>(&config, Option::None)?;
cmd.run(partials.client)
},
#[cfg(feature = "dali")]
id if id.contains("dali") => {
let partials =
new_partial::<dali_runtime::RuntimeApi, DaliExecutor>(&config)?;
let partials = new_partial::<dali_runtime::RuntimeApi, DaliExecutor>(
&config,
Option::None,
)?;
cmd.run(partials.client)
},
#[cfg(feature = "composable")]
id if id.contains("composable") => {
let partials = new_partial::<
composable_runtime::RuntimeApi,
ComposableExecutor,
>(&config)?;
>(&config, Option::None)?;
cmd.run(partials.client)
},
id => panic!("Unknown Chain: {}", id),
Expand All @@ -278,16 +280,17 @@ pub fn run() -> Result<()> {
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| match config.chain_spec.id() {
id if id.contains("picasso") => {
let partials =
new_partial::<picasso_runtime::RuntimeApi, PicassoExecutor>(&config)?;
let partials = new_partial::<picasso_runtime::RuntimeApi, PicassoExecutor>(
&config, None,
)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();
cmd.run(config, partials.client, db, storage)
},
#[cfg(feature = "dali")]
id if id.contains("dali") => {
let partials =
new_partial::<dali_runtime::RuntimeApi, DaliExecutor>(&config)?;
new_partial::<dali_runtime::RuntimeApi, DaliExecutor>(&config, None)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();
cmd.run(config, partials.client, db, storage)
Expand All @@ -297,7 +300,7 @@ pub fn run() -> Result<()> {
let partials = new_partial::<
composable_runtime::RuntimeApi,
ComposableExecutor,
>(&config)?;
>(&config, None)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();
cmd.run(config, partials.client, db, storage)
Expand Down
85 changes: 54 additions & 31 deletions code/parachain/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use sc_consensus::ImportQueue;
use sc_network_common::service::NetworkBlock;
// Substrate Imports
use crate::{
chain_spec,
client::{Client, FullBackend, FullClient},
rpc,
runtime::{
Expand Down Expand Up @@ -110,8 +111,10 @@ pub fn new_chain_ops(
let components = match config.chain_spec.id() {
#[cfg(feature = "composable")]
chain if chain.contains("composable") => {
let components =
new_partial::<composable_runtime::RuntimeApi, ComposableExecutor>(config)?;
let components = new_partial::<composable_runtime::RuntimeApi, ComposableExecutor>(
config,
Some(chain_spec::composable::DALEK_END_BLOCK),
)?;
(
Arc::new(Client::from(components.client)),
components.backend,
Expand All @@ -121,7 +124,8 @@ pub fn new_chain_ops(
},
#[cfg(feature = "dali")]
chain if chain.contains("dali") => {
let components = new_partial::<dali_runtime::RuntimeApi, DaliExecutor>(config)?;
let components =
new_partial::<dali_runtime::RuntimeApi, DaliExecutor>(config, Option::None)?;
(
Arc::new(Client::from(components.client)),
components.backend,
Expand All @@ -130,7 +134,10 @@ pub fn new_chain_ops(
)
},
chain if chain.contains("picasso") => {
let components = new_partial::<picasso_runtime::RuntimeApi, PicassoExecutor>(config)?;
let components = new_partial::<picasso_runtime::RuntimeApi, PicassoExecutor>(
config,
Some(chain_spec::picasso::DALEK_END_BLOCK),
)?;
(
Arc::new(Client::from(components.client)),
components.backend,
Expand All @@ -147,6 +154,8 @@ pub fn new_chain_ops(
#[allow(clippy::type_complexity)]
pub fn new_partial<RuntimeApi, Executor>(
config: &Configuration,
// The block number until ed25519-dalek should be used for signature verification.
dalek_end_block: Option<u32>,
) -> Result<
PartialComponents<
FullClient<RuntimeApi, Executor>,
Expand Down Expand Up @@ -197,6 +206,13 @@ where
)?;
let client = Arc::new(client);

use sc_client_api::ExecutorProvider;
client.execution_extensions().set_extensions_factory(
sc_client_api::execution_extensions::ExtensionBeforeBlock::<
crate::client::Block,
sp_io::UseDalekExt,
>::new(dalek_end_block.unwrap_or(0)),
);
let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());

let telemetry = telemetry.map(|(worker, telemetry)| {
Expand Down Expand Up @@ -241,33 +257,38 @@ pub async fn start_node(
collator_options: CollatorOptions,
id: ParaId,
) -> sc_service::error::Result<TaskManager> {
let task_manager =
match config.chain_spec.id() {
#[cfg(feature = "composable")]
chain if chain.contains("composable") => crate::service::start_node_impl::<
composable_runtime::RuntimeApi,
ComposableExecutor,
>(config, polkadot_config, collator_options, id)
let task_manager = match config.chain_spec.id() {
#[cfg(feature = "composable")]
chain if chain.contains("composable") =>
crate::service::start_node_impl::<composable_runtime::RuntimeApi, ComposableExecutor>(
config,
polkadot_config,
collator_options,
id,
Some(chain_spec::composable::DALEK_END_BLOCK),
)
.await?,
#[cfg(feature = "dali")]
chain if chain.contains("dali") =>
crate::service::start_node_impl::<dali_runtime::RuntimeApi, DaliExecutor>(
config,
polkadot_config,
collator_options,
id,
)
.await?,
chain if chain.contains("picasso") =>
crate::service::start_node_impl::<picasso_runtime::RuntimeApi, PicassoExecutor>(
config,
polkadot_config,
collator_options,
id,
)
.await?,
_ => panic!("Unknown chain_id: {}", config.chain_spec.id()),
};
#[cfg(feature = "dali")]
chain if chain.contains("dali") =>
crate::service::start_node_impl::<dali_runtime::RuntimeApi, DaliExecutor>(
config,
polkadot_config,
collator_options,
id,
Option::None,
)
.await?,
chain if chain.contains("picasso") =>
crate::service::start_node_impl::<picasso_runtime::RuntimeApi, PicassoExecutor>(
config,
polkadot_config,
collator_options,
id,
Some(chain_spec::picasso::DALEK_END_BLOCK),
)
.await?,
_ => panic!("Unknown chain_id: {}", config.chain_spec.id()),
};

Ok(task_manager)
}
Expand All @@ -281,6 +302,8 @@ async fn start_node_impl<RuntimeApi, Executor>(
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
// The block number until ed25519-dalek should be used for signature verification.
dalek_end_block: Option<u32>,
) -> sc_service::error::Result<TaskManager>
where
RuntimeApi:
Expand All @@ -298,7 +321,7 @@ where
{
let parachain_config = prepare_node_config(parachain_config);

let params = new_partial::<RuntimeApi, Executor>(&parachain_config)?;
let params = new_partial::<RuntimeApi, Executor>(&parachain_config, dalek_end_block)?;

#[cfg(feature = "ocw")]
{
Expand Down

0 comments on commit 7692fb8

Please sign in to comment.