Unverified Commit f63d83f8 authored by Sergey Pepyakin's avatar Sergey Pepyakin Committed by GitHub
Browse files

Skeleton of the Router module (#1726)

The purpose of this commit is to establish a foundation of the router module, it paves the way for the implementation of other features.
parent ff1dd3a2
Pipeline #107271 failed with stages
in 8 minutes and 29 seconds
......@@ -22,14 +22,14 @@ use frame_support::{
weights::DispatchClass,
};
use frame_system::ensure_root;
use runtime_parachains::paras::{
self,
ParaGenesisArgs,
use runtime_parachains::{
router,
paras::{self, ParaGenesisArgs},
};
use primitives::v1::Id as ParaId;
/// The module's configuration trait.
pub trait Trait: paras::Trait { }
pub trait Trait: paras::Trait + router::Trait { }
decl_error! {
pub enum Error for Module<T: Trait> { }
......@@ -57,6 +57,7 @@ decl_module! {
pub fn sudo_schedule_para_cleanup(origin, id: ParaId) -> DispatchResult {
ensure_root(origin)?;
paras::Module::<T>::schedule_para_cleanup(id);
router::Module::<T>::schedule_para_cleanup(id);
Ok(())
}
}
......
......@@ -27,7 +27,10 @@ use frame_support::{
};
use sp_runtime::traits::One;
use codec::{Encode, Decode};
use crate::{configuration::{self, HostConfiguration}, paras, scheduler, inclusion};
use crate::{
configuration::{self, HostConfiguration},
paras, router, scheduler, inclusion,
};
/// Information about a session change that has just occurred.
#[derive(Default, Clone)]
......@@ -55,7 +58,12 @@ struct BufferedSessionChange<N> {
}
pub trait Trait:
frame_system::Trait + configuration::Trait + paras::Trait + scheduler::Trait + inclusion::Trait
frame_system::Trait
+ configuration::Trait
+ paras::Trait
+ scheduler::Trait
+ inclusion::Trait
+ router::Trait
{
/// A randomness beacon.
type Randomness: Randomness<Self::Hash>;
......@@ -114,10 +122,12 @@ decl_module! {
// - Scheduler
// - Inclusion
// - Validity
// - Router
let total_weight = configuration::Module::<T>::initializer_initialize(now) +
paras::Module::<T>::initializer_initialize(now) +
scheduler::Module::<T>::initializer_initialize(now) +
inclusion::Module::<T>::initializer_initialize(now);
inclusion::Module::<T>::initializer_initialize(now) +
router::Module::<T>::initializer_initialize(now);
HasInitialized::set(Some(()));
......@@ -127,6 +137,7 @@ decl_module! {
fn on_finalize() {
// reverse initialization order.
router::Module::<T>::initializer_finalize();
inclusion::Module::<T>::initializer_finalize();
scheduler::Module::<T>::initializer_finalize();
paras::Module::<T>::initializer_finalize();
......@@ -170,6 +181,7 @@ impl<T: Trait> Module<T> {
paras::Module::<T>::initializer_on_new_session(&notification);
scheduler::Module::<T>::initializer_on_new_session(&notification);
inclusion::Module::<T>::initializer_on_new_session(&notification);
router::Module::<T>::initializer_on_new_session(&notification);
}
/// Should be called when a new session occurs. Buffers the session notification to be applied
......
......@@ -20,7 +20,6 @@
//! particular the `Initializer` module, as it is responsible for initializing the state
//! of the other modules.
#![cfg_attr(not(feature = "std"), no_std)]
use sp_std::result;
......@@ -33,6 +32,7 @@ pub mod inclusion;
pub mod inclusion_inherent;
pub mod initializer;
pub mod paras;
pub mod router;
pub mod scheduler;
pub mod validity;
......
......@@ -103,6 +103,8 @@ impl crate::configuration::Trait for Test { }
impl crate::paras::Trait for Test { }
impl crate::router::Trait for Test { }
impl crate::scheduler::Trait for Test { }
impl crate::inclusion::Trait for Test {
......@@ -120,6 +122,11 @@ pub type Configuration = crate::configuration::Module<Test>;
/// Mocked paras.
pub type Paras = crate::paras::Module<Test>;
/// Mocked router.
// TODO: Will be used in the follow ups.
#[allow(dead_code)]
pub type Router = crate::router::Module<Test>;
/// Mocked scheduler.
pub type Scheduler = crate::scheduler::Module<Test>;
......
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! The router module is responsible for handling messaging.
//!
//! The core of the messaging is checking and processing messages sent out by the candidates,
//! routing the messages at their destinations and informing the parachains about the incoming
//! messages.
use crate::{configuration, initializer};
use sp_std::prelude::*;
use frame_support::{decl_error, decl_module, decl_storage, weights::Weight};
use primitives::v1::{Id as ParaId};
pub trait Trait: frame_system::Trait + configuration::Trait {}
decl_storage! {
trait Store for Module<T: Trait> as Router {
/// Paras that are to be cleaned up at the end of the session.
/// The entries are sorted ascending by the para id.
OutgoingParas: Vec<ParaId>;
}
}
decl_error! {
pub enum Error for Module<T: Trait> { }
}
decl_module! {
/// The router module.
pub struct Module<T: Trait> for enum Call where origin: <T as frame_system::Trait>::Origin {
type Error = Error<T>;
}
}
impl<T: Trait> Module<T> {
/// Block initialization logic, called by initializer.
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
0
}
/// Block finalization logic, called by initializer.
pub(crate) fn initializer_finalize() {}
/// Called by the initializer to note that a new session has started.
pub(crate) fn initializer_on_new_session(
_notification: &initializer::SessionChangeNotification<T::BlockNumber>,
) {
let outgoing = OutgoingParas::take();
for _outgoing_para in outgoing {
}
}
/// Schedule a para to be cleaned up at the start of the next session.
pub fn schedule_para_cleanup(id: ParaId) {
OutgoingParas::mutate(|v| {
if let Err(i) = v.binary_search(&id) {
v.insert(i, id);
}
});
}
}
#[cfg(test)]
mod tests {
}
......@@ -68,6 +68,7 @@ use runtime_parachains::inclusion as parachains_inclusion;
use runtime_parachains::inclusion_inherent as parachains_inclusion_inherent;
use runtime_parachains::initializer as parachains_initializer;
use runtime_parachains::paras as parachains_paras;
use runtime_parachains::router as parachains_router;
use runtime_parachains::scheduler as parachains_scheduler;
pub use pallet_balances::Call as BalancesCall;
......@@ -371,6 +372,7 @@ construct_runtime! {
Scheduler: parachains_scheduler::{Module, Call, Storage},
Paras: parachains_paras::{Module, Call, Storage},
Initializer: parachains_initializer::{Module, Call, Storage},
Router: parachains_router::{Module, Call, Storage},
ParasSudoWrapper: paras_sudo_wrapper::{Module, Call},
}
......@@ -721,6 +723,8 @@ impl parachains_inclusion::Trait for Runtime {
impl parachains_paras::Trait for Runtime { }
impl parachains_router::Trait for Runtime { }
impl parachains_inclusion_inherent::Trait for Runtime { }
impl parachains_scheduler::Trait for Runtime { }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment