Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rek committed Jan 9, 2024
1 parent 18e1de6 commit 5e87d4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
18 changes: 11 additions & 7 deletions types/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ use cid::CidGeneric;
use multihash::Multihash;
use nmt_rs::NamespaceMerkleHasher;
use serde::{Deserialize, Serialize};
use tendermint::Hash;
use tendermint_proto::Protobuf;

use crate::nmt::{NamespacedSha2Hasher, Nmt};
use crate::rsmt2d::ExtendedDataSquare;
use crate::{Error, Result, Share};
use crate::{DataAvailabilityHeader, Error, Result, Share};

const ROW_ID_SIZE: usize = RowId::size();
pub const ROW_ID_MULTIHASH_CODE: u64 = 0x7811;
pub const ROW_ID_CODEC: u64 = 0x7810;

/// Represents particular particular Row in a specific Data Square,
/// Represents particular particular row in a specific Data Square,
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct RowId {
///
/// Block height of the EDS the row belongs to
pub block_height: u64,
/// Index of the row
pub index: u16,
}

Expand All @@ -32,7 +32,6 @@ pub struct RowId {
pub struct Row {
/// Location of the row in the EDS and associated block height
pub row_id: RowId,

/// Shares contained in the row
pub shares: Vec<Share>,
}
Expand All @@ -49,7 +48,8 @@ impl Row {
Ok(Row { row_id, shares })
}

pub fn validate(&self, root_hash: Hash) -> Result<()> {
/// Validate the row against roots from DAH
pub fn validate(&self, dah: &DataAvailabilityHeader) -> Result<()> {
let mut tree = Nmt::with_hasher(NamespacedSha2Hasher::with_ignore_max_ns(true));

for s in &self.shares {
Expand All @@ -66,8 +66,12 @@ impl Row {
.map_err(Error::Nmt)?;
}
*/
let index = self.row_id.index.into();
let Some(root) = dah.row_root(index) else {
return Err(Error::EdsIndexOutOfRange(index));
};

if tree.root().hash() != root_hash.as_ref() {
if tree.root().hash() != root.hash() {
return Err(Error::RootMismatch);
}

Expand Down
7 changes: 3 additions & 4 deletions types/src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub const SAMPLE_ID_CODEC: u64 = 0x7800;
/// Represents a location of a sample on the EDS
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct SampleId {
/// Row of the EDS being sampled
pub row: RowId,
/// Index in the row of the share being sampled
pub index: u16,
}

Expand All @@ -33,13 +35,10 @@ pub struct SampleId {
pub struct Sample {
/// Location of the sample in the EDS and associated block height
pub sample_id: SampleId,

/// Indication whether sampling was done row or column-wise
pub sample_proof_type: AxisType,

/// Share that is being sampled
pub share: Share,

/// Proof of the inclusion of the share
pub proof: NamespaceProof,
}
Expand Down Expand Up @@ -84,7 +83,7 @@ impl Sample {
}

/// Validate sample with root hash from ExtendedHeader
pub fn validate(&self, dah: DataAvailabilityHeader) -> Result<()> {
pub fn validate(&self, dah: &DataAvailabilityHeader) -> Result<()> {
// TODO: tests
let index = match self.sample_proof_type {
AxisType::Row => self.sample_id.row.index,
Expand Down

0 comments on commit 5e87d4f

Please sign in to comment.