pub struct Storage<N: Network>(/* private fields */);

Implementations§

source§

impl<N: Network> Storage<N>

source

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>

source

pub fn current_height(&self) -> u32

Returns the current height.

source§

impl<N: Network> Storage<N>

source

pub fn current_round(&self) -> u64

Returns the current round.

source

pub fn gc_round(&self) -> u64

Returns the round that garbage collection has occurred up to (inclusive).

source

pub fn max_gc_rounds(&self) -> u64

Returns the maximum number of rounds to keep in storage.

source

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>

source

pub fn contains_certificates_for_round(&self, round: u64) -> bool

Returns true if the storage contains the specified round.

source

pub fn contains_certificate(&self, certificate_id: Field<N>) -> bool

Returns true if the storage contains the specified certificate ID.

source

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.

source

pub fn contains_batch(&self, batch_id: Field<N>) -> bool

Returns true if the storage contains the specified batch ID.

source

pub fn contains_transmission( &self, transmission_id: impl Into<TransmissionID<N>> ) -> bool

Returns true if the storage contains the specified transmission ID.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn get_certificate_for_round_with_author( &self, round: u64, author: Address<N> ) -> Option<BatchCertificate<N>>

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.

source

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.

source

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).
source

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).
source

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).

Trait Implementations§

source§

impl<N: Clone + Network> Clone for Storage<N>

source§

fn clone(&self) -> Storage<N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<N: Debug + Network> Debug for Storage<N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<N: Network> Deref for Storage<N>

§

type Target = Arc<StorageInner<N>>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more