Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr authored and ggwpez committed May 7, 2024
1 parent 428a654 commit b8828a2
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 53 deletions.
26 changes: 11 additions & 15 deletions polkadot/node/core/runtime-api/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ use schnellru::{ByLength, LruMap};
use sp_consensus_babe::Epoch;

use polkadot_primitives::{
async_backing, slashing,
vstaging::{self, ApprovalVotingParams},
AuthorityDiscoveryId, BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash,
CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams, GroupRotationInfo, Hash,
Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption,
PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo,
ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
async_backing, slashing, ApprovalVotingParams, AuthorityDiscoveryId, BlockNumber,
CandidateCommitments, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreIndex,
CoreState, DisputeState, ExecutorParams, GroupRotationInfo, Hash, Id as ParaId,
InboundDownwardMessage, InboundHrmpMessage, NodeFeatures, OccupiedCoreAssumption,
PersistedValidationData, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode,
ValidationCodeHash, ValidatorId, ValidatorIndex,
};

/// For consistency we have the same capacity for all caches. We use 128 as we'll only need that
Expand Down Expand Up @@ -531,7 +530,7 @@ pub(crate) enum RequestResult {
// The structure of each variant is (relay_parent, [params,]*, result)
Authorities(Hash, Vec<AuthorityDiscoveryId>),
Validators(Hash, Vec<ValidatorId>),
MinimumBackingVotes(Hash, SessionIndex, u32),
MinimumBackingVotes(SessionIndex, u32),
ValidatorGroups(Hash, (Vec<Vec<ValidatorIndex>>, GroupRotationInfo)),
AvailabilityCores(Hash, Vec<CoreState>),
PersistedValidationData(Hash, ParaId, OccupiedCoreAssumption, Option<PersistedValidationData>),
Expand Down Expand Up @@ -559,19 +558,16 @@ pub(crate) enum RequestResult {
FetchOnChainVotes(Hash, Option<ScrapedOnChainVotes>),
PvfsRequirePrecheck(Hash, Vec<ValidationCodeHash>),
// This is a request with side-effects and no result, hence ().
SubmitPvfCheckStatement(Hash, PvfCheckStatement, ValidatorSignature, ()),
#[allow(dead_code)]
SubmitPvfCheckStatement(()),
ValidationCodeHash(Hash, ParaId, OccupiedCoreAssumption, Option<ValidationCodeHash>),
Version(Hash, u32),
Disputes(Hash, Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>),
UnappliedSlashes(Hash, Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>),
KeyOwnershipProof(Hash, ValidatorId, Option<slashing::OpaqueKeyOwnershipProof>),
// This is a request with side-effects.
SubmitReportDisputeLost(
Hash,
slashing::DisputeProof,
slashing::OpaqueKeyOwnershipProof,
Option<()>,
),
#[allow(dead_code)]
SubmitReportDisputeLost(Option<()>),
ApprovalVotingParams(Hash, SessionIndex, ApprovalVotingParams),
DisabledValidators(Hash, Vec<ValidatorIndex>),
ParaBackingState(Hash, ParaId, Option<async_backing::BackingState>),
Expand Down
19 changes: 11 additions & 8 deletions polkadot/node/core/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ where
self.requests_cache.cache_authorities(relay_parent, authorities),
Validators(relay_parent, validators) =>
self.requests_cache.cache_validators(relay_parent, validators),
MinimumBackingVotes(_, session_index, minimum_backing_votes) => self
MinimumBackingVotes(session_index, minimum_backing_votes) => self
.requests_cache
.cache_minimum_backing_votes(session_index, minimum_backing_votes),
ValidatorGroups(relay_parent, groups) =>
Expand Down Expand Up @@ -152,7 +152,7 @@ where
self.requests_cache.cache_on_chain_votes(relay_parent, scraped),
PvfsRequirePrecheck(relay_parent, pvfs) =>
self.requests_cache.cache_pvfs_require_precheck(relay_parent, pvfs),
SubmitPvfCheckStatement(_, _, _, ()) => {},
SubmitPvfCheckStatement(()) => {},
ValidationCodeHash(relay_parent, para_id, assumption, hash) => self
.requests_cache
.cache_validation_code_hash((relay_parent, para_id, assumption), hash),
Expand All @@ -167,7 +167,7 @@ where
.cache_key_ownership_proof((relay_parent, validator_id), key_ownership_proof),
RequestResult::ApprovalVotingParams(_relay_parent, session_index, params) =>
self.requests_cache.cache_approval_voting_params(session_index, params),
SubmitReportDisputeLost(_, _, _, _) => {},
SubmitReportDisputeLost(_) => {},
DisabledValidators(relay_parent, disabled_validators) =>
self.requests_cache.cache_disabled_validators(relay_parent, disabled_validators),
ParaBackingState(relay_parent, para_id, constraints) => self
Expand Down Expand Up @@ -359,7 +359,7 @@ where
async fn poll_requests(&mut self) {
// If there are no active requests, this future should be pending forever.
if self.active_requests.len() == 0 {
return futures::pending!()
return futures::pending!();
}

// If there are active requests, this will always resolve to `Some(_)` when a request is
Expand Down Expand Up @@ -428,7 +428,7 @@ where
}};
($req_variant:ident, $api_name:ident ($($param:expr),*), ver = $version:expr, $sender:expr, result = ( $($results:expr),* ) ) => {{
let sender = $sender;
let version: u32 = $version; // enforce type for the version expression
let version: u32 = $version; // enforce type for the version expression
let runtime_version = client.api_version_parachain_host(relay_parent).await
.unwrap_or_else(|e| {
gum::warn!(
Expand Down Expand Up @@ -552,7 +552,8 @@ where
SubmitPvfCheckStatement,
submit_pvf_check_statement(stmt, signature),
ver = 2,
sender
sender,
result = ()
)
},
Request::PvfsRequirePrecheck(sender) => {
Expand Down Expand Up @@ -588,13 +589,15 @@ where
SubmitReportDisputeLost,
submit_report_dispute_lost(dispute_proof, key_ownership_proof),
ver = Request::SUBMIT_REPORT_DISPUTE_LOST_RUNTIME_REQUIREMENT,
sender
sender,
result = ()
),
Request::MinimumBackingVotes(index, sender) => query!(
MinimumBackingVotes,
minimum_backing_votes(index),
ver = Request::MINIMUM_BACKING_VOTES_RUNTIME_REQUIREMENT,
sender
sender,
result = (index)
),
Request::DisabledValidators(sender) => query!(
DisabledValidators,
Expand Down
1 change: 1 addition & 0 deletions polkadot/node/network/approval-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ enum ApprovalEntryError {
InvalidCandidateIndex,
DuplicateApproval,
UnknownAssignment,
#[allow(dead_code)]
AssignmentsFollowedDifferentPaths(RequiredRouting, RequiredRouting),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ enum AdvertisementError {
/// parent.
ProtocolMisuse,
/// Advertisement is invalid.
#[allow(dead_code)]
Invalid(InsertAdvertisementError),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::collections::{HashMap, HashSet};

use futures::{future::RemoteHandle, Future, FutureExt};
use futures::{Future, FutureExt};

use polkadot_node_network_protocol::{
request_response::{
Expand Down Expand Up @@ -64,7 +64,7 @@ pub struct SendTask<M> {
/// Status of a particular vote/statement delivery to a particular validator.
enum DeliveryStatus {
/// Request is still in flight.
Pending(RemoteHandle<()>),
Pending,
/// Succeeded - no need to send request to this peer anymore.
Succeeded,
}
Expand Down Expand Up @@ -297,9 +297,8 @@ async fn send_requests<Context, M: 'static + Send + Sync>(
metrics.time_dispute_request(),
);

let (remote, remote_handle) = fut.remote_handle();
ctx.spawn("dispute-sender", remote.boxed()).map_err(FatalError::SpawnTask)?;
statuses.insert(receiver, DeliveryStatus::Pending(remote_handle));
ctx.spawn("dispute-sender", fut.boxed()).map_err(FatalError::SpawnTask)?;
statuses.insert(receiver, DeliveryStatus::Pending);
}

let msg = NetworkBridgeTxMessage::SendRequests(reqs, IfDisconnected::ImmediateError);
Expand Down
47 changes: 35 additions & 12 deletions polkadot/runtime/parachains/src/inclusion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,22 +388,45 @@ pub mod pallet {
const LOG_TARGET: &str = "runtime::inclusion";

/// The reason that a candidate's outputs were rejected for.
#[derive(derive_more::From)]
#[cfg_attr(feature = "std", derive(Debug))]
enum AcceptanceCheckErr<BlockNumber> {
enum AcceptanceCheckErr {
HeadDataTooLarge,
/// Code upgrades are not permitted at the current time.
PrematureCodeUpgrade,
/// The new runtime blob is too large.
NewCodeTooLarge,
/// The candidate violated this DMP acceptance criteria.
ProcessedDownwardMessages(dmp::ProcessedDownwardMessagesAcceptanceErr),
ProcessedDownwardMessages,
/// The candidate violated this UMP acceptance criteria.
UpwardMessages(UmpAcceptanceCheckErr),
UpwardMessages,
/// The candidate violated this HRMP watermark acceptance criteria.
HrmpWatermark(hrmp::HrmpWatermarkAcceptanceErr<BlockNumber>),
HrmpWatermark,
/// The candidate violated this outbound HRMP acceptance criteria.
OutboundHrmp(hrmp::OutboundHrmpAcceptanceErr),
OutboundHrmp,
}

impl From<dmp::ProcessedDownwardMessagesAcceptanceErr> for AcceptanceCheckErr {
fn from(_: dmp::ProcessedDownwardMessagesAcceptanceErr) -> Self {
Self::ProcessedDownwardMessages
}
}

impl From<UmpAcceptanceCheckErr> for AcceptanceCheckErr {
fn from(_: UmpAcceptanceCheckErr) -> Self {
Self::UpwardMessages
}
}

impl<BlockNumber> From<hrmp::HrmpWatermarkAcceptanceErr<BlockNumber>> for AcceptanceCheckErr {
fn from(_: hrmp::HrmpWatermarkAcceptanceErr<BlockNumber>) -> Self {
Self::HrmpWatermark
}
}

impl From<hrmp::OutboundHrmpAcceptanceErr> for AcceptanceCheckErr {
fn from(_: hrmp::OutboundHrmpAcceptanceErr) -> Self {
Self::OutboundHrmp
}
}

/// An error returned by [`Pallet::check_upward_messages`] that indicates a violation of one of
Expand Down Expand Up @@ -1139,7 +1162,7 @@ const fn availability_threshold(n_validators: usize) -> usize {
supermajority_threshold(n_validators)
}

impl<BlockNumber> AcceptanceCheckErr<BlockNumber> {
impl AcceptanceCheckErr {
/// Returns the same error so that it can be threaded through a needle of `DispatchError` and
/// ultimately returned from a `Dispatchable`.
fn strip_into_dispatch_err<T: Config>(self) -> Error<T> {
Expand All @@ -1148,10 +1171,10 @@ impl<BlockNumber> AcceptanceCheckErr<BlockNumber> {
HeadDataTooLarge => Error::<T>::HeadDataTooLarge,
PrematureCodeUpgrade => Error::<T>::PrematureCodeUpgrade,
NewCodeTooLarge => Error::<T>::NewCodeTooLarge,
ProcessedDownwardMessages(_) => Error::<T>::IncorrectDownwardMessageHandling,
UpwardMessages(_) => Error::<T>::InvalidUpwardMessages,
HrmpWatermark(_) => Error::<T>::HrmpWatermarkMishandling,
OutboundHrmp(_) => Error::<T>::InvalidOutboundHrmp,
ProcessedDownwardMessages => Error::<T>::IncorrectDownwardMessageHandling,
UpwardMessages => Error::<T>::InvalidUpwardMessages,
HrmpWatermark => Error::<T>::HrmpWatermarkMishandling,
OutboundHrmp => Error::<T>::InvalidOutboundHrmp,
}
}
}
Expand Down Expand Up @@ -1303,7 +1326,7 @@ impl<T: Config> CandidateCheckContext<T> {
upward_messages: &[primitives::UpwardMessage],
hrmp_watermark: BlockNumberFor<T>,
horizontal_messages: &[primitives::OutboundHrmpMessage<ParaId>],
) -> Result<(), AcceptanceCheckErr<BlockNumberFor<T>>> {
) -> Result<(), AcceptanceCheckErr> {
ensure!(
head_data.0.len() <= self.config.max_head_data_size as _,
AcceptanceCheckErr::HeadDataTooLarge,
Expand Down
12 changes: 6 additions & 6 deletions substrate/client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,15 +579,15 @@ mod tests {
type Error = sp_blockchain::Error;

struct DummyFactory(Arc<TestClient>);
struct DummyProposer(u64, Arc<TestClient>);
struct DummyProposer(Arc<TestClient>);

impl Environment<TestBlock> for DummyFactory {
type Proposer = DummyProposer;
type CreateProposer = futures::future::Ready<Result<DummyProposer, Error>>;
type Error = Error;

fn init(&mut self, parent_header: &<TestBlock as BlockT>::Header) -> Self::CreateProposer {
futures::future::ready(Ok(DummyProposer(parent_header.number + 1, self.0.clone())))
fn init(&mut self, _: &<TestBlock as BlockT>::Header) -> Self::CreateProposer {
futures::future::ready(Ok(DummyProposer(self.0.clone())))
}
}

Expand All @@ -604,9 +604,9 @@ mod tests {
_: Duration,
_: Option<usize>,
) -> Self::Proposal {
let r = BlockBuilderBuilder::new(&*self.1)
.on_parent_block(self.1.chain_info().best_hash)
.fetch_parent_block_number(&*self.1)
let r = BlockBuilderBuilder::new(&*self.0)
.on_parent_block(self.0.chain_info().best_hash)
.fetch_parent_block_number(&*self.0)
.unwrap()
.with_inherent_digests(digests)
.build()
Expand Down
10 changes: 3 additions & 7 deletions substrate/client/consensus/grandpa/src/communication/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ use std::{

#[derive(Debug)]
pub(crate) enum Event {
EventStream(TracingUnboundedSender<NetworkEvent>),
WriteNotification(PeerId, Vec<u8>),
Report(PeerId, ReputationChange),
Announce(Hash),
}

#[derive(Clone)]
Expand Down Expand Up @@ -141,9 +139,7 @@ impl NetworkEventStream for TestNetwork {
&self,
_name: &'static str,
) -> Pin<Box<dyn Stream<Item = NetworkEvent> + Send>> {
let (tx, rx) = tracing_unbounded("test", 100_000);
let _ = self.sender.unbounded_send(Event::EventStream(tx));
Box::pin(rx)
futures::stream::pending().boxed()
}
}

Expand All @@ -166,8 +162,8 @@ impl NetworkNotification for TestNetwork {
}

impl NetworkBlock<Hash, NumberFor<Block>> for TestNetwork {
fn announce_block(&self, hash: Hash, _data: Option<Vec<u8>>) {
let _ = self.sender.unbounded_send(Event::Announce(hash));
fn announce_block(&self, _: Hash, _data: Option<Vec<u8>>) {
unimplemented!();
}

fn new_best_block_imported(&self, _hash: Hash, _number: NumberFor<Block>) {
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/support/test/tests/derive_no_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use frame_support::{
};

#[derive(RuntimeDebugNoBound)]
#[allow(dead_code)]
struct Unnamed(u64);

#[test]
Expand Down

0 comments on commit b8828a2

Please sign in to comment.