diff --git a/polkadot/api/src/lib.rs b/polkadot/api/src/lib.rs index bf747624c3..731c19a496 100644 --- a/polkadot/api/src/lib.rs +++ b/polkadot/api/src/lib.rs @@ -153,17 +153,30 @@ impl CheckedBlockId for CheckedId { } } -// set up the necessary scaffolding to execute the runtime. +// set up the necessary scaffolding to execute a set of calls to the runtime. +// this creates a new block on top of the given ID and initialises it. macro_rules! with_runtime { ($client: ident, $at: expr, $exec: expr) => {{ - $client.state_at($at.block_id()).map_err(Error::from).and_then(|state| { + let parent = $at.block_id(); + let header = Header { + parent_hash: $client.block_hash_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))?, + number: $client.block_number_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))? + 1, + state_root: Default::default(), + extrinsics_root: Default::default(), + digest: Default::default(), + }; + + $client.state_at(parent).map_err(Error::from).and_then(|state| { let mut changes = Default::default(); let mut ext = state_machine::Ext { overlay: &mut changes, backend: &state, }; - ::substrate_executor::with_native_environment(&mut ext, $exec).map_err(Into::into) + ::substrate_executor::with_native_environment(&mut ext, || { + ::runtime::Executive::initialise_block(&header); + ($exec)() + }).map_err(Into::into) }) }} } @@ -196,16 +209,7 @@ impl PolkadotApi for Client> } fn duty_roster(&self, at: &CheckedId) -> Result { - // duty roster can only be queried at the start of a block, - // so we create a dummy. - let id = at.block_id(); - let parent_hash = self.block_hash_from_id(id)?.ok_or(ErrorKind::UnknownBlock(*id))?; - let number = self.block_number_from_id(id)?.ok_or(ErrorKind::UnknownBlock(*id))? + 1; - - with_runtime!(self, at, || { - ::runtime::System::initialise(&number, &parent_hash, &Default::default()); - ::runtime::Parachains::calculate_duty_roster() - }) + with_runtime!(self, at, ::runtime::Parachains::calculate_duty_roster) } fn timestamp(&self, at: &CheckedId) -> Result { @@ -422,4 +426,12 @@ mod tests { fn fails_to_check_id_for_unknown_block() { assert!(client().check_id(BlockId::Number(100)).is_err()); } + + #[test] + fn gets_random_seed_with_genesis() { + let client = client(); + + let id = client.check_id(BlockId::Number(0)).unwrap(); + assert!(client.random_seed(&id).is_ok()); + } } diff --git a/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm b/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm index 05ff2f4505..3f05418e5e 100644 Binary files a/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm and b/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm differ diff --git a/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm b/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm index 4bb8fff698..4d67e2c551 100755 Binary files a/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm and b/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm differ