From 28b1cecf2f7dddfcf66ccebe51159058819b088a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 1 Jun 2018 18:32:40 +0200 Subject: [PATCH] Runtime dispatch calls return `Result` (#192) * Merge remote-tracking branch 'origin/master' into gav-xts-dont-panic * Update wasm. * consensus, session and staking all panic-safe. * Democracy doesn't panic in apply. * Fix tests. * Extra helper macro, council depanicked. * Fix one test. * Fix up all council tests. No panics! * Council voting depanicked. * Dispatch returns result. * session & staking tests updated * Fix democracy tests. * Fix council tests. * Fix up polkadot parachains in runtime * Fix borked merge --- polkadot/runtime/src/parachains.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/polkadot/runtime/src/parachains.rs b/polkadot/runtime/src/parachains.rs index 1a6a77d7fe..50da4306cb 100644 --- a/polkadot/runtime/src/parachains.rs +++ b/polkadot/runtime/src/parachains.rs @@ -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; @@ -44,7 +45,7 @@ decl_module! { pub struct Module; pub enum Call where aux: ::PublicAux { // provide candidate receipts for parachains, in ascending order by id. - fn set_heads(aux, heads: Vec) = 0; + fn set_heads(aux, heads: Vec) -> Result = 0; } } @@ -137,13 +138,13 @@ impl Module { >::put(parachains); } - fn set_heads(aux: &::PublicAux, heads: Vec) { - assert!(aux.is_empty()); - assert!(!>::exists(), "Parachain heads must be updated only once in the block"); - assert!( + fn set_heads(aux: &::PublicAux, heads: Vec) -> Result { + ensure!(aux.is_empty(), "set_heads must not be signed"); + ensure!(!>::exists(), "Parachain heads must be updated only once in the block"); + ensure!( >::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 ); let active_parachains = Self::active_parachains(); @@ -151,10 +152,10 @@ impl Module { // 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() ); } @@ -164,6 +165,8 @@ impl Module { } >::put(true); + + Ok(()) } }