Struct snarkos_node_bft::helpers::storage::Storage
source · 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>>, max_gc_rounds: u64) -> Self
pub fn new(ledger: Arc<dyn LedgerService<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_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.
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, None is returned.
sourcepub fn check_batch_header(
&self,
batch_header: &BatchHeader<N>,
transmissions: HashMap<TransmissionID<N>, Transmission<N>>
) -> Result<HashMap<TransmissionID<N>, Transmission<N>>>
pub fn check_batch_header( &self, batch_header: &BatchHeader<N>, transmissions: HashMap<TransmissionID<N>, Transmission<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 (2f+1).
sourcepub fn check_certificate(
&self,
certificate: &BatchCertificate<N>,
transmissions: HashMap<TransmissionID<N>, Transmission<N>>
) -> Result<HashMap<TransmissionID<N>, Transmission<N>>>
pub fn check_certificate( &self, certificate: &BatchCertificate<N>, transmissions: HashMap<TransmissionID<N>, Transmission<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 (2f+1).
- The timestamps from the signers are all within the allowed time range.
- The signers have reached the quorum threshold (2f+1).
sourcepub fn insert_certificate(
&self,
certificate: BatchCertificate<N>,
transmissions: HashMap<TransmissionID<N>, Transmission<N>>
) -> Result<()>
pub fn insert_certificate( &self, certificate: BatchCertificate<N>, transmissions: HashMap<TransmissionID<N>, Transmission<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 (2f+1).