Skip to content

Commit

Permalink
Merge pull request #3091 from autonomys/subspace-core-primitives-refa…
Browse files Browse the repository at this point in the history
…ctoring-part-3

`subspace-core-primitives` refactoring (part 3)
  • Loading branch information
nazar-pc authored Oct 4, 2024
2 parents 95035b9 + 9fe2bf5 commit 4efd8d6
Show file tree
Hide file tree
Showing 62 changed files with 497 additions and 476 deletions.
6 changes: 3 additions & 3 deletions crates/pallet-subspace/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ mod benchmarks {
use sp_consensus_subspace::{SignedVote, Vote};
use sp_std::boxed::Box;
use sp_std::num::NonZeroU32;
use subspace_core_primitives::hashes::Blake3Hash;
use subspace_core_primitives::pot::{PotCheckpoints, PotOutput};
use subspace_core_primitives::segments::{
ArchivedBlockProgress, LastArchivedBlock, SegmentHeader, SegmentIndex,
};
use subspace_core_primitives::{
Blake3Hash, PublicKey, RewardSignature, Solution, SolutionRange,
};
use subspace_core_primitives::solutions::{RewardSignature, Solution, SolutionRange};
use subspace_core_primitives::PublicKey;

const SEED: u32 = 0;

Expand Down
10 changes: 5 additions & 5 deletions crates/pallet-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ use subspace_core_primitives::sectors::{SectorId, SectorIndex};
use subspace_core_primitives::segments::{
ArchivedHistorySegment, HistorySize, SegmentHeader, SegmentIndex,
};
use subspace_core_primitives::solutions::{RewardSignature, SolutionRange};
use subspace_core_primitives::{
BlockHash, PublicKey, RewardSignature, ScalarBytes, SlotNumber, SolutionRange,
REWARD_SIGNING_CONTEXT,
BlockHash, PublicKey, ScalarBytes, SlotNumber, REWARD_SIGNING_CONTEXT,
};
use subspace_verification::{
check_reward_signature, derive_next_solution_range, derive_pot_entropy, PieceCheckParams,
Expand Down Expand Up @@ -112,13 +112,13 @@ pub mod pallet {
use sp_std::collections::btree_map::BTreeMap;
use sp_std::num::NonZeroU32;
use sp_std::prelude::*;
use subspace_core_primitives::hashes::Blake3Hash;
use subspace_core_primitives::pieces::PieceOffset;
use subspace_core_primitives::pot::PotCheckpoints;
use subspace_core_primitives::sectors::SectorIndex;
use subspace_core_primitives::segments::{HistorySize, SegmentHeader, SegmentIndex};
use subspace_core_primitives::{
Blake3Hash, PublicKey, Randomness, RewardSignature, ScalarBytes, SolutionRange,
};
use subspace_core_primitives::solutions::{RewardSignature, SolutionRange};
use subspace_core_primitives::{PublicKey, Randomness, ScalarBytes};

pub(super) struct InitialSolutionRanges<T: Config> {
_config: T,
Expand Down
7 changes: 3 additions & 4 deletions crates/pallet-subspace/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use std::simd::Simd;
use std::sync::{Once, OnceLock};
use std::{iter, slice};
use subspace_archiving::archiver::{Archiver, NewArchivedSegment};
use subspace_core_primitives::hashes::Blake3Hash;
use subspace_core_primitives::pieces::{Piece, PieceOffset, Record};
use subspace_core_primitives::pos::PosSeed;
use subspace_core_primitives::pot::PotOutput;
Expand All @@ -43,10 +44,8 @@ use subspace_core_primitives::segments::{
ArchivedBlockProgress, ArchivedHistorySegment, HistorySize, LastArchivedBlock,
RecordedHistorySegment, SegmentCommitment, SegmentHeader, SegmentIndex,
};
use subspace_core_primitives::{
Blake3Hash, BlockNumber, PublicKey, RewardSignature, SlotNumber, Solution, SolutionRange,
REWARD_SIGNING_CONTEXT,
};
use subspace_core_primitives::solutions::{RewardSignature, Solution, SolutionRange};
use subspace_core_primitives::{BlockNumber, PublicKey, SlotNumber, REWARD_SIGNING_CONTEXT};
use subspace_erasure_coding::ErasureCoding;
use subspace_farmer_components::auditing::audit_sector_sync;
use subspace_farmer_components::plotting::{plot_sector, CpuRecordsEncoder, PlotSectorOptions};
Expand Down
3 changes: 2 additions & 1 deletion crates/pallet-subspace/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ use std::sync::{Arc, Mutex};
use subspace_core_primitives::pieces::PieceOffset;
use subspace_core_primitives::pot::PotOutput;
use subspace_core_primitives::segments::SegmentIndex;
use subspace_core_primitives::{PublicKey, RewardSignature, ScalarBytes, SolutionRange};
use subspace_core_primitives::solutions::{RewardSignature, SolutionRange};
use subspace_core_primitives::{PublicKey, ScalarBytes};
use subspace_runtime_primitives::{FindBlockRewardAddress, FindVotingRewardAddresses};

#[test]
Expand Down
4 changes: 3 additions & 1 deletion crates/sc-consensus-subspace-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Weak};
use std::time::Duration;
use subspace_archiving::archiver::NewArchivedSegment;
use subspace_core_primitives::hashes::Blake3Hash;
use subspace_core_primitives::objects::GlobalObjectMapping;
use subspace_core_primitives::pieces::{Piece, PieceIndex};
use subspace_core_primitives::segments::{HistorySize, SegmentHeader, SegmentIndex};
use subspace_core_primitives::{Blake3Hash, BlockHash, PublicKey, SlotNumber, Solution};
use subspace_core_primitives::solutions::Solution;
use subspace_core_primitives::{BlockHash, PublicKey, SlotNumber};
use subspace_erasure_coding::ErasureCoding;
use subspace_farmer_components::FarmerProtocolInfo;
use subspace_kzg::Kzg;
Expand Down
3 changes: 2 additions & 1 deletion crates/sc-consensus-subspace/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ use std::marker::PhantomData;
use std::sync::Arc;
use subspace_core_primitives::sectors::SectorId;
use subspace_core_primitives::segments::{HistorySize, SegmentHeader, SegmentIndex};
use subspace_core_primitives::{BlockNumber, PublicKey, SolutionRange};
use subspace_core_primitives::solutions::SolutionRange;
use subspace_core_primitives::{BlockNumber, PublicKey};
use subspace_proof_of_space::Table;
use subspace_verification::{calculate_block_weight, PieceCheckParams, VerifySolutionParams};
use tracing::warn;
Expand Down
5 changes: 2 additions & 3 deletions crates/sc-consensus-subspace/src/slot_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use subspace_core_primitives::pot::{PotCheckpoints, PotOutput};
use subspace_core_primitives::sectors::SectorId;
use subspace_core_primitives::{
BlockNumber, PublicKey, RewardSignature, Solution, SolutionRange, REWARD_SIGNING_CONTEXT,
};
use subspace_core_primitives::solutions::{RewardSignature, Solution, SolutionRange};
use subspace_core_primitives::{BlockNumber, PublicKey, REWARD_SIGNING_CONTEXT};
use subspace_proof_of_space::Table;
use subspace_verification::{
check_reward_signature, verify_solution, PieceCheckParams, VerifySolutionParams,
Expand Down
2 changes: 1 addition & 1 deletion crates/sc-proof-of-time/src/verifier/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::verifier::PotVerifier;
use sp_consensus_slots::Slot;
use sp_consensus_subspace::{PotNextSlotInput, PotParametersChange};
use std::num::NonZeroU32;
use subspace_core_primitives::hashes::Blake3Hash;
use subspace_core_primitives::pot::PotSeed;
use subspace_core_primitives::Blake3Hash;

const SEED: [u8; 16] = [
0xd6, 0x66, 0xcc, 0xd8, 0xd5, 0x93, 0xc2, 0x3d, 0xa8, 0xdb, 0x6b, 0x5b, 0x14, 0x13, 0xb1, 0x3a,
Expand Down
3 changes: 2 additions & 1 deletion crates/sp-consensus-subspace/src/digests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use sp_std::fmt;
use sp_std::num::NonZeroU32;
use subspace_core_primitives::pot::PotOutput;
use subspace_core_primitives::segments::{SegmentCommitment, SegmentIndex};
use subspace_core_primitives::{PublicKey, RewardSignature, Solution, SolutionRange};
use subspace_core_primitives::solutions::{RewardSignature, Solution, SolutionRange};
use subspace_core_primitives::PublicKey;

/// A Subspace pre-runtime digest. This contains all data required to validate a block and for the
/// Subspace runtime module.
Expand Down
7 changes: 3 additions & 4 deletions crates/sp-consensus-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ use sp_runtime::{ConsensusEngineId, Justification};
use sp_runtime_interface::pass_by::PassBy;
use sp_runtime_interface::{pass_by, runtime_interface};
use sp_std::num::NonZeroU32;
use subspace_core_primitives::hashes::Blake3Hash;
use subspace_core_primitives::pot::{PotCheckpoints, PotOutput, PotSeed};
use subspace_core_primitives::segments::{
HistorySize, SegmentCommitment, SegmentHeader, SegmentIndex,
};
use subspace_core_primitives::{
Blake3Hash, BlockHash, BlockNumber, PublicKey, RewardSignature, SlotNumber, Solution,
SolutionRange,
};
use subspace_core_primitives::solutions::{RewardSignature, Solution, SolutionRange};
use subspace_core_primitives::{BlockHash, BlockNumber, PublicKey, SlotNumber};
#[cfg(feature = "std")]
use subspace_kzg::Kzg;
#[cfg(feature = "std")]
Expand Down
2 changes: 1 addition & 1 deletion crates/sp-domains/src/bundle_producer_election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_core::crypto::{VrfPublic, Wraps};
use sp_core::sr25519::vrf::{VrfPreOutput, VrfSignature, VrfTranscript};
use subspace_core_primitives::Blake3Hash;
use subspace_core_primitives::hashes::Blake3Hash;

const VRF_TRANSCRIPT_LABEL: &[u8] = b"bundle_producer_election";

Expand Down
5 changes: 3 additions & 2 deletions crates/sp-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ use sp_version::RuntimeVersion;
use sp_weights::Weight;
#[cfg(feature = "std")]
use std::collections::BTreeSet;
use subspace_core_primitives::crypto::blake3_hash;
use subspace_core_primitives::hashes::{blake3_hash, Blake3Hash};
use subspace_core_primitives::pot::PotOutput;
use subspace_core_primitives::{bidirectional_distance, Blake3Hash, Randomness, U256};
use subspace_core_primitives::solutions::bidirectional_distance;
use subspace_core_primitives::{Randomness, U256};
use subspace_runtime_primitives::{Balance, Moment};

/// Key type for Operator.
Expand Down
5 changes: 1 addition & 4 deletions crates/sp-domains/src/proof_provider_and_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ extern crate alloc;
#[cfg(not(feature = "std"))]
use alloc::collections::BTreeSet;
#[cfg(not(feature = "std"))]
use alloc::fmt;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use core::fmt;
use frame_support::PalletError;
use hash_db::Hasher;
#[cfg(feature = "std")]
Expand All @@ -24,8 +23,6 @@ use sp_trie::{read_trie_value, LayoutV1, StorageProof};
#[cfg(feature = "std")]
use std::collections::BTreeSet;
#[cfg(feature = "std")]
use std::fmt;
#[cfg(feature = "std")]
use trie_db::{DBValue, TrieDBMutBuilder, TrieLayout, TrieMut};

/// Verification error.
Expand Down
4 changes: 2 additions & 2 deletions crates/subspace-archiving/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use core::cmp::Ordering;
use parity_scale_codec::{Compact, CompactLen, Decode, Encode, Input, Output};
#[cfg(feature = "parallel")]
use rayon::prelude::*;
use subspace_core_primitives::crypto::blake3_254_hash_to_scalar;
use subspace_core_primitives::hashes::{blake3_254_hash_to_scalar, Blake3Hash};
use subspace_core_primitives::objects::{
BlockObject, BlockObjectMapping, GlobalObject, PieceObject, PieceObjectMapping,
};
Expand All @@ -38,7 +38,7 @@ use subspace_core_primitives::segments::{
ArchivedBlockProgress, ArchivedHistorySegment, LastArchivedBlock, RecordedHistorySegment,
SegmentCommitment, SegmentHeader, SegmentIndex,
};
use subspace_core_primitives::{Blake3Hash, BlockNumber, ScalarBytes};
use subspace_core_primitives::{BlockNumber, ScalarBytes};
use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::{Kzg, Scalar};

Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-archiving/src/piece_reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use alloc::string::String;
use alloc::vec::Vec;
#[cfg(feature = "parallel")]
use rayon::prelude::*;
use subspace_core_primitives::crypto::blake3_254_hash_to_scalar;
use subspace_core_primitives::hashes::blake3_254_hash_to_scalar;
use subspace_core_primitives::pieces::{Piece, RawRecord};
use subspace_core_primitives::segments::ArchivedHistorySegment;
use subspace_erasure_coding::ErasureCoding;
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-archiving/tests/integration/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use std::io::Write;
use std::iter;
use std::num::NonZeroUsize;
use subspace_archiving::archiver::{Archiver, ArchiverInstantiationError, SegmentItem};
use subspace_core_primitives::hashes::Blake3Hash;
use subspace_core_primitives::objects::{BlockObject, BlockObjectMapping, PieceObject};
use subspace_core_primitives::pieces::{Piece, Record};
use subspace_core_primitives::segments::{
ArchivedBlockProgress, ArchivedHistorySegment, LastArchivedBlock, RecordedHistorySegment,
SegmentCommitment, SegmentHeader, SegmentIndex,
};
use subspace_core_primitives::Blake3Hash;
use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::Kzg;
use subspace_verification::is_piece_valid;
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-core-primitives/src/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(test)]
mod tests;

use crate::Blake3Hash;
use crate::hashes::Blake3Hash;
use parity_scale_codec::{Decode, Encode, EncodeLike, Error, Input, Output};

/// Output wrapper for SCALE codec that will write Blake3 checksum at the end of the encoding
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-core-primitives/src/checksum/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::Blake3Checksummed;
use crate::Blake3Hash;
use crate::hashes::Blake3Hash;
use parity_scale_codec::{Decode, Encode};
use rand::prelude::*;

Expand Down
57 changes: 0 additions & 57 deletions crates/subspace-core-primitives/src/crypto.rs

This file was deleted.

Loading

0 comments on commit 4efd8d6

Please sign in to comment.