Do not call externalities without Ext being set (#3436)

* Do not call externalities without `Ext` being set

* Fix compare and set

* Bump runtime version.

* Bump hashmap_core
This commit is contained in:
Bastian Köcher
2019-08-19 12:52:39 +02:00
committed by Gavin Wood
parent 017752df41
commit 3b0af8bbf4
4 changed files with 56 additions and 22 deletions
+5 -5
View File
@@ -836,7 +836,7 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"hashmap_core 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1136,7 +1136,7 @@ dependencies = [
[[package]]
name = "hashmap_core"
version = "0.1.10"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -2078,7 +2078,7 @@ version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"hashmap_core 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -5562,7 +5562,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"hashmap_core 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -6239,7 +6239,7 @@ dependencies = [
"checksum hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32c87fec93c4a2d264483ef843ac1930ae7c7999d97d73721305a5188b4c23a4"
"checksum hash256-std-hasher 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16293646125e09e5bc216d9f73fa81ab31c4f97007d56c036bbf15a58e970540"
"checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da"
"checksum hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8e04cb7a5051270ef3fa79f8c7604d581ecfa73d520e74f554e45541c4b5881a"
"checksum hashmap_core 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "2d6852e5a86250521973b0c1d39677166d8a9c0047c908d7e04f1aa04177973c"
"checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461"
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
+46 -12
View File
@@ -663,7 +663,12 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
.map_err(|_| "Invalid attempt to get id in ext_ed25519_public_keys")?;
let key_type = KeyTypeId(id);
let keys = runtime_io::ed25519_public_keys(key_type).encode();
let keys = this.ext
.keystore()
.ok_or("No `keystore` associated for the current context!")?
.read()
.ed25519_public_keys(key_type)
.encode();
let len = keys.len() as u32;
let offset = this.heap.allocate(len)? as u32;
@@ -717,7 +722,12 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
.map_err(|_| "Seed not a valid utf8 string in ext_sr25119_generate")
).transpose()?;
let pubkey = runtime_io::ed25519_generate(key_type, seed);
let pubkey = this.ext
.keystore()
.ok_or("No `keystore` associated for the current context!")?
.write()
.ed25519_generate_new(key_type, seed)
.map_err(|_| "`ed25519` key generation failed")?;
this.memory.set(out, pubkey.as_ref())
.map_err(|_| "Invalid attempt to set out in ext_ed25519_generate".into())
@@ -741,7 +751,15 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
let msg = this.memory.get(msg_data, msg_len as usize)
.map_err(|_| "Invalid attempt to get message in ext_ed25519_sign")?;
let signature = runtime_io::ed25519_sign(key_type, &ed25519::Public(pubkey), &msg);
let pub_key = ed25519::Public::try_from(pubkey.as_ref())
.map_err(|_| "Invalid `ed25519` public key")?;
let signature = this.ext
.keystore()
.ok_or("No `keystore` associated for the current context!")?
.read()
.ed25519_key_pair(key_type, &pub_key)
.map(|k| k.sign(msg.as_ref()));
match signature {
Some(signature) => {
@@ -759,7 +777,12 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
.map_err(|_| "Invalid attempt to get id in ext_sr25519_public_keys")?;
let key_type = KeyTypeId(id);
let keys = runtime_io::sr25519_public_keys(key_type).encode();
let keys = this.ext
.keystore()
.ok_or("No `keystore` associated for the current context!")?
.read()
.sr25519_public_keys(key_type)
.encode();
let len = keys.len() as u32;
let offset = this.heap.allocate(len)? as u32;
@@ -813,7 +836,12 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
)
.transpose()?;
let pubkey = runtime_io::sr25519_generate(key_type, seed);
let pubkey = this.ext
.keystore()
.ok_or("No `keystore` associated for the current context!")?
.write()
.sr25519_generate_new(key_type, seed)
.map_err(|_| "`sr25519` key generation failed")?;
this.memory.set(out, pubkey.as_ref())
.map_err(|_| "Invalid attempt to set out in ext_sr25519_generate".into())
@@ -837,7 +865,15 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
let msg = this.memory.get(msg_data, msg_len as usize)
.map_err(|_| "Invalid attempt to get message in ext_sr25519_sign")?;
let signature = runtime_io::sr25519_sign(key_type, &sr25519::Public(pubkey), &msg);
let pub_key = sr25519::Public::try_from(pubkey.as_ref())
.map_err(|_| "Invalid `sr25519` public key")?;
let signature = this.ext
.keystore()
.ok_or("No `keystore` associated for the current context!")?
.read()
.sr25519_key_pair(key_type, &pub_key)
.map(|k| k.sign(msg.as_ref()));
match signature {
Some(signature) => {
@@ -877,11 +913,9 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
Ok(0)
},
ext_is_validator() -> u32 => {
Ok(if runtime_io::is_validator() {
1
} else {
0
})
this.ext.offchain()
.map(|o| if o.is_validator() { 1 } else { 0 })
.ok_or("Calling unavailable API ext_is_validator: wasm".into())
},
ext_submit_transaction(msg_data: *const u8, len: u32) -> u32 => {
let extrinsic = this.memory.get(msg_data, len as usize)
@@ -986,7 +1020,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
.map_err(|_| "OOB while ext_local_storage_compare_and_set: wasm")?;
let res = {
if old_value == u32::max_value() {
if old_value_len == u32::max_value() {
this.ext.offchain()
.map(|api| api.local_storage_compare_and_set(kind, &key, None, &new_value))
.ok_or_else(|| "Calling unavailable API ext_local_storage_compare_and_set: wasm")?
+4 -4
View File
@@ -206,7 +206,7 @@ impl CryptoApi for () {
ext::with(|ext| {
ext.keystore()
.expect("No `keystore` associated for the current context!")
.write()
.read()
.ed25519_public_keys(id)
}).expect("`ed25519_public_keys` cannot be called outside of an Externalities-provided environment.")
}
@@ -233,7 +233,7 @@ impl CryptoApi for () {
.expect("No `keystore` associated for the current context!")
.read()
.ed25519_key_pair(id, &pub_key)
.map(|k| k.sign(msg.as_ref()).into())
.map(|k| k.sign(msg.as_ref()))
}).expect("`ed25519_sign` cannot be called outside of an Externalities-provided environment.")
}
@@ -245,7 +245,7 @@ impl CryptoApi for () {
ext::with(|ext| {
ext.keystore()
.expect("No `keystore` associated for the current context!")
.write()
.read()
.sr25519_public_keys(id)
}).expect("`sr25519_public_keys` cannot be called outside of an Externalities-provided environment.")
}
@@ -272,7 +272,7 @@ impl CryptoApi for () {
.expect("No `keystore` associated for the current context!")
.read()
.sr25519_key_pair(id, &pub_key)
.map(|k| k.sign(msg.as_ref()).into())
.map(|k| k.sign(msg.as_ref()))
}).expect("`sr25519_sign` cannot be called outside of an Externalities-provided environment.")
}
+1 -1
View File
@@ -81,7 +81,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 147,
impl_version: 148,
impl_version: 149,
apis: RUNTIME_API_VERSIONS,
};