From 6b612a74a1e57eba2887019694cb87486c10a141 Mon Sep 17 00:00:00 2001 From: agus Date: Mon, 19 Jun 2023 11:21:40 -0300 Subject: [PATCH] parameterize seal_header() function and fmt --- nimbus-consensus/src/lib.rs | 23 ++++++++++------------- nimbus-consensus/src/manual_seal.rs | 9 +++++++-- parachain-template/node/src/cli.rs | 5 +---- parachain-template/node/src/service.rs | 10 +++++----- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/nimbus-consensus/src/lib.rs b/nimbus-consensus/src/lib.rs index 7a3753c6..4cc235a1 100644 --- a/nimbus-consensus/src/lib.rs +++ b/nimbus-consensus/src/lib.rs @@ -37,13 +37,13 @@ use sp_application_crypto::ByteArray; use sp_consensus::{ BlockOrigin, EnableProofRecording, Environment, ProofRecording, Proposal, Proposer, }; +use sp_core::{crypto::CryptoTypeId, sr25519}; use sp_inherents::{CreateInherentDataProviders, InherentData, InherentDataProvider}; use sp_keystore::{Keystore, KeystorePtr}; use sp_runtime::{ traits::{Block as BlockT, Header as HeaderT}, DigestItem, }; -use sp_core::{sr25519, ed25519, ecdsa}; use std::convert::TryInto; use std::{marker::PhantomData, sync::Arc, time::Duration}; use tracing::error; @@ -250,27 +250,19 @@ pub(crate) fn seal_header( header: &B::Header, keystore: &dyn Keystore, public_pair: &Vec, - crypto_algorithm: &u8 + crypto_id: &CryptoTypeId, ) -> DigestItem where B: BlockT, { let pre_hash = header.hash(); - // Choose the CryptoTypeId to use - let crypto_id = match *crypto_algorithm { - 1 => sr25519::CRYPTO_ID, - 2 => ed25519::CRYPTO_ID, - 3 => ecdsa::CRYPTO_ID, - _ => sr25519::CRYPTO_ID - }; - let raw_sig = Keystore::sign_with( &*keystore, NIMBUS_KEY_ID, - crypto_id, + *crypto_id, public_pair, - pre_hash.as_ref() + pre_hash.as_ref(), ) .expect("Keystore should be able to sign") .expect("We already checked that the key was present"); @@ -399,7 +391,12 @@ where let (header, extrinsics) = block.clone().deconstruct(); - let sig_digest = seal_header::(&header, &*self.keystore, &type_public_pair, &1u8); + let sig_digest = seal_header::( + &header, + &*self.keystore, + &type_public_pair, + &sr25519::CRYPTO_ID, + ); let mut block_import_params = BlockImportParams::new(BlockOrigin::Own, header.clone()); block_import_params.post_digests.push(sig_digest.clone()); diff --git a/nimbus-consensus/src/manual_seal.rs b/nimbus-consensus/src/manual_seal.rs index 16b38bf8..1e01b510 100644 --- a/nimbus-consensus/src/manual_seal.rs +++ b/nimbus-consensus/src/manual_seal.rs @@ -24,6 +24,7 @@ use sc_consensus::BlockImportParams; use sc_consensus_manual_seal::{ConsensusDataProvider, Error}; use sp_api::{BlockT, HeaderT, ProvideRuntimeApi, TransactionFor}; use sp_application_crypto::ByteArray; +use sp_core::sr25519; use sp_inherents::InherentData; use sp_keystore::KeystorePtr; use sp_runtime::{Digest, DigestItem}; @@ -121,8 +122,12 @@ where let nimbus_public = NimbusId::from_slice(&claimed_author) .map_err(|_| Error::StringError(String::from("invalid nimbus id (wrong length)")))?; - let sig_digest = - crate::seal_header::(¶ms.header, &*self.keystore, &nimbus_public.to_raw_vec(), &1u8); + let sig_digest = crate::seal_header::( + ¶ms.header, + &*self.keystore, + &nimbus_public.to_raw_vec(), + &sr25519::CRYPTO_ID, + ); params.post_digests.push(sig_digest); diff --git a/parachain-template/node/src/cli.rs b/parachain-template/node/src/cli.rs index 5600dbb8..f17741a8 100644 --- a/parachain-template/node/src/cli.rs +++ b/parachain-template/node/src/cli.rs @@ -75,10 +75,7 @@ impl RelayChainCli { ) -> Self { let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec); let chain_id = extension.map(|e| e.relay_chain.clone()); - let base_path = para_config - .base_path - .path() - .join("polkadot"); + let base_path = para_config.base_path.path().join("polkadot"); Self { base_path: Some(base_path), chain_id, diff --git a/parachain-template/node/src/service.rs b/parachain-template/node/src/service.rs index 351b632f..db7924a4 100644 --- a/parachain-template/node/src/service.rs +++ b/parachain-template/node/src/service.rs @@ -31,7 +31,7 @@ use polkadot_service::CollatorPair; use sc_consensus::ImportQueue; use sc_consensus_manual_seal::{run_instant_seal, InstantSealParams}; use sc_executor::NativeElseWasmExecutor; -use sc_network::{NetworkBlock, config::FullNetworkConfiguration}; +use sc_network::{config::FullNetworkConfiguration, NetworkBlock}; use sc_network_sync::SyncingService; use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; @@ -294,7 +294,7 @@ where Box::new(block_announce_validator) })), warp_sync_params: None, - net_config + net_config, })?; let rpc_extensions_builder = { @@ -366,7 +366,7 @@ where recovery_handle: Box::new(overseer_handle), collator_key: collator_key.expect("Command line arguments do not allow this. qed"), relay_chain_slot_duration, - sync_service + sync_service, }; start_collator(params).await?; @@ -380,7 +380,7 @@ where relay_chain_slot_duration, import_queue: import_queue_service, recovery_handle: Box::new(overseer_handle), - sync_service + sync_service, }; start_full_node(params)?; @@ -493,7 +493,7 @@ pub fn start_instant_seal_node(config: Configuration) -> Result