mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 23:15:42 +00:00
Reduce provisioner work (#12749)
* Move create_inherent_data call to use side * Make provide_inherent_data async * Fix tests * Apply suggestions from code review Co-authored-by: Bastian Köcher <git@kchr.de> * Log errors * Fix test * Fix test * fix * Deduplicate test code * fix * flag * Update client/consensus/slots/src/lib.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Revert "Deduplicate test code" This reverts commit ba46adbe089329c78cd69ccdb08e27ed67bd77cf. * Fix test * remove commented out code * minor to start CI run * start CI * Update client/consensus/slots/src/lib.rs Co-authored-by: Marcin S. <marcin@bytedude.com> * Apply PR suggestions * Apply PR suggestions * Update client/consensus/slots/src/lib.rs Co-authored-by: Bastian Köcher <git@kchr.de> * minor * kickoff CI * PR suggestions * Compute remaining duration instead of using slot_info.duration * Don't rely on sub implementation for Instant * Apply PR suggestions * Use saturating_duration_since Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Marcin S. <marcin@bytedude.com> Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -83,16 +83,16 @@ pub trait InherentDataProvider: Send + Sync {
|
||||
/// Convenience function for creating [`InherentData`].
|
||||
///
|
||||
/// Basically maps around [`Self::provide_inherent_data`].
|
||||
fn create_inherent_data(&self) -> Result<InherentData, Error> {
|
||||
async fn create_inherent_data(&self) -> Result<InherentData, Error> {
|
||||
let mut inherent_data = InherentData::new();
|
||||
self.provide_inherent_data(&mut inherent_data)?;
|
||||
self.provide_inherent_data(&mut inherent_data).await?;
|
||||
Ok(inherent_data)
|
||||
}
|
||||
|
||||
/// Provide inherent data that should be included in a block.
|
||||
///
|
||||
/// The data should be stored in the given `InherentData` structure.
|
||||
fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error>;
|
||||
async fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error>;
|
||||
|
||||
/// Convert the given encoded error to a string.
|
||||
///
|
||||
@@ -108,8 +108,8 @@ pub trait InherentDataProvider: Send + Sync {
|
||||
#[async_trait::async_trait]
|
||||
impl InherentDataProvider for Tuple {
|
||||
for_tuples!( where #( Tuple: Send + Sync )* );
|
||||
fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> {
|
||||
for_tuples!( #( Tuple.provide_inherent_data(inherent_data)?; )* );
|
||||
async fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> {
|
||||
for_tuples!( #( Tuple.provide_inherent_data(inherent_data).await?; )* );
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
//!
|
||||
//! #[async_trait::async_trait]
|
||||
//! impl sp_inherents::InherentDataProvider for InherentDataProvider {
|
||||
//! fn provide_inherent_data(
|
||||
//! async fn provide_inherent_data(
|
||||
//! &self,
|
||||
//! inherent_data: &mut InherentData,
|
||||
//! ) -> Result<(), sp_inherents::Error> {
|
||||
@@ -106,7 +106,7 @@
|
||||
//! # struct InherentDataProvider;
|
||||
//! # #[async_trait::async_trait]
|
||||
//! # impl sp_inherents::InherentDataProvider for InherentDataProvider {
|
||||
//! # fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), sp_inherents::Error> {
|
||||
//! # async fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), sp_inherents::Error> {
|
||||
//! # inherent_data.put_data(INHERENT_IDENTIFIER, &"hello")
|
||||
//! # }
|
||||
//! # async fn try_handle_error(
|
||||
@@ -443,7 +443,7 @@ mod tests {
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl InherentDataProvider for TestInherentDataProvider {
|
||||
fn provide_inherent_data(&self, data: &mut InherentData) -> Result<(), Error> {
|
||||
async fn provide_inherent_data(&self, data: &mut InherentData) -> Result<(), Error> {
|
||||
data.put_data(TEST_INHERENT_0, &42)
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ mod tests {
|
||||
fn create_inherent_data() {
|
||||
let provider = TestInherentDataProvider;
|
||||
|
||||
let inherent_data = provider.create_inherent_data().unwrap();
|
||||
let inherent_data = futures::executor::block_on(provider.create_inherent_data()).unwrap();
|
||||
|
||||
assert_eq!(inherent_data.get_data::<u32>(&TEST_INHERENT_0).unwrap().unwrap(), 42u32);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user