mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 09:17:58 +00:00
Adds --no-validator CLI flag (#3348)
* Implement `is_validator` for offchain-workers * Introduce `--no-validator` flag * Don't run babe/grandpa/im-online when `--no-validator` is given * Fixes compilation * Bump spec version * Improve error handling in executor * Add missing extern function * Revert making error public * Remove `--no-validator` CLI
This commit is contained in:
@@ -38,8 +38,8 @@ pub enum Error {
|
||||
#[display(fmt="Method not found: '{}'", _0)]
|
||||
MethodNotFound(String),
|
||||
/// Code is invalid (expected single byte)
|
||||
#[display(fmt="Invalid Code")]
|
||||
InvalidCode,
|
||||
#[display(fmt="Invalid Code: {}", _0)]
|
||||
InvalidCode(String),
|
||||
/// Could not get runtime version.
|
||||
#[display(fmt="On-chain runtime does not specify version")]
|
||||
VersionInvalid,
|
||||
|
||||
@@ -22,7 +22,7 @@ use runtime_version::{NativeVersion, RuntimeVersion};
|
||||
use codec::{Decode, Encode};
|
||||
use crate::RuntimeInfo;
|
||||
use primitives::{Blake2Hasher, NativeOrEncoded};
|
||||
use log::trace;
|
||||
use log::{trace, warn};
|
||||
|
||||
use crate::RuntimesCache;
|
||||
|
||||
@@ -107,8 +107,14 @@ impl<D: NativeExecutionDispatch> RuntimeInfo for NativeExecutor<D> {
|
||||
) -> Option<RuntimeVersion> {
|
||||
RUNTIMES_CACHE.with(|cache| {
|
||||
let cache = &mut cache.borrow_mut();
|
||||
cache.fetch_runtime(&self.fallback, ext, self.default_heap_pages)
|
||||
.ok()?.version().clone()
|
||||
|
||||
match cache.fetch_runtime(&self.fallback, ext, self.default_heap_pages) {
|
||||
Ok(runtime) => runtime.version(),
|
||||
Err(e) => {
|
||||
warn!(target: "executor", "Failed to fetch runtime: {:?}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -876,6 +876,13 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
|
||||
|
||||
Ok(0)
|
||||
},
|
||||
ext_is_validator() -> u32 => {
|
||||
Ok(if runtime_io::is_validator() {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
})
|
||||
},
|
||||
ext_submit_transaction(msg_data: *const u8, len: u32) -> u32 => {
|
||||
let extrinsic = this.memory.get(msg_data, len as usize)
|
||||
.map_err(|_| "OOB while ext_submit_transaction: wasm")?;
|
||||
|
||||
@@ -248,12 +248,12 @@ impl RuntimesCache {
|
||||
) -> Result<Rc<CachedRuntime>, Error> {
|
||||
let code_hash = ext
|
||||
.original_storage_hash(well_known_keys::CODE)
|
||||
.ok_or(Error::InvalidCode)?;
|
||||
.ok_or(Error::InvalidCode("`CODE` not found in storage.".into()))?;
|
||||
|
||||
// This is direct result from fighting with borrowck.
|
||||
let handle_result =
|
||||
|cached_result: &Result<Rc<CachedRuntime>, CacheError>| match *cached_result {
|
||||
Err(_) => Err(Error::InvalidCode),
|
||||
Err(ref e) => Err(Error::InvalidCode(format!("{:?}", e))),
|
||||
Ok(ref cached_runtime) => Ok(Rc::clone(cached_runtime)),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user