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

Commit 65c388b

Browse files
committed
Merge remote-tracking branch 'origin/master' into prgn-run-rococo
2 parents 731ebf4 + 5ec559c commit 65c388b

File tree

8 files changed

+263
-170
lines changed

8 files changed

+263
-170
lines changed

Cargo.lock

Lines changed: 148 additions & 162 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/common/src/paras_sudo_wrapper.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ use frame_support::{
2222
weights::DispatchClass,
2323
};
2424
use frame_system::ensure_root;
25-
use runtime_parachains::paras::{
26-
self,
27-
ParaGenesisArgs,
25+
use runtime_parachains::{
26+
router,
27+
paras::{self, ParaGenesisArgs},
2828
};
2929
use primitives::v1::Id as ParaId;
3030

3131
/// The module's configuration trait.
32-
pub trait Trait: paras::Trait { }
32+
pub trait Trait: paras::Trait + router::Trait { }
3333

3434
decl_error! {
3535
pub enum Error for Module<T: Trait> { }
@@ -57,6 +57,7 @@ decl_module! {
5757
pub fn sudo_schedule_para_cleanup(origin, id: ParaId) -> DispatchResult {
5858
ensure_root(origin)?;
5959
paras::Module::<T>::schedule_para_cleanup(id);
60+
router::Module::<T>::schedule_para_cleanup(id);
6061
Ok(())
6162
}
6263
}

runtime/parachains/src/initializer.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ use frame_support::{
2727
};
2828
use sp_runtime::traits::One;
2929
use codec::{Encode, Decode};
30-
use crate::{configuration::{self, HostConfiguration}, paras, scheduler, inclusion};
30+
use crate::{
31+
configuration::{self, HostConfiguration},
32+
paras, router, scheduler, inclusion,
33+
};
3134

3235
/// Information about a session change that has just occurred.
3336
#[derive(Default, Clone)]
@@ -55,7 +58,12 @@ struct BufferedSessionChange<N> {
5558
}
5659

5760
pub trait Trait:
58-
frame_system::Trait + configuration::Trait + paras::Trait + scheduler::Trait + inclusion::Trait
61+
frame_system::Trait
62+
+ configuration::Trait
63+
+ paras::Trait
64+
+ scheduler::Trait
65+
+ inclusion::Trait
66+
+ router::Trait
5967
{
6068
/// A randomness beacon.
6169
type Randomness: Randomness<Self::Hash>;
@@ -114,10 +122,12 @@ decl_module! {
114122
// - Scheduler
115123
// - Inclusion
116124
// - Validity
125+
// - Router
117126
let total_weight = configuration::Module::<T>::initializer_initialize(now) +
118127
paras::Module::<T>::initializer_initialize(now) +
119128
scheduler::Module::<T>::initializer_initialize(now) +
120-
inclusion::Module::<T>::initializer_initialize(now);
129+
inclusion::Module::<T>::initializer_initialize(now) +
130+
router::Module::<T>::initializer_initialize(now);
121131

122132
HasInitialized::set(Some(()));
123133

@@ -127,6 +137,7 @@ decl_module! {
127137
fn on_finalize() {
128138
// reverse initialization order.
129139

140+
router::Module::<T>::initializer_finalize();
130141
inclusion::Module::<T>::initializer_finalize();
131142
scheduler::Module::<T>::initializer_finalize();
132143
paras::Module::<T>::initializer_finalize();
@@ -170,6 +181,7 @@ impl<T: Trait> Module<T> {
170181
paras::Module::<T>::initializer_on_new_session(&notification);
171182
scheduler::Module::<T>::initializer_on_new_session(&notification);
172183
inclusion::Module::<T>::initializer_on_new_session(&notification);
184+
router::Module::<T>::initializer_on_new_session(&notification);
173185
}
174186

175187
/// Should be called when a new session occurs. Buffers the session notification to be applied

runtime/parachains/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
//! particular the `Initializer` module, as it is responsible for initializing the state
2121
//! of the other modules.
2222
23-
2423
#![cfg_attr(not(feature = "std"), no_std)]
2524

2625
use sp_std::result;
@@ -33,6 +32,7 @@ pub mod inclusion;
3332
pub mod inclusion_inherent;
3433
pub mod initializer;
3534
pub mod paras;
35+
pub mod router;
3636
pub mod scheduler;
3737
pub mod validity;
3838

runtime/parachains/src/mock.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ impl crate::configuration::Trait for Test { }
103103

104104
impl crate::paras::Trait for Test { }
105105

106+
impl crate::router::Trait for Test { }
107+
106108
impl crate::scheduler::Trait for Test { }
107109

108110
impl crate::inclusion::Trait for Test {
@@ -120,6 +122,11 @@ pub type Configuration = crate::configuration::Module<Test>;
120122
/// Mocked paras.
121123
pub type Paras = crate::paras::Module<Test>;
122124

125+
/// Mocked router.
126+
// TODO: Will be used in the follow ups.
127+
#[allow(dead_code)]
128+
pub type Router = crate::router::Module<Test>;
129+
123130
/// Mocked scheduler.
124131
pub type Scheduler = crate::scheduler::Module<Test>;
125132

runtime/parachains/src/router.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2020 Parity Technologies (UK) Ltd.
2+
// This file is part of Polkadot.
3+
4+
// Polkadot is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Polkadot is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! The router module is responsible for handling messaging.
18+
//!
19+
//! The core of the messaging is checking and processing messages sent out by the candidates,
20+
//! routing the messages at their destinations and informing the parachains about the incoming
21+
//! messages.
22+
23+
use crate::{configuration, initializer};
24+
use sp_std::prelude::*;
25+
use frame_support::{decl_error, decl_module, decl_storage, weights::Weight};
26+
use primitives::v1::{Id as ParaId};
27+
28+
pub trait Trait: frame_system::Trait + configuration::Trait {}
29+
30+
decl_storage! {
31+
trait Store for Module<T: Trait> as Router {
32+
/// Paras that are to be cleaned up at the end of the session.
33+
/// The entries are sorted ascending by the para id.
34+
OutgoingParas: Vec<ParaId>;
35+
}
36+
}
37+
38+
decl_error! {
39+
pub enum Error for Module<T: Trait> { }
40+
}
41+
42+
decl_module! {
43+
/// The router module.
44+
pub struct Module<T: Trait> for enum Call where origin: <T as frame_system::Trait>::Origin {
45+
type Error = Error<T>;
46+
}
47+
}
48+
49+
impl<T: Trait> Module<T> {
50+
/// Block initialization logic, called by initializer.
51+
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
52+
0
53+
}
54+
55+
/// Block finalization logic, called by initializer.
56+
pub(crate) fn initializer_finalize() {}
57+
58+
/// Called by the initializer to note that a new session has started.
59+
pub(crate) fn initializer_on_new_session(
60+
_notification: &initializer::SessionChangeNotification<T::BlockNumber>,
61+
) {
62+
let outgoing = OutgoingParas::take();
63+
for _outgoing_para in outgoing {
64+
65+
}
66+
}
67+
68+
/// Schedule a para to be cleaned up at the start of the next session.
69+
pub fn schedule_para_cleanup(id: ParaId) {
70+
OutgoingParas::mutate(|v| {
71+
if let Err(i) = v.binary_search(&id) {
72+
v.insert(i, id);
73+
}
74+
});
75+
}
76+
}
77+
78+
#[cfg(test)]
79+
mod tests {
80+
}

runtime/rococo-v1/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ use runtime_parachains::inclusion as parachains_inclusion;
7070
use runtime_parachains::inclusion_inherent as parachains_inclusion_inherent;
7171
use runtime_parachains::initializer as parachains_initializer;
7272
use runtime_parachains::paras as parachains_paras;
73+
use runtime_parachains::router as parachains_router;
7374
use runtime_parachains::scheduler as parachains_scheduler;
7475

7576
pub use pallet_balances::Call as BalancesCall;
@@ -374,6 +375,7 @@ construct_runtime! {
374375
Scheduler: parachains_scheduler::{Module, Call, Storage},
375376
Paras: parachains_paras::{Module, Call, Storage},
376377
Initializer: parachains_initializer::{Module, Call, Storage},
378+
Router: parachains_router::{Module, Call, Storage},
377379

378380
ParasSudoWrapper: paras_sudo_wrapper::{Module, Call},
379381
}
@@ -734,6 +736,8 @@ impl parachains_inclusion::Trait for Runtime {
734736

735737
impl parachains_paras::Trait for Runtime { }
736738

739+
impl parachains_router::Trait for Runtime { }
740+
737741
impl parachains_inclusion_inherent::Trait for Runtime { }
738742

739743
impl parachains_scheduler::Trait for Runtime { }

runtime/test-runtime/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use polkadot_runtime_parachains::{
2727
inclusion,
2828
initializer,
2929
paras,
30+
router,
3031
runtime_api_impl::v1 as runtime_impl,
3132
scheduler,
3233
};
@@ -437,6 +438,8 @@ impl initializer::Trait for Runtime {
437438

438439
impl paras::Trait for Runtime {}
439440

441+
impl router::Trait for Runtime {}
442+
440443
impl scheduler::Trait for Runtime {}
441444

442445
construct_runtime! {

0 commit comments

Comments
 (0)