mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-25 02:25:51 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -56,41 +56,39 @@
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use futures::{
|
||||
prelude::*,
|
||||
StreamExt,
|
||||
};
|
||||
use futures::{prelude::*, StreamExt};
|
||||
use log::{debug, error, info};
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use parking_lot::RwLock;
|
||||
use prometheus_endpoint::{PrometheusError, Registry};
|
||||
use sc_client_api::{
|
||||
backend::{AuxStore, Backend},
|
||||
LockImportRun, BlockchainEvents, CallExecutor,
|
||||
ExecutionStrategy, Finalizer, TransactionFor, ExecutorProvider,
|
||||
BlockchainEvents, CallExecutor, ExecutionStrategy, ExecutorProvider, Finalizer, LockImportRun,
|
||||
TransactionFor,
|
||||
};
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use prometheus_endpoint::{PrometheusError, Registry};
|
||||
use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_INFO};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_blockchain::{HeaderBackend, Error as ClientError, HeaderMetadata};
|
||||
use sp_runtime::generic::BlockId;
|
||||
use sp_runtime::traits::{NumberFor, Block as BlockT, DigestFor, Zero};
|
||||
use sp_consensus::{SelectChain, BlockImport};
|
||||
use sp_core::{
|
||||
crypto::Public,
|
||||
};
|
||||
use sp_keystore::{SyncCryptoStorePtr, SyncCryptoStore};
|
||||
use sp_application_crypto::AppKey;
|
||||
use sp_blockchain::{Error as ClientError, HeaderBackend, HeaderMetadata};
|
||||
use sp_consensus::{BlockImport, SelectChain};
|
||||
use sp_core::crypto::Public;
|
||||
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, DigestFor, NumberFor, Zero},
|
||||
};
|
||||
use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver};
|
||||
use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_INFO, CONSENSUS_DEBUG};
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use finality_grandpa::Error as GrandpaError;
|
||||
use finality_grandpa::{voter, voter_set::VoterSet};
|
||||
pub use finality_grandpa::BlockNumberOps;
|
||||
use finality_grandpa::{voter, voter_set::VoterSet, Error as GrandpaError};
|
||||
|
||||
use std::{fmt, io};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Poll, Context};
|
||||
use std::{
|
||||
fmt, io,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
task::{Context, Poll},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
// utility logging macro that takes as first argument a conditional to
|
||||
// decide whether to log under debug or info level (useful to restrict
|
||||
@@ -123,6 +121,7 @@ mod voting_rule;
|
||||
|
||||
pub use authorities::{AuthoritySet, AuthoritySetChanges, SharedAuthoritySet};
|
||||
pub use aux_schema::best_justification;
|
||||
pub use finality_grandpa::voter::report;
|
||||
pub use finality_proof::{FinalityProof, FinalityProofError, FinalityProofProvider};
|
||||
pub use import::{find_forced_change, find_scheduled_change, GrandpaBlockImport};
|
||||
pub use justification::GrandpaJustification;
|
||||
@@ -132,13 +131,12 @@ pub use voting_rule::{
|
||||
BeforeBestBlockBy, ThreeQuartersOfTheUnfinalizedChain, VotingRule, VotingRuleResult,
|
||||
VotingRulesBuilder,
|
||||
};
|
||||
pub use finality_grandpa::voter::report;
|
||||
|
||||
use aux_schema::PersistentData;
|
||||
use communication::{Network as NetworkT, NetworkBridge};
|
||||
use environment::{Environment, VoterSetState};
|
||||
use until_imported::UntilGlobalMessageBlocksImported;
|
||||
use sp_finality_grandpa::{AuthorityList, AuthoritySignature, SetId};
|
||||
use until_imported::UntilGlobalMessageBlocksImported;
|
||||
|
||||
// Re-export these two because it's just so damn convenient.
|
||||
pub use sp_finality_grandpa::{AuthorityId, AuthorityPair, GrandpaApi, ScheduledChange};
|
||||
@@ -159,7 +157,8 @@ pub type SignedMessage<Block> = finality_grandpa::SignedMessage<
|
||||
>;
|
||||
|
||||
/// A primary propose message for this chain's block type.
|
||||
pub type PrimaryPropose<Block> = finality_grandpa::PrimaryPropose<<Block as BlockT>::Hash, NumberFor<Block>>;
|
||||
pub type PrimaryPropose<Block> =
|
||||
finality_grandpa::PrimaryPropose<<Block as BlockT>::Hash, NumberFor<Block>>;
|
||||
/// A prevote message for this chain's block type.
|
||||
pub type Prevote<Block> = finality_grandpa::Prevote<<Block as BlockT>::Hash, NumberFor<Block>>;
|
||||
/// A precommit message for this chain's block type.
|
||||
@@ -198,22 +197,14 @@ type CommunicationIn<Block> = finality_grandpa::voter::CommunicationIn<
|
||||
/// Global communication input stream for commits and catch up messages, with
|
||||
/// the hash type not being derived from the block, useful for forcing the hash
|
||||
/// to some type (e.g. `H256`) when the compiler can't do the inference.
|
||||
type CommunicationInH<Block, H> = finality_grandpa::voter::CommunicationIn<
|
||||
H,
|
||||
NumberFor<Block>,
|
||||
AuthoritySignature,
|
||||
AuthorityId,
|
||||
>;
|
||||
type CommunicationInH<Block, H> =
|
||||
finality_grandpa::voter::CommunicationIn<H, NumberFor<Block>, AuthoritySignature, AuthorityId>;
|
||||
|
||||
/// Global communication sink for commits with the hash type not being derived
|
||||
/// from the block, useful for forcing the hash to some type (e.g. `H256`) when
|
||||
/// the compiler can't do the inference.
|
||||
type CommunicationOutH<Block, H> = finality_grandpa::voter::CommunicationOut<
|
||||
H,
|
||||
NumberFor<Block>,
|
||||
AuthoritySignature,
|
||||
AuthorityId,
|
||||
>;
|
||||
type CommunicationOutH<Block, H> =
|
||||
finality_grandpa::voter::CommunicationOut<H, NumberFor<Block>, AuthoritySignature, AuthorityId>;
|
||||
|
||||
/// Shared voter state for querying.
|
||||
pub struct SharedVoterState {
|
||||
@@ -223,18 +214,14 @@ pub struct SharedVoterState {
|
||||
impl SharedVoterState {
|
||||
/// Create a new empty `SharedVoterState` instance.
|
||||
pub fn empty() -> Self {
|
||||
Self {
|
||||
inner: Arc::new(RwLock::new(None)),
|
||||
}
|
||||
Self { inner: Arc::new(RwLock::new(None)) }
|
||||
}
|
||||
|
||||
fn reset(
|
||||
&self,
|
||||
voter_state: Box<dyn voter::VoterState<AuthorityId> + Sync + Send>,
|
||||
) -> Option<()> {
|
||||
let mut shared_voter_state = self
|
||||
.inner
|
||||
.try_write_for(Duration::from_secs(1))?;
|
||||
let mut shared_voter_state = self.inner.try_write_for(Duration::from_secs(1))?;
|
||||
|
||||
*shared_voter_state = Some(voter_state);
|
||||
Some(())
|
||||
@@ -323,7 +310,8 @@ pub(crate) trait BlockStatus<Block: BlockT> {
|
||||
fn block_number(&self, hash: Block::Hash) -> Result<Option<NumberFor<Block>>, Error>;
|
||||
}
|
||||
|
||||
impl<Block: BlockT, Client> BlockStatus<Block> for Arc<Client> where
|
||||
impl<Block: BlockT, Client> BlockStatus<Block> for Arc<Client>
|
||||
where
|
||||
Client: HeaderBackend<Block>,
|
||||
NumberFor<Block>: BlockNumberOps,
|
||||
{
|
||||
@@ -337,24 +325,36 @@ impl<Block: BlockT, Client> BlockStatus<Block> for Arc<Client> where
|
||||
/// Ideally this would be a trait alias, we're not there yet.
|
||||
/// tracking issue <https://github.com/rust-lang/rust/issues/41517>
|
||||
pub trait ClientForGrandpa<Block, BE>:
|
||||
LockImportRun<Block, BE> + Finalizer<Block, BE> + AuxStore
|
||||
+ HeaderMetadata<Block, Error = sp_blockchain::Error> + HeaderBackend<Block>
|
||||
+ BlockchainEvents<Block> + ProvideRuntimeApi<Block> + ExecutorProvider<Block>
|
||||
LockImportRun<Block, BE>
|
||||
+ Finalizer<Block, BE>
|
||||
+ AuxStore
|
||||
+ HeaderMetadata<Block, Error = sp_blockchain::Error>
|
||||
+ HeaderBackend<Block>
|
||||
+ BlockchainEvents<Block>
|
||||
+ ProvideRuntimeApi<Block>
|
||||
+ ExecutorProvider<Block>
|
||||
+ BlockImport<Block, Transaction = TransactionFor<BE, Block>, Error = sp_consensus::Error>
|
||||
where
|
||||
BE: Backend<Block>,
|
||||
Block: BlockT,
|
||||
{}
|
||||
where
|
||||
BE: Backend<Block>,
|
||||
Block: BlockT,
|
||||
{
|
||||
}
|
||||
|
||||
impl<Block, BE, T> ClientForGrandpa<Block, BE> for T
|
||||
where
|
||||
BE: Backend<Block>,
|
||||
Block: BlockT,
|
||||
T: LockImportRun<Block, BE> + Finalizer<Block, BE> + AuxStore
|
||||
+ HeaderMetadata<Block, Error = sp_blockchain::Error> + HeaderBackend<Block>
|
||||
+ BlockchainEvents<Block> + ProvideRuntimeApi<Block> + ExecutorProvider<Block>
|
||||
+ BlockImport<Block, Transaction = TransactionFor<BE, Block>, Error = sp_consensus::Error>,
|
||||
{}
|
||||
where
|
||||
BE: Backend<Block>,
|
||||
Block: BlockT,
|
||||
T: LockImportRun<Block, BE>
|
||||
+ Finalizer<Block, BE>
|
||||
+ AuxStore
|
||||
+ HeaderMetadata<Block, Error = sp_blockchain::Error>
|
||||
+ HeaderBackend<Block>
|
||||
+ BlockchainEvents<Block>
|
||||
+ ProvideRuntimeApi<Block>
|
||||
+ ExecutorProvider<Block>
|
||||
+ BlockImport<Block, Transaction = TransactionFor<BE, Block>, Error = sp_consensus::Error>,
|
||||
{
|
||||
}
|
||||
|
||||
/// Something that one can ask to do a block sync request.
|
||||
pub(crate) trait BlockSyncRequester<Block: BlockT> {
|
||||
@@ -364,14 +364,25 @@ pub(crate) trait BlockSyncRequester<Block: BlockT> {
|
||||
/// If the given vector of peers is empty then the underlying implementation
|
||||
/// should make a best effort to fetch the block from any peers it is
|
||||
/// connected to (NOTE: this assumption will change in the future #3629).
|
||||
fn set_sync_fork_request(&self, peers: Vec<sc_network::PeerId>, hash: Block::Hash, number: NumberFor<Block>);
|
||||
fn set_sync_fork_request(
|
||||
&self,
|
||||
peers: Vec<sc_network::PeerId>,
|
||||
hash: Block::Hash,
|
||||
number: NumberFor<Block>,
|
||||
);
|
||||
}
|
||||
|
||||
impl<Block, Network> BlockSyncRequester<Block> for NetworkBridge<Block, Network> where
|
||||
impl<Block, Network> BlockSyncRequester<Block> for NetworkBridge<Block, Network>
|
||||
where
|
||||
Block: BlockT,
|
||||
Network: NetworkT<Block>,
|
||||
{
|
||||
fn set_sync_fork_request(&self, peers: Vec<sc_network::PeerId>, hash: Block::Hash, number: NumberFor<Block>) {
|
||||
fn set_sync_fork_request(
|
||||
&self,
|
||||
peers: Vec<sc_network::PeerId>,
|
||||
hash: Block::Hash,
|
||||
number: NumberFor<Block>,
|
||||
) {
|
||||
NetworkBridge::set_sync_fork_request(self, peers, hash, number)
|
||||
}
|
||||
}
|
||||
@@ -391,7 +402,7 @@ pub(crate) enum VoterCommand<H, N> {
|
||||
/// Pause the voter for given reason.
|
||||
Pause(String),
|
||||
/// New authorities.
|
||||
ChangeAuthorities(NewAuthoritySet<H, N>)
|
||||
ChangeAuthorities(NewAuthoritySet<H, N>),
|
||||
}
|
||||
|
||||
impl<H, N> fmt::Display for VoterCommand<H, N> {
|
||||
@@ -436,7 +447,7 @@ impl<H, N> From<VoterCommand<H, N>> for CommandOrError<H, N> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<H: fmt::Debug, N: fmt::Debug> ::std::error::Error for CommandOrError<H, N> { }
|
||||
impl<H: fmt::Debug, N: fmt::Debug> ::std::error::Error for CommandOrError<H, N> {}
|
||||
|
||||
impl<H, N> fmt::Display for CommandOrError<H, N> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
@@ -476,8 +487,10 @@ pub trait GenesisAuthoritySetProvider<Block: BlockT> {
|
||||
fn get(&self) -> Result<AuthorityList, ClientError>;
|
||||
}
|
||||
|
||||
impl<Block: BlockT, E> GenesisAuthoritySetProvider<Block> for Arc<dyn ExecutorProvider<Block, Executor = E>>
|
||||
where E: CallExecutor<Block>,
|
||||
impl<Block: BlockT, E> GenesisAuthoritySetProvider<Block>
|
||||
for Arc<dyn ExecutorProvider<Block, Executor = E>>
|
||||
where
|
||||
E: CallExecutor<Block>,
|
||||
{
|
||||
fn get(&self) -> Result<AuthorityList, ClientError> {
|
||||
// This implementation uses the Grandpa runtime API instead of reading directly from the
|
||||
@@ -492,10 +505,12 @@ impl<Block: BlockT, E> GenesisAuthoritySetProvider<Block> for Arc<dyn ExecutorPr
|
||||
None,
|
||||
)
|
||||
.and_then(|call_result| {
|
||||
Decode::decode(&mut &call_result[..])
|
||||
.map_err(|err| ClientError::CallResultDecode(
|
||||
"failed to decode GRANDPA authorities set proof", err
|
||||
))
|
||||
Decode::decode(&mut &call_result[..]).map_err(|err| {
|
||||
ClientError::CallResultDecode(
|
||||
"failed to decode GRANDPA authorities set proof",
|
||||
err,
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -507,13 +522,7 @@ pub fn block_import<BE, Block: BlockT, Client, SC>(
|
||||
genesis_authorities_provider: &dyn GenesisAuthoritySetProvider<Block>,
|
||||
select_chain: SC,
|
||||
telemetry: Option<TelemetryHandle>,
|
||||
) -> Result<
|
||||
(
|
||||
GrandpaBlockImport<BE, Block, Client, SC>,
|
||||
LinkHalf<Block, Client, SC>,
|
||||
),
|
||||
ClientError,
|
||||
>
|
||||
) -> Result<(GrandpaBlockImport<BE, Block, Client, SC>, LinkHalf<Block, Client, SC>), ClientError>
|
||||
where
|
||||
SC: SelectChain<Block>,
|
||||
BE: Backend<Block> + 'static,
|
||||
@@ -539,13 +548,7 @@ pub fn block_import_with_authority_set_hard_forks<BE, Block: BlockT, Client, SC>
|
||||
select_chain: SC,
|
||||
authority_set_hard_forks: Vec<(SetId, (Block::Hash, NumberFor<Block>), AuthorityList)>,
|
||||
telemetry: Option<TelemetryHandle>,
|
||||
) -> Result<
|
||||
(
|
||||
GrandpaBlockImport<BE, Block, Client, SC>,
|
||||
LinkHalf<Block, Client, SC>,
|
||||
),
|
||||
ClientError,
|
||||
>
|
||||
) -> Result<(GrandpaBlockImport<BE, Block, Client, SC>, LinkHalf<Block, Client, SC>), ClientError>
|
||||
where
|
||||
SC: SelectChain<Block>,
|
||||
BE: Backend<Block> + 'static,
|
||||
@@ -554,11 +557,8 @@ where
|
||||
let chain_info = client.info();
|
||||
let genesis_hash = chain_info.genesis_hash;
|
||||
|
||||
let persistent_data = aux_schema::load_persistent(
|
||||
&*client,
|
||||
genesis_hash,
|
||||
<NumberFor<Block>>::zero(),
|
||||
{
|
||||
let persistent_data =
|
||||
aux_schema::load_persistent(&*client, genesis_hash, <NumberFor<Block>>::zero(), {
|
||||
let telemetry = telemetry.clone();
|
||||
move || {
|
||||
let authorities = genesis_authorities_provider.get()?;
|
||||
@@ -570,13 +570,11 @@ where
|
||||
);
|
||||
Ok(authorities)
|
||||
}
|
||||
},
|
||||
)?;
|
||||
})?;
|
||||
|
||||
let (voter_commands_tx, voter_commands_rx) = tracing_unbounded("mpsc_grandpa_voter_command");
|
||||
|
||||
let (justification_sender, justification_stream) =
|
||||
GrandpaJustificationStream::channel();
|
||||
let (justification_sender, justification_stream) = GrandpaJustificationStream::channel();
|
||||
|
||||
// create pending change objects with 0 delay and enacted on finality
|
||||
// (i.e. standard changes) for each authority set hard fork.
|
||||
@@ -646,11 +644,8 @@ where
|
||||
let is_voter = local_authority_id(voters, keystore).is_some();
|
||||
|
||||
// verification stream
|
||||
let (global_in, global_out) = network.global_communication(
|
||||
communication::SetId(set_id),
|
||||
voters.clone(),
|
||||
is_voter,
|
||||
);
|
||||
let (global_in, global_out) =
|
||||
network.global_communication(communication::SetId(set_id), voters.clone(), is_voter);
|
||||
|
||||
// block commit and catch up messages until relevant blocks are imported.
|
||||
let global_in = UntilGlobalMessageBlocksImported::new(
|
||||
@@ -758,23 +753,18 @@ where
|
||||
);
|
||||
|
||||
let conf = config.clone();
|
||||
let telemetry_task = if let Some(telemetry_on_connect) = telemetry
|
||||
.as_ref()
|
||||
.map(|x| x.on_connect_stream())
|
||||
{
|
||||
let authorities = persistent_data.authority_set.clone();
|
||||
let telemetry = telemetry.clone();
|
||||
let events = telemetry_on_connect
|
||||
.for_each(move |_| {
|
||||
let telemetry_task =
|
||||
if let Some(telemetry_on_connect) = telemetry.as_ref().map(|x| x.on_connect_stream()) {
|
||||
let authorities = persistent_data.authority_set.clone();
|
||||
let telemetry = telemetry.clone();
|
||||
let events = telemetry_on_connect.for_each(move |_| {
|
||||
let current_authorities = authorities.current_authorities();
|
||||
let set_id = authorities.set_id();
|
||||
let authority_id = local_authority_id(¤t_authorities, conf.keystore.as_ref())
|
||||
.unwrap_or_default();
|
||||
|
||||
let authorities = current_authorities
|
||||
.iter()
|
||||
.map(|(id, _)| id.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
let authorities =
|
||||
current_authorities.iter().map(|(id, _)| id.to_string()).collect::<Vec<_>>();
|
||||
|
||||
let authorities = serde_json::to_string(&authorities).expect(
|
||||
"authorities is always at least an empty vector; \
|
||||
@@ -792,10 +782,10 @@ where
|
||||
|
||||
future::ready(())
|
||||
});
|
||||
future::Either::Left(events)
|
||||
} else {
|
||||
future::Either::Right(future::pending())
|
||||
};
|
||||
future::Either::Left(events)
|
||||
} else {
|
||||
future::Either::Right(future::pending())
|
||||
};
|
||||
|
||||
let voter_work = VoterWork::new(
|
||||
client,
|
||||
@@ -819,8 +809,7 @@ where
|
||||
});
|
||||
|
||||
// Make sure that `telemetry_task` doesn't accidentally finish and kill grandpa.
|
||||
let telemetry_task = telemetry_task
|
||||
.then(|_| future::pending::<()>());
|
||||
let telemetry_task = telemetry_task.then(|_| future::pending::<()>());
|
||||
|
||||
Ok(future::select(voter_work, telemetry_task).map(drop))
|
||||
}
|
||||
@@ -842,7 +831,9 @@ impl Metrics {
|
||||
/// Future that powers the voter.
|
||||
#[must_use]
|
||||
struct VoterWork<B, Block: BlockT, C, N: NetworkT<Block>, SC, VR> {
|
||||
voter: Pin<Box<dyn Future<Output = Result<(), CommandOrError<Block::Hash, NumberFor<Block>>>> + Send>>,
|
||||
voter: Pin<
|
||||
Box<dyn Future<Output = Result<(), CommandOrError<Block::Hash, NumberFor<Block>>>> + Send>,
|
||||
>,
|
||||
shared_voter_state: SharedVoterState,
|
||||
env: Arc<Environment<B, Block, C, N, SC, VR>>,
|
||||
voter_commands_rx: TracingUnboundedReceiver<VoterCommand<Block::Hash, NumberFor<Block>>>,
|
||||
@@ -881,7 +872,7 @@ where
|
||||
Some(Err(e)) => {
|
||||
debug!(target: "afg", "Failed to register metrics: {:?}", e);
|
||||
None
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
|
||||
@@ -937,12 +928,7 @@ where
|
||||
|
||||
let chain_info = self.env.client.info();
|
||||
|
||||
let authorities = self
|
||||
.env
|
||||
.voters
|
||||
.iter()
|
||||
.map(|(id, _)| id.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
let authorities = self.env.voters.iter().map(|(id, _)| id.to_string()).collect::<Vec<_>>();
|
||||
|
||||
let authorities = serde_json::to_string(&authorities).expect(
|
||||
"authorities is always at least an empty vector; elements are always of type string; qed.",
|
||||
@@ -961,10 +947,7 @@ where
|
||||
|
||||
match &*self.env.voter_set_state.read() {
|
||||
VoterSetState::Live { completed_rounds, .. } => {
|
||||
let last_finalized = (
|
||||
chain_info.finalized_hash,
|
||||
chain_info.finalized_number,
|
||||
);
|
||||
let last_finalized = (chain_info.finalized_hash, chain_info.finalized_number);
|
||||
|
||||
let global_comms = global_communication(
|
||||
self.env.set_id,
|
||||
@@ -997,20 +980,18 @@ where
|
||||
|
||||
self.voter = Box::pin(voter);
|
||||
},
|
||||
VoterSetState::Paused { .. } =>
|
||||
self.voter = Box::pin(future::pending()),
|
||||
VoterSetState::Paused { .. } => self.voter = Box::pin(future::pending()),
|
||||
};
|
||||
}
|
||||
|
||||
fn handle_voter_command(
|
||||
&mut self,
|
||||
command: VoterCommand<Block::Hash, NumberFor<Block>>
|
||||
command: VoterCommand<Block::Hash, NumberFor<Block>>,
|
||||
) -> Result<(), Error> {
|
||||
match command {
|
||||
VoterCommand::ChangeAuthorities(new) => {
|
||||
let voters: Vec<String> = new.authorities.iter().map(move |(a, _)| {
|
||||
format!("{}", a)
|
||||
}).collect();
|
||||
let voters: Vec<String> =
|
||||
new.authorities.iter().map(move |(a, _)| format!("{}", a)).collect();
|
||||
telemetry!(
|
||||
self.telemetry;
|
||||
CONSENSUS_INFO;
|
||||
@@ -1034,14 +1015,12 @@ where
|
||||
Ok(Some(set_state))
|
||||
})?;
|
||||
|
||||
let voters = Arc::new(VoterSet::new(new.authorities.into_iter())
|
||||
.expect(
|
||||
"new authorities come from pending change; \
|
||||
let voters = Arc::new(VoterSet::new(new.authorities.into_iter()).expect(
|
||||
"new authorities come from pending change; \
|
||||
pending change comes from `AuthoritySet`; \
|
||||
`AuthoritySet` validates authorities is non-empty and weights are non-zero; \
|
||||
qed."
|
||||
)
|
||||
);
|
||||
qed.",
|
||||
));
|
||||
|
||||
self.env = Arc::new(Environment {
|
||||
voters,
|
||||
@@ -1061,7 +1040,7 @@ where
|
||||
|
||||
self.rebuild_voter();
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
VoterCommand::Pause(reason) => {
|
||||
info!(target: "afg", "Pausing old validator set: {}", reason);
|
||||
|
||||
@@ -1076,7 +1055,7 @@ where
|
||||
|
||||
self.rebuild_voter();
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1096,37 +1075,35 @@ where
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
|
||||
match Future::poll(Pin::new(&mut self.voter), cx) {
|
||||
Poll::Pending => {}
|
||||
Poll::Pending => {},
|
||||
Poll::Ready(Ok(())) => {
|
||||
// voters don't conclude naturally
|
||||
return Poll::Ready(
|
||||
Err(Error::Safety("finality-grandpa inner voter has concluded.".into()))
|
||||
)
|
||||
}
|
||||
return Poll::Ready(Err(Error::Safety(
|
||||
"finality-grandpa inner voter has concluded.".into(),
|
||||
)))
|
||||
},
|
||||
Poll::Ready(Err(CommandOrError::Error(e))) => {
|
||||
// return inner observer error
|
||||
return Poll::Ready(Err(e))
|
||||
}
|
||||
},
|
||||
Poll::Ready(Err(CommandOrError::VoterCommand(command))) => {
|
||||
// some command issued internally
|
||||
self.handle_voter_command(command)?;
|
||||
cx.waker().wake_by_ref();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
match Stream::poll_next(Pin::new(&mut self.voter_commands_rx), cx) {
|
||||
Poll::Pending => {}
|
||||
Poll::Pending => {},
|
||||
Poll::Ready(None) => {
|
||||
// the `voter_commands_rx` stream should never conclude since it's never closed.
|
||||
return Poll::Ready(
|
||||
Err(Error::Safety("`voter_commands_rx` was closed.".into()))
|
||||
)
|
||||
}
|
||||
return Poll::Ready(Err(Error::Safety("`voter_commands_rx` was closed.".into())))
|
||||
},
|
||||
Poll::Ready(Some(command)) => {
|
||||
// some command issued externally
|
||||
self.handle_voter_command(command)?;
|
||||
cx.waker().wake_by_ref();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Future::poll(Pin::new(&mut self.network), cx)
|
||||
@@ -1142,10 +1119,10 @@ fn local_authority_id(
|
||||
) -> Option<AuthorityId> {
|
||||
keystore.and_then(|keystore| {
|
||||
voters
|
||||
.iter()
|
||||
.find(|(p, _)| {
|
||||
SyncCryptoStore::has_keys(&**keystore, &[(p.to_raw_vec(), AuthorityId::ID)])
|
||||
})
|
||||
.map(|(p, _)| p.clone())
|
||||
.iter()
|
||||
.find(|(p, _)| {
|
||||
SyncCryptoStore::has_keys(&**keystore, &[(p.to_raw_vec(), AuthorityId::ID)])
|
||||
})
|
||||
.map(|(p, _)| p.clone())
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user