Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Make offchain worker calls more future proof. (#4618)
Browse files Browse the repository at this point in the history
* Add warning if offchain workers version is not supported.

* Support only v2.

* Make it a warning.
  • Loading branch information
tomusdrw authored and bkchr committed Jan 14, 2020
1 parent 8cb71bd commit 37be263
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions client/offchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ impl<Client, Storage, Block> OffchainWorkers<
let has_api_v1 = runtime.has_api_with::<dyn OffchainWorkerApi<Block, Error = ()>, _>(
&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) {
(_, Ok(true)) => 2,
(Ok(true), _) => 1,
_ => 0,
};

debug!("Checking offchain workers at {:?}: version:{}", at, version);
if version > 0 {
let (api, runner) = api::AsyncApi::new(
Expand Down Expand Up @@ -139,6 +140,8 @@ impl<Client, Storage, Block> OffchainWorkers<
});
futures::future::Either::Left(runner.process())
} 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(()))
}
}
Expand Down

0 comments on commit 37be263

Please sign in to comment.