Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethereum RPC Data Providers #680

Merged
merged 22 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
11 changes: 11 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions client/consensus/src/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ impl MockRuntimeApi {
if let Some(para_id) = self.0 {
let _ =
sender.send(Ok(vec![CoreState::Scheduled(ScheduledCore {
para_id: para_id,
para_id,
collator: None,
})]));
} else {
Expand Down Expand Up @@ -888,7 +888,7 @@ impl CollatorLookaheadTestBuilder {
CancellationToken,
) {
// Creation of keystore
let _ = sp_tracing::try_init_simple();
sp_tracing::try_init_simple();
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
let keystore = LocalKeystore::open(keystore_path.path(), None).expect("Creates keystore.");
let alice_public = keystore
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async fn claim_slot_respects_min_slot_freq() {
#[tokio::test]
async fn collate_returns_correct_block() {
let net = AuraTestNet::new(4);
let _ = sp_tracing::try_init_simple();
sp_tracing::try_init_simple();

let keystore_path = tempfile::tempdir().expect("Creates keystore path");
let keystore = LocalKeystore::open(keystore_path.path(), None).expect("Creates keystore.");
Expand Down
1 change: 1 addition & 0 deletions client/node-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ serde = { workspace = true, features = [ "derive" ] }

# Local
tc-consensus = { workspace = true }
tp-traits = { workspace = true }

# Nimbus
nimbus-consensus = { workspace = true }
Expand Down
46 changes: 34 additions & 12 deletions client/node-common/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,36 @@ use {
#[allow(deprecated)]
use sc_executor::NativeElseWasmExecutor;

tp_traits::alias!(
pub trait MinimalRuntimeApi<
Block: (cumulus_primitives_core::BlockT),
Client: (sp_api::CallApiAt<Block>),
> :
ConstructRuntimeApi<
Block,
Client,
RuntimeApi:
TaggedTransactionQueue<Block>
+ BlockBuilder<Block> + OffchainWorkerApi<Block>
+ sp_api::Metadata<Block>
+ sp_session::SessionKeys<Block>,
> + Send + Sync + 'static
);

tp_traits::alias!(
pub trait MinimalCumulusRuntimeApi<
Block: (cumulus_primitives_core::BlockT),
Client: (sp_api::CallApiAt<Block>),
> :
MinimalRuntimeApi<Block, Client> +
ConstructRuntimeApi<
Block,
Client,
RuntimeApi:
cumulus_primitives_core::CollectCollationInfo<Block>,
>
);

/// Trait to configure the main types the builder rely on, bundled in a single
/// type to reduce verbosity and the amount of type parameters.
pub trait NodeBuilderConfig {
Expand All @@ -83,10 +113,7 @@ pub trait NodeBuilderConfig {
BlockOf<Self>: cumulus_primitives_core::BlockT,
ExecutorOf<Self>:
Clone + CodeExecutor + RuntimeVersionOf + TanssiExecutorExt + Sync + Send + 'static,
RuntimeApiOf<Self>:
ConstructRuntimeApi<BlockOf<Self>, ClientOf<Self>> + Sync + Send + 'static,
ConstructedRuntimeApiOf<Self>:
TaggedTransactionQueue<BlockOf<Self>> + BlockBuilder<BlockOf<Self>>,
RuntimeApiOf<Self>: MinimalRuntimeApi<BlockOf<Self>, ClientOf<Self>>,
{
NodeBuilder::<Self>::new(parachain_config, hwbench)
}
Expand Down Expand Up @@ -137,8 +164,7 @@ pub struct NodeBuilder<
> where
BlockOf<T>: cumulus_primitives_core::BlockT,
ExecutorOf<T>: Clone + CodeExecutor + RuntimeVersionOf + Sync + Send + 'static,
RuntimeApiOf<T>: ConstructRuntimeApi<BlockOf<T>, ClientOf<T>> + Sync + Send + 'static,
ConstructedRuntimeApiOf<T>: TaggedTransactionQueue<BlockOf<T>> + BlockBuilder<BlockOf<T>>,
RuntimeApiOf<T>: MinimalRuntimeApi<BlockOf<T>, ClientOf<T>>,
{
pub client: Arc<ClientOf<T>>,
pub backend: Arc<BackendOf<T>>,
Expand Down Expand Up @@ -198,8 +224,7 @@ where
BlockOf<T>: cumulus_primitives_core::BlockT,
ExecutorOf<T>:
Clone + CodeExecutor + RuntimeVersionOf + TanssiExecutorExt + Sync + Send + 'static,
RuntimeApiOf<T>: ConstructRuntimeApi<BlockOf<T>, ClientOf<T>> + Sync + Send + 'static,
ConstructedRuntimeApiOf<T>: TaggedTransactionQueue<BlockOf<T>> + BlockBuilder<BlockOf<T>>,
RuntimeApiOf<T>: MinimalRuntimeApi<BlockOf<T>, ClientOf<T>>,
{
/// Create a new `NodeBuilder` which prepare objects required to launch a
/// node. However it only starts telemetry, and doesn't provide any
Expand Down Expand Up @@ -293,10 +318,7 @@ impl<T: NodeBuilderConfig, SNetwork, STxHandler, SImportQueueService>
where
BlockOf<T>: cumulus_primitives_core::BlockT,
ExecutorOf<T>: Clone + CodeExecutor + RuntimeVersionOf + Sync + Send + 'static,
RuntimeApiOf<T>: ConstructRuntimeApi<BlockOf<T>, ClientOf<T>> + Sync + Send + 'static,
ConstructedRuntimeApiOf<T>: TaggedTransactionQueue<BlockOf<T>>
+ BlockBuilder<BlockOf<T>>
+ cumulus_primitives_core::CollectCollationInfo<BlockOf<T>>,
RuntimeApiOf<T>: MinimalCumulusRuntimeApi<BlockOf<T>, ClientOf<T>>,
{
pub async fn build_relay_chain_interface(
&mut self,
Expand Down
4 changes: 4 additions & 0 deletions client/service-container-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ pallet-data-preservers = { workspace = true, features = [ "std" ] }
services-payment-rpc = { workspace = true }
stream-payment-rpc = { workspace = true }
tc-consensus = { workspace = true }
tp-traits = { workspace = true }

# Dancekit
dc-orchestrator-chain-interface = { workspace = true }
dp-container-chain-genesis-data = { workspace = true, features = [ "json", "std" ] }
dp-slot-duration-runtime-api = { workspace = true }

# Substrate
frame-support = { workspace = true }
sc-basic-authorship = { workspace = true }
sc-chain-spec = { workspace = true }
sc-cli = { workspace = true }
Expand All @@ -55,6 +57,7 @@ sc-transaction-pool = { workspace = true }
sc-transaction-pool-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-consensus = { workspace = true }
sp-transaction-pool = { workspace = true }
substrate-frame-rpc-system = { workspace = true }
substrate-prometheus-endpoint = { workspace = true }

Expand All @@ -79,6 +82,7 @@ cumulus-primitives-core = { workspace = true }
cumulus-relay-chain-interface = { workspace = true }

# Nimbus
async-backing-primitives = { workspace = true }
nimbus-consensus = { workspace = true }
nimbus-primitives = { workspace = true }

Expand Down
23 changes: 12 additions & 11 deletions client/service-container-chain/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use {
spawner::{CcSpawnMsg, ContainerChainSpawnerState},
},
cumulus_primitives_core::ParaId,
frame_support::DefaultNoBound,
std::{
cell::Cell,
collections::VecDeque,
Expand All @@ -32,16 +33,16 @@ use {
},
};

#[derive(Default)]
pub struct SpawnedContainersMonitor {
#[derive(DefaultNoBound)]
pub struct SpawnedContainersMonitor<RuntimeApi> {
/// List of the N most recently started container chains, with some statistics related to
/// stopping time and reference count.
list: VecDeque<SpawnedContainer>,
list: VecDeque<SpawnedContainer<RuntimeApi>>,
/// Count the number of times a container chain has been started
count: usize,
}

pub struct SpawnedContainer {
pub struct SpawnedContainer<RuntimeApi> {
/// Unique identifier for a spawned container (not ParaId)
pub id: usize,
/// Container chain para id
Expand All @@ -59,10 +60,10 @@ pub struct SpawnedContainer {
/// Used to check the reference count, if it's 0 it means the database has been closed
pub backend: std::sync::Weak<ContainerChainBackend>,
/// Used to check the reference count, if it's 0 it means that the client has been closed.
pub client: std::sync::Weak<ContainerChainClient>,
nanocryk marked this conversation as resolved.
Show resolved Hide resolved
pub client: std::sync::Weak<ContainerChainClient<RuntimeApi>>,
}

impl SpawnedContainer {
impl<RuntimeApi> SpawnedContainer<RuntimeApi> {
pub fn is_stopped(&self) -> bool {
self.stop_refcount_time.get().is_some() || {
// Check reference count, and set stop_refcount_time if zero
Expand Down Expand Up @@ -118,9 +119,9 @@ impl SpawnedContainer {
}
}

impl SpawnedContainersMonitor {
impl<RuntimeApi> SpawnedContainersMonitor<RuntimeApi> {
/// Returns a unique id which is not the ParaId
pub fn push(&mut self, mut x: SpawnedContainer) -> usize {
pub fn push(&mut self, mut x: SpawnedContainer<RuntimeApi>) -> usize {
assert_eq!(x.id, 0, "SpawnedContainer.id must be set to 0, the actual id will be returned from push function");
let id = self.count;
x.id = id;
Expand Down Expand Up @@ -155,7 +156,7 @@ impl SpawnedContainersMonitor {
}
}

pub fn running_chains(&self) -> Vec<&SpawnedContainer> {
pub fn running_chains(&self) -> Vec<&SpawnedContainer<RuntimeApi>> {
self.list
.iter()
.filter(|container| !container.is_stopped())
Expand Down Expand Up @@ -200,7 +201,7 @@ impl SpawnedContainersMonitor {
}

/// Background task that monitors the number of running container chains.
pub async fn monitor_task(state: Arc<Mutex<ContainerChainSpawnerState>>) {
pub async fn monitor_task<RuntimeApi>(state: Arc<Mutex<ContainerChainSpawnerState<RuntimeApi>>>) {
// Main loop frequency, doesn't need to be fast
let monitor_period = Duration::from_secs(300 * 0 + 10);
// Max number of allowed container chains before printing warnings.
Expand Down Expand Up @@ -286,7 +287,7 @@ mod tests {

#[test]
fn test_truncate() {
let mut monitor = SpawnedContainersMonitor::default();
let mut monitor = SpawnedContainersMonitor::<dancebox_runtime::RuntimeApi>::default();
let default_container = || SpawnedContainer {
id: Default::default(),
para_id: Default::default(),
Expand Down
Loading
Loading