Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
parameterize seal_header() function and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusrodri committed Jun 19, 2023
1 parent 8f4e435 commit 6b612a7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
23 changes: 10 additions & 13 deletions nimbus-consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -250,27 +250,19 @@ pub(crate) fn seal_header<B>(
header: &B::Header,
keystore: &dyn Keystore,
public_pair: &Vec<u8>,
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");
Expand Down Expand Up @@ -399,7 +391,12 @@ where

let (header, extrinsics) = block.clone().deconstruct();

let sig_digest = seal_header::<B>(&header, &*self.keystore, &type_public_pair, &1u8);
let sig_digest = seal_header::<B>(
&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());
Expand Down
9 changes: 7 additions & 2 deletions nimbus-consensus/src/manual_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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::<B>(&params.header, &*self.keystore, &nimbus_public.to_raw_vec(), &1u8);
let sig_digest = crate::seal_header::<B>(
&params.header,
&*self.keystore,
&nimbus_public.to_raw_vec(),
&sr25519::CRYPTO_ID,
);

params.post_digests.push(sig_digest);

Expand Down
5 changes: 1 addition & 4 deletions parachain-template/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions parachain-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -294,7 +294,7 @@ where
Box::new(block_announce_validator)
})),
warp_sync_params: None,
net_config
net_config,
})?;

let rpc_extensions_builder = {
Expand Down Expand Up @@ -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?;
Expand All @@ -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)?;
Expand Down Expand Up @@ -493,7 +493,7 @@ pub fn start_instant_seal_node(config: Configuration) -> Result<TaskManager, sc_
import_queue,
block_announce_validator_builder: None,
warp_sync_params: None,
net_config
net_config,
})?;

if config.offchain_worker.enabled {
Expand Down

0 comments on commit 6b612a7

Please sign in to comment.