Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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
4,483 changes: 2,244 additions & 2,239 deletions Cargo.lock

Large diffs are not rendered by default.

53 changes: 24 additions & 29 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use polkadot_collator::{
PolkadotClient,
};
use polkadot_primitives::{
parachain::{self, BlockData, Status as ParachainStatus, Id as ParaId}, Block as PBlock,
parachain::{self, BlockData, LocalValidationData, Id as ParaId}, Block as PBlock,
Hash as PHash,
};

Expand Down Expand Up @@ -65,14 +65,14 @@ impl<Block, PF, BI> Collator<Block, PF, BI> {
fn new(
proposer_factory: PF,
inherent_data_providers: InherentDataProviders,
collator_network: Arc<dyn CollatorNetwork>,
collator_network: impl CollatorNetwork + Clone + 'static,
block_import: BI,
) -> Self {
Self {
proposer_factory: Arc::new(Mutex::new(proposer_factory)),
inherent_data_providers,
_phantom: PhantomData,
collator_network,
collator_network: Arc::new(collator_network),
block_import: Arc::new(Mutex::new(block_import)),
}
}
Expand Down Expand Up @@ -111,15 +111,15 @@ where
fn produce_candidate(
&mut self,
_relay_chain_parent: PHash,
status: ParachainStatus,
status: LocalValidationData,
) -> Self::ProduceCandidate {
let factory = self.proposer_factory.clone();
let inherent_providers = self.inherent_data_providers.clone();
let block_import = self.block_import.clone();

trace!(target: "cumulus-collator", "Producing candidate");

let last_head = match HeadData::<Block>::decode(&mut &status.head_data.0[..]) {
let last_head = match HeadData::<Block>::decode(&mut &status.parent_head.0[..]) {
Ok(x) => x,
Err(e) => {
error!(target: "cumulus-collator", "Could not decode the head data: {:?}", e);
Expand Down Expand Up @@ -285,7 +285,7 @@ where
self,
polkadot_client: Arc<PolkadotClient<B, E, R>>,
spawner: Spawner,
network: Arc<dyn CollatorNetwork>,
network: impl CollatorNetwork + Clone + 'static,
) -> Result<Self::ParachainContext, ()>
where
PolkadotClient<B, E, R>: sp_api::ProvideRuntimeApi<PBlock>,
Expand All @@ -296,11 +296,11 @@ where
Extrinsic: codec::Codec + Send + Sync + 'static,
<<PolkadotClient<B, E, R> as sp_api::ProvideRuntimeApi<PBlock>>::Api as sp_api::ApiExt<
PBlock,
>>::StateBackend: sp_api::StateBackend<sp_core::Blake2Hasher>,
>>::StateBackend: sp_api::StateBackend<sp_runtime::traits::BlakeTwo256>,
R: Send + Sync + 'static,
B: sc_client_api::Backend<PBlock> + 'static,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
B::State: sp_api::StateBackend<sp_core::Blake2Hasher>,
B::State: sp_api::StateBackend<sp_runtime::traits::BlakeTwo256>,
{
let follow =
match cumulus_consensus::follow_polkadot(self.para_id, self.client, polkadot_client) {
Expand Down Expand Up @@ -333,8 +333,8 @@ mod tests {
use super::*;
use std::time::Duration;

use polkadot_collator::{collate, CollatorId, PeerId, SignedStatement};
use polkadot_primitives::parachain::{FeeSchedule, HeadData, Id as ParaId};
use polkadot_collator::{collate, SignedStatement};
use polkadot_primitives::parachain::{HeadData, Id as ParaId};

use sp_blockchain::Result as ClientResult;
use sp_inherents::InherentData;
Expand Down Expand Up @@ -406,17 +406,11 @@ mod tests {
}
}

#[derive(Clone)]
struct DummyCollatorNetwork;

impl CollatorNetwork for DummyCollatorNetwork {
fn collator_id_to_peer_id(
&self,
_: CollatorId,
) -> Box<dyn Future<Output = Option<PeerId>> + Send> {
unimplemented!("Not required in tests")
}

fn checked_statements(&self, _: PHash) -> Box<dyn Stream<Item = SignedStatement>> {
fn checked_statements(&self, _: PHash) -> Pin<Box<dyn Stream<Item = SignedStatement>>> {
unimplemented!("Not required in tests")
}
}
Expand Down Expand Up @@ -455,16 +449,21 @@ mod tests {
Arc::new(TestClientBuilder::new().build()),
);
let context = builder
.build::<_, _, polkadot_service::polkadot_runtime::RuntimeApi, _, _>(
.build(
Arc::new(
substrate_test_client::TestClientBuilder::<_, _, _, ()>::default()
.build_with_native_executor(Some(NativeExecutor::<
polkadot_service::PolkadotExecutor,
>::new(Interpreted, None)))
.build_with_native_executor::<polkadot_service::polkadot_runtime::RuntimeApi, _>(
Some(
NativeExecutor::<polkadot_service::PolkadotExecutor>::new(
Interpreted,
None,
)
)
)
.0,
),
spawner,
Arc::new(DummyCollatorNetwork),
DummyCollatorNetwork,
)
.expect("Creates parachain context");

Expand All @@ -479,13 +478,9 @@ mod tests {
let collation = collate(
Default::default(),
id,
ParachainStatus {
head_data: HeadData(header.encode()),
LocalValidationData {
parent_head: HeadData(header.encode()),
balance: 10,
fee_schedule: FeeSchedule {
base: 0,
per_byte: 1,
},
},
context,
Arc::new(Sr25519Keyring::Alice.pair().into()),
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ where
<Client<B, E, PBlock, RA> as ProvideRuntimeApi<PBlock>>::Api:
ParachainHost<PBlock, Error = ClientError>,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
StateBackendFor<B, PBlock>: StateBackend<sp_core::Blake2Hasher>,
StateBackendFor<B, PBlock>: StateBackend<sp_runtime::traits::BlakeTwo256>,
{
type Error = ClientError;

Expand All @@ -181,8 +181,8 @@ where
para_id: ParaId,
) -> ClientResult<Option<Vec<u8>>> {
self.runtime_api()
.parachain_status(at, para_id)
.map(|s| s.map(|s| s.head_data.0))
.local_validation_data(at, para_id)
.map(|s| s.map(|s| s.parent_head.0))
}
}

Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sp-trie = { git = "https://github.com/paritytech/substrate", default-features =
parachain = { package = "polkadot-parachain", git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false, features = [ "wasm-api" ] }

[dev-dependencies]
sc-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
Expand Down
10 changes: 5 additions & 5 deletions runtime/src/validate_block/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use crate::WitnessData;
use frame_executive::ExecuteBlock;
use sp_runtime::traits::{Block as BlockT, HasherFor, Header as HeaderT};
use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT};

use sp_trie::{delta_trie_root, read_trie_value, Layout, MemoryDB};

Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(params: ValidationParams) -
/// The storage implementation used when validating a block that is using the
/// witness data as source.
struct WitnessStorage<B: BlockT> {
witness_data: MemoryDB<HasherFor<B>>,
witness_data: MemoryDB<HashFor<B>>,
overlay: hashbrown::HashMap<Vec<u8>, Option<Vec<u8>>>,
storage_root: B::Hash,
}
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<B: BlockT> Storage for WitnessStorage<B> {
.get(key)
.cloned()
.or_else(|| {
read_trie_value::<Layout<HasherFor<B>>, _>(
read_trie_value::<Layout<HashFor<B>>, _>(
&self.witness_data,
&self.storage_root,
key,
Expand All @@ -168,7 +168,7 @@ impl<B: BlockT> Storage for WitnessStorage<B> {
}

fn storage_root(&mut self) -> Vec<u8> {
let root = delta_trie_root::<Layout<HasherFor<B>>, _, _, _, _>(
let root = delta_trie_root::<Layout<HashFor<B>>, _, _, _, _>(
&mut self.witness_data,
self.storage_root.clone(),
self.overlay.drain(),
Expand All @@ -184,7 +184,7 @@ impl<B: BlockT> Storage for WitnessStorage<B> {
}
});

let trie = match TrieDB::<Layout<HasherFor<B>>>::new(&self.witness_data, &self.storage_root)
let trie = match TrieDB::<Layout<HashFor<B>>>::new(&self.witness_data, &self.storage_root)
{
Ok(r) => r,
Err(_) => panic!(),
Expand Down
26 changes: 15 additions & 11 deletions runtime/src/validate_block/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
use crate::{ParachainBlockData, WitnessData};

use parachain::{ValidationParams, ValidationResult};
use sc_executor::{call_in_wasm, error::Result, WasmExecutionMethod};
use sc_executor::{
error::Result, WasmExecutionMethod, WasmExecutor, sp_wasm_interface::HostFunctions,
};
use sc_block_builder::BlockBuilderProvider;
use sp_blockchain::HeaderBackend;
use sp_consensus::SelectChain;
use sp_core::traits::CallInWasm;
use sp_io::TestExternalities;
use sp_keyring::AccountKeyring;
use sp_runtime::{
Expand All @@ -45,22 +49,22 @@ fn call_validate_block(
}
.encode();

call_in_wasm::<
(
sp_io::SubstrateHostFunctions,
sc_executor::deprecated_host_interface::SubstrateExternals,
),
>(
let executor = WasmExecutor::new(
WasmExecutionMethod::Interpreted,
Some(1024),
sp_io::SubstrateHostFunctions::host_functions(),
false,
);

executor.call_in_wasm(
&WASM_BINARY,
"validate_block",
&params,
WasmExecutionMethod::Interpreted,
&mut ext_ext,
&WASM_BINARY,
1024,
false,
)
.map(|v| ValidationResult::decode(&mut &v[..]).expect("Decode `ValidationResult`."))
.map(|v| Header::decode(&mut &v.head_data[..]).expect("Decode `Header`."))
.map_err(|err| err.into())
}

fn create_extrinsics() -> Vec<<Block as BlockT>::Extrinsic> {
Expand Down
1 change: 1 addition & 0 deletions test/parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sc-network = { git = "https://github.com/paritytech/substrate", branch = "cumulu
sc-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }

# Cumulus dependencies
cumulus-consensus = { path = "../../consensus" }
Expand Down
Loading