Skip to content

Commit

Permalink
fix: corrected the erroneous variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkingLee committed Jan 19, 2024
1 parent 6a99ba5 commit 541b13c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/proof-of-space/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub use piece::{Piece, PieceMetadata, PiecePosition};
#[cfg(feature = "std")]
pub use solution::find_solutions;
pub use solution::Solution;
pub use y_value_manager::{XValueManager, YPos};
pub use y_value_manager::{YValueManager, YPos};
pub use z_value_manager::ZValueManager;

#[derive(Default, Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)]
Expand Down
6 changes: 3 additions & 3 deletions crates/proof-of-space/src/piece.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
#[cfg(feature = "std")]
use crate::{CellMetadata, DasKv, YPos, ZValueManager};
use crate::{Decode, Encode, FarmerId, Segment, Vec, XValueManager};
use crate::{Decode, Encode, FarmerId, Segment, Vec, YValueManager};
#[cfg(feature = "std")]
use anyhow::{anyhow, Ok, Result};
use melo_das_primitives::Position;
Expand Down Expand Up @@ -127,7 +127,7 @@ where
farmer_id: &'a FarmerId,
) -> impl Iterator<Item = (u32, &Segment)> + 'a {
self.segments.iter().map(move |segment| {
let y = XValueManager::<BlockNumber>::calculate_y(farmer_id, segment);
let y = YValueManager::<BlockNumber>::calculate_y(farmer_id, segment);
(y, segment)
})
}
Expand Down Expand Up @@ -171,7 +171,7 @@ where
CellMetadata { piece_metadata: metadata_clone.clone(), offset: index as u32 };

let x_value_manager =
XValueManager::<BlockNumber>::new(&metadata_clone, index as u32, x);
YValueManager::<BlockNumber>::new(&metadata_clone, index as u32, x);

let x_pos = YPos::from_u32(index as u32);

Expand Down
28 changes: 14 additions & 14 deletions crates/proof-of-space/src/y_value_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl YPos {
}

/// Manages the X-value in a blockchain context, linking to `CellMetadata`.
pub struct XValueManager<BlockNumber>
pub struct YValueManager<BlockNumber>
where
BlockNumber: Clone + sp_std::hash::Hash + Encode + Decode,
{
Expand All @@ -82,7 +82,7 @@ where
pos: YPos,
}

impl<BlockNumber> XValueManager<BlockNumber>
impl<BlockNumber> YValueManager<BlockNumber>
where
BlockNumber: Clone + sp_std::hash::Hash + Encode + Decode,
{
Expand All @@ -100,7 +100,7 @@ where
utils::fold_hash(&buffer)
}

/// Constructs a new `XValueManager` instance.
/// Constructs a new `YValueManager` instance.
pub fn new(piece_metadata: &PieceMetadata<BlockNumber>, index: u32, y: u32) -> Self {
let pos = YPos::from_u32(index);
Self {
Expand All @@ -110,7 +110,7 @@ where
}
}

