pub struct Journal<F, E, C, H>{ /* private fields */ }Expand description
An append-only data structure that maintains a sequential journal of items alongside a Merkle-family structure. The item at index i in the journal corresponds to the leaf at Location i in the Merkle structure. This structure enables efficient proofs that an item is included in the journal at a specific location.
Implementations§
Source§impl<F, E, C, H> Journal<F, E, C, H>
impl<F, E, C, H> Journal<F, E, C, H>
Source§impl<F, E, C, H> Journal<F, E, C, H>where
F: Family,
E: Context,
C: Contiguous<Item: EncodeShared> + Persistable<Error = Error>,
H: Hasher,
impl<F, E, C, H> Journal<F, E, C, H>where
F: Family,
E: Context,
C: Contiguous<Item: EncodeShared> + Persistable<Error = Error>,
H: Hasher,
Source§impl<F, E, C, H> Journal<F, E, C, H>
impl<F, E, C, H> Journal<F, E, C, H>
Sourcepub async fn from_components(
merkle: Journaled<F, E, H::Digest>,
journal: C,
hasher: StandardHasher<H>,
apply_batch_size: u64,
) -> Result<Self, Error<F>>
pub async fn from_components( merkle: Journaled<F, E, H::Digest>, journal: C, hasher: StandardHasher<H>, apply_batch_size: u64, ) -> Result<Self, Error<F>>
Create a new Journal from the given components after aligning the Merkle structure with the journal.
Sourcepub async fn append(&mut self, item: &C::Item) -> Result<Location<F>, Error<F>>
pub async fn append(&mut self, item: &C::Item) -> Result<Location<F>, Error<F>>
Append an item to the journal and update the Merkle structure.
Sourcepub async fn apply_batch(
&mut self,
batch: &MerkleizedBatch<F, H::Digest, C::Item>,
) -> Result<(), Error<F>>
pub async fn apply_batch( &mut self, batch: &MerkleizedBatch<F, H::Digest, C::Item>, ) -> Result<(), Error<F>>
Apply a batch to the journal.
A batch is valid if the journal has not been modified since the batch chain was created, or if only ancestors of this batch have been applied. Already-committed ancestors are skipped automatically. Applying a batch from a different fork returns an error.
Source§impl<F, E, C, H> Journal<F, E, C, H>
impl<F, E, C, H> Journal<F, E, C, H>
Sourcepub async fn proof(
&self,
start_loc: Location<F>,
max_ops: NonZeroU64,
) -> Result<(Proof<F, H::Digest>, Vec<C::Item>), Error<F>>
pub async fn proof( &self, start_loc: Location<F>, max_ops: NonZeroU64, ) -> Result<(Proof<F, H::Digest>, Vec<C::Item>), Error<F>>
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::Merkle with merkle::Error::LocationOverflow if
start_loc> Family::MAX_LEAVES. - Returns Error::Merkle with merkle::Error::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<F>,
start_loc: Location<F>,
max_ops: NonZeroU64,
) -> Result<(Proof<F, H::Digest>, Vec<C::Item>), Error<F>>
pub async fn historical_proof( &self, historical_leaves: Location<F>, start_loc: Location<F>, max_ops: NonZeroU64, ) -> Result<(Proof<F, H::Digest>, Vec<C::Item>), Error<F>>
Generate a historical proof with respect to the state of the Merkle structure 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::Merkle with merkle::Error::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<F, E, C, H> Journal<F, E, C, H>where
F: Family,
E: Context,
C: Contiguous<Item: EncodeShared> + Persistable<Error = Error>,
H: Hasher,
impl<F, E, C, H> Journal<F, E, C, H>where
F: Family,
E: Context,
C: Contiguous<Item: EncodeShared> + Persistable<Error = Error>,
H: Hasher,
Source§impl<F, E, O, H> Journal<F, E, Journal<E, O>, H>
impl<F, E, O, H> Journal<F, E, Journal<E, O>, H>
Sourcepub async fn new(
context: E,
merkle_cfg: Config,
journal_cfg: Config,
rewind_predicate: fn(&O) -> bool,
) -> Result<Self, Error<F>>
pub async fn new( context: E, merkle_cfg: Config, journal_cfg: Config, rewind_predicate: fn(&O) -> bool, ) -> Result<Self, Error<F>>
Create a new authenticated Journal.
The inner journal will be rewound to the last item matching rewind_predicate,
and the merkle structure will be aligned to match.
Source§impl<F, E, O, H> Journal<F, E, Journal<E, O>, H>
impl<F, E, O, H> Journal<F, E, Journal<E, O>, H>
Sourcepub async fn new(
context: E,
merkle_cfg: Config,
journal_cfg: Config<O::Cfg>,
rewind_predicate: fn(&O) -> bool,
) -> Result<Self, Error<F>>
pub async fn new( context: E, merkle_cfg: Config, journal_cfg: Config<O::Cfg>, rewind_predicate: fn(&O) -> bool, ) -> Result<Self, Error<F>>
Create a new authenticated Journal.
The inner journal will be rewound to the last item matching rewind_predicate,
and the merkle structure will be aligned to match.
Trait Implementations§
Source§impl<F, E, C, H> Contiguous for Journal<F, E, C, H>
impl<F, E, C, H> Contiguous for Journal<F, E, C, H>
Source§impl<F, E, C, H> Mutable for Journal<F, E, C, H>
impl<F, E, C, H> Mutable for Journal<F, 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§fn append_many<'a>(
&'a mut self,
items: Many<'a, Self::Item>,
) -> impl Future<Output = Result<u64, Error>> + Send + 'a
fn append_many<'a>( &'a mut self, items: Many<'a, Self::Item>, ) -> impl Future<Output = Result<u64, Error>> + Send + 'a
Source§impl<F, E, C, H> Persistable for Journal<F, E, C, H>where
F: Family,
E: Context,
C: Contiguous<Item: EncodeShared> + Persistable<Error = Error>,
H: Hasher,
impl<F, E, C, H> Persistable for Journal<F, E, C, H>where
F: Family,
E: Context,
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<F, E, C, H> !Freeze for Journal<F, E, C, H>
impl<F, E, C, H> !RefUnwindSafe for Journal<F, E, C, H>
impl<F, E, C, H> Send for Journal<F, E, C, H>
impl<F, E, C, H> Sync for Journal<F, E, C, H>
impl<F, E, C, H> Unpin for Journal<F, E, C, H>
impl<F, E, C, H> UnsafeUnpin for Journal<F, E, C, H>where
C: UnsafeUnpin,
E: UnsafeUnpin,
<H as Hasher>::Digest: UnsafeUnpin,
<E as Storage>::Blob: UnsafeUnpin,
impl<F, E, C, H> !UnwindSafe for Journal<F, 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