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

add support for async backing #42

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 11 additions & 6 deletions simnode/src/client/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ use sc_service::{
use sc_transaction_pool::FullPool;
use sc_transaction_pool_api::{OffchainTransactionPoolFactory, TransactionPool};
use simnode_runtime_api::CreateTransactionApi;
use sp_api::{ApiExt, ConstructRuntimeApi, Core};
use sp_api::{ApiExt, ConstructRuntimeApi, Core, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder;
use sp_blockchain::HeaderBackend;
use sp_consensus::SelectChain;
use sp_core::{crypto::AccountId32, Bytes};
use sp_consensus_aura::AuraApi;
use sp_core::{crypto::AccountId32, traits::SpawnEssentialNamed, Bytes};
use sp_runtime::traits::{Block as BlockT, Header};
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;

use sp_core::traits::SpawnEssentialNamed;
use std::sync::Arc;

/// Parachain handler implementation for Simnode RPC API.
Expand Down Expand Up @@ -213,8 +212,14 @@ where
other: (block_import, mut telemetry, _),
} = components;

let parachain_inherent_provider =
Arc::new(Mutex::new(ParachainSproofInherentProvider::<C>::new(client.clone())));
let slot_duration = client
.runtime_api()
.slot_duration(client.info().best_hash)
.map_err(|err| sc_service::Error::Application(Box::new(err)))?;

let parachain_inherent_provider = Arc::new(Mutex::new(
ParachainSproofInherentProvider::<C>::new(client.clone(), slot_duration.as_millis()),
));

let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);
let (network, system_rpc_tx, tx_handler_controller, _network_starter, sync_service) = {
Expand Down
20 changes: 16 additions & 4 deletions simnode/src/sproof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct ParachainSproofInherentProvider<T: ChainInfo> {
client: Arc<FullClientFor<T>>,
// sproof builder
sproof_builder: Option<RelayStateSproofBuilder>,
// slot duration for the node
slot_duration: u64,
// phantom type
_phantom: PhantomData<T>,
}
Expand All @@ -51,8 +53,13 @@ where
<<T::Block as Block>::Header as Header>::Number: AsPrimitive<u32>,
{
/// Construct a new sproof-er
pub fn new(client: Arc<FullClientFor<T>>) -> Self {
ParachainSproofInherentProvider { client, sproof_builder: None, _phantom: PhantomData }
pub fn new(client: Arc<FullClientFor<T>>, slot_duration: u64) -> Self {
ParachainSproofInherentProvider {
client,
slot_duration,
sproof_builder: None,
_phantom: PhantomData,
}
}

/// updates the sproof to a new state
Expand All @@ -71,8 +78,13 @@ where
sproof.para_id = with_state::<T, _>(self.client.clone(), None, || {
parachain_info::Pallet::<T::Runtime>::parachain_id()
});
// relay chain is twice as fast the parachain
sproof.current_slot = ((slot * 2) + 1).into();
sproof.current_slot = if self.slot_duration == 12_000 {
// relay chain is twice as fast the parachain
((slot * 2) + 1).into()
} else {
// async backing is enabled
slot.into()
};
sproof.host_config.validation_upgrade_delay = 2;
sproof.host_config.max_code_size = 15 * 1024 * 1024;
sproof.included_para_head =
Expand Down
Loading