Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
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
Fix up polkadot parachains in runtime
  • Loading branch information
gavofyork committed May 31, 2018
commit f3c1b9bd4c8fdf0fa2c2d75aac74ee6204c1eb1a
23 changes: 13 additions & 10 deletions polkadot/runtime/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use polkadot_primitives::parachain::{Id, Chain, DutyRoster, CandidateReceipt};
use {system, session};

use runtime_support::{StorageValue, StorageMap};
use runtime_support::dispatch::Result;

#[cfg(any(feature = "std", test))]
use rstd::marker::PhantomData;
Expand All @@ -44,7 +45,7 @@ decl_module! {
pub struct Module<T: Trait>;
pub enum Call where aux: <T as Trait>::PublicAux {
// provide candidate receipts for parachains, in ascending order by id.
fn set_heads(aux, heads: Vec<CandidateReceipt>) = 0;
fn set_heads(aux, heads: Vec<CandidateReceipt>) -> Result = 0;
}
}

Expand Down Expand Up @@ -137,24 +138,24 @@ impl<T: Trait> Module<T> {
<Parachains<T>>::put(parachains);
}

fn set_heads(aux: &<T as Trait>::PublicAux, heads: Vec<CandidateReceipt>) {
assert!(aux.is_empty());
assert!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block");
assert!(
fn set_heads(aux: &<T as Trait>::PublicAux, heads: Vec<CandidateReceipt>) -> Result {
ensure!(aux.is_empty(), "set_heads must not be signed");
ensure!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block");
ensure!(
<system::Module<T>>::extrinsic_index() == T::SET_POSITION,
"Parachain heads update extrinsic must be at position {} in the block",
T::SET_POSITION
"Parachain heads update extrinsic must be at position {} in the block"
// , T::SET_POSITION
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left in for completeness, but given we're returning &'static str (for efficiency) and have no formatting tools (since it would severely bloat the runtime), I doubt there's much that can be done right now. A later PR could perhaps switch &'static str to String in the case of compiling to native and then it can be formatted properly.

);

let active_parachains = Self::active_parachains();
let mut iter = active_parachains.iter();

// perform this check before writing to storage.
for head in &heads {
assert!(
ensure!(
iter.find(|&p| p == &head.parachain_index).is_some(),
"Submitted candidate for unregistered or out-of-order parachain {}",
head.parachain_index.into_inner()
"Submitted candidate for unregistered or out-of-order parachain {}"
// , head.parachain_index.into_inner()
);
}

Expand All @@ -164,6 +165,8 @@ impl<T: Trait> Module<T> {
}

<DidUpdate<T>>::put(true);

Ok(())
}
}

Expand Down