pub struct Storage<N: Network>(/* private fields */);Implementations§
Source§impl<N: Network> Storage<N>
impl<N: Network> Storage<N>
Sourcepub fn new(
ledger: Arc<dyn LedgerService<N>>,
transmissions: Arc<dyn StorageService<N>>,
max_gc_rounds: u64,
) -> Self
pub fn new( ledger: Arc<dyn LedgerService<N>>, transmissions: Arc<dyn StorageService<N>>, max_gc_rounds: u64, ) -> Self
Initializes a new instance of storage.
Source§impl<N: Network> Storage<N>
impl<N: Network> Storage<N>
Sourcepub fn current_height(&self) -> u32
pub fn current_height(&self) -> u32
Returns the current height.
Source§impl<N: Network> Storage<N>
impl<N: Network> Storage<N>
Sourcepub fn current_round(&self) -> u64
pub fn current_round(&self) -> u64
Returns the current round.
Sourcepub fn gc_round(&self) -> u64
pub fn gc_round(&self) -> u64
Returns the round that garbage collection has occurred up to (inclusive).
Sourcepub fn max_gc_rounds(&self) -> u64
pub fn max_gc_rounds(&self) -> u64
Returns the maximum number of rounds to keep in storage.
Sourcepub fn increment_to_next_round(&self, current_round: u64) -> Result<u64>
pub fn increment_to_next_round(&self, current_round: u64) -> Result<u64>
Increments storage to the next round, updating the current round. Note: This method is only called once per round, upon certification of the primary’s batch.
Source§impl<N: Network> Storage<N>
impl<N: Network> Storage<N>
Sourcepub fn contains_certificates_for_round(&self, round: u64) -> bool
pub fn contains_certificates_for_round(&self, round: u64) -> bool
Returns true if the storage contains the specified round.
Sourcepub fn contains_certificate(&self, certificate_id: Field<N>) -> bool
pub fn contains_certificate(&self, certificate_id: Field<N>) -> bool
Returns true if the storage contains the specified certificate ID.
Sourcepub fn contains_certificate_in_round_from(
&self,
round: u64,
author: Address<N>,
) -> bool
pub fn contains_certificate_in_round_from( &self, round: u64, author: Address<N>, ) -> bool
Returns true if the storage contains a certificate from the specified author in the given round.
Sourcepub fn contains_unprocessed_certificate(&self, certificate_id: Field<N>) -> bool
pub fn contains_unprocessed_certificate(&self, certificate_id: Field<N>) -> bool
Returns true if the storage contains the specified certificate ID.
Sourcepub fn contains_batch(&self, batch_id: Field<N>) -> bool
pub fn contains_batch(&self, batch_id: Field<N>) -> bool
Returns true if the storage contains the specified batch ID.
Sourcepub fn contains_transmission(
&self,
transmission_id: impl Into<TransmissionID<N>>,
) -> bool
pub fn contains_transmission( &self, transmission_id: impl Into<TransmissionID<N>>, ) -> bool
Returns true if the storage contains the specified transmission ID.
Sourcepub fn get_transmission(
&self,
transmission_id: impl Into<TransmissionID<N>>,
) -> Option<Transmission<N>>
pub fn get_transmission( &self, transmission_id: impl Into<TransmissionID<N>>, ) -> Option<Transmission<N>>
Returns the transmission for the given transmission ID.
If the transmission ID does not exist in storage, None is returned.
Sourcepub fn get_round_for_certificate(&self, certificate_id: Field<N>) -> Option<u64>
pub fn get_round_for_certificate(&self, certificate_id: Field<N>) -> Option<u64>
Returns the round for the given certificate ID.
If the certificate ID does not exist in storage, None is returned.
Sourcepub fn get_round_for_batch(&self, batch_id: Field<N>) -> Option<u64>
pub fn get_round_for_batch(&self, batch_id: Field<N>) -> Option<u64>
Returns the round for the given batch ID.
If the batch ID does not exist in storage, None is returned.
Sourcepub fn get_certificate_round(&self, certificate_id: Field<N>) -> Option<u64>
pub fn get_certificate_round(&self, certificate_id: Field<N>) -> Option<u64>
Returns the certificate round for the given certificate ID.
If the certificate ID does not exist in storage, None is returned.
Sourcepub fn get_certificate(
&self,
certificate_id: Field<N>,
) -> Option<BatchCertificate<N>>
pub fn get_certificate( &self, certificate_id: Field<N>, ) -> Option<BatchCertificate<N>>
Returns the certificate for the given certificate ID.
If the certificate ID does not exist in storage, None is returned.
Sourcepub fn get_unprocessed_certificate(
&self,
certificate_id: Field<N>,
) -> Option<BatchCertificate<N>>
pub fn get_unprocessed_certificate( &self, certificate_id: Field<N>, ) -> Option<BatchCertificate<N>>
Returns the unprocessed certificate for the given certificate ID.
If the certificate ID does not exist in storage, None is returned.
Returns the certificate for the given round and author.
If the round does not exist in storage, None is returned.
If the author for the round does not exist in storage, None is returned.
Sourcepub fn get_certificates_for_round(
&self,
round: u64,
) -> IndexSet<BatchCertificate<N>>
pub fn get_certificates_for_round( &self, round: u64, ) -> IndexSet<BatchCertificate<N>>
Returns the certificates for the given round.
If the round does not exist in storage, an empty set is returned.
Sourcepub fn get_certificate_ids_for_round(&self, round: u64) -> IndexSet<Field<N>>
pub fn get_certificate_ids_for_round(&self, round: u64) -> IndexSet<Field<N>>
Returns the certificate IDs for the given round.
If the round does not exist in storage, an empty set is returned.
Returns the certificate authors for the given round.
If the round does not exist in storage, an empty set is returned.
Sourcepub fn check_batch_header(
&self,
batch_header: &BatchHeader<N>,
transmissions: HashMap<TransmissionID<N>, Transmission<N>>,
aborted_transmissions: HashSet<TransmissionID<N>>,
) -> Result<HashMap<TransmissionID<N>, Transmission<N>>>
pub fn check_batch_header( &self, batch_header: &BatchHeader<N>, transmissions: HashMap<TransmissionID<N>, Transmission<N>>, aborted_transmissions: HashSet<TransmissionID<N>>, ) -> Result<HashMap<TransmissionID<N>, Transmission<N>>>
Checks the given batch_header for validity, returning the missing transmissions from storage.
This method ensures the following invariants:
- The batch ID does not already exist in storage.
- The author is a member of the committee for the batch round.
- The timestamp is within the allowed time range.
- None of the transmissions are from any past rounds (up to GC).
- All transmissions declared in the batch header are provided or exist in storage (up to GC).
- All previous certificates declared in the certificate exist in storage (up to GC).
- All previous certificates are for the previous round (i.e. round - 1).
- All previous certificates contain a unique author.
- The previous certificates reached the quorum threshold (N - f).
Sourcepub fn check_incoming_certificate(
&self,
certificate: &BatchCertificate<N>,
) -> Result<()>
pub fn check_incoming_certificate( &self, certificate: &BatchCertificate<N>, ) -> Result<()>
Check the validity of a certificate coming from another validator.
It suffices to check that the signers (author and endorsers) are members of the applicable committee
and that they form a quorum in the committee.
Under the fundamental fault tolerance assumption of at most f (stake of) faulty validators,
the quorum check on signers guarantees that at least one correct validator
has ensured the validity of the proposal contained in the certificate,
either by construction (by the author) or by checking (by an endorser):
given N > 0 total stake, and f the largest integer < N/3 (where / is exact rational division),
we have N >= 3f + 1, which implies N - f >= 2f + 1, which is always > f;
N - f is the quorum stake.
Sourcepub fn check_certificate(
&self,
certificate: &BatchCertificate<N>,
transmissions: HashMap<TransmissionID<N>, Transmission<N>>,
aborted_transmissions: HashSet<TransmissionID<N>>,
) -> Result<HashMap<TransmissionID<N>, Transmission<N>>>
pub fn check_certificate( &self, certificate: &BatchCertificate<N>, transmissions: HashMap<TransmissionID<N>, Transmission<N>>, aborted_transmissions: HashSet<TransmissionID<N>>, ) -> Result<HashMap<TransmissionID<N>, Transmission<N>>>
Checks the given certificate for validity, returning the missing transmissions from storage.
This method ensures the following invariants:
- The certificate ID does not already exist in storage.
- The batch ID does not already exist in storage.
- The author is a member of the committee for the batch round.
- The author has not already created a certificate for the batch round.
- The timestamp is within the allowed time range.
- None of the transmissions are from any past rounds (up to GC).
- All transmissions declared in the batch header are provided or exist in storage (up to GC).
- All previous certificates declared in the certificate exist in storage (up to GC).
- All previous certificates are for the previous round (i.e. round - 1).
- The previous certificates reached the quorum threshold (N - f).
- The timestamps from the signers are all within the allowed time range.
- The signers have reached the quorum threshold (N - f).
Sourcepub fn insert_certificate(
&self,
certificate: BatchCertificate<N>,
transmissions: HashMap<TransmissionID<N>, Transmission<N>>,
aborted_transmissions: HashSet<TransmissionID<N>>,
) -> Result<()>
pub fn insert_certificate( &self, certificate: BatchCertificate<N>, transmissions: HashMap<TransmissionID<N>, Transmission<N>>, aborted_transmissions: HashSet<TransmissionID<N>>, ) -> Result<()>
Inserts the given certificate into storage.
This method triggers updates to the rounds, certificates, batch_ids, and transmissions maps.
This method ensures the following invariants:
- The certificate ID does not already exist in storage.
- The batch ID does not already exist in storage.
- All transmissions declared in the certificate are provided or exist in storage (up to GC).
- All previous certificates declared in the certificate exist in storage (up to GC).
- All previous certificates are for the previous round (i.e. round - 1).
- The previous certificates reached the quorum threshold (N - f).
Sourcepub fn insert_unprocessed_certificate(
&self,
certificate: BatchCertificate<N>,
) -> Result<()>
pub fn insert_unprocessed_certificate( &self, certificate: BatchCertificate<N>, ) -> Result<()>
Inserts the given unprocessed certificate into storage.
This is a temporary storage, which is cleared again when calling insert_certificate_atomic.
Trait Implementations§
Auto Trait Implementations§
impl<N> Freeze for Storage<N>
impl<N> !RefUnwindSafe for Storage<N>
impl<N> Send for Storage<N>
impl<N> Sync for Storage<N>
impl<N> Unpin for Storage<N>
impl<N> !UnwindSafe for Storage<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
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