Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix frontier template pending #366

Merged
merged 6 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions client/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ cumulus-primitives-parachain-inherent = { workspace = true }
nimbus-consensus = { workspace = true }
nimbus-primitives = { workspace = true, features = [ "std" ] }

# Frontier Dependencies
fc-rpc = { workspace = true }

girazoki marked this conversation as resolved.
Show resolved Hide resolved

# Other deps
async-trait = { workspace = true }
futures = { workspace = true }
Expand Down
46 changes: 21 additions & 25 deletions client/consensus/src/manual_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,53 +145,34 @@ pub fn get_aura_id_from_seed(seed: &str) -> NimbusId {
}

/// Consensus data provider for Container Manual Seal Aura.
pub struct ContainerManualSealAuraConsensusDataProvider<B, C, P> {
pub struct ContainerManualSealAuraConsensusDataProvider<B> {
// slot duration
slot_duration: SlotDuration,
/// Shared reference to keystore
pub keystore: KeystorePtr,

/// Shared reference to the client
pub client: Arc<C>,
// Authorities from which the author should be calculated
pub authorities: Vec<NimbusId>,
// phantom data for required generics
_phantom: PhantomData<(B, C, P)>,
_phantom: PhantomData<B>,
}

impl<B, C, P> ContainerManualSealAuraConsensusDataProvider<B, C, P>
impl<B> ContainerManualSealAuraConsensusDataProvider<B>
where
B: BlockT,
C: AuxStore + ProvideRuntimeApi<B> + UsageProvider<B>,
{
/// Creates a new instance of the [`AuraConsensusDataProvider`], requires that `client`
/// implements [`sp_consensus_aura::AuraApi`]
pub fn new(
client: Arc<C>,
keystore: KeystorePtr,
slot_duration: SlotDuration,
authorities: Vec<NimbusId>,
) -> Self {
pub fn new(slot_duration: SlotDuration, authorities: Vec<NimbusId>) -> Self {
Self {
slot_duration,
keystore,
client,
authorities,
_phantom: PhantomData,
}
}
}
impl<B, C, P> ConsensusDataProvider<B> for ContainerManualSealAuraConsensusDataProvider<B, C, P>
impl<B> ConsensusDataProvider<B> for ContainerManualSealAuraConsensusDataProvider<B>
where
B: BlockT,
C: AuxStore
+ HeaderBackend<B>
+ HeaderMetadata<B, Error = sp_blockchain::Error>
+ UsageProvider<B>
+ ProvideRuntimeApi<B>,
P: Send + Sync,
{
type Proof = P;
type Proof = ();

fn create_digest(
&self,
Expand Down Expand Up @@ -238,3 +219,18 @@ where
Ok(())
}
}

impl<B> fc_rpc::pending::ConsensusDataProvider<B>
for ContainerManualSealAuraConsensusDataProvider<B>
where
B: BlockT,
{
fn create_digest(
&self,
_parent: &B::Header,
inherents: &InherentData,
) -> Result<sp_runtime::Digest, sp_inherents::Error> {
<Self as ConsensusDataProvider<B>>::create_digest(self, _parent, inherents)
.map_err(|_| sp_inherents::Error::FatalErrorReported)
}
}
6 changes: 1 addition & 5 deletions client/node-common/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,6 @@ where
self.telemetry.as_ref().map(|x| x.handle()),
);

// // Create channels for mocked XCM messages.
// let (downward_xcm_sender, downward_xcm_receiver) = flume::bounded::<Vec<u8>>(100);
// let (hrmp_xcm_sender, hrmp_xcm_receiver) = flume::bounded::<(ParaId, Vec<u8>)>(100);
// let xcm_senders = Some((downward_xcm_sender, hrmp_xcm_sender));
let mut command_sink = None;

if let Some(deadline) = soft_deadline {
Expand Down Expand Up @@ -619,7 +615,7 @@ where
Timer::interval(Duration::from_millis(millis)),
|_| EngineCommand::SealNewBlock {
create_empty: true,
finalize: false,
finalize: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

otherwise the import was not working when doing the interval one

parent_hash: None,
sender: None,
},
Expand Down
1 change: 1 addition & 0 deletions container-chains/templates/frontier/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ cumulus-client-service = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-primitives-parachain-inherent = { workspace = true }
cumulus-relay-chain-interface = { workspace = true }
cumulus-test-relay-sproof-builder = { workspace = true }

# Frontier
fc-api = { workspace = true }
Expand Down
67 changes: 64 additions & 3 deletions container-chains/templates/frontier/node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@

pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};

use sp_consensus_aura::SlotDuration;
use {
container_chain_template_frontier_runtime::{opaque::Block, AccountId, Hash, Index},
cumulus_primitives_core::ParaId,
cumulus_primitives_core::PersistedValidationData,
cumulus_primitives_parachain_inherent::ParachainInherentData,
cumulus_test_relay_sproof_builder::RelayStateSproofBuilder,
fc_rpc::{EthTask, TxPool},
fc_rpc_core::TxPoolApiServer,
fp_rpc::EthereumRuntimeRPCApi,
Expand All @@ -52,7 +56,6 @@ use {
sp_runtime::traits::{BlakeTwo256, Block as BlockT},
std::{sync::Arc, time::Duration},
};

pub struct DefaultEthConfig<C, BE>(std::marker::PhantomData<(C, BE)>);

impl<C, BE> fc_rpc::EthConfig<Block, C> for DefaultEthConfig<C, BE>
Expand Down Expand Up @@ -174,8 +177,56 @@ where
}
}
let convert_transaction: Option<Never> = None;
let authorities = vec![get_aura_id_from_seed("alice")];

