mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 13:27:57 +00:00
cargo +nightly fmt (#3540)
* cargo +nightly fmt * add cargo-fmt check to ci * update ci * fmt * fmt * skip macro * ignore bridges
This commit is contained in:
@@ -25,13 +25,14 @@ use sp_application_crypto::AppKey;
|
||||
use sp_core::crypto::Public;
|
||||
use sp_keystore::{CryptoStore, SyncCryptoStorePtr};
|
||||
|
||||
use polkadot_primitives::v1::{CoreState, EncodeAs, GroupIndex, GroupRotationInfo, Hash, OccupiedCore, SessionIndex, SessionInfo, Signed, SigningContext, UncheckedSigned, ValidatorId, ValidatorIndex};
|
||||
use polkadot_node_subsystem::{SubsystemSender, SubsystemContext};
|
||||
|
||||
use polkadot_node_subsystem::{SubsystemContext, SubsystemSender};
|
||||
use polkadot_primitives::v1::{
|
||||
CoreState, EncodeAs, GroupIndex, GroupRotationInfo, Hash, OccupiedCore, SessionIndex,
|
||||
SessionInfo, Signed, SigningContext, UncheckedSigned, ValidatorId, ValidatorIndex,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
request_session_index_for_child, request_session_info,
|
||||
request_availability_cores,
|
||||
request_availability_cores, request_session_index_for_child, request_session_info,
|
||||
request_validator_groups,
|
||||
};
|
||||
|
||||
@@ -39,7 +40,7 @@ use crate::{
|
||||
mod error;
|
||||
|
||||
use error::{recv_runtime, Result};
|
||||
pub use error::{Error, NonFatal, Fatal};
|
||||
pub use error::{Error, Fatal, NonFatal};
|
||||
|
||||
/// Configuration for construction a `RuntimeInfo`.
|
||||
pub struct Config {
|
||||
@@ -100,10 +101,7 @@ impl Default for Config {
|
||||
impl RuntimeInfo {
|
||||
/// Create a new `RuntimeInfo` for convenient runtime fetches.
|
||||
pub fn new(keystore: Option<SyncCryptoStorePtr>) -> Self {
|
||||
Self::new_with_config(Config {
|
||||
keystore,
|
||||
..Default::default()
|
||||
})
|
||||
Self::new_with_config(Config { keystore, ..Default::default() })
|
||||
}
|
||||
|
||||
/// Create with more elaborate configuration options.
|
||||
@@ -128,11 +126,10 @@ impl RuntimeInfo {
|
||||
Some(index) => Ok(*index),
|
||||
None => {
|
||||
let index =
|
||||
recv_runtime(request_session_index_for_child(parent, sender).await)
|
||||
.await?;
|
||||
recv_runtime(request_session_index_for_child(parent, sender).await).await?;
|
||||
self.session_index_cache.put(parent, index);
|
||||
Ok(index)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,17 +167,14 @@ impl RuntimeInfo {
|
||||
.ok_or(NonFatal::NoSuchSession(session_index))?;
|
||||
let validator_info = self.get_validator_info(&session_info).await?;
|
||||
|
||||
let full_info = ExtendedSessionInfo {
|
||||
session_info,
|
||||
validator_info,
|
||||
};
|
||||
let full_info = ExtendedSessionInfo { session_info, validator_info };
|
||||
|
||||
self.session_info_cache.put(session_index, full_info);
|
||||
}
|
||||
Ok(
|
||||
self.session_info_cache.get(&session_index)
|
||||
.expect("We just put the value there. qed.")
|
||||
)
|
||||
Ok(self
|
||||
.session_info_cache
|
||||
.get(&session_index)
|
||||
.expect("We just put the value there. qed."))
|
||||
}
|
||||
|
||||
/// Convenience function for checking the signature of something signed.
|
||||
@@ -189,7 +183,9 @@ impl RuntimeInfo {
|
||||
sender: &mut Sender,
|
||||
parent: Hash,
|
||||
signed: UncheckedSigned<Payload, RealPayload>,
|
||||
) -> Result<std::result::Result<Signed<Payload, RealPayload>, UncheckedSigned<Payload, RealPayload>>>
|
||||
) -> Result<
|
||||
std::result::Result<Signed<Payload, RealPayload>, UncheckedSigned<Payload, RealPayload>>,
|
||||
>
|
||||
where
|
||||
Sender: SubsystemSender,
|
||||
Payload: EncodeAs<RealPayload> + Clone,
|
||||
@@ -204,17 +200,11 @@ impl RuntimeInfo {
|
||||
///
|
||||
///
|
||||
/// Returns: `None` if not a validator.
|
||||
async fn get_validator_info(
|
||||
&self,
|
||||
session_info: &SessionInfo,
|
||||
) -> Result<ValidatorInfo>
|
||||
{
|
||||
async fn get_validator_info(&self, session_info: &SessionInfo) -> Result<ValidatorInfo> {
|
||||
if let Some(our_index) = self.get_our_index(&session_info.validators).await {
|
||||
// Get our group index:
|
||||
let our_group = session_info.validator_groups
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find_map(|(i, g)| {
|
||||
let our_group =
|
||||
session_info.validator_groups.iter().enumerate().find_map(|(i, g)| {
|
||||
g.iter().find_map(|v| {
|
||||
if *v == our_index {
|
||||
Some(GroupIndex(i as u32))
|
||||
@@ -222,12 +212,8 @@ impl RuntimeInfo {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
let info = ValidatorInfo {
|
||||
our_index: Some(our_index),
|
||||
our_group,
|
||||
};
|
||||
});
|
||||
let info = ValidatorInfo { our_index: Some(our_index), our_group };
|
||||
return Ok(info)
|
||||
}
|
||||
return Ok(ValidatorInfo { our_index: None, our_group: None })
|
||||
@@ -239,10 +225,8 @@ impl RuntimeInfo {
|
||||
async fn get_our_index(&self, validators: &[ValidatorId]) -> Option<ValidatorIndex> {
|
||||
let keystore = self.keystore.as_ref()?;
|
||||
for (i, v) in validators.iter().enumerate() {
|
||||
if CryptoStore::has_keys(&**keystore, &[(v.to_raw_vec(), ValidatorId::ID)])
|
||||
.await
|
||||
{
|
||||
return Some(ValidatorIndex(i as u32));
|
||||
if CryptoStore::has_keys(&**keystore, &[(v.to_raw_vec(), ValidatorId::ID)]).await {
|
||||
return Some(ValidatorIndex(i as u32))
|
||||
}
|
||||
}
|
||||
None
|
||||
@@ -260,22 +244,22 @@ where
|
||||
Payload: EncodeAs<RealPayload> + Clone,
|
||||
RealPayload: Encode + Clone,
|
||||
{
|
||||
let signing_context = SigningContext {
|
||||
session_index,
|
||||
parent_hash: relay_parent,
|
||||
};
|
||||
let signing_context = SigningContext { session_index, parent_hash: relay_parent };
|
||||
|
||||
session_info.validators
|
||||
session_info
|
||||
.validators
|
||||
.get(signed.unchecked_validator_index().0 as usize)
|
||||
.ok_or_else(|| signed.clone())
|
||||
.and_then(|v| signed.try_into_checked(&signing_context, v))
|
||||
}
|
||||
|
||||
/// Request availability cores from the runtime.
|
||||
pub async fn get_availability_cores<Context>(ctx: &mut Context, relay_parent: Hash)
|
||||
-> Result<Vec<CoreState>>
|
||||
where
|
||||
Context: SubsystemContext,
|
||||
pub async fn get_availability_cores<Context>(
|
||||
ctx: &mut Context,
|
||||
relay_parent: Hash,
|
||||
) -> Result<Vec<CoreState>>
|
||||
where
|
||||
Context: SubsystemContext,
|
||||
{
|
||||
recv_runtime(request_availability_cores(relay_parent, ctx.sender()).await).await
|
||||
}
|
||||
@@ -299,18 +283,20 @@ where
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
)
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Get group rotation info based on the given `relay_parent`.
|
||||
pub async fn get_group_rotation_info<Context>(ctx: &mut Context, relay_parent: Hash)
|
||||
-> Result<GroupRotationInfo>
|
||||
pub async fn get_group_rotation_info<Context>(
|
||||
ctx: &mut Context,
|
||||
relay_parent: Hash,
|
||||
) -> Result<GroupRotationInfo>
|
||||
where
|
||||
Context: SubsystemContext,
|
||||
{
|
||||
// We drop `groups` here as we don't need them, because of `RuntimeInfo`. Ideally we would not
|
||||
// fetch them in the first place.
|
||||
let (_, info) = recv_runtime(request_validator_groups(relay_parent, ctx.sender()).await).await?;
|
||||
let (_, info) =
|
||||
recv_runtime(request_validator_groups(relay_parent, ctx.sender()).await).await?;
|
||||
Ok(info)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user