Skip to content

Commit

Permalink
Merge pull request #1326 from bifrost-finance/fix_manual_seal
Browse files Browse the repository at this point in the history
Fix manual seal
  • Loading branch information
Wsteth authored Aug 2, 2024
2 parents f0eb01e + 3d2e2f2 commit 8a233e2
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ cumulus-client-consensus-aura = { git = "https://github.com/pari
cumulus-client-consensus-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0" }
cumulus-client-consensus-relay-chain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0" }
cumulus-client-network = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0" }
cumulus-client-parachain-inherent = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0" }
cumulus-client-pov-recovery = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0" }
cumulus-client-service = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0" }
cumulus-relay-chain-inprocess-interface = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0" }
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,20 @@ make try-polkadot-runtime-upgrade

## Run development chain

```bash
make run-dev
run node with `--chain=bifrost-polkadot-dev` to enable development mode.

Before use dev mode, modify OnTimestampSet to be ()

```rust
impl pallet_timestamp::Config for Runtime {
type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
/// A timestamp: milliseconds since the unix epoch.
type Moment = Moment;
-type OnTimestampSet = Aura;
+type OnTimestampSet = ();
type WeightInfo = pallet_timestamp::weights::SubstrateWeight<Runtime>;
}

```

## Run local testnet with polkadot-launch
Expand Down
1 change: 1 addition & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ cumulus-client-consensus-proposer = { workspace = true }
cumulus-client-network = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-client-service = { workspace = true }
cumulus-client-parachain-inherent = { workspace = true }
cumulus-primitives-parachain-inherent = { workspace = true }
cumulus-relay-chain-interface = { workspace = true }
cumulus-test-relay-sproof-builder = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion node/service/src/collator_polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ pub async fn start_node<Net: NetworkBackend<Block, Hash>>(
hwbench: Option<sc_sysinfo::HwBench>,
) -> sc_service::error::Result<(TaskManager, Arc<FullClient>)> {
if parachain_config.chain_spec.is_dev() {
crate::dev::start_node::<Net>(parachain_config, eth_config).await
crate::dev::start_node::<Net>(parachain_config, eth_config, para_id).await
} else {
start_node_impl::<Net>(
parachain_config,
Expand Down
61 changes: 49 additions & 12 deletions node/service/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,23 @@

use std::{cell::RefCell, sync::Arc};

use cumulus_primitives_core::relay_chain::Hash;
use crate::{
collator_polkadot::FullClient,
eth::{spawn_frontier_tasks, EthConfiguration},
};
use bifrost_polkadot_runtime::{constants::time::SLOT_DURATION, TransactionConverter};
use cumulus_client_parachain_inherent::{MockValidationDataInherentDataProvider, MockXcmConfig};
use cumulus_primitives_core::{relay_chain::Hash, ParaId};
use fc_storage::StorageOverrideHandler;
use jsonrpsee::core::async_trait;
use sc_client_api::Backend;
use sc_network::NetworkBackend;
use sc_service::{Configuration, TaskManager};
use sc_transaction_pool_api::OffchainTransactionPoolFactory;

use bifrost_polkadot_runtime::{constants::time::SLOT_DURATION, TransactionConverter};

use crate::{
collator_polkadot::FullClient,
eth::{spawn_frontier_tasks, EthConfiguration},
};

use sp_blockchain::HeaderBackend;
use sp_core::Encode;
pub type Block = bifrost_primitives::Block;
pub type RuntimeApi = bifrost_polkadot_runtime::RuntimeApi;

pub type FullBackend = sc_service::TFullBackend<Block>;
pub type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;

Expand Down Expand Up @@ -73,6 +72,7 @@ impl sp_inherents::InherentDataProvider for MockTimestampInherentDataProvider {
pub async fn start_node<Net>(
parachain_config: Configuration,
eth_config: EthConfiguration,
para_id: ParaId,
) -> sc_service::error::Result<(TaskManager, Arc<FullClient>)>
where
Net: NetworkBackend<bifrost_primitives::Block, Hash>,
Expand Down Expand Up @@ -152,6 +152,12 @@ where

// Channel for the rpc handler to communicate with the authorship task.
let (command_sink, commands_stream) = futures::channel::mpsc::channel(1024);
let client_set_aside_for_cidp = client.clone();

// 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 authorship_future =
sc_consensus_manual_seal::run_manual_seal(sc_consensus_manual_seal::ManualSealParams {
block_import: client.clone(),
Expand All @@ -161,8 +167,39 @@ where
commands_stream,
select_chain,
consensus_data_provider: None,
create_inherent_data_providers: move |_, ()| async move {
Ok(sp_timestamp::InherentDataProvider::from_system_time())
create_inherent_data_providers: move |block, ()| {
let maybe_current_para_block = client_set_aside_for_cidp.number(block);
let maybe_current_para_head = client_set_aside_for_cidp.expect_header(block);
let downward_xcm_receiver = downward_xcm_receiver.clone();
let hrmp_xcm_receiver = hrmp_xcm_receiver.clone();

let client_for_xcm = client_set_aside_for_cidp.clone();
async move {
let time = sp_timestamp::InherentDataProvider::from_system_time();

let current_para_block = maybe_current_para_block?
.ok_or(sp_blockchain::Error::UnknownBlock(block.to_string()))?;

let current_para_block_head =
Some(polkadot_primitives::HeadData(maybe_current_para_head?.encode()));

let mocked_parachain = MockValidationDataInherentDataProvider {
current_para_block,
current_para_block_head,
para_id,
relay_offset: 1000,
relay_blocks_per_para_block: 2,
// TODO: Recheck
para_blocks_per_relay_epoch: 10,
relay_randomness_config: (),
xcm_config: MockXcmConfig::new(&*client_for_xcm, block, Default::default()),
raw_downward_messages: downward_xcm_receiver.drain().collect(),
raw_horizontal_messages: hrmp_xcm_receiver.drain().collect(),
additional_key_values: None,
};

Ok((time, mocked_parachain))
}
},
});
// we spawn the future on a background thread managed by service.
Expand Down

0 comments on commit 8a233e2

Please sign in to comment.