Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Introduce interface for relay chain interaction #835

Merged
merged 63 commits into from
Dec 22, 2021
Merged

Conversation

skunert
Copy link
Contributor

@skunert skunert commented Dec 6, 2021

In this PR, I introduce an interface that exposes methods for interaction with the relay chain, as discussed in #545.
These changes are only refactoring and have no impact on functionality.
Outline of the changes:

  • Introduce trait RelayChainInterface
  • Implement RelayChainInterface for RelayChainLocal, a status-quo implementation that uses a full node in the same process
  • replace all occurrences of polkadot client and backend with RelayChainLocal

skunert and others added 30 commits October 15, 2021 10:11
Remove polkadot-client fromcollator crate.
@skunert skunert added the B0-silent Changes should not be mentioned in any release notes label Dec 20, 2021
@@ -252,13 +244,12 @@ pub struct BuildAuraConsensusParams<PF, BI, RBackend, CIDP, Client, BS, SO> {
/// Build the [`AuraConsensus`].
///
/// Returns a boxed [`ParachainConsensus`].
pub fn build_aura_consensus<P, Block, PF, BI, RBackend, CIDP, Client, SO, BS, Error>(
pub fn build_aura_consensus<P, Block, PF, BI, CIDP, Client, SO, BS, Error, RCInterface>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new function is essentially the same. Aka we should remove this one build_aura_consensus function and maybe rename the new function to build.

However, the new function could also use the BuildAuraConsensusParams.

create_inherent_data_providers: Arc<CIDP>,
relay_chain_client: Arc<RClient>,
relay_chain_backend: Arc<RBackend>,
relay_chain_interface: RCInterface,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually use this anywhere? I could not find any usage?

use sp_core::sp_std::collections::btree_map::BTreeMap;
use sp_state_machine::StorageValue;

pub enum BlockCheckResult {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs.

}

fn is_major_syncing(&self) -> bool {
let mut network = self.sync_oracle.lock().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No unwraps in the code. Either use expect with a proof or remove.

Here you can just replace std::Mutex with parking_lot::Mutex. Parkinglot mutex isn't poisened.

sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" }

futures = { version = "0.3.1", features = ["compat"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
futures = { version = "0.3.1", features = ["compat"] }

Not used?


/// Should be used for all interaction with the relay chain in cumulus.
pub trait RelayChainInterface: Send + Sync {
fn get_storage_by_key(&self, block_id: &BlockId, key: &[u8]) -> Option<StorageValue>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs?

Also weird that we return None here for when the key doesn't exist or there was an error.

Comment on lines 42 to 46
fn validators(&self, block_id: &BlockId) -> Result<Vec<ValidatorId>, ApiError>;

fn block_status(&self, block_id: BlockId) -> Result<BlockStatus, sp_blockchain::Error>;

fn best_block_hash(&self) -> PHash;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs please

Comment on lines 85 to 87
/// Check if block is in chain. If it is, we return BlockCheckResult::InChain.
/// If it is not in the chain, we return BlockCheckResult::NotFound with a listener that can be used to wait on the block.
fn check_block_in_chain(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of the docs should go to the BlockCheckResult type.

However, I'm not really happy with the naming here.

Maybe something like wait_for_block and return a future that either resolves directly or waits for the block to be imported.

client/relay-chain-interface/Cargo.toml Show resolved Hide resolved
/// the builder gets access to this concrete instance.
struct BlockAnnounceValidatorBuilder<Block, B> {
/// Builds a [`BlockAnnounceValidator`] for a parachain.
struct BlockAnnounceValidatorBuilder<Block, RCInterface> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still relevant.

@skunert skunert requested a review from bkchr December 22, 2021 10:53
}

// Helper function to check if a block is in chain.
pub fn check_block_in_chain<Client>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper function came back to solve an issue which the lock guard that was not Send in the async function. Also makes this reusable in the test.

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just some last small nitpicks.

.map_err(|e| {
tracing::error!(
target: LOG_TARGET,
error = ?e,
"Cannot obtain the hrmp ingress channel index."
relay_parent = ?relay_parent_block_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
relay_parent = ?relay_parent_block_id,
relay_parent = ?relay_parent,

error = ?e,
"Cannot obtain the hrmp ingress channel index."
relay_parent = ?relay_parent_block_id,
error = ?e, "Cannot obtain the hrmp ingress channel."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
error = ?e, "Cannot obtain the hrmp ingress channel."
error = ?e,
"Cannot obtain the hrmp ingress channel.",

@@ -408,88 +379,14 @@ where
/// Build a block announce validator instance.
///
/// Returns a boxed [`BlockAnnounceValidator`].
pub fn build_block_announce_validator<Block: BlockT, B>(
relay_chain_client: polkadot_client::Client,
pub fn build_block_announce_validator<Block: BlockT, RCInterface>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is rather useless now, please remove.

block_proposal_slot_portion,
max_block_proposal_slot_portion,
}: BuildAuraConsensusParams<PF, BI, CIDP, Client, BS, SO>,
) -> Box<dyn ParachainConsensus<B>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
) -> Box<dyn ParachainConsensus<B>>
) -> Self

We don't need to box anymore. This was just a short coming of the old implementation with all the ExecuteWithClient stuff etc, that is now solved.

@skunert skunert merged commit 7b42df1 into master Dec 22, 2021
@skunert skunert deleted the relay-chain-interface branch December 22, 2021 18:02
HCastano added a commit to paritytech/canvas that referenced this pull request Jan 8, 2022
cmichi pushed a commit to paritytech/canvas that referenced this pull request Jan 10, 2022
* Bump Cumulus, Polkadot, and Substrate

Also bumps some other depenencies

* Remove duplicate `polkadot` dependency

* Update `service.rs`

Changes related to: paritytech/cumulus#835

* Update `command.rs`

* Add `AddressGenerator` config type

From: paritytech/substrate#10521

* Allow Root to execute overweight XCMP messages

From: paritytech/cumulus#799

* Add `header` argument to `collect_collation_info`

From: paritytech/cumulus#882

* Update Cumulus and friends again

* Add Fork ID to genesis config

paritytech/cumulus#870

* Add `state_version` field

paritytech/substrate#9732

* Add `MaxConsumers` config parameter

paritytech/substrate#10382

* Update Substrate compatibility note in README
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
B0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants