ab_core_primitives/segments/archival_history_segment.rs
1use crate::pieces::{FlatPieces, Piece};
2use crate::segments::RecordedHistorySegment;
3use derive_more::{Deref, DerefMut};
4
5/// Archived history segment after archiving is applied.
6#[derive(Debug, Clone, Eq, PartialEq, Deref, DerefMut)]
7#[repr(transparent)]
8pub struct ArchivedHistorySegment(FlatPieces);
9
10impl Default for ArchivedHistorySegment {
11 #[inline]
12 fn default() -> Self {
13 Self(FlatPieces::new(Self::NUM_PIECES))
14 }
15}
16
17impl ArchivedHistorySegment {
18 /// Number of pieces in one segment of archived history.
19 pub const NUM_PIECES: usize = RecordedHistorySegment::NUM_PIECES;
20 /// Size of archived history segment in bytes.
21 ///
22 /// It includes erasure coded [`crate::pieces::PieceArray`]s (both source and parity) that are
23 /// composed of [`crate::pieces::Record`]s together with corresponding roots and
24 /// proofs.
25 pub const SIZE: usize = Piece::SIZE * Self::NUM_PIECES;
26
27 /// Ensure archived history segment contains cheaply cloneable shared data.
28 ///
29 /// Internally archived history segment uses CoW mechanism and can store either mutable owned
30 /// data or data that is cheap to clone, calling this method will ensure further clones and
31 /// returned pieces will not result in additional memory allocations.
32 pub fn to_shared(self) -> Self {
33 Self(self.0.to_shared())
34 }
35}