Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename from state to status
  • Loading branch information
maciejnems committed Dec 30, 2022
commit ccfd30abf1646c1f5fe86c385f824a8c123f9e6a
24 changes: 12 additions & 12 deletions finality-aleph/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ pub trait Finalizer<J: Justification> {
fn finalize(&self, justification: J) -> Result<(), Self::Error>;
}

/// A notification about the chain state changing.
pub enum ChainStateNotification<BI: BlockIdentifier> {
/// A notification about the chain status changing.
pub enum ChainStatusNotification<BI: BlockIdentifier> {
/// A block has been imported.
BlockImported(BI),
/// A block has been finalized.
BlockFinalized(BI),
}

/// A stream of notifications about the chain state in the database changing.
/// A stream of notifications about the chain status in the database changing.
#[async_trait::async_trait]
pub trait ChainStateNotifier<BI: BlockIdentifier> {
pub trait ChainStatusNotifier<BI: BlockIdentifier> {
type Error: Display;

/// Returns a chain state notification when it is available.
async fn next(&mut self) -> Result<ChainStateNotification<BI>, Self::Error>;
/// Returns a chain status notification when it is available.
async fn next(&mut self) -> Result<ChainStatusNotification<BI>, Self::Error>;
}

/// The state of a block in the database.
pub enum BlockState<J: Justification> {
/// The status of a block in the database.
pub enum BlockStatus<J: Justification> {
/// The block is justified and thus finalized.
Justified(J),
/// The block is present, might be finalized if a descendant is justified.
Expand All @@ -88,10 +88,10 @@ pub enum BlockState<J: Justification> {
Unknown,
}

/// The knowledge about the chain state.
pub trait ChainState<J: Justification> {
/// The state of the block.
fn state_of(&self, id: <J::Header as Header>::Identifier) -> BlockState<J>;
/// The knowledge about the chain status.
pub trait ChainStatus<J: Justification> {
/// The status of the block.
fn status_of(&self, id: <J::Header as Header>::Identifier) -> BlockStatus<J>;

/// The header of the best block.
fn best_block(&self) -> J::Header;
Expand Down
2 changes: 1 addition & 1 deletion finality-aleph/src/sync/substrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sp_runtime::traits::{CheckedSub, Header as SubstrateHeader, One};

use crate::sync::{BlockIdentifier, Header};

mod state_notifier;
mod status_notifier;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BlockId<H: SubstrateHeader<Number = BlockNumber>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use sc_client_api::client::{FinalityNotifications, ImportNotifications};
use sp_runtime::traits::{Block as BlockT, Header as SubstrateHeader};
use tokio::select;

use crate::sync::{substrate::BlockId, ChainStateNotification, ChainStateNotifier, Header};
use crate::sync::{substrate::BlockId, ChainStatusNotification, ChainStatusNotifier, Header};

/// What can go wrong when waiting for next chain state notification.
/// What can go wrong when waiting for next chain status notification.
#[derive(Debug)]
pub enum Error {
JustificationStream,
Expand All @@ -29,8 +29,8 @@ impl Display for Error {
}
}

/// Substrate specific implementation of `ChainStateNotifier`.
pub struct SubstrateChainStateNotifier<H, B>
/// Substrate specific implementation of `ChainStatusNotifier`.
pub struct SubstrateChainStatusNotifier<H, B>
where
H: SubstrateHeader<Number = BlockNumber>,
B: BlockT<Header = H>,
Expand All @@ -39,7 +39,7 @@ where
import_notifications: ImportNotifications<B>,
}

impl<H, B> SubstrateChainStateNotifier<H, B>
impl<H, B> SubstrateChainStatusNotifier<H, B>
where
H: SubstrateHeader<Number = BlockNumber>,
B: BlockT<Header = H>,
Expand All @@ -56,24 +56,24 @@ where
}

#[async_trait::async_trait]
impl<H, B> ChainStateNotifier<BlockId<H>> for SubstrateChainStateNotifier<H, B>
impl<H, B> ChainStatusNotifier<BlockId<H>> for SubstrateChainStatusNotifier<H, B>
where
H: SubstrateHeader<Number = BlockNumber>,
B: BlockT<Header = H>,
{
type Error = Error;

/// Returns next chain state notification.
async fn next(&mut self) -> Result<ChainStateNotification<BlockId<H>>, Self::Error> {
/// Returns next chain status notification.
async fn next(&mut self) -> Result<ChainStatusNotification<BlockId<H>>, Self::Error> {
select! {
maybe_block = self.finality_notifications.next() => {
maybe_block
.map(|block| ChainStateNotification::BlockFinalized(block.header.id()))
.map(|block| ChainStatusNotification::BlockFinalized(block.header.id()))
.ok_or(Error::JustificationStream)
},
maybe_block = self.import_notifications.next() => {
maybe_block
.map(|block| ChainStateNotification::BlockImported(block.header.id()))
.map(|block| ChainStatusNotification::BlockImported(block.header.id()))
.ok_or(Error::ImportStream)
}
}
Expand Down