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:
Bastian Köcher
2019-08-09 14:24:18 +02:00
committed by GitHub
parent b4b53cbb6e
commit c824c959d7
18 changed files with 97 additions and 28 deletions
+13 -2
View File
@@ -47,11 +47,15 @@ pub(crate) struct Api<Storage, Block: traits::Block> {
db: Storage,
network_state: Arc<dyn NetworkStateInfo + Send + Sync>,
_at: BlockId<Block>,
/// Is this node a potential validator?
is_validator: bool,
}
fn unavailable_yet<R: Default>(name: &str) -> R {
error!("The {:?} API is not available for offchain workers yet. Follow \
https://github.com/paritytech/substrate/issues/1458 for details", name);
error!(
"The {:?} API is not available for offchain workers yet. Follow \
https://github.com/paritytech/substrate/issues/1458 for details", name
);
Default::default()
}
@@ -63,6 +67,10 @@ where
Storage: OffchainStorage,
Block: traits::Block,
{
fn is_validator(&self) -> bool {
self.is_validator
}
fn submit_transaction(&mut self, ext: Vec<u8>) -> Result<(), ()> {
self.sender
.unbounded_send(ExtMessage::SubmitExtrinsic(ext))
@@ -277,6 +285,7 @@ impl<A: ChainApi> AsyncApi<A> {
db: S,
at: BlockId<A::Block>,
network_state: Arc<dyn NetworkStateInfo + Send + Sync>,
is_validator: bool,
) -> (Api<S, A::Block>, AsyncApi<A>) {
let (sender, rx) = mpsc::unbounded();
@@ -285,6 +294,7 @@ impl<A: ChainApi> AsyncApi<A> {
db,
network_state,
_at: at,
is_validator,
};
let async_api = AsyncApi {
@@ -362,6 +372,7 @@ mod tests {
db,
BlockId::Number(Zero::zero()),
mock,
false,
)
}
+4 -4
View File
@@ -98,9 +98,8 @@ impl<Client, Storage, Block> OffchainWorkers<
number: &<Block::Header as traits::Header>::Number,
pool: &Arc<Pool<A>>,
network_state: Arc<dyn NetworkStateInfo + Send + Sync>,
) -> impl Future<Output = ()> where
A: ChainApi<Block=Block> + 'static,
{
is_validator: bool,
) -> impl Future<Output = ()> where A: ChainApi<Block=Block> + 'static {
let runtime = self.client.runtime_api();
let at = BlockId::number(*number);
let has_api = runtime.has_api::<dyn OffchainWorkerApi<Block>>(&at);
@@ -112,6 +111,7 @@ impl<Client, Storage, Block> OffchainWorkers<
self.db.clone(),
at.clone(),
network_state.clone(),
is_validator,
);
debug!("Spawning offchain workers at {:?}", at);
let number = *number;
@@ -177,7 +177,7 @@ mod tests {
// when
let offchain = OffchainWorkers::new(client, db);
futures::executor::block_on(offchain.on_block_imported(&0u64, &pool, network_state));
futures::executor::block_on(offchain.on_block_imported(&0u64, &pool, network_state, false));
// then
assert_eq!(pool.status().ready, 1);
+4
View File
@@ -134,6 +134,10 @@ impl TestOffchainExt {
}
impl offchain::Externalities for TestOffchainExt {
fn is_validator(&self) -> bool {
unimplemented!("not needed in tests so far")
}
fn submit_transaction(&mut self, _ex: Vec<u8>) -> Result<(), ()> {
unimplemented!("not needed in tests so far")
}