From f66ab216cca3f5da65af7d162073ddc85bd6a01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Florkiewicz?= Date: Mon, 8 Jan 2024 22:59:06 +0100 Subject: [PATCH] rework a bit after review --- rpc/tests/share.rs | 10 +- types/src/byzantine.rs | 2 +- types/src/data_availability_header.rs | 2 +- types/src/extended_data_square.rs | 150 ------------------------- types/src/lib.rs | 1 - types/src/namespaced_data.rs | 6 +- types/src/row.rs | 61 +++++----- types/src/rsmt2d.rs | 154 +++++++++++++++++++++++++- types/src/sample.rs | 39 ++++--- 9 files changed, 221 insertions(+), 204 deletions(-) delete mode 100644 types/src/extended_data_square.rs diff --git a/rpc/tests/share.rs b/rpc/tests/share.rs index 4dd4ca9db..d54ab2da6 100644 --- a/rpc/tests/share.rs +++ b/rpc/tests/share.rs @@ -6,7 +6,7 @@ use celestia_types::consts::appconsts::{ SHARE_INFO_BYTES, }; use celestia_types::nmt::{Namespace, NamespacedSha2Hasher, Nmt}; -use celestia_types::{Blob, Share}; +use celestia_types::Blob; use nmt_rs::NamespaceMerkleHasher; pub mod utils; @@ -158,12 +158,12 @@ async fn get_eds() { for (x, leaf) in chunk.iter().enumerate() { if x < width / 2 && y < width / 2 { // the `OriginalDataSquare` part of the `EDS` - let share = Share::from_raw(leaf).unwrap(); - let ns = share.namespace(); - nmt.push_leaf(share.as_ref(), *ns).unwrap(); + let ns = leaf.namespace(); + nmt.push_leaf(leaf.as_ref(), *ns).unwrap(); } else { // the parity data computed using `eds.codec` - nmt.push_leaf(leaf, *Namespace::PARITY_SHARE).unwrap(); + nmt.push_leaf(leaf.as_ref(), *Namespace::PARITY_SHARE) + .unwrap(); } } diff --git a/types/src/byzantine.rs b/types/src/byzantine.rs index ca77c564a..3144aaa52 100644 --- a/types/src/byzantine.rs +++ b/types/src/byzantine.rs @@ -7,12 +7,12 @@ use tendermint_proto::Protobuf; use crate::bail_validation; use crate::consts::appconsts; -use crate::extended_data_square::AxisType; use crate::fraud_proof::FraudProof; use crate::nmt::{ Namespace, NamespaceProof, NamespacedHash, NamespacedHashExt, NMT_CODEC, NMT_ID_SIZE, NMT_MULTIHASH_CODE, NS_SIZE, }; +use crate::rsmt2d::AxisType; use crate::{Error, ExtendedHeader, Result, Share}; type Cid = CidGeneric; diff --git a/types/src/data_availability_header.rs b/types/src/data_availability_header.rs index 0e315771d..20544244f 100644 --- a/types/src/data_availability_header.rs +++ b/types/src/data_availability_header.rs @@ -7,9 +7,9 @@ use tendermint_proto::Protobuf; use crate::consts::data_availability_header::{ MAX_EXTENDED_SQUARE_WIDTH, MIN_EXTENDED_SQUARE_WIDTH, }; -use crate::extended_data_square::AxisType; use crate::hash::Hash; use crate::nmt::{NamespacedHash, NamespacedHashExt}; +use crate::rsmt2d::AxisType; use crate::{bail_validation, Error, Result, ValidateBasic, ValidationError}; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/types/src/extended_data_square.rs b/types/src/extended_data_square.rs deleted file mode 100644 index 571366cac..000000000 --- a/types/src/extended_data_square.rs +++ /dev/null @@ -1,150 +0,0 @@ -use std::result::Result as StdResult; - -use nmt_rs::NamespaceMerkleHasher; - -use crate::namespaced_data::{NamespacedData, NamespacedDataId}; -use crate::nmt::{Namespace, NamespacedSha2Hasher, Nmt}; -use crate::{DataAvailabilityHeader, Share}; -use crate::{Error, Result}; - -/// Represents either Column or Row of the Data Square. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -#[repr(u8)] -pub enum AxisType { - Row = 0, - Col, -} - -impl TryFrom for AxisType { - type Error = Error; - - fn try_from(value: u8) -> StdResult { - match value { - 0 => Ok(AxisType::Row), - 1 => Ok(AxisType::Col), - n => Err(Error::InvalidAxis(n.into())), - } - } -} - -/// Represents ExtendedDataSquare with deserialized Shares -pub struct ExtendedDataSquare { - shares: Vec, - square_len: usize, -} - -impl ExtendedDataSquare { - /// Create a new EDS out of the provided shares. Returns error if share number doesn't - /// create a square - pub fn new(shares: Vec) -> Result { - let square_len = f64::sqrt(shares.len() as f64) as usize; - if square_len * square_len != shares.len() { - return Err(Error::EdsInvalidDimentions); - } - - Ok(Self { shares, square_len }) - } - - /// Return row with index - pub fn row(&self, index: usize) -> Result> { - self.shares - .get(index * self.square_len..(index + 1) * self.square_len) - .ok_or(Error::EdsIndexOutOfRange(index)) - .map(|v| v.to_vec()) - } - - /// Return colum with index - pub fn column(&self, mut index: usize) -> Result> { - let mut r = Vec::with_capacity(self.square_len); - while index < self.shares.len() { - r.push( - self.shares - .get(index) - .ok_or(Error::EdsIndexOutOfRange(index))? - .clone(), - ); - index += self.square_len; - } - Ok(r) - } - - /// Return column or row with the provided index - pub fn axis(&self, axis: AxisType, index: usize) -> Result> { - match axis { - AxisType::Col => self.column(index), - AxisType::Row => self.row(index), - } - } - - /// Get EDS square length - pub fn square_len(&self) -> usize { - self.square_len - } - - /// 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 - pub fn get_namespaced_data( - &self, - namespace: Namespace, - dah: &DataAvailabilityHeader, - height: u64, - ) -> Result> { - let mut data = Vec::new(); - - for i in 0..self.square_len { - let row_root = dah.row_root(i).unwrap(); - if !row_root.contains::(*namespace) { - continue; - } - - let mut shares = Vec::with_capacity(self.square_len); - - let mut tree = Nmt::with_hasher(NamespacedSha2Hasher::with_ignore_max_ns(true)); - for s in &self.shares { - tree.push_leaf(s.data(), *s.namespace()) - .map_err(Error::Nmt)?; - if s.namespace() == namespace { - shares.push(s.clone()); - } - } - - let proof = tree.get_namespace_proof(*namespace); - let namespaced_data_id = NamespacedDataId { - row_index: i.try_into().unwrap(), - namespace, - hash: dah.hash().as_ref().try_into().unwrap(), - block_height: height, - }; - - data.push(NamespacedData { - namespaced_data_id, - proof: proof.into(), - shares, - }) - } - - Ok(data) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn axis_type_serialization() { - assert_eq!(AxisType::Row as u8, 0); - assert_eq!(AxisType::Col as u8, 1); - } - - #[test] - fn axis_type_deserialization() { - assert_eq!(AxisType::try_from(0).unwrap(), AxisType::Row); - assert_eq!(AxisType::try_from(1).unwrap(), AxisType::Col); - - let axis_type_err = AxisType::try_from(2).unwrap_err(); - assert!(matches!(axis_type_err, Error::InvalidAxis(2))); - let axis_type_err = AxisType::try_from(99).unwrap_err(); - assert!(matches!(axis_type_err, Error::InvalidAxis(99))); - } -} diff --git a/types/src/lib.rs b/types/src/lib.rs index a7d0ee1dc..e2e14aa45 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -4,7 +4,6 @@ mod byzantine; pub mod consts; mod data_availability_header; mod error; -mod extended_data_square; mod extended_header; pub mod fraud_proof; pub mod hash; diff --git a/types/src/namespaced_data.rs b/types/src/namespaced_data.rs index dcb7ff8cf..b141f10dd 100644 --- a/types/src/namespaced_data.rs +++ b/types/src/namespaced_data.rs @@ -9,8 +9,8 @@ use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use tendermint_proto::Protobuf; -use crate::extended_data_square::AxisType; use crate::nmt::{Namespace, NamespaceProof, NamespacedHashExt, HASH_SIZE, NS_SIZE}; +use crate::rsmt2d::AxisType; use crate::{DataAvailabilityHeader, Error, Result, Share}; const NAMESPACED_DATA_ID_SIZE: usize = NamespacedDataId::size(); @@ -26,6 +26,10 @@ pub struct NamespacedDataId { pub block_height: u64, } +/// `NamespacedData` is constructed out of the ExtendedDataSquare, containing up to a row of +/// shares belonging to a particular namespace and a proof of their inclusion. If, for +/// particular EDS, shares from the namespace span multiple rows, one needs multiple +/// NamespacedData instances to cover the whole range. #[derive(Serialize, Deserialize, Clone)] #[serde(try_from = "RawNamespacedData", into = "RawNamespacedData")] pub struct NamespacedData { diff --git a/types/src/row.rs b/types/src/row.rs index 17d98ffd4..784ab26f9 100644 --- a/types/src/row.rs +++ b/types/src/row.rs @@ -10,8 +10,8 @@ use serde::{Deserialize, Serialize}; use tendermint::Hash; use tendermint_proto::Protobuf; -use crate::extended_data_square::ExtendedDataSquare; use crate::nmt::{NamespacedSha2Hasher, Nmt}; +use crate::rsmt2d::ExtendedDataSquare; use crate::{Error, Result, Share}; const ROW_ID_SIZE: usize = RowId::size(); @@ -21,6 +21,7 @@ pub const ROW_ID_CODEC: u64 = 0x7810; /// Represents particular particular Row in a specific Data Square, #[derive(Debug, PartialEq, Clone, Copy)] pub struct RowId { + /// pub block_height: u64, pub index: u16, } @@ -29,8 +30,10 @@ pub struct RowId { #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(try_from = "RawRow", into = "RawRow")] 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, } @@ -59,7 +62,7 @@ impl Row { /* let parity_shares : Vec = unimplemented!(); for s in parity_shares { - tree.push_leaf(s.data(), *s.namespace()) + tree.push_leaf(s.data(), *Namespace::PARITY_SHARE) .map_err(Error::Nmt)?; } */ @@ -77,9 +80,9 @@ impl Protobuf for Row {} impl TryFrom for Row { type Error = Error; - fn try_from(axis: RawRow) -> Result { - let row_id = RowId::decode(&axis.row_id)?; - let shares = axis + fn try_from(row: RawRow) -> Result { + let row_id = RowId::decode(&row.row_id)?; + let shares = row .row_half .into_iter() .map(|s| Share::from_raw(&s)) @@ -90,13 +93,13 @@ impl TryFrom for Row { } impl From for RawRow { - fn from(axis: Row) -> RawRow { - let mut axis_id_bytes = BytesMut::new(); - axis.row_id.encode(&mut axis_id_bytes); + fn from(row: Row) -> RawRow { + let mut row_id_bytes = BytesMut::new(); + row.row_id.encode(&mut row_id_bytes); RawRow { - row_id: axis_id_bytes.to_vec(), - row_half: axis.shares.into_iter().map(|s| s.data.to_vec()).collect(), + row_id: row_id_bytes.to_vec(), + row_half: row.shares.into_iter().map(|s| s.data.to_vec()).collect(), } } } @@ -179,9 +182,9 @@ impl TryFrom> for RowId { impl TryFrom for CidGeneric { type Error = CidError; - fn try_from(axis: RowId) -> Result { + fn try_from(row: RowId) -> Result { let mut bytes = BytesMut::with_capacity(ROW_ID_SIZE); - axis.encode(&mut bytes); + row.encode(&mut bytes); // length is correct, so unwrap is safe let mh = Multihash::wrap(ROW_ID_MULTIHASH_CODE, &bytes[..]).unwrap(); @@ -197,22 +200,22 @@ mod tests { #[test] fn round_trip_test() { - let axis_id = RowId::new(5, 100).unwrap(); - let cid = CidGeneric::try_from(axis_id).unwrap(); + let row_id = RowId::new(5, 100).unwrap(); + let cid = CidGeneric::try_from(row_id).unwrap(); let multihash = cid.hash(); assert_eq!(multihash.code(), ROW_ID_MULTIHASH_CODE); assert_eq!(multihash.size(), ROW_ID_SIZE as u8); - let deserialized_axis_id = RowId::try_from(cid).unwrap(); - assert_eq!(axis_id, deserialized_axis_id); + let deserialized_row_id = RowId::try_from(cid).unwrap(); + assert_eq!(row_id, deserialized_row_id); } #[test] fn index_calculation() { let height = 100; let shares = vec![Share::from_raw(&[0; SHARE_SIZE]).unwrap(); 8 * 8]; - let eds = ExtendedDataSquare::new(shares).unwrap(); + let eds = ExtendedDataSquare::new(shares, "codec".to_string()).unwrap(); Row::new(1, &eds, height).unwrap(); Row::new(7, &eds, height).unwrap(); @@ -230,7 +233,7 @@ mod tests { 0x91, 0xF0, 0x01, // multihash code = 7811 0x0A, // len = ROW_ID_SIZE = 10 64, 0, 0, 0, 0, 0, 0, 0, // block height = 64 - 7, 0, // axis index = 7 + 7, 0, // row index = 7 ]; let cid = CidGeneric::::read_bytes(bytes.as_ref()).unwrap(); @@ -238,9 +241,9 @@ mod tests { let mh = cid.hash(); assert_eq!(mh.code(), ROW_ID_MULTIHASH_CODE); assert_eq!(mh.size(), ROW_ID_SIZE as u8); - let axis_id = RowId::try_from(cid).unwrap(); - assert_eq!(axis_id.index, 7); - assert_eq!(axis_id.block_height, 64); + let row_id = RowId::try_from(cid).unwrap(); + assert_eq!(row_id.index, 7); + assert_eq!(row_id.block_height, 64); } #[test] @@ -251,7 +254,7 @@ mod tests { 0x91, 0xF0, 0x01, // code = 7811 0x0A, // len = ROW_ID_SIZE = 10 0, 0, 0, 0, 0, 0, 0, 0, // invalid block height = 0 ! - 7, 0, // axis index = 7 + 7, 0, // row index = 7 ]; let cid = CidGeneric::::read_bytes(bytes.as_ref()).unwrap(); @@ -259,9 +262,9 @@ mod tests { let mh = cid.hash(); assert_eq!(mh.code(), ROW_ID_MULTIHASH_CODE); assert_eq!(mh.size(), ROW_ID_SIZE as u8); - let axis_err = RowId::try_from(cid).unwrap_err(); + let row_err = RowId::try_from(cid).unwrap_err(); assert_eq!( - axis_err, + row_err, CidError::InvalidCid("Zero block height".to_string()) ); } @@ -270,9 +273,9 @@ mod tests { fn multihash_invalid_code() { let multihash = Multihash::::wrap(999, &[0; ROW_ID_SIZE]).unwrap(); let cid = CidGeneric::::new_v1(ROW_ID_CODEC, multihash); - let axis_err = RowId::try_from(cid).unwrap_err(); + let row_err = RowId::try_from(cid).unwrap_err(); assert_eq!( - axis_err, + row_err, CidError::InvalidMultihashCode(999, ROW_ID_MULTIHASH_CODE) ); } @@ -282,12 +285,12 @@ mod tests { let multihash = Multihash::::wrap(ROW_ID_MULTIHASH_CODE, &[0; ROW_ID_SIZE]).unwrap(); let cid = CidGeneric::::new_v1(1234, multihash); - let axis_err = RowId::try_from(cid).unwrap_err(); - assert_eq!(axis_err, CidError::InvalidCidCodec(1234)); + let row_err = RowId::try_from(cid).unwrap_err(); + assert_eq!(row_err, CidError::InvalidCidCodec(1234)); } #[test] - fn decode_axis_bytes() { + fn decode_row_bytes() { let bytes = include_bytes!("../test_data/shwap_samples/row.data"); let mut row = Row::decode(&bytes[..]).unwrap(); diff --git a/types/src/rsmt2d.rs b/types/src/rsmt2d.rs index 7ebceb6af..2b55c3f60 100644 --- a/types/src/rsmt2d.rs +++ b/types/src/rsmt2d.rs @@ -1,8 +1,158 @@ +use std::result::Result as StdResult; + +use nmt_rs::NamespaceMerkleHasher; use serde::{Deserialize, Serialize}; +use crate::namespaced_data::{NamespacedData, NamespacedDataId}; +use crate::nmt::{Namespace, NamespacedSha2Hasher, Nmt}; +use crate::{DataAvailabilityHeader, Share}; +use crate::{Error, Result}; + +/// Represents either Column or Row of the Data Square. +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[repr(u8)] +pub enum AxisType { + Row = 0, + Col, +} + +impl TryFrom for AxisType { + type Error = Error; + + fn try_from(value: u8) -> StdResult { + match value { + 0 => Ok(AxisType::Row), + 1 => Ok(AxisType::Col), + n => Err(Error::InvalidAxis(n.into())), + } + } +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ExtendedDataSquare { - #[serde(with = "tendermint_proto::serializers::bytes::vec_base64string")] - pub data_square: Vec>, + //#[serde(with = "tendermint_proto::serializers::bytes::vec_base64string")] + pub data_square: Vec, pub codec: String, + #[serde(skip)] + pub square_len: usize, +} + +impl ExtendedDataSquare { + /// Create a new EDS out of the provided shares. Returns error if share number doesn't + /// create a square + pub fn new(shares: Vec, codec: String) -> Result { + let square_len = f64::sqrt(shares.len() as f64) as usize; + if square_len * square_len != shares.len() { + return Err(Error::EdsInvalidDimentions); + } + + Ok(Self { + data_square: shares, + codec, + square_len, + }) + } + + /// Return row with index + pub fn row(&self, index: usize) -> Result> { + self.data_square + .get(index * self.square_len..(index + 1) * self.square_len) + .ok_or(Error::EdsIndexOutOfRange(index)) + .map(|v| v.to_vec()) + } + + /// Return colum with index + pub fn column(&self, mut index: usize) -> Result> { + let mut r = Vec::with_capacity(self.square_len); + while index < self.data_square.len() { + r.push( + self.data_square + .get(index) + .ok_or(Error::EdsIndexOutOfRange(index))? + .clone(), + ); + index += self.square_len; + } + Ok(r) + } + + /// Return column or row with the provided index + pub fn axis(&self, axis: AxisType, index: usize) -> Result> { + match axis { + AxisType::Col => self.column(index), + AxisType::Row => self.row(index), + } + } + + /// Get EDS square length + pub fn square_len(&self) -> usize { + self.square_len + } + + /// 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 + pub fn get_namespaced_data( + &self, + namespace: Namespace, + dah: &DataAvailabilityHeader, + height: u64, + ) -> Result> { + let mut data = Vec::new(); + + for i in 0..self.square_len { + let row_root = dah.row_root(i).unwrap(); + if !row_root.contains::(*namespace) { + continue; + } + + let mut shares = Vec::with_capacity(self.square_len); + + let mut tree = Nmt::with_hasher(NamespacedSha2Hasher::with_ignore_max_ns(true)); + for s in &self.data_square { + tree.push_leaf(s.data(), *s.namespace()) + .map_err(Error::Nmt)?; + if s.namespace() == namespace { + shares.push(s.clone()); + } + } + + let proof = tree.get_namespace_proof(*namespace); + let namespaced_data_id = NamespacedDataId { + row_index: i.try_into().unwrap(), + namespace, + hash: dah.hash().as_ref().try_into().unwrap(), + block_height: height, + }; + + data.push(NamespacedData { + namespaced_data_id, + proof: proof.into(), + shares, + }) + } + + Ok(data) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn axis_type_serialization() { + assert_eq!(AxisType::Row as u8, 0); + assert_eq!(AxisType::Col as u8, 1); + } + + #[test] + fn axis_type_deserialization() { + assert_eq!(AxisType::try_from(0).unwrap(), AxisType::Row); + assert_eq!(AxisType::try_from(1).unwrap(), AxisType::Col); + + let axis_type_err = AxisType::try_from(2).unwrap_err(); + assert!(matches!(axis_type_err, Error::InvalidAxis(2))); + let axis_type_err = AxisType::try_from(99).unwrap_err(); + assert!(matches!(axis_type_err, Error::InvalidAxis(99))); + } } diff --git a/types/src/sample.rs b/types/src/sample.rs index 3ae584199..b86ca86f1 100644 --- a/types/src/sample.rs +++ b/types/src/sample.rs @@ -9,13 +9,12 @@ use multihash::Multihash; use nmt_rs::nmt_proof::NamespaceProof as NmtNamespaceProof; use nmt_rs::NamespaceMerkleHasher; use serde::{Deserialize, Serialize}; -use tendermint::Hash; use tendermint_proto::Protobuf; -use crate::extended_data_square::{AxisType, ExtendedDataSquare}; -use crate::nmt::{NamespaceProof, NamespacedHash, NamespacedHashExt, NamespacedSha2Hasher, Nmt}; +use crate::nmt::{NamespaceProof, NamespacedHashExt, NamespacedSha2Hasher, Nmt, Namespace}; use crate::row::RowId; -use crate::{Error, Result, Share}; +use crate::rsmt2d::{AxisType, ExtendedDataSquare}; +use crate::{Error, Result, Share, DataAvailabilityHeader}; const SAMPLE_ID_SIZE: usize = SampleId::size(); pub const SAMPLE_ID_MULTIHASH_CODE: u64 = 0x7801; @@ -32,10 +31,16 @@ pub struct SampleId { #[derive(Serialize, Deserialize, Clone)] #[serde(try_from = "RawSample", into = "RawSample")] 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, } @@ -58,9 +63,8 @@ impl Sample { let mut tree = Nmt::with_hasher(NamespacedSha2Hasher::with_ignore_max_ns(true)); - // XXX: are erasure coded shares correctly prefixed with parity namespace? for s in &shares { - tree.push_leaf(s.data(), *s.namespace()) + tree.push_leaf(s.data(), *Namespace::PARITY_SHARE) .map_err(Error::Nmt)?; } @@ -80,10 +84,17 @@ impl Sample { } /// Validate sample with root hash from ExtendedHeader - pub fn validate(&self, hash: Hash) -> Result<()> { - let namespaced_hash = NamespacedHash::from_raw(hash.as_ref())?; + pub fn validate(&self, dah: DataAvailabilityHeader) -> Result<()> { + // TODO: tests + let index = match self.sample_proof_type { + AxisType::Row => self.sample_id.row.index, + AxisType::Col => self.sample_id.index + }.into(); + + let root = dah.root(self.sample_proof_type, index).ok_or(Error::EdsIndexOutOfRange(index))?; + self.proof - .verify_range(&namespaced_hash, &[&self.share], *self.share.namespace()) + .verify_range(&root, &[&self.share], *self.share.namespace()) .map_err(Error::RangeProofError) } } @@ -259,7 +270,7 @@ mod tests { 0x81, 0xF0, 0x01, // multihash code = 7801 0x0C, // len = SAMPLE_ID_SIZE = 12 64, 0, 0, 0, 0, 0, 0, 0, // block height = 64 - 7, 0, // axis index = 7 + 7, 0, // row index = 7 5, 0, // sample index = 5 ]; @@ -278,9 +289,9 @@ mod tests { fn multihash_invalid_code() { let multihash = Multihash::::wrap(888, &[0; SAMPLE_ID_SIZE]).unwrap(); let cid = CidGeneric::::new_v1(SAMPLE_ID_CODEC, multihash); - let axis_err = SampleId::try_from(cid).unwrap_err(); + let code_err = SampleId::try_from(cid).unwrap_err(); assert_eq!( - axis_err, + code_err, CidError::InvalidMultihashCode(888, SAMPLE_ID_MULTIHASH_CODE) ); } @@ -291,8 +302,8 @@ mod tests { Multihash::::wrap(SAMPLE_ID_MULTIHASH_CODE, &[0; SAMPLE_ID_SIZE]) .unwrap(); let cid = CidGeneric::::new_v1(4321, multihash); - let axis_err = SampleId::try_from(cid).unwrap_err(); - assert!(matches!(axis_err, CidError::InvalidCidCodec(4321))); + let codec_err = SampleId::try_from(cid).unwrap_err(); + assert!(matches!(codec_err, CidError::InvalidCidCodec(4321))); } #[test]