pub struct ExtendedDataSquare { /* private fields */ }Expand description
The data matrix in Celestia blocks extended with parity data.
It is created by a fixed size chunks of data, called Shares.
Each share is a cell of the ExtendedDataSquare.
§Structure
The ExtendedDataSquare consists of four quadrants. The first
quadrant (upper-left) is the original data submitted to the network,
referred to as OriginalDataSquare. The other three quadrants are
the parity data encoded row-wise or column-wise using Reed-Solomon
codec specified in EDS.
The below diagram shows how the EDS is constructed. First, the 2nd
and 3rd quadrants are created by computing Reed-Solomon parity data
of the original data square, row-wise for 2nd and column-wise for
3rd quadrant. Then, the 4th quadrant is computed either row-wise
from 3rd or column-wise from 2nd quadrant.
---------------------------
| | |
| --|-> |
| 1 --|-> 2 |
| --|-> |
| | | | | |
-------------+-------------
| v v v | |
| --|-> |
| 3 --|-> 4 |
| --|-> |
| | |
---------------------------§Data availability
The DataAvailabilityHeader is created by computing Nmt merkle
roots of each row and column of ExtendedDataSquare.
By putting those together there are some key
properties those have in terms of data availability.
Thanks to the parity data, to make original data unrecoverable, a malicious
actor would need to hide more than a half of the data from each row and column.
If we take k as the width of the OriginalDataSquare, then the attacker
needs to hide more than (k + 1)^2 shares from the ExtendedDataSquare.
For the EDS with a width of 4, the attacker needs to hide more than 50% of
all the shares and that value approaches 25% as the square grows.
This allows for really efficient data sampling, as the sampling node can reach very high confidence that whole data is available by taking only a few samples.
§Example
This example shows rebuilding the merkle trees for each row of the EDS and compares them with the root hashes stored in data availability header.
use celestia_types::Share;
let block_height = 15;
let header = get_header(block_height);
let eds = get_eds(block_height);
let width = header.dah.square_width();
// for each row of the data square, build an nmt
for row in 0..eds.square_width() {
// check if the root corresponds to the one from the dah
let root = eds.row_nmt(row).unwrap().root();
assert_eq!(root, header.dah.row_root(row).unwrap());
}Implementations§
Source§impl ExtendedDataSquare
impl ExtendedDataSquare
Sourcepub fn new(
shares: Vec<Vec<u8>>,
codec: String,
app_version: AppVersion,
) -> Result<Self>
pub fn new( shares: Vec<Vec<u8>>, codec: String, app_version: AppVersion, ) -> Result<Self>
Create a new EDS out of the provided shares.
Shares should be provided in a row-major order, i.e. first shares of the first row, then of the second row and so on.
§Errors
Returns an error if:
- shares are of sizes different than
SHARE_SIZE - amount of shares doesn’t allow for forming a square
- width of the square is smaller than
MIN_EXTENDED_SQUARE_WIDTH - width of the square is bigger than
max_extended_square_width - width of the square isn’t a power of 2
- namespaces of shares aren’t in non-decreasing order row and column wise
Sourcepub fn from_raw(
raw_eds: RawExtendedDataSquare,
app_version: AppVersion,
) -> Result<Self>
pub fn from_raw( raw_eds: RawExtendedDataSquare, app_version: AppVersion, ) -> Result<Self>
Creates an ExtendedDataSquare from RawExtendedDataSquare and an AppVersion.
Sourcepub fn empty() -> ExtendedDataSquare
pub fn empty() -> ExtendedDataSquare
Crate a new EDS that represents an empty block
Sourcepub fn from_ods(
ods_shares: Vec<Vec<u8>>,
app_version: AppVersion,
) -> Result<ExtendedDataSquare>
pub fn from_ods( ods_shares: Vec<Vec<u8>>, app_version: AppVersion, ) -> Result<ExtendedDataSquare>
Create a new EDS out of the provided original data square shares.
This method is similar to the ExtendedDataSquare::new but parity data
will be encoded automatically using the leopard_codec
Shares should be provided in a row-major order.
§Errors
The same errors as in ExtendedDataSquare::new applies. The constrain
will be checked after the parity data is generated.
Additionally, this function will propagate any error from encoding parity data.
Sourcepub fn data_square(&self) -> &[Share]
pub fn data_square(&self) -> &[Share]
The raw data of the EDS.
Returns the share of the provided coordinates.
Sourcepub fn axis(&self, axis: AxisType, index: u16) -> Result<Vec<Share>>
pub fn axis(&self, axis: AxisType, index: u16) -> Result<Vec<Share>>
Returns the shares of column or row.
Sourcepub fn axis_nmt(&self, axis: AxisType, index: u16) -> Result<Nmt>
pub fn axis_nmt(&self, axis: AxisType, index: u16) -> Result<Nmt>
Returns the Nmt of column or row.
Sourcepub fn square_width(&self) -> u16
pub fn square_width(&self) -> u16
Get EDS square length.
Sourcepub fn get_namespace_data(
&self,
namespace: Namespace,
dah: &DataAvailabilityHeader,
height: u64,
) -> Result<Vec<(RowNamespaceDataId, RowNamespaceData)>>
pub fn get_namespace_data( &self, namespace: Namespace, dah: &DataAvailabilityHeader, height: u64, ) -> Result<Vec<(RowNamespaceDataId, RowNamespaceData)>>
Return all the shares that belong to the provided namespace in the EDS. Results are returned as a list of rows of shares with the inclusion proof.
Trait Implementations§
Source§impl Clone for ExtendedDataSquare
impl Clone for ExtendedDataSquare
Source§fn clone(&self) -> ExtendedDataSquare
fn clone(&self) -> ExtendedDataSquare
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ExtendedDataSquare
impl Debug for ExtendedDataSquare
Source§impl From<ExtendedDataSquare> for RawExtendedDataSquare
impl From<ExtendedDataSquare> for RawExtendedDataSquare
Source§fn from(eds: ExtendedDataSquare) -> RawExtendedDataSquare
fn from(eds: ExtendedDataSquare) -> RawExtendedDataSquare
Source§impl PartialEq for ExtendedDataSquare
impl PartialEq for ExtendedDataSquare
Source§impl Serialize for ExtendedDataSquare
impl Serialize for ExtendedDataSquare
impl Eq for ExtendedDataSquare
impl StructuralPartialEq for ExtendedDataSquare
Auto Trait Implementations§
impl Freeze for ExtendedDataSquare
impl RefUnwindSafe for ExtendedDataSquare
impl Send for ExtendedDataSquare
impl Sync for ExtendedDataSquare
impl Unpin for ExtendedDataSquare
impl UnwindSafe for ExtendedDataSquare
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.