pub struct Journal<E, C, H>{ /* private fields */ }Expand description
An append-only data structure that maintains a sequential journal of items alongside a Merkle Mountain Range (MMR). The item at index i in the journal corresponds to the leaf at Location i in the MMR. This structure enables efficient proofs that an item is included in the journal at a specific location.
Implementations§
Source§impl<E, C, H> Journal<E, C, H>
impl<E, C, H> Journal<E, C, H>
Source§impl<E, C, H> Journal<E, C, H>where
E: Storage + Clock + Metrics,
C: Contiguous<Item: EncodeShared> + Persistable<Error = Error>,
H: Hasher,
impl<E, C, H> Journal<E, C, H>where
E: Storage + Clock + Metrics,
C: Contiguous<Item: EncodeShared> + Persistable<Error = Error>,
H: Hasher,
Source§impl<E, C, H> Journal<E, C, H>
impl<E, C, H> Journal<E, C, H>
Sourcepub async fn from_components(
mmr: Mmr<E, H::Digest>,
journal: C,
hasher: StandardHasher<H>,
apply_batch_size: u64,
) -> Result<Self, Error>
pub async fn from_components( mmr: Mmr<E, H::Digest>, journal: C, hasher: StandardHasher<H>, apply_batch_size: u64, ) -> Result<Self, Error>
Create a new Journal from the given components after aligning the MMR with the journal.
Sourcepub async fn append(&mut self, item: &C::Item) -> Result<Location, Error>
pub async fn append(&mut self, item: &C::Item) -> Result<Location, Error>
Append an item to the journal and update the MMR.
Sourcepub async fn apply_batch(
&mut self,
batch: Changeset<H::Digest, C::Item>,
) -> Result<(), Error>
pub async fn apply_batch( &mut self, batch: Changeset<H::Digest, C::Item>, ) -> Result<(), Error>
Apply a changeset to the journal.
A changeset is only valid if the journal has not been modified since the batch that produced it was created. Multiple batches can be forked from the same parent for speculative execution, but only one may be applied. Applying a stale changeset returns an error.
Source§impl<E, C, H> Journal<E, C, H>
impl<E, C, H> Journal<E, C, H>
Sourcepub async fn proof(
&self,
start_loc: Location,
max_ops: NonZeroU64,
) -> Result<(Proof<H::Digest>, Vec<C::Item>), Error>
pub async fn proof( &self, start_loc: Location, max_ops: NonZeroU64, ) -> Result<(Proof<H::Digest>, Vec<C::Item>), Error>
Generate a proof of inclusion for items starting at start_loc.
Returns a proof and the items corresponding to the leaves in the range start_loc..end_loc,
where end_loc is the minimum of the current item count and start_loc + max_ops.
§Errors
- Returns Error::Mmr with MmrError::LocationOverflow if
start_loc> crate::mmr::MAX_LOCATION. - Returns Error::Mmr with MmrError::RangeOutOfBounds if
start_loc>= current item count. - Returns Error::Journal with crate::journal::Error::ItemPruned if
start_lochas been pruned.
Sourcepub async fn historical_proof(
&self,
historical_leaves: Location,
start_loc: Location,
max_ops: NonZeroU64,
) -> Result<(Proof<H::Digest>, Vec<C::Item>), Error>
pub async fn historical_proof( &self, historical_leaves: Location, start_loc: Location, max_ops: NonZeroU64, ) -> Result<(Proof<H::Digest>, Vec<C::Item>), Error>
Generate a historical proof with respect to the state of the MMR when it had
historical_leaves leaves.
Returns a proof and the items corresponding to the leaves in the range start_loc..end_loc,
where end_loc is the minimum of historical_leaves and start_loc + max_ops.
§Errors
- Returns Error::Mmr with MmrError::RangeOutOfBounds if
start_loc>=historical_leavesorhistorical_leaves> number of items in the journal. - Returns Error::Journal with crate::journal::Error::ItemPruned if
start_lochas been pruned.
Source§impl<E, C, H> Journal<E, C, H>where
E: Storage + Clock + Metrics,
C: Contiguous<Item: EncodeShared> + Persistable<Error = Error>,
H: Hasher,
impl<E, C, H> Journal<E, C, H>where
E: Storage + Clock + Metrics,
C: Contiguous<Item: EncodeShared> + Persistable<Error = Error>,
H: Hasher,
Trait Implementations§
Source§impl<E, C, H> Contiguous for Journal<E, C, H>
impl<E, C, H> Contiguous for Journal<E, C, H>
Source§impl<E, C, H> Mutable for Journal<E, C, H>
impl<E, C, H> Mutable for Journal<E, C, H>
Source§async fn append(&mut self, item: &Self::Item) -> Result<u64, JournalError>
async fn append(&mut self, item: &Self::Item) -> Result<u64, JournalError>
Source§async fn prune(&mut self, min_position: u64) -> Result<bool, JournalError>
async fn prune(&mut self, min_position: u64) -> Result<bool, JournalError>
min_position. Read moreSource§async fn rewind(&mut self, size: u64) -> Result<(), JournalError>
async fn rewind(&mut self, size: u64) -> Result<(), JournalError>
Source§impl<E, C, H> Persistable for Journal<E, C, H>where
E: Storage + Clock + Metrics,
C: Contiguous<Item: EncodeShared> + Persistable<Error = Error>,
H: Hasher,
impl<E, C, H> Persistable for Journal<E, C, H>where
E: Storage + Clock + Metrics,
C: Contiguous<Item: EncodeShared> + Persistable<Error = Error>,
H: Hasher,
Source§type Error = Error
type Error = Error
Source§async fn commit(&self) -> Result<(), JournalError>
async fn commit(&self) -> Result<(), JournalError>
Auto Trait Implementations§
impl<E, C, H> !Freeze for Journal<E, C, H>
impl<E, C, H> !RefUnwindSafe for Journal<E, C, H>
impl<E, C, H> Send for Journal<E, C, H>
impl<E, C, H> Sync for Journal<E, C, H>
impl<E, C, H> Unpin for Journal<E, C, H>
impl<E, C, H> UnsafeUnpin for Journal<E, C, H>where
C: UnsafeUnpin,
H: UnsafeUnpin,
E: UnsafeUnpin,
<H as Hasher>::Digest: UnsafeUnpin,
<E as Storage>::Blob: UnsafeUnpin,
impl<E, C, H> !UnwindSafe for Journal<E, C, H>
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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