Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Unify function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed May 29, 2022
1 parent 74c10ce commit 03977f4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
10 changes: 5 additions & 5 deletions crates/pallet-subspace/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test>;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -388,10 +389,9 @@ pub fn create_signed_vote(
) -> SignedVote<u64, <Block as BlockT>::Hash, <Test as frame_system::Config>::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::<u64, <Block as BlockT>::Hash, _>::V0 {
height,
Expand Down
4 changes: 2 additions & 2 deletions crates/sc-consensus-subspace/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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::<u64>::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 {
Expand Down
6 changes: 3 additions & 3 deletions crates/sp-consensus-subspace/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -206,7 +206,7 @@ fn check_piece_tag<Header, RewardAddress>(
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));
}

Expand Down
9 changes: 4 additions & 5 deletions crates/subspace-farmer/src/commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -136,7 +137,7 @@ impl Commitments {

let tags: Vec<Tag> = 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..) {
Expand Down Expand Up @@ -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)?;
}
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/subspace-farmer/src/plotting/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions test/subspace-test-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -161,7 +161,7 @@ async fn start_farming<Client>(
}) = new_slot_notification_stream.next().await
{
if Into::<u64>::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 {
Expand Down

0 comments on commit 03977f4

Please sign in to comment.