From 5cca17bf12b7bcdb73329ea771e7b45c0bb84e70 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Tue, 16 Nov 2021 16:40:30 +0200 Subject: [PATCH] Eliminate wildcard imports (except prelude) to make it clearer what is imported where --- crates/pallet-feeds/src/lib.rs | 4 +- crates/pallet-feeds/src/tests.rs | 3 +- crates/pallet-offences-subspace/src/lib.rs | 12 +++-- crates/pallet-offences-subspace/src/tests.rs | 4 +- crates/pallet-rewards/src/lib.rs | 9 ++-- crates/pallet-subspace/src/lib.rs | 27 ++++++---- crates/pallet-subspace/src/tests.rs | 21 ++++++-- .../sc-consensus-subspace/src/authorship.rs | 23 ++++++++- crates/sc-consensus-subspace/src/lib.rs | 38 +++++++------- .../sc-consensus-subspace/src/slot_worker.rs | 23 ++++++++- crates/sc-consensus-subspace/src/tests.rs | 50 +++++++++++++++---- crates/subspace-runtime/src/lib.rs | 11 ++-- 12 files changed, 157 insertions(+), 68 deletions(-) diff --git a/crates/pallet-feeds/src/lib.rs b/crates/pallet-feeds/src/lib.rs index 350c87535d1e8..e70399ee93165 100644 --- a/crates/pallet-feeds/src/lib.rs +++ b/crates/pallet-feeds/src/lib.rs @@ -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))] @@ -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 { diff --git a/crates/pallet-feeds/src/tests.rs b/crates/pallet-feeds/src/tests.rs index 648aeaaedfc50..d68de7728c719 100644 --- a/crates/pallet-feeds/src/tests.rs +++ b/crates/pallet-feeds/src/tests.rs @@ -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; diff --git a/crates/pallet-offences-subspace/src/lib.rs b/crates/pallet-offences-subspace/src/lib.rs index fcfba7edd6248..4c1ff60d2011e 100644 --- a/crates/pallet-offences-subspace/src/lib.rs +++ b/crates/pallet-offences-subspace/src/lib.rs @@ -25,15 +25,14 @@ 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; @@ -41,9 +40,12 @@ type OpaqueTimeSlot = Vec; type ReportIdOf = ::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)] diff --git a/crates/pallet-offences-subspace/src/tests.rs b/crates/pallet-offences-subspace/src/tests.rs index 320f9c0c931d9..0b61d0cdd6724 100644 --- a/crates/pallet-offences-subspace/src/tests.rs +++ b/crates/pallet-offences-subspace/src/tests.rs @@ -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; diff --git a/crates/pallet-rewards/src/lib.rs b/crates/pallet-rewards/src/lib.rs index 680f37d6ccfa6..d583db9b4eb44 100644 --- a/crates/pallet-rewards/src/lib.rs +++ b/crates/pallet-rewards/src/lib.rs @@ -28,19 +28,20 @@ pub use pallet::*; use sp_consensus_subspace::digests::PreDigest; use sp_consensus_subspace::SUBSPACE_ENGINE_ID; -type BalanceOf = - <::Currency as Currency<::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 = + <::Currency as Currency<::AccountId>>::Balance; + #[pallet::config] pub trait Config: frame_system::Config { /// `pallet-rewards` events diff --git a/crates/pallet-subspace/src/lib.rs b/crates/pallet-subspace/src/lib.rs index 2c8d8ed0b5b9f..62bf47bc729d8 100644 --- a/crates/pallet-subspace/src/lib.rs +++ b/crates/pallet-subspace/src/lib.rs @@ -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}, @@ -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, @@ -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; @@ -121,15 +119,22 @@ impl EonChangeTrigger for NormalEonChange { } } -const UNDER_CONSTRUCTION_SEGMENT_LENGTH: u32 = 256; - -type MaybeRandomness = Option; - #[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; /// The Subspace Pallet #[pallet::pallet] diff --git a/crates/pallet-subspace/src/tests.rs b/crates/pallet-subspace/src/tests.rs index 4f35549a552dc..a49d5c0d11e10 100644 --- a/crates/pallet-subspace/src/tests.rs +++ b/crates/pallet-subspace/src/tests.rs @@ -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, diff --git a/crates/sc-consensus-subspace/src/authorship.rs b/crates/sc-consensus-subspace/src/authorship.rs index 373a6357068e7..cce6e2c968743 100644 --- a/crates/sc-consensus-subspace/src/authorship.rs +++ b/crates/sc-consensus-subspace/src/authorship.rs @@ -14,7 +14,28 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -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 = ViableEpochDescriptor<::Hash, NumberFor, Epoch>; diff --git a/crates/sc-consensus-subspace/src/lib.rs b/crates/sc-consensus-subspace/src/lib.rs index c3f8ad6dcf202..04833b5e20846 100644 --- a/crates/sc-consensus-subspace/src/lib.rs +++ b/crates/sc-consensus-subspace/src/lib.rs @@ -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; @@ -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}, }; @@ -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::{ @@ -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 { diff --git a/crates/sc-consensus-subspace/src/slot_worker.rs b/crates/sc-consensus-subspace/src/slot_worker.rs index 7bedc1dc9d02a..04fd38680cc2e 100644 --- a/crates/sc-consensus-subspace/src/slot_worker.rs +++ b/crates/sc-consensus-subspace/src/slot_worker.rs @@ -15,7 +15,28 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -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 { pub(super) client: Arc, diff --git a/crates/sc-consensus-subspace/src/tests.rs b/crates/sc-consensus-subspace/src/tests.rs index e493f4e6d3a3d..9ad18e8feca65 100644 --- a/crates/sc-consensus-subspace/src/tests.rs +++ b/crates/sc-consensus-subspace/src/tests.rs @@ -17,15 +17,28 @@ //! PoC testsuite -use super::*; +use crate::{ + find_pre_digest, start_subspace, Config, Epoch, NewSlotNotification, SubspaceIntermediate, + SubspaceLink, SubspaceParams, SubspaceVerifier, INTERMEDIATE_KEY, +}; +use codec::Encode; +use futures::channel::oneshot; use futures::executor::block_on; -use log::debug; +use futures::{future, SinkExt, StreamExt}; +use log::{debug, trace}; use parking_lot::Mutex; use rand::prelude::*; use sc_block_builder::{BlockBuilder, BlockBuilderProvider}; -use sc_client_api::{backend::TransactionFor, BlockchainEvents}; -use sc_consensus::{BoxBlockImport, BoxJustificationImport}; -use sc_consensus_slots::BackoffAuthoringOnFinalizedHeadLagging; +use sc_client_api::backend::TransactionFor; +use sc_client_api::BlockchainEvents; +use sc_consensus::block_import::ForkChoiceStrategy; +use sc_consensus::{ + BlockCheckParams, BlockImport, BlockImportParams, BoxBlockImport, BoxJustificationImport, + ImportResult, Verifier, +}; +use sc_consensus_epochs::descendent_query; +use sc_consensus_epochs::SharedEpochChanges; +use sc_consensus_slots::{BackoffAuthoringOnFinalizedHeadLagging, SlotProportion}; use sc_network::config::ProtocolConfig; use sc_network_test::{ BlockImportAdapter, Peer, PeersClient, PeersFullClient, TestClientBuilder, @@ -33,20 +46,35 @@ use sc_network_test::{ }; use sc_service::TaskManager; use schnorrkel::Keypair; -use sp_consensus::{AlwaysCanAuthor, DisableProofRecording, NoNetwork as DummyOracle, Proposal}; +use sp_api::{HeaderT, ProvideRuntimeApi}; +use sp_consensus::{ + AlwaysCanAuthor, BlockOrigin, CacheKeyId, DisableProofRecording, Environment, + NoNetwork as DummyOracle, Proposal, Proposer, +}; use sp_consensus_slots::Slot; +use sp_consensus_subspace::digests::{ + CompatibleDigestItem, NextEpochDescriptor, PreDigest, SaltDescriptor, Solution, + SolutionRangeDescriptor, +}; use sp_consensus_subspace::inherents::InherentDataProvider; -use sp_core::Public; -use sp_runtime::{ - generic::DigestItem, - traits::{Block as BlockT, DigestFor}, +use sp_consensus_subspace::{ + ConsensusLog, FarmerPublicKey, SubspaceApi, SubspaceEpochConfiguration, SUBSPACE_ENGINE_ID, }; +use sp_core::Public; +use sp_inherents::{CreateInherentDataProviders, InherentData}; +use sp_runtime::generic::{BlockId, DigestItem}; +use sp_runtime::traits::{Block as BlockT, DigestFor, Zero}; use sp_timestamp::InherentDataProvider as TimestampInherentDataProvider; +use std::borrow::Cow; +use std::collections::HashMap; +use std::future::Future; +use std::pin::Pin; +use std::sync::Arc; use std::{cell::RefCell, task::Poll, time::Duration}; use subspace_archiving::archiver::ObjectArchiver; use subspace_archiving::pre_genesis_data; use subspace_core_primitives::{LocalChallenge, Piece, Signature, Tag}; -use subspace_solving::SubspaceCodec; +use subspace_solving::{SubspaceCodec, SOLUTION_SIGNING_CONTEXT}; use substrate_test_runtime::{Block as TestBlock, Hash}; type Item = DigestItem; diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index cd890bb16f658..6167290319fe5 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -38,7 +38,7 @@ use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, Verify}; use sp_runtime::{ - create_runtime_str, generic, impl_opaque_keys, + create_runtime_str, generic, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, MultiSignature, Perbill, }; @@ -76,14 +76,15 @@ pub type Moment = u64; /// of data like extrinsics, allowing for them to continue syncing the network through upgrades /// to even the core data structures. pub mod opaque { - use super::*; - - use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; + use super::{BlockNumber, Subspace}; + use sp_runtime::traits::BlakeTwo256; + use sp_runtime::{generic, impl_opaque_keys, OpaqueExtrinsic}; + use sp_std::vec::Vec; /// Opaque block header type. pub type Header = generic::Header; /// Opaque block type. - pub type Block = generic::Block; + pub type Block = generic::Block; /// Opaque block identifier type. pub type BlockId = generic::BlockId;