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

Allow integrated relay chain light client #2270

Merged
merged 57 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f6eda5b
Add embedded light client to cli
skunert Feb 21, 2023
d5c7791
Prepare for light-client-worker
skunert Feb 23, 2023
efc9ebc
First working version
skunert Feb 27, 2023
a316e51
Clean up
skunert Feb 28, 2023
5c0af7e
Remove unwanted logs
skunert Feb 28, 2023
cd9ebe0
Simplify subscription code
skunert Feb 28, 2023
19c82f9
Let jsonrpsee handle rpc management
skunert Mar 1, 2023
30490cc
Simplify implementation
skunert Mar 1, 2023
3a807c1
Reorganize crate structure
skunert Mar 1, 2023
1aee380
Use relay chain arg chainspec for light-client
skunert Mar 1, 2023
fbcd69d
Clean up command line
skunert Mar 1, 2023
27c0ef9
Add light client worker file
skunert Mar 2, 2023
7368580
Merge branch 'master' into smoldot-integration
skunert Mar 2, 2023
007a699
Use smoldot master to avoid wasmtime conflict
skunert Mar 2, 2023
85c6156
Remove sleep
skunert Mar 2, 2023
489f1ae
Improve naming of cli option
skunert Mar 2, 2023
45e5b45
Remove conflict with `validator`
skunert Mar 3, 2023
35f9649
Improve docs
skunert Mar 3, 2023
164d430
Merge branch 'master' into smoldot-integration
skunert Mar 3, 2023
08efa4b
Update smoldot, remove unwanted change
skunert Mar 3, 2023
e450413
Apply suggestions from code review
skunert Mar 3, 2023
7997f2b
Merge branch 'master' into smoldot-integration
skunert Mar 7, 2023
9ce2ddd
Disable collation
skunert Mar 7, 2023
33a1b4c
Reviewer comments
skunert Mar 9, 2023
79d440d
Merge branch 'master' into smoldot-integration
skunert Mar 27, 2023
7d0635c
Update smoldot and tokio-platform
skunert Mar 27, 2023
181ce72
Update smoldot
skunert Mar 31, 2023
0faada2
Merge remote-tracking branch 'origin/master' into smoldot-integration
skunert Mar 31, 2023
595fd4a
Merge branch 'master' into smoldot-integration
skunert Jun 6, 2023
2dbed4b
Update smoldot
skunert Jun 6, 2023
4982892
Adjust to new version
skunert Jun 6, 2023
197a77d
Patch substrate
skunert Jun 7, 2023
9eba856
Use constants
skunert Jun 7, 2023
410be7c
Add readme entry, improve zombienet tests
skunert Jun 7, 2023
a1d5b3d
Apply suggestions from code review
skunert Jun 7, 2023
26fce06
Make execution mode an enum
skunert Jun 7, 2023
d11800c
Merge branch 'master' into smoldot-integration
skunert Jun 7, 2023
b4f372b
Update smoldot, remove substrate patch
skunert Jun 8, 2023
660bd56
Merge branch 'master' into smoldot-integration
skunert Jun 8, 2023
0c79ece
Update client/relay-chain-rpc-interface/src/rpc_client.rs
skunert Jun 19, 2023
4bba54e
Reduce duplicate code
skunert Jun 19, 2023
8a560bf
Merge branch 'master' into smoldot-integration
skunert Jun 19, 2023
b98a70f
Update smoldot
skunert Jun 19, 2023
6cffdb9
Merge branch 'master' into smoldot-integration
skunert Jul 4, 2023
b96de21
Merge branch 'master' into smoldot-integration
skunert Jul 19, 2023
3779ab1
Update smoldot
skunert Jul 19, 2023
e826941
Merge branch 'master' into smoldot-integration
skunert Aug 21, 2023
145f396
Fix build
skunert Aug 21, 2023
59c275d
Update smoldot
skunert Aug 21, 2023
74c54b5
Make platform compile
skunert Aug 22, 2023
145d2c5
Clean up dependencies
skunert Aug 22, 2023
4be2a3e
Use crates.io instead of github for smoldot
skunert Aug 22, 2023
0708c63
Apply suggestions from code review
skunert Aug 22, 2023
e58e322
Docs
skunert Aug 22, 2023
0bbc284
Improve docs
skunert Aug 22, 2023
3e481e6
Remove `RpcFrontend`
skunert Aug 22, 2023
4ba2920
Merge branch 'master' into smoldot-integration
skunert Aug 22, 2023
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
700 changes: 616 additions & 84 deletions Cargo.lock
skunert marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ pub struct RunCmd {
alias = "relay-chain-rpc-url"
)]
pub relay_chain_rpc_urls: Vec<Url>,

/// EXPERIMENTAL: Embed a light client for the relay chain. Only supported for full-nodes.
/// Will use the specified relay chain chainspec.
#[arg(long, conflicts_with_all = ["relay_chain_rpc_urls", "collator"])]
pub relay_chain_light_client: bool,
}

