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 1 commit
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: 1 addition & 1 deletion client/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ mod tests {
let para_id = ParaId::from(100);
let announce_block = |_, _| ();
let client = Arc::new(TestClientBuilder::new().build());
let header = client.header(&BlockId::Number(0)).unwrap().unwrap();
let header = client.header(client.chain_info().genesis_hash).unwrap().unwrap();

let (sub_tx, sub_rx) = mpsc::channel(64);

Expand Down
17 changes: 3 additions & 14 deletions client/relay-chain-minimal-node/src/blockchain_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,20 +381,9 @@ fn block_local<T>(fut: impl Future<Output = T>) -> T {
impl HeaderBackend<Block> for BlockChainRpcClient {
fn header(
&self,
id: BlockId,
hash: <Block as polkadot_service::BlockT>::Hash,
) -> sp_blockchain::Result<Option<<Block as polkadot_service::BlockT>::Header>> {
let fetch_header = |hash| block_local(self.rpc_client.chain_get_header(Some(hash)));

match id {
BlockId::Hash(hash) => Ok(fetch_header(hash)?),
BlockId::Number(number) => {
if let Some(hash) = HeaderBackend::<Block>::hash(self, number)? {
Ok(fetch_header(hash)?)
} else {
Ok(None)
}
},
}
Ok(block_local(self.rpc_client.chain_get_header(Some(hash)))?)
}

fn info(&self) -> Info<Block> {
Expand Down Expand Up @@ -425,7 +414,7 @@ impl HeaderBackend<Block> for BlockChainRpcClient {
id: sp_api::BlockId<Block>,
) -> sp_blockchain::Result<sp_blockchain::BlockStatus> {
let exists = match id {
BlockId::Hash(_) => self.header(id)?.is_some(),
BlockId::Hash(hash) => self.header(hash)?.is_some(),
BlockId::Number(n) => {
let best_header = block_local(self.rpc_client.chain_get_header(None))?;
if let Some(best) = best_header {
Expand Down
4 changes: 2 additions & 2 deletions pallets/parachain-system/src/validate_block/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use cumulus_test_client::{
};
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use sp_keyring::AccountKeyring::*;
use sp_runtime::{generic::BlockId, traits::Header as HeaderT};
use sp_runtime::traits::Header as HeaderT;
use std::{env, process::Command};

fn call_validate_block_encoded_header(
Expand Down Expand Up @@ -60,7 +60,7 @@ fn create_test_client() -> (Client, Header) {
.build();

let genesis_header = client
.header(&BlockId::number(0))
.header(client.chain_info().genesis_hash)
.ok()
.flatten()
.expect("Genesis header exists; qed");
Expand Down
30 changes: 17 additions & 13 deletions primitives/timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ mod tests {
ValidationParams,
};
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use sp_runtime::{generic::BlockId, traits::Header as HeaderT};
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Header as HeaderT},
};
use std::{env, process::Command, str::FromStr};

const SLOT_DURATION: u64 = 6000;
Expand All @@ -106,14 +109,14 @@ mod tests {

fn build_block(
client: &Client,
at: BlockId<Block>,
hash: <Block as BlockT>::Hash,
timestamp: u64,
relay_chain_slot: Slot,
) -> (ParachainBlockData, PHash) {
let sproof_builder =
RelayStateSproofBuilder { current_slot: relay_chain_slot, ..Default::default() };

let parent_header = client.header(&at).ok().flatten().expect("Genesis header exists");
let parent_header = client.header(hash).ok().flatten().expect("Genesis header exists");

let relay_parent_storage_root = sproof_builder.clone().into_state_root_and_proof().0;

Expand All @@ -125,7 +128,7 @@ mod tests {

let block = client
.init_block_builder_with_timestamp(
&at,
&BlockId::Hash(hash),
Some(validation_data),
sproof_builder,
timestamp,
Expand All @@ -146,19 +149,20 @@ mod tests {
.expect("TIMESTAMP is a valid `u64`");

let block =
build_block(&client, BlockId::number(0), SLOT_DURATION, 1.into()).0.into_block();
futures::executor::block_on(client.import(sp_consensus::BlockOrigin::Own, block))
.unwrap();
build_block(&client, client.chain_info().genesis_hash, SLOT_DURATION, 1.into())
.0
.into_block();
futures::executor::block_on(
client.import(sp_consensus::BlockOrigin::Own, block.clone()),
)
.unwrap();

let hashof1 = block.hash();
let (block, relay_chain_root) =
build_block(&client, BlockId::number(1), timestamp, relay_chain_slot.into());
build_block(&client, hashof1, timestamp, relay_chain_slot.into());

let header = call_validate_block(
client
.header(&BlockId::number(1))
.ok()
.flatten()
.expect("Genesis header exists"),
client.header(hashof1).ok().flatten().expect("Genesis header exists"),
block.clone(),
relay_chain_root,
)
Expand Down
8 changes: 6 additions & 2 deletions test/service/tests/migrate_solo_to_para.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use codec::Encode;
use cumulus_primitives_core::ParaId;
use cumulus_test_service::{initial_head_data, run_relay_chain_validator_node, Keyring::*};
use sc_client_api::{BlockBackend, UsageProvider};
use sp_runtime::generic::BlockId;

#[substrate_test_utils::test(flavor = "multi_thread")]
#[ignore]
Expand Down Expand Up @@ -93,7 +92,12 @@ async fn test_migrate_solo_to_para() {
solo.client.block_hash(0).ok().flatten().unwrap(),
);

let solo_chain_header = solo.client.header(&BlockId::Number(0)).ok().flatten().unwrap();
let solo_chain_header = solo
.client
.header(solo.client.chain_info().genesis_hash)
.ok()
.flatten()
.unwrap();

// Send the transaction to set the custom header, aka the header of the solo chain.
parachain
Expand Down