Skip to content

Commit

Permalink
add support for async backing (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege authored May 10, 2024
1 parent 821d66a commit f9f2f9e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
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

0 comments on commit f9f2f9e

Please sign in to comment.