impl RunCmd {
Expand All @@ -312,7 +317,10 @@ impl RunCmd {

/// Create [`CollatorOptions`] representing options only relevant to parachain collator nodes
pub fn collator_options(&self) -> CollatorOptions {
CollatorOptions { relay_chain_rpc_urls: self.relay_chain_rpc_urls.clone() }
CollatorOptions {
relay_chain_rpc_urls: self.relay_chain_rpc_urls.clone(),
relay_chain_light_client: self.relay_chain_light_client,
}
}
}

Expand All @@ -321,6 +329,9 @@ impl RunCmd {
pub struct CollatorOptions {
dmitry-markin marked this conversation as resolved.
Show resolved Hide resolved
/// Location of relay chain full node
pub relay_chain_rpc_urls: Vec<Url>,

/// Use embedded light client for the relay chain
pub relay_chain_light_client: bool,
}
skunert marked this conversation as resolved.
Show resolved Hide resolved

/// A non-redundant version of the `RunCmd` that sets the `validator` field when the
Expand Down
24 changes: 1 addition & 23 deletions client/relay-chain-minimal-node/src/blockchain_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use cumulus_relay_chain_rpc_interface::RelayChainRpcClient;
use futures::{Future, Stream, StreamExt};
use polkadot_core_primitives::{Block, Hash, Header};
use polkadot_overseer::RuntimeApiSubsystemClient;
use polkadot_service::{AuxStore, HeaderBackend};
use polkadot_service::HeaderBackend;
use sc_authority_discovery::AuthorityDiscovery;

use sp_api::{ApiError, RuntimeApiInfo};
Expand Down Expand Up @@ -52,28 +52,6 @@ impl BlockChainRpcClient {
}
}

// Implementation required by Availability-Distribution subsystem
// but never called in our case.
impl AuxStore for BlockChainRpcClient {
fn insert_aux<
'a,
'b: 'a,
'c: 'a,
I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>,
D: IntoIterator<Item = &'a &'b [u8]>,
>(
&self,
_insert: I,
_delete: D,
) -> sp_blockchain::Result<()> {
unimplemented!("Not supported on the RPC collator")
}

fn get_aux(&self, _key: &[u8]) -> sp_blockchain::Result<Option<Vec<u8>>> {
unimplemented!("Not supported on the RPC collator")
}
}

#[async_trait::async_trait]
impl RuntimeApiSubsystemClient for BlockChainRpcClient {
async fn validators(
Expand Down
41 changes: 37 additions & 4 deletions client/relay-chain-minimal-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ use futures::StreamExt;

use sp_runtime::{app_crypto::Pair, traits::Block as BlockT};

mod blockchain_rpc_client;
mod collator_overseer;

mod network;

mod blockchain_rpc_client;
pub use blockchain_rpc_client::BlockChainRpcClient;

const LOG_TARGET: &str = "minimal-relaychain-node";

fn build_authority_discovery_service<Block: BlockT>(
task_manager: &TaskManager,
client: Arc<BlockChainRpcClient>,
Expand Down Expand Up @@ -106,6 +107,40 @@ pub async fn build_minimal_relay_chain_node(
))
}

pub async fn build_minimal_relay_chain_node_light_client(
skunert marked this conversation as resolved.
Show resolved Hide resolved
polkadot_config: Configuration,
task_manager: &mut TaskManager,
) -> RelayChainResult<(Arc<(dyn RelayChainInterface + 'static)>, Option<CollatorPair>)> {
tracing::info!(
target: LOG_TARGET,
chain_name = polkadot_config.chain_spec.name(),
chain_id = polkadot_config.chain_spec.id(),
"Initializing embedded light client with chain spec."
);

let spec = polkadot_config
.chain_spec
.as_json(false)
.map_err(RelayChainError::GenericError)?;

let client = cumulus_relay_chain_rpc_interface::create_client_and_start_light_client_worker(
spec,
task_manager,
)
.await?;
let collator_pair = CollatorPair::generate().0;
let collator_node = new_minimal_relay_chain(
polkadot_config,
collator_pair.clone(),
Arc::new(BlockChainRpcClient::new(client.clone())),
)
.await?;
task_manager.add_child(collator_node.task_manager);
Ok((
Arc::new(RelayChainRpcInterface::new(client, collator_node.overseer_handle)),
Some(collator_pair),
))
}
/// Builds a minimal relay chain node. Chain data is fetched
/// via [`BlockChainRpcClient`] and fed into the overseer and its subsystems.
///
Expand All @@ -117,8 +152,6 @@ pub async fn build_minimal_relay_chain_node(
/// - NetworkBridgeRx
/// - NetworkBridgeTx
/// - RuntimeApi
/// - ChainApi
/// - AvailabilityDistribution
#[sc_tracing::logging::prefix_logs_with("Relaychain")]
async fn new_minimal_relay_chain(
mut config: Configuration,
Expand Down
11 changes: 10 additions & 1 deletion client/relay-chain-rpc-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "
sp-storage = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
tokio = { version = "1.25.0", features = ["sync"] }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" }

tokio = { version = "1.25.0", features = ["sync"] }
tokio-util = { version = "0.7.7", features = ["compat"] }
futures = "0.3.26"
futures-timer = "3.0.2"
parity-scale-codec = "3.4.0"
Expand All @@ -31,3 +33,10 @@ url = "2.3.1"
serde_json = "1.0.93"
serde = "1.0.152"
lru = "0.9.0"
smoldot = { git = "https://github.com/smol-dot/smoldot", branch = "main" }
smoldot-light = { git = "https://github.com/smol-dot/smoldot", branch = "main", default_features = false }
parking_lot = "0.12.1"
either = "1.8.1"
event-listener = "2.5.3"
thiserror = "1.0.38"
soketto = "0.7.1"
skunert marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 7 additions & 1 deletion client/relay-chain-rpc-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ use std::pin::Pin;

pub use url::Url;

mod light_client_worker;
mod reconnecting_ws_client;
mod rpc_client;
pub use rpc_client::{create_client_and_start_worker, RelayChainRpcClient};
mod tokio_platform;

pub use rpc_client::{
create_client_and_start_light_client_worker, create_client_and_start_worker,
RelayChainRpcClient,
};

const TIMEOUT_IN_SECONDS: u64 = 6;

Expand Down
Loading