let pending_create_inherent_data_providers = move |_, _| async move { Ok(()) };
let pending_create_inherent_data_providers = move |_, _| async move {
let mocked_authorities_noting =
ccp_authorities_noting_inherent::MockAuthoritiesNotingInherentDataProvider {
current_para_block: 1000,
relay_offset: 1000,
relay_blocks_per_para_block: 2,
orchestrator_para_id: 1000u32.into(),
container_para_id: 2000u32.into(),
authorities: vec![get_aura_id_from_seed("alice")],
};

let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
// Create a dummy parachain inherent data provider which is required to pass
// the checks by the para chain system. We use dummy values because in the 'pending context'
// neither do we have access to the real values nor do we need them.
let (relay_parent_storage_root, relay_chain_state) = RelayStateSproofBuilder {
additional_key_values: mocked_authorities_noting.get_key_values(),
..Default::default()
}
.into_state_root_and_proof();
let vfp = PersistedValidationData {
// This is a hack to make `cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases`
// happy. Relay parent number can't be bigger than u32::MAX.
relay_parent_number: u32::MAX,
relay_parent_storage_root,
..Default::default()
};
let parachain_inherent_data = ParachainInherentData {
validation_data: vfp,
relay_chain_state: relay_chain_state,
downward_messages: Default::default(),
horizontal_messages: Default::default(),
};
Ok((
timestamp,
parachain_inherent_data,
mocked_authorities_noting,
))
};

let pending_consensus_data_provider_frontier: Option<
Box<(dyn fc_rpc::pending::ConsensusDataProvider<_>)>,
> = Some(Box::new(
tc_consensus::ContainerManualSealAuraConsensusDataProvider::new(
SlotDuration::from_millis(container_chain_template_frontier_runtime::SLOT_DURATION),
authorities.clone(),
),
));

io.merge(
Eth::<_, _, _, _, _, _, _, DefaultEthConfig<C, BE>>::new(
Expand All @@ -195,7 +246,7 @@ where
None,
// TODO: resvisit
girazoki marked this conversation as resolved.
Show resolved Hide resolved
pending_create_inherent_data_providers,
None,
pending_consensus_data_provider_frontier,
)
.into_rpc(),
)?;
Expand Down Expand Up @@ -402,3 +453,13 @@ impl<Api> RuntimeApiCollection for Api where
+ cumulus_primitives_core::CollectCollationInfo<Block>
{
}

use nimbus_primitives::NimbusId;
girazoki marked this conversation as resolved.
Show resolved Hide resolved
use sp_core::Pair;
/// Helper function to generate a crypto pair from seed
pub fn get_aura_id_from_seed(seed: &str) -> NimbusId {
sp_core::sr25519::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
.into()
}
2 changes: 0 additions & 2 deletions container-chains/templates/frontier/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,6 @@ pub async fn start_dev_node(
select_chain: sc_consensus::LongestChain::new(node_builder.backend.clone()),
consensus_data_provider: Some(Box::new(
tc_consensus::ContainerManualSealAuraConsensusDataProvider::new(
client.clone(),
node_builder.keystore_container.keystore(),
SlotDuration::from_millis(
container_chain_template_frontier_runtime::SLOT_DURATION,
),
Expand Down
2 changes: 0 additions & 2 deletions container-chains/templates/simple/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ pub async fn start_dev_node(
select_chain: sc_consensus::LongestChain::new(node_builder.backend.clone()),
consensus_data_provider: Some(Box::new(
tc_consensus::ContainerManualSealAuraConsensusDataProvider::new(
client.clone(),
node_builder.keystore_container.keystore(),
SlotDuration::from_millis(
container_chain_template_simple_runtime::SLOT_DURATION,
),
Expand Down
Loading