Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
UMP: Initial plumbing
  • Loading branch information
pepyakin committed Oct 29, 2020
commit e0f9af1671a1bcb2b84bc74184ed9e4610e7cfe6
17 changes: 17 additions & 0 deletions runtime/parachains/src/inclusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ decl_error! {
InternalError,
/// The downward message queue is not processed correctly.
IncorrectDownwardMessageHandling,
/// At least one upward message sent does not pass the acceptance criteria.
InvalidUpwardMessages,
}
}

Expand Down Expand Up @@ -412,6 +414,7 @@ impl<T: Trait> Module<T> {
&candidate.candidate.commitments.head_data,
&candidate.candidate.commitments.new_validation_code,
candidate.candidate.commitments.processed_downward_messages,
&candidate.candidate.commitments.upward_messages,
)?;

for (i, assignment) in scheduled[skip..].iter().enumerate() {
Expand Down Expand Up @@ -544,6 +547,7 @@ impl<T: Trait> Module<T> {
&validation_outputs.head_data,
&validation_outputs.new_validation_code,
validation_outputs.processed_downward_messages,
&validation_outputs.upward_messages,
)
}

Expand All @@ -570,6 +574,10 @@ impl<T: Trait> Module<T> {
receipt.descriptor.para_id,
commitments.processed_downward_messages,
);
weight += <router::Module<T>>::enact_upward_messages(
receipt.descriptor.para_id,
commitments.upward_messages,
);

Self::deposit_event(
Event::<T>::CandidateIncluded(plain, commitments.head_data.clone())
Expand Down Expand Up @@ -693,6 +701,7 @@ impl<T: Trait> CandidateCheckContext<T> {
head_data: &HeadData,
new_validation_code: &Option<primitives::v1::ValidationCode>,
processed_downward_messages: u32,
upward_messages: &[primitives::v1::UpwardMessage],
) -> Result<(), DispatchError> {
ensure!(
head_data.0.len() <= self.config.max_head_data_size as _,
Expand Down Expand Up @@ -722,6 +731,14 @@ impl<T: Trait> CandidateCheckContext<T> {
),
Error::<T>::IncorrectDownwardMessageHandling,
);
ensure!(
<router::Module<T>>::check_upward_messages(
&self.config,
para_id,
upward_messages,
),
Error::<T>::InvalidUpwardMessages,
);

Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions runtime/parachains/src/inclusion_inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use frame_system::ensure_none;
use crate::{
inclusion,
scheduler::{self, FreedReason},
router,
};
use inherents::{InherentIdentifier, InherentData, MakeFatalError, ProvideInherent};

Expand Down Expand Up @@ -115,6 +116,9 @@ decl_module! {
// Note which of the scheduled cores were actually occupied by a backed candidate.
<scheduler::Module<T>>::occupied(&occupied);

// Give some time slice to dispatch pending upward messages.
<router::Module<T>>::process_pending_upward_messages();

// And track that we've finished processing the inherent for this block.
Included::set(Some(()));

Expand Down
1 change: 1 addition & 0 deletions runtime/parachains/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use frame_support::{decl_error, decl_module, decl_storage, weights::Weight};
use primitives::v1::{Id as ParaId, InboundDownwardMessage, Hash};

mod dmp;
mod ump;

pub use dmp::QueueDownwardMessageError;

Expand Down
59 changes: 59 additions & 0 deletions runtime/parachains/src/router/ump.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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/>.

use super::{Trait, Module};
use crate::configuration::HostConfiguration;
use sp_std::prelude::*;
use frame_support::weights::Weight;
use primitives::v1::{Id as ParaId, UpwardMessage};

impl<T: Trait> Module<T> {
/// Check that all the upward messages sent by a candidate pass the acceptance criteria. Returns
/// false, if any of the messages doesn't pass.
pub(crate) fn check_upward_messages(
config: &HostConfiguration<T::BlockNumber>,
para: ParaId,
upward_messages: &[UpwardMessage],
) -> bool {
drop(para);

if upward_messages.len() as u32 > config.max_upward_message_num_per_candidate {
return false;
}

for _ in upward_messages {
return false;
}

true
}

/// Enacts all the upward messages sent by a candidate.
pub(crate) fn enact_upward_messages(para: ParaId, upward_messages: Vec<UpwardMessage>) -> Weight {
drop(para);

for _ in upward_messages {
todo!()
}

0
}

/// Devote some time into dispatching pending upward messages.
pub(crate) fn process_pending_upward_messages() {
// no-op for now, will be filled in the following commits
}
}