/// Generates a key for the current `XValueManager`.
/// Generates a key for the current `YValueManager`.
pub fn key(&self) -> Vec<u8> {
Self::key_by_x_pos(&self.pos, self.y)
}
Expand Down Expand Up @@ -197,8 +197,8 @@ mod tests {

let segs = poly_to_segment_vec(&poly, &kzg, 0, chunk_len).unwrap();

let y1 = XValueManager::<u32>::calculate_y(&FarmerId::default(), &segs[0]);
let y2 = XValueManager::<u32>::calculate_y(&FarmerId::default(), &segs[1]);
let y1 = YValueManager::<u32>::calculate_y(&FarmerId::default(), &segs[0]);
let y2 = YValueManager::<u32>::calculate_y(&FarmerId::default(), &segs[1]);

if y1 == y2 {
print!("y: {:?}\n", y1);
Expand Down Expand Up @@ -299,17 +299,17 @@ mod tests {
#[test]
fn test_x_value_manager_new() {
let piece_metadata = PieceMetadata::<u32>::default();
let x_value_manager = XValueManager::new(&piece_metadata, 10, 20);
let x_value_manager = YValueManager::new(&piece_metadata, 10, 20);
assert_eq!(x_value_manager.y, 20);
assert_eq!(x_value_manager.pos, YPos::from_u32(10));
}

#[test]
fn test_x_value_manager_key() {
let piece_metadata = PieceMetadata::<u32>::default();
let x_value_manager = XValueManager::new(&piece_metadata, 10, 20);
let x_value_manager = YValueManager::new(&piece_metadata, 10, 20);
let key = x_value_manager.key();
let expected_key = XValueManager::<u32>::key_by_x_pos(&YPos::from_u32(10), 20);
let expected_key = YValueManager::<u32>::key_by_x_pos(&YPos::from_u32(10), 20);
assert_eq!(key, expected_key);
}

Expand All @@ -318,7 +318,7 @@ mod tests {

let seg = get_mock_seg(bs, 0, 0, &proof, FIELD_ELEMENTS_PER_SEGMENT);

let y = XValueManager::<u32>::calculate_y(&farmer_id, &seg);
let y = YValueManager::<u32>::calculate_y(&farmer_id, &seg);

assert!(y == y_e);
}
Expand All @@ -339,12 +339,12 @@ mod tests {
let index = 5;
let y = 10;

let x_value_manager = XValueManager::new(&piece_metadata, index, y);
let x_value_manager = YValueManager::new(&piece_metadata, index, y);

assert_eq!(x_value_manager.pos, YPos::from_u32(index));

let key = x_value_manager.key();
let expected_key = XValueManager::<u32>::key_by_x_pos(&YPos::from_u32(index), y);
let expected_key = YValueManager::<u32>::key_by_x_pos(&YPos::from_u32(index), y);
assert_eq!(key, expected_key);
}

Expand Down Expand Up @@ -403,7 +403,7 @@ mod tests {
&mut db,
);

let x_value_manager = XValueManager::new(&PieceMetadata::<u32>::default(), 0, Y1);
let x_value_manager = YValueManager::new(&PieceMetadata::<u32>::default(), 0, Y1);
let match_cells_set = x_value_manager.match_cells(&mut db).unwrap();

assert_eq!(match_cells_set.len(), 1);
Expand All @@ -416,7 +416,7 @@ mod tests {
let index = 5;
let y = 10;

let x_value_manager = XValueManager::new(&piece_metadata, index, y);
let x_value_manager = YValueManager::new(&piece_metadata, index, y);

x_value_manager.save(&mut db);

Expand Down
6 changes: 3 additions & 3 deletions crates/proof-of-space/src/z_value_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#[cfg(feature = "std")]
use crate::DasKv;
use crate::{utils, BlakeTwo256, CellMetadata, Decode, Encode, FarmerId, HashT, XValueManager};
use crate::{utils, BlakeTwo256, CellMetadata, Decode, Encode, FarmerId, HashT, YValueManager};
#[cfg(feature = "std")]
use anyhow::{Context, Result};
use melo_das_primitives::Segment;
Expand Down Expand Up @@ -143,8 +143,8 @@ where
) -> bool {
let calculated_z = Self::calculate_z(left_cell, right_cell);
let is_pair = left_cell_metadata.is_pair(right_cell_metadata);
let is_y_equal = XValueManager::<BlockNumber>::calculate_y(farmer_id, left_cell) ==
XValueManager::<BlockNumber>::calculate_y(farmer_id, right_cell);
let is_y_equal = YValueManager::<BlockNumber>::calculate_y(farmer_id, left_cell) ==
YValueManager::<BlockNumber>::calculate_y(farmer_id, right_cell);
z == calculated_z && is_pair && is_y_equal
}
}
Expand Down

0 comments on commit 541b13c

Please sign in to comment.