diff --git a/crates/pallet-subspace/src/mock.rs b/crates/pallet-subspace/src/mock.rs index be51d892b0a38..fd45a7a4836c5 100644 --- a/crates/pallet-subspace/src/mock.rs +++ b/crates/pallet-subspace/src/mock.rs @@ -41,7 +41,8 @@ use subspace_core_primitives::{ Sha256Hash, Solution, Tag, PIECE_SIZE, }; use subspace_solving::{ - create_tag_signature, derive_local_challenge, SubspaceCodec, REWARD_SIGNING_CONTEXT, + create_tag, create_tag_signature, derive_global_challenge, derive_local_challenge, + SubspaceCodec, REWARD_SIGNING_CONTEXT, }; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; @@ -195,7 +196,7 @@ pub fn go_to_block( let piece_index = 0; let mut encoding = Piece::default(); subspace_codec.encode(&mut encoding, piece_index).unwrap(); - let tag: Tag = subspace_solving::create_tag(&encoding, { + let tag: Tag = create_tag(&encoding, { let salts = Subspace::salts(); if salts.switch_next_block { salts.next.unwrap() @@ -388,10 +389,9 @@ pub fn create_signed_vote( ) -> SignedVote::Hash, ::AccountId> { let reward_signing_context = schnorrkel::signing_context(REWARD_SIGNING_CONTEXT); - let global_challenge = - subspace_solving::derive_global_challenge(global_randomnesses, slot.into()); + let global_challenge = derive_global_challenge(global_randomnesses, slot.into()); - let tag = subspace_solving::create_tag(&encoding, salt); + let tag = create_tag(&encoding, salt); let vote = Vote::::Hash, _>::V0 { height, diff --git a/crates/sc-consensus-subspace/src/tests.rs b/crates/sc-consensus-subspace/src/tests.rs index 9f21db07d9b9e..ac6b8dbbc78f6 100644 --- a/crates/sc-consensus-subspace/src/tests.rs +++ b/crates/sc-consensus-subspace/src/tests.rs @@ -72,7 +72,7 @@ use subspace_archiving::archiver::Archiver; use subspace_core_primitives::objects::BlockObjectMapping; use subspace_core_primitives::{FlatPieces, LocalChallenge, Piece, Solution, Tag, TagSignature}; use subspace_solving::{ - create_tag_signature, derive_local_challenge, SubspaceCodec, REWARD_SIGNING_CONTEXT, + create_tag, create_tag_signature, derive_local_challenge, SubspaceCodec, REWARD_SIGNING_CONTEXT, }; use substrate_test_runtime::{Block as TestBlock, Hash}; @@ -589,7 +589,7 @@ fn run_one_test(mutator: impl Fn(&mut TestHeader, Stage) + Send + Sync + 'static }) = new_slot_notification_stream.next().await { if Into::::into(new_slot_info.slot) % 3 == (*peer_id) as u64 { - let tag: Tag = subspace_solving::create_tag(&encoding, new_slot_info.salt); + let tag: Tag = create_tag(&encoding, new_slot_info.salt); let _ = solution_sender .send(Solution { diff --git a/crates/sp-consensus-subspace/src/verification.rs b/crates/sp-consensus-subspace/src/verification.rs index e1d43b0290ad8..66766ee1db3cf 100644 --- a/crates/sp-consensus-subspace/src/verification.rs +++ b/crates/sp-consensus-subspace/src/verification.rs @@ -27,8 +27,8 @@ use sp_runtime::DigestItem; use subspace_archiving::archiver; use subspace_core_primitives::{PieceIndex, Randomness, Salt, Sha256Hash, Solution, Tag}; use subspace_solving::{ - derive_global_challenge, derive_target, verify_local_challenge, verify_tag_signature, - PieceDistance, SubspaceCodec, + derive_global_challenge, derive_target, is_tag_valid, verify_local_challenge, + verify_tag_signature, PieceDistance, SubspaceCodec, }; /// Errors encountered by the Subspace authorship task. @@ -206,7 +206,7 @@ fn check_piece_tag( where Header: HeaderT, { - if !subspace_solving::is_tag_valid(&solution.encoding, salt, solution.tag) { + if !is_tag_valid(&solution.encoding, salt, solution.tag) { return Err(VerificationError::InvalidTag(slot)); } diff --git a/crates/subspace-farmer/src/commitments.rs b/crates/subspace-farmer/src/commitments.rs index 0dad8059ba0d9..be1a05d6a173f 100644 --- a/crates/subspace-farmer/src/commitments.rs +++ b/crates/subspace-farmer/src/commitments.rs @@ -13,6 +13,7 @@ use std::io; use std::path::PathBuf; use std::sync::Arc; use subspace_core_primitives::{Piece, Salt, Tag, PIECE_SIZE}; +use subspace_solving::create_tag; use thiserror::Error; use tracing::trace; @@ -136,7 +137,7 @@ impl Commitments { let tags: Vec = pieces .par_chunks_exact(PIECE_SIZE) - .map(|piece| subspace_solving::create_tag(piece, salt)) + .map(|piece| create_tag(piece, salt)) .collect(); for (tag, offset) in tags.iter().zip(batch_start..) { @@ -198,7 +199,7 @@ impl Commitments { if let Some(db) = db_guard.as_ref() { for piece in pieces { - let tag = subspace_solving::create_tag(piece, salt); + let tag = create_tag(piece, salt); db.delete(tag).map_err(CommitmentError::CommitmentDb)?; } } @@ -236,9 +237,7 @@ impl Commitments { if let Some(db) = db_guard.as_ref() { let tags_with_offset: Vec<(PieceOffset, Tag)> = pieces_with_offsets() - .map(|(piece_offset, piece)| { - (piece_offset, subspace_solving::create_tag(piece, salt)) - }) + .map(|(piece_offset, piece)| (piece_offset, create_tag(piece, salt))) .collect(); for (piece_offset, tag) in tags_with_offset { diff --git a/crates/subspace-farmer/src/plotting/tests.rs b/crates/subspace-farmer/src/plotting/tests.rs index 8bfb86c0f8576..b2c9769580fc2 100644 --- a/crates/subspace-farmer/src/plotting/tests.rs +++ b/crates/subspace-farmer/src/plotting/tests.rs @@ -11,7 +11,7 @@ use subspace_archiving::archiver::Archiver; use subspace_core_primitives::objects::BlockObjectMapping; use subspace_core_primitives::{PieceIndexHash, Salt, PIECE_SIZE, SHA256_HASH_SIZE}; use subspace_rpc_primitives::FarmerMetadata; -use subspace_solving::SubspaceCodec; +use subspace_solving::{create_tag, SubspaceCodec}; use tempfile::TempDir; const MERKLE_NUM_LEAVES: usize = 8_usize; @@ -181,7 +181,7 @@ async fn plotting_piece_eviction() { // allow `None` and not errors once that is the case if let Ok(mut read_piece) = plot.read_piece(PieceIndexHash::from_index(piece_index)) { - let correct_tag = subspace_solving::create_tag(&read_piece, salt); + let correct_tag = create_tag(&read_piece, salt); subspace_codec.decode(&mut read_piece, piece_index).unwrap(); diff --git a/test/subspace-test-client/src/lib.rs b/test/subspace-test-client/src/lib.rs index ad9500317d834..0fd98938a20f8 100644 --- a/test/subspace-test-client/src/lib.rs +++ b/test/subspace-test-client/src/lib.rs @@ -35,7 +35,7 @@ use subspace_core_primitives::{FlatPieces, Piece, Solution, Tag}; use subspace_runtime_primitives::opaque::Block; use subspace_service::{FullClient, NewFull}; use subspace_solving::{ - create_tag_signature, derive_local_challenge, SubspaceCodec, REWARD_SIGNING_CONTEXT, + create_tag, create_tag_signature, derive_local_challenge, SubspaceCodec, REWARD_SIGNING_CONTEXT, }; use zeroize::Zeroizing; @@ -161,7 +161,7 @@ async fn start_farming( }) = new_slot_notification_stream.next().await { if Into::::into(new_slot_info.slot) % 2 == 0 { - let tag: Tag = subspace_solving::create_tag(&encoding, new_slot_info.salt); + let tag: Tag = create_tag(&encoding, new_slot_info.salt); let _ = solution_sender .send(Solution {