Make offchain worker calls more future proof. (#4618)

* Add warning if offchain workers version is not supported.

* Support only v2.

* Make it a warning.
This commit is contained in:
Tomasz Drwięga
2020-01-14 22:35:35 +01:00
committed by Bastian Köcher
parent c5c73abc05
commit e58fafc3ef
+5 -2
View File
@@ -101,13 +101,14 @@ impl<Client, Storage, Block> OffchainWorkers<
let has_api_v1 = runtime.has_api_with::<dyn OffchainWorkerApi<Block, Error = ()>, _>( let has_api_v1 = runtime.has_api_with::<dyn OffchainWorkerApi<Block, Error = ()>, _>(
&at, |v| v == 1 &at, |v| v == 1
); );
let has_api_v2 = runtime.has_api::<dyn OffchainWorkerApi<Block, Error = ()>>(&at); let has_api_v2 = runtime.has_api_with::<dyn OffchainWorkerApi<Block, Error = ()>, _>(
&at, |v| v == 2
);
let version = match (has_api_v1, has_api_v2) { let version = match (has_api_v1, has_api_v2) {
(_, Ok(true)) => 2, (_, Ok(true)) => 2,
(Ok(true), _) => 1, (Ok(true), _) => 1,
_ => 0, _ => 0,
}; };
debug!("Checking offchain workers at {:?}: version:{}", at, version); debug!("Checking offchain workers at {:?}: version:{}", at, version);
if version > 0 { if version > 0 {
let (api, runner) = api::AsyncApi::new( let (api, runner) = api::AsyncApi::new(
@@ -139,6 +140,8 @@ impl<Client, Storage, Block> OffchainWorkers<
}); });
futures::future::Either::Left(runner.process()) futures::future::Either::Left(runner.process())
} else { } else {
let help = "Consider turning off offchain workers if they are not part of your runtime.";
log::error!("Unsupported Offchain Worker API version: {}. {}", version, help);
futures::future::Either::Right(futures::future::ready(())) futures::future::Either::Right(futures::future::ready(()))
} }
} }