pub struct Consensus<N: Network> { /* private fields */ }Expand description
Wrapper around BFT that adds additional functionality, such as a mempool.
Consensus acts as a rate limiter to prevents workers in BFT from being overloaded. Each worker maintains a ready queue (which is essentially also a mempool), but verifies transactions/solutions before enqueuing them. Consensus only passes more transactions/solutions to the BFT layer if its ready queues are not already full.
Implementations§
Source§impl<N: Network> Consensus<N>
impl<N: Network> Consensus<N>
Sourcepub async fn new(
account: Account<N>,
ledger: Arc<dyn LedgerService<N>>,
block_sync: Arc<BlockSync<N>>,
ip: Option<SocketAddr>,
trusted_validators: &[SocketAddr],
trusted_peers_only: bool,
storage_mode: StorageMode,
node_data_dir: NodeDataDir,
ping: Arc<Ping<N>>,
dev: Option<u16>,
) -> Result<Self>
pub async fn new( account: Account<N>, ledger: Arc<dyn LedgerService<N>>, block_sync: Arc<BlockSync<N>>, ip: Option<SocketAddr>, trusted_validators: &[SocketAddr], trusted_peers_only: bool, storage_mode: StorageMode, node_data_dir: NodeDataDir, ping: Arc<Ping<N>>, dev: Option<u16>, ) -> Result<Self>
Initializes a new instance of consensus.
pub fn contains_transaction(&self, transaction_id: &N::TransactionID) -> bool
Source§impl<N: Network> Consensus<N>
impl<N: Network> Consensus<N>
Sourcepub fn num_unconfirmed_transmissions(&self) -> usize
pub fn num_unconfirmed_transmissions(&self) -> usize
Returns the number of unconfirmed transmissions in the BFT’s workers (not in the mempool).
Sourcepub fn num_unconfirmed_ratifications(&self) -> usize
pub fn num_unconfirmed_ratifications(&self) -> usize
Returns the number of unconfirmed ratifications in the BFT’s workers (not in the mempool).
Sourcepub fn num_unconfirmed_solutions(&self) -> usize
pub fn num_unconfirmed_solutions(&self) -> usize
Returns the number unconfirmed solutions in the BFT’s workers (not in the mempool).
Sourcepub fn num_unconfirmed_transactions(&self) -> usize
pub fn num_unconfirmed_transactions(&self) -> usize
Returns the number of unconfirmed transactions.
Source§impl<N: Network> Consensus<N>
impl<N: Network> Consensus<N>
Sourcepub fn unconfirmed_transmission_ids(
&self,
) -> impl '_ + Iterator<Item = TransmissionID<N>>
pub fn unconfirmed_transmission_ids( &self, ) -> impl '_ + Iterator<Item = TransmissionID<N>>
Returns the unconfirmed transmission IDs.
Sourcepub fn unconfirmed_transmissions(
&self,
) -> impl '_ + Iterator<Item = (TransmissionID<N>, Transmission<N>)>
pub fn unconfirmed_transmissions( &self, ) -> impl '_ + Iterator<Item = (TransmissionID<N>, Transmission<N>)>
Returns the unconfirmed transmissions.
Sourcepub fn unconfirmed_solutions(
&self,
) -> impl '_ + Iterator<Item = (SolutionID<N>, Data<Solution<N>>)>
pub fn unconfirmed_solutions( &self, ) -> impl '_ + Iterator<Item = (SolutionID<N>, Data<Solution<N>>)>
Returns the unconfirmed solutions.
Sourcepub fn unconfirmed_transactions(
&self,
) -> impl '_ + Iterator<Item = (N::TransactionID, Data<Transaction<N>>)>
pub fn unconfirmed_transactions( &self, ) -> impl '_ + Iterator<Item = (N::TransactionID, Data<Transaction<N>>)>
Returns the unconfirmed transactions.
Source§impl<N: Network> Consensus<N>
impl<N: Network> Consensus<N>
Sourcepub fn worker_transmission_ids(
&self,
) -> impl '_ + Iterator<Item = TransmissionID<N>>
pub fn worker_transmission_ids( &self, ) -> impl '_ + Iterator<Item = TransmissionID<N>>
Returns the worker transmission IDs.
Sourcepub fn worker_transmissions(
&self,
) -> impl '_ + Iterator<Item = (TransmissionID<N>, Transmission<N>)>
pub fn worker_transmissions( &self, ) -> impl '_ + Iterator<Item = (TransmissionID<N>, Transmission<N>)>
Returns the worker transmissions.
Sourcepub fn worker_solutions(
&self,
) -> impl '_ + Iterator<Item = (SolutionID<N>, Data<Solution<N>>)>
pub fn worker_solutions( &self, ) -> impl '_ + Iterator<Item = (SolutionID<N>, Data<Solution<N>>)>
Returns the worker solutions.
Sourcepub fn worker_transactions(
&self,
) -> impl '_ + Iterator<Item = (N::TransactionID, Data<Transaction<N>>)>
pub fn worker_transactions( &self, ) -> impl '_ + Iterator<Item = (N::TransactionID, Data<Transaction<N>>)>
Returns the worker transactions.
Source§impl<N: Network> Consensus<N>
impl<N: Network> Consensus<N>
Sourcepub fn inbound_transmission_ids(
&self,
) -> impl '_ + Iterator<Item = TransmissionID<N>>
pub fn inbound_transmission_ids( &self, ) -> impl '_ + Iterator<Item = TransmissionID<N>>
Returns the transmission IDs in the inbound queue.
Sourcepub fn inbound_transmissions(
&self,
) -> impl '_ + Iterator<Item = (TransmissionID<N>, Transmission<N>)>
pub fn inbound_transmissions( &self, ) -> impl '_ + Iterator<Item = (TransmissionID<N>, Transmission<N>)>
Returns the transmissions in the inbound queue.
Sourcepub fn inbound_solutions(
&self,
) -> impl '_ + Iterator<Item = (SolutionID<N>, Data<Solution<N>>)>
pub fn inbound_solutions( &self, ) -> impl '_ + Iterator<Item = (SolutionID<N>, Data<Solution<N>>)>
Returns the solutions in the inbound queue.
Sourcepub fn inbound_transactions(
&self,
) -> impl '_ + Iterator<Item = (N::TransactionID, Data<Transaction<N>>)>
pub fn inbound_transactions( &self, ) -> impl '_ + Iterator<Item = (N::TransactionID, Data<Transaction<N>>)>
Returns the transactions in the inbound queue.
Source§impl<N: Network> Consensus<N>
impl<N: Network> Consensus<N>
Sourcepub async fn add_unconfirmed_solution(
&self,
solution: Solution<N>,
) -> Result<()>
pub async fn add_unconfirmed_solution( &self, solution: Solution<N>, ) -> Result<()>
Adds the given unconfirmed solution to the memory pool, which will then eventually be passed to the BFT layer for inclusion in a batch.
Sourcepub async fn add_unconfirmed_transaction(
&self,
transaction: Transaction<N>,
) -> Result<()>
pub async fn add_unconfirmed_transaction( &self, transaction: Transaction<N>, ) -> Result<()>
Adds the given unconfirmed transaction to the memory pool, which will then eventually be passed to the BFT layer for inclusion in a batch.
Source§impl<N: Network> Consensus<N>
impl<N: Network> Consensus<N>
Sourcepub async fn start_consensus_handlers(&self) -> Result<()>
pub async fn start_consensus_handlers(&self) -> Result<()>
Starts the BFT and consensus handlers.
This consumes the deferred state stored during construction and must only be invoked once, after the node has finished syncing from the CDN, so that no blocks are committed during the initial sync.
Trait Implementations§
Auto Trait Implementations§
impl<N> !RefUnwindSafe for Consensus<N>
impl<N> !UnwindSafe for Consensus<N>
impl<N> Freeze for Consensus<N>
impl<N> Send for Consensus<N>
impl<N> Sync for Consensus<N>
impl<N> Unpin for Consensus<N>where
N: Unpin,
impl<N> UnsafeUnpin for Consensus<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more