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

Commit

Permalink
Merge pull request paritytech#138 from subspace/refactor-imports
Browse files Browse the repository at this point in the history
Eliminate wildcard imports (except prelude) to make it clearer what is imported where
  • Loading branch information
nazar-pc authored Nov 17, 2021
2 parents cd524c4 + 5cca17b commit b41f20f
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 68 deletions.
4 changes: 1 addition & 3 deletions crates/pallet-feeds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

use core::mem;
pub use pallet::*;
use sp_std::vec::Vec;
use subspace_core_primitives::{crypto, Sha256Hash};

#[cfg(all(feature = "std", test))]
Expand All @@ -31,11 +30,10 @@ mod tests;

#[frame_support::pallet]
mod pallet {
use super::*;
use frame_support::dispatch::DispatchResult;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use scale_info::TypeInfo;
use sp_std::prelude::*;

#[pallet::config]
pub trait Config: frame_system::Config {
Expand Down
3 changes: 2 additions & 1 deletion crates/pallet-feeds/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{mock::*, Error, FeedId, ObjectMetadata, PutDataObject, TotalObjectsAndSize};
use crate::mock::{new_test_ext, Event, Feeds, Origin, System, Test};
use crate::{Error, FeedId, ObjectMetadata, PutDataObject, TotalObjectsAndSize};
use frame_support::{assert_noop, assert_ok};

const FEED_ID: FeedId = 0;
Expand Down
12 changes: 7 additions & 5 deletions crates/pallet-offences-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@ mod mock;
mod tests;

use codec::{Decode, Encode};
pub use pallet::*;
use sp_consensus_subspace::{
offence::{Kind, Offence, OffenceDetails, OffenceError, OnOffenceHandler, ReportOffence},
offence::{Offence, OffenceDetails, OffenceError, OnOffenceHandler, ReportOffence},
FarmerPublicKey,
};
use sp_runtime::traits::Hash;
use sp_std::prelude::*;

pub use pallet::*;

/// A binary blob which represents a SCALE codec-encoded `O::TimeSlot`.
type OpaqueTimeSlot = Vec<u8>;

/// A type alias for a report identifier.
type ReportIdOf<T> = <T as frame_system::Config>::Hash;

#[frame_support::pallet]
pub mod pallet {
use super::*;
mod pallet {
use super::{OpaqueTimeSlot, ReportIdOf};
use frame_support::pallet_prelude::*;
use sp_consensus_subspace::offence::{Kind, OffenceDetails, OnOffenceHandler};
use sp_consensus_subspace::FarmerPublicKey;
use sp_std::prelude::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
Expand Down
4 changes: 3 additions & 1 deletion crates/pallet-offences-subspace/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

#![cfg(test)]

use super::*;
use crate::mock::{
new_test_ext, offence_reports, report_id, with_on_offence_fractions, Event, Offence,
OffencesSubspace, System, KIND,
};
use codec::{Decode, Encode};
use frame_system::{EventRecord, Phase};
use schnorrkel::Keypair;
use sp_consensus_subspace::offence::{OffenceDetails, OffenceError, ReportOffence};
use sp_consensus_subspace::FarmerPublicKey;
use sp_core::Public;
use sp_runtime::Perbill;

Expand Down
9 changes: 5 additions & 4 deletions crates/pallet-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ pub use pallet::*;
use sp_consensus_subspace::digests::PreDigest;
use sp_consensus_subspace::SUBSPACE_ENGINE_ID;

type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

pub trait WeightInfo {
fn on_initialize() -> Weight;
}

#[frame_support::pallet]
mod pallet {
use super::*;
use super::WeightInfo;
use frame_support::pallet_prelude::*;
use frame_support::traits::Currency;
use frame_system::pallet_prelude::*;

type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

#[pallet::config]
pub trait Config: frame_system::Config {
/// `pallet-rewards` events
Expand Down
27 changes: 16 additions & 11 deletions crates/pallet-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ mod tests;

use codec::{Decode, Encode};
use equivocation::{HandleEquivocation, SubspaceEquivocationOffence};
use frame_support::inherent::{InherentData, InherentIdentifier, ProvideInherent};
use frame_support::{
dispatch::{DispatchResult, DispatchResultWithPostInfo},
traits::{ConstU32, Get, OnTimestampSet},
Expand All @@ -41,11 +40,10 @@ use frame_support::{
use num_traits::float::FloatCore;
pub use pallet::*;
use sp_consensus_slots::Slot;
use sp_consensus_subspace::inherents::{InherentError, InherentType, INHERENT_IDENTIFIER};
use sp_consensus_subspace::{
digests::{
NextConfigDescriptor, NextEpochDescriptor, NextSaltDescriptor, NextSolutionRangeDescriptor,
PreDigest, SaltDescriptor, SolutionRangeDescriptor,
NextEpochDescriptor, NextSaltDescriptor, NextSolutionRangeDescriptor, PreDigest,
SaltDescriptor, SolutionRangeDescriptor,
},
offence::{OffenceDetails, OnOffenceHandler},
ConsensusLog, Epoch, EquivocationProof, FarmerPublicKey, SubspaceEpochConfiguration,
Expand All @@ -60,7 +58,7 @@ use sp_runtime::{
traits::{One, SaturatedConversion, Saturating, Zero},
};
use sp_std::prelude::*;
use subspace_core_primitives::{RootBlock, Sha256Hash, RANDOMNESS_LENGTH};
use subspace_core_primitives::{RootBlock, RANDOMNESS_LENGTH};

pub trait WeightInfo {
fn plan_config_change() -> Weight;
Expand Down Expand Up @@ -121,15 +119,22 @@ impl EonChangeTrigger for NormalEonChange {
}
}

const UNDER_CONSTRUCTION_SEGMENT_LENGTH: u32 = 256;

type MaybeRandomness = Option<subspace_core_primitives::Randomness>;

#[frame_support::pallet]
pub mod pallet {
use super::*;
mod pallet {
use super::{EonChangeTrigger, EpochChangeTrigger, EraChangeTrigger, WeightInfo};
use crate::equivocation::HandleEquivocation;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use sp_consensus_slots::Slot;
use sp_consensus_subspace::digests::NextConfigDescriptor;
use sp_consensus_subspace::inherents::{InherentError, InherentType, INHERENT_IDENTIFIER};
use sp_consensus_subspace::{EquivocationProof, FarmerPublicKey, SubspaceEpochConfiguration};
use sp_std::prelude::*;
use subspace_core_primitives::{RootBlock, Sha256Hash};

pub(super) const UNDER_CONSTRUCTION_SEGMENT_LENGTH: u32 = 256;

pub(super) type MaybeRandomness = Option<subspace_core_primitives::Randomness>;

/// The Subspace Pallet
#[pallet::pallet]
Expand Down
21 changes: 17 additions & 4 deletions crates/pallet-subspace/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,35 @@

//! Consensus extension module tests for Subspace consensus.

use super::{Call, *};
use crate::mock::{
create_root_block, generate_equivocation_proof, go_to_block, make_pre_digest, new_test_ext,
progress_to_block, Event, Origin, ReportLongevity, Subspace, System, Test,
INITIAL_SOLUTION_RANGE, SLOT_PROBABILITY,
};
use crate::{
compute_randomness, Call, Config, CurrentSlot, EpochConfig, EpochStart, Error, NextEpochConfig,
NextRandomness, SegmentIndex, UnderConstruction, WeightInfo,
};
use codec::Encode;
use frame_support::weights::Pays;
use frame_support::{
assert_err, assert_noop, assert_ok, traits::OnFinalize, weights::GetDispatchInfo,
};
use frame_system::{EventRecord, Phase};
use mock::{Event, *};
use schnorrkel::Keypair;
use sp_consensus_slots::Slot;
use sp_consensus_subspace::{digests::Solution, SubspaceEpochConfiguration};
use sp_consensus_subspace::digests::NextConfigDescriptor;
use sp_consensus_subspace::{
digests::Solution, FarmerPublicKey, SubspaceEpochConfiguration, SUBSPACE_ENGINE_ID,
};
use sp_core::Public;
use sp_runtime::traits::Header;
use sp_runtime::transaction_validity::{
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
ValidTransaction,
};
use sp_runtime::DispatchError;
use sp_runtime::{DigestItem, DispatchError};
use subspace_core_primitives::RANDOMNESS_LENGTH;

const EMPTY_RANDOMNESS: [u8; 32] = [
74, 25, 49, 128, 53, 97, 244, 49, 222, 202, 176, 2, 231, 66, 95, 10, 133, 49, 213, 228, 86,
Expand Down
23 changes: 22 additions & 1 deletion crates/sc-consensus-subspace/src/authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,28 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use super::*;
use crate::slot_worker::SubspaceSlotWorker;
use crate::{subspace_err, verification, Epoch, Error, NewSlotInfo, NewSlotNotification};
use futures::StreamExt;
use log::{debug, trace, warn};
use sc_consensus::block_import::BlockImport;
use sc_consensus_epochs::ViableEpochDescriptor;
use sc_consensus_slots::BackoffAuthoringBlocksStrategy;
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver};
use schnorrkel::SecretKey;
use sp_api::{NumberFor, ProvideRuntimeApi};
use sp_blockchain::{Error as ClientError, HeaderBackend, HeaderMetadata, ProvideCache};
use sp_consensus::{Environment, Error as ConsensusError, Proposer, SyncOracle};
use sp_consensus_slots::Slot;
use sp_consensus_subspace::digests::{
CompatibleDigestItem, NextSaltDescriptor, NextSolutionRangeDescriptor, PreDigest, Solution,
};
use sp_consensus_subspace::{ConsensusLog, SubspaceApi, SUBSPACE_ENGINE_ID};
use sp_core::sr25519::Pair;
use sp_runtime::generic::{BlockId, OpaqueDigestItemId};
use sp_runtime::traits::{Block as BlockT, DigestItemFor, Header, Zero};
pub use subspace_archiving::archiver::ArchivedSegment;
use subspace_core_primitives::{Randomness, Salt};

type EpochData<B> = ViableEpochDescriptor<<B as BlockT>::Hash, NumberFor<B>, Epoch>;

Expand Down
38 changes: 17 additions & 21 deletions crates/sc-consensus-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@
#![forbid(unsafe_code)]
#![warn(missing_docs)]

pub use self::archiver::start_subspace_archiver;
mod archiver;
mod authorship;
pub mod aux_schema;
pub mod notification;
mod slot_worker;
#[cfg(test)]
mod tests;
mod verification;

use crate::notification::{SubspaceNotificationSender, SubspaceNotificationStream};
use crate::slot_worker::SubspaceSlotWorker;
pub use archiver::start_subspace_archiver;
use codec::{Decode, Encode};
use futures::channel::{mpsc, oneshot};
use futures::{future, FutureExt, SinkExt, StreamExt, TryFutureExt};
use futures::{future, FutureExt, SinkExt, StreamExt};
use log::{debug, info, log, trace, warn};
use lru::LruCache;
use parking_lot::Mutex;
Expand All @@ -62,7 +71,6 @@ use sc_client_api::{backend::AuxStore, BlockchainEvents, ProvideUncles, UsagePro
use sc_consensus::{
block_import::{
BlockCheckParams, BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult,
StateAction,
},
import_queue::{BasicQueue, BoxJustificationImport, DefaultImportQueue, Verifier},
};
Expand All @@ -71,12 +79,11 @@ use sc_consensus_epochs::{
};
use sc_consensus_slots::{
check_equivocation, BackoffAuthoringBlocksStrategy, CheckedHeader, InherentDataProviderExt,
SimpleSlotWorker, SlotInfo, SlotProportion, StorageChanges,
SlotProportion,
};
use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_TRACE};
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use sc_utils::mpsc::TracingUnboundedSender;
use schnorrkel::context::SigningContext;
use schnorrkel::SecretKey;
use sp_api::{ApiExt, NumberFor, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::{
Expand All @@ -88,35 +95,24 @@ use sp_consensus::{
};
use sp_consensus_slots::Slot;
use sp_consensus_subspace::digests::{
CompatibleDigestItem, NextConfigDescriptor, NextEpochDescriptor, NextSaltDescriptor,
NextSolutionRangeDescriptor, PreDigest, SaltDescriptor, Solution, SolutionRangeDescriptor,
CompatibleDigestItem, NextConfigDescriptor, NextEpochDescriptor, PreDigest, SaltDescriptor,
Solution, SolutionRangeDescriptor,
};
use sp_consensus_subspace::inherents::{InherentType, SubspaceInherentData};
use sp_consensus_subspace::{
ConsensusLog, FarmerPublicKey, SubspaceApi, SubspaceEpochConfiguration,
SubspaceGenesisConfiguration, SUBSPACE_ENGINE_ID,
};
use sp_core::sr25519::Pair;
use sp_core::{ExecutionContext, Pair as PairTrait};
use sp_core::ExecutionContext;
use sp_inherents::{CreateInherentDataProviders, InherentData, InherentDataProvider};
use sp_runtime::generic::{BlockId, OpaqueDigestItemId};
use sp_runtime::traits::{Block as BlockT, DigestItemFor, Header, One, Zero};
use std::cmp::Ordering;
use std::future::Future;
use std::{borrow::Cow, collections::HashMap, pin::Pin, sync::Arc, time::Duration, u64};
use std::{borrow::Cow, collections::HashMap, pin::Pin, sync::Arc, time::Duration};
pub use subspace_archiving::archiver::ArchivedSegment;
use subspace_core_primitives::{Randomness, RootBlock, Salt, Tag};
use subspace_solving::SOLUTION_SIGNING_CONTEXT;

mod archiver;
mod authorship;
pub mod aux_schema;
pub mod notification;
mod slot_worker;
#[cfg(test)]
mod tests;
mod verification;

/// Information about new slot that just arrived
#[derive(Debug, Copy, Clone)]
pub struct NewSlotInfo {
Expand Down
23 changes: 22 additions & 1 deletion crates/sc-consensus-subspace/src/slot_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,28 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use super::*;
use crate::{
authorship, find_pre_digest, Epoch, SubspaceIntermediate, SubspaceLink, INTERMEDIATE_KEY,
};
use futures::TryFutureExt;
use sc_consensus::block_import::{BlockImport, BlockImportParams, StateAction};
use sc_consensus_epochs::{descendent_query, ViableEpochDescriptor};
use sc_consensus_slots::{
BackoffAuthoringBlocksStrategy, SimpleSlotWorker, SlotInfo, SlotProportion, StorageChanges,
};
use sc_telemetry::TelemetryHandle;
use schnorrkel::context::SigningContext;
use sp_api::{NumberFor, ProvideRuntimeApi};
use sp_blockchain::{Error as ClientError, HeaderBackend, HeaderMetadata, ProvideCache};
use sp_consensus::{BlockOrigin, Environment, Error as ConsensusError, Proposer, SyncOracle};
use sp_consensus_slots::Slot;
use sp_consensus_subspace::digests::{CompatibleDigestItem, PreDigest};
use sp_consensus_subspace::SubspaceApi;
use sp_core::sr25519::Pair;
use sp_core::Pair as _;
use sp_runtime::traits::{Block as BlockT, DigestItemFor, Header};
use std::future::Future;
use std::{borrow::Cow, pin::Pin, sync::Arc};

pub(super) struct SubspaceSlotWorker<B: BlockT, C, E, I, SO, L, BS> {
pub(super) client: Arc<C>,
Expand Down
Loading

0 comments on commit b41f20f

Please sign in to comment.