Skip to content

Commit

Permalink
refactor: resolve various warnings during build or by clippy (#1761)
Browse files Browse the repository at this point in the history
  • Loading branch information
PastaPastaPasta authored Mar 10, 2024
1 parent 1e5569a commit e831503
Show file tree
Hide file tree
Showing 70 changed files with 187 additions and 209 deletions.
1 change: 1 addition & 0 deletions packages/dapi-grpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub use prost::Message;

#[cfg(feature = "core")]
pub mod core {
#![allow(non_camel_case_types)]
pub mod v0 {
include!("core/proto/org.dash.platform.dapi.v0.rs");
}
Expand Down
6 changes: 3 additions & 3 deletions packages/rs-dpp/src/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ pub mod signer;

pub mod accessors;
pub(crate) mod conversion;
mod fields;
pub mod fields;
#[cfg(feature = "client")]
mod identity_facade;
#[cfg(feature = "factories")]
pub mod identity_factory;
pub mod identity_nonce;
mod methods;
pub mod methods;
#[cfg(feature = "random-identities")]
pub mod random;
mod v0;
pub mod v0;
pub mod versions;

pub use fields::*;
Expand Down
4 changes: 3 additions & 1 deletion packages/rs-dpp/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::identity::KeyType;
use crate::serialization::PlatformMessageSignable;
#[cfg(feature = "message-signature-verification")]
use crate::validation::SimpleConsensusValidationResult;
use crate::{BlsModule, ProtocolError};
#[cfg(feature = "message-signing")]
use crate::BlsModule;
use crate::ProtocolError;
use dashcore::signer;

impl PlatformMessageSignable for &[u8] {
Expand Down
14 changes: 7 additions & 7 deletions packages/rs-dpp/src/state_transition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ use crate::identity::identity_public_key::accessors::v0::IdentityPublicKeyGetter
#[cfg(feature = "state-transition-signing")]
use crate::identity::signer::Signer;
use crate::identity::state_transition::OptionallyAssetLockProved;
#[cfg(feature = "state-transition-signing")]
use crate::identity::Purpose;
#[cfg(any(
feature = "state-transition-signing",
feature = "state-transition-validation"
))]
use crate::identity::{IdentityPublicKey, KeyType, Purpose};
use crate::identity::{IdentityPublicKey, KeyType};
use crate::identity::{KeyID, SecurityLevel};
use crate::prelude::{AssetLockProof, UserFeeIncrease};
pub use state_transitions::*;
Expand All @@ -76,15 +78,13 @@ use crate::state_transition::data_contract_update_transition::{
use crate::state_transition::documents_batch_transition::{
DocumentsBatchTransition, DocumentsBatchTransitionSignable,
};
#[cfg(any(
feature = "state-transition-signing",
feature = "state-transition-validation"
))]
#[cfg(feature = "state-transition-signing")]
use crate::state_transition::errors::InvalidSignaturePublicKeyError;
#[cfg(feature = "state-transition-signing")]
use crate::state_transition::errors::WrongPublicKeyPurposeError;
#[cfg(feature = "state-transition-validation")]
use crate::state_transition::errors::{
InvalidIdentityPublicKeyTypeError, InvalidSignaturePublicKeyError, PublicKeyMismatchError,
StateTransitionIsNotSignedError,
InvalidIdentityPublicKeyTypeError, PublicKeyMismatchError, StateTransitionIsNotSignedError,
};
use crate::state_transition::identity_create_transition::{
IdentityCreateTransition, IdentityCreateTransitionSignable,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod from_document;
pub mod v0;
mod v0_methods;
pub mod v0_methods;

use bincode::{Decode, Encode};
use derive_more::{Display, From};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod from_document;
pub mod v0;
mod v0_methods;
pub mod v0_methods;

use crate::document::Document;
use crate::ProtocolError;
Expand Down
3 changes: 3 additions & 0 deletions packages/rs-dpp/src/util/deserializer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#[cfg(feature = "cbor")]
use crate::consensus::basic::decode::ProtocolVersionParsingError;
#[cfg(feature = "cbor")]
use crate::consensus::basic::BasicError;
#[cfg(feature = "cbor")]
use crate::consensus::ConsensusError;
use integer_encoding::VarInt;
use platform_version::version::FeatureVersion;
Expand Down
1 change: 0 additions & 1 deletion packages/rs-drive-abci/src/abci/app/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::platform_types::platform::Platform;
use crate::rpc::core::CoreRPCLike;
use dpp::version::PlatformVersion;
use drive::grovedb::Transaction;
use std::cell::{Ref, RefCell, RefMut};
use std::fmt::Debug;
use std::sync::RwLock;
use tenderdash_abci::proto::abci as proto;
Expand Down
1 change: 0 additions & 1 deletion packages/rs-drive-abci/src/abci/handler/finalize_block.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::abci::app::{BlockExecutionApplication, PlatformApplication, TransactionalApplication};
use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::execution::types::block_execution_context::v0::BlockExecutionContextV0Getters;
use crate::rpc::core::CoreRPCLike;
use tenderdash_abci::proto::abci as proto;

Expand Down
2 changes: 0 additions & 2 deletions packages/rs-drive-abci/src/abci/handler/init_chain.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::abci::app::{BlockExecutionApplication, PlatformApplication, TransactionalApplication};
use crate::error::Error;
use crate::platform_types::platform_state::PlatformState;
use crate::rpc::core::CoreRPCLike;
use std::sync::Arc;
use tenderdash_abci::proto::abci as proto;

pub fn init_chain<'a, A, C>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ where
// special logic on init chain
let transaction_guard = app.transaction().read().unwrap();
if transaction_guard.is_none() {
return Err(Error::Abci(AbciError::BadRequest("received a prepare proposal request for the genesis height before an init chain request".to_string())))?;
Err(Error::Abci(AbciError::BadRequest("received a prepare proposal request for the genesis height before an init chain request".to_string())))?;
};
if request.round > 0 {
transaction_guard
Expand Down
10 changes: 5 additions & 5 deletions packages/rs-drive-abci/src/abci/handler/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ where
} else {
// We are getting a different block hash for a block of the same round
// This is a terrible issue
return Err(Error::Abci(AbciError::BadRequest(
Err(Error::Abci(AbciError::BadRequest(
"received a process proposal request twice with different hash".to_string(),
)));
)))?;
}
} else {
let Some(proposal_info) = block_execution_context.proposer_results() else {
return Err(Error::Abci(AbciError::BadRequest(
Err(Error::Abci(AbciError::BadRequest(
"received a process proposal request twice".to_string(),
)));
)))?
};

let expected_transactions = proposal_info
Expand Down Expand Up @@ -154,7 +154,7 @@ where
// special logic on init chain
let transaction_guard = app.transaction().read().unwrap();
if transaction_guard.is_none() {
return Err(Error::Abci(AbciError::BadRequest("received a process proposal request for the genesis height before an init chain request".to_string())));
Err(Error::Abci(AbciError::BadRequest("received a process proposal request for the genesis height before an init chain request".to_string())))?;
}
if request.round > 0 {
transaction_guard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ where

let expected_withdrawals = block_execution_context.unsigned_withdrawal_transactions();

if expected_withdrawals != &vote_extensions {
if expected_withdrawals != vote_extensions.as_slice() {
let expected_extensions: Vec<ExtendVoteExtension> = expected_withdrawals.into();

tracing::error!(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::platform_types::platform::Platform;
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::platform_types::platform_state::PlatformState;
use crate::platform_types::{block_execution_outcome, block_proposal};
use crate::rpc::core::CoreRPCLike;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::execution::types::block_execution_context::v0::BlockExecutionContextV0OwnedGetters;
use crate::platform_types::platform::Platform;
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::platform_types::platform_state::PlatformState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::rpc::core::CoreRPCLike;
use dpp::block::block_info::BlockInfo;
use dpp::version::PlatformVersion;
use drive::grovedb::Transaction;
use std::sync::Arc;

impl<C> Platform<C>
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ pub mod v0;
/// As we ask to make sure that core is synced to the chain lock, we get back one of 3
pub enum CoreSyncStatus {
/// Core is synced
CoreIsSynced,
Done,
/// Core is 1 or 2 blocks off, we should retry shortly
CoreAlmostSynced,
Almost,
/// Core is more than 2 blocks off
CoreNotSynced,
Not,
}

impl<C> Platform<C>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::rpc::core::CoreRPCLike;
use dashcore_rpc::dashcore::ChainLock;
use dpp::version::PlatformVersion;
use crate::execution::platform_events::core_chain_lock::make_sure_core_is_synced_to_chain_lock::CoreSyncStatus;
use crate::execution::platform_events::core_chain_lock::make_sure_core_is_synced_to_chain_lock::CoreSyncStatus::{CoreIsSynced, CoreAlmostSynced, CoreNotSynced};

impl<C> Platform<C>
where
Expand All @@ -21,17 +20,17 @@ where
// We need to make sure core is synced to the core height we see as valid for the state transitions
let best_chain_locked_height = self.core_rpc.submit_chain_lock(chain_lock)?;
Ok(if best_chain_locked_height >= given_chain_lock_height {
CoreIsSynced
CoreSyncStatus::Done
} else if best_chain_locked_height - given_chain_lock_height
<= platform_version
.drive_abci
.methods
.core_chain_lock
.recent_block_count_amount
{
CoreAlmostSynced
CoreSyncStatus::Almost
} else {
CoreNotSynced
CoreSyncStatus::Not
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ where
{
Ok(sync_status) => {
match sync_status {
CoreSyncStatus::CoreIsSynced => Ok(VerifyChainLockResult {
CoreSyncStatus::Done => Ok(VerifyChainLockResult {
chain_lock_signature_is_deserializable: true,
found_valid_locally: Some(true),
found_valid_by_core: None,
core_is_synced: Some(true),
}),
CoreSyncStatus::CoreAlmostSynced => {
CoreSyncStatus::Almost => {
for _i in 0..CORE_ALMOST_SYNCED_RETRIES {
// The chain lock is valid we just need to sleep a bit and retry
sleep(Duration::from_millis(CORE_ALMOST_SYNCED_SLEEP_TIME));
Expand All @@ -63,7 +63,7 @@ where
core_is_synced: Some(false),
})
}
CoreSyncStatus::CoreNotSynced => Ok(VerifyChainLockResult {
CoreSyncStatus::Not => Ok(VerifyChainLockResult {
chain_lock_signature_is_deserializable: true,
found_valid_locally: Some(valid),
found_valid_by_core: Some(true),
Expand Down Expand Up @@ -102,13 +102,13 @@ where
if let Some(sync_status) = status {
// if we had make_sure_core_is_synced set to true
match sync_status {
CoreSyncStatus::CoreIsSynced => Ok(VerifyChainLockResult {
CoreSyncStatus::Done => Ok(VerifyChainLockResult {
chain_lock_signature_is_deserializable: true,
found_valid_locally: None,
found_valid_by_core: None,
core_is_synced: Some(true),
}),
CoreSyncStatus::CoreAlmostSynced => {
CoreSyncStatus::Almost => {
for _i in 0..CORE_ALMOST_SYNCED_RETRIES {
// The chain lock is valid we just need to sleep a bit and retry
sleep(Duration::from_millis(CORE_ALMOST_SYNCED_SLEEP_TIME));
Expand All @@ -129,7 +129,7 @@ where
core_is_synced: Some(false),
})
}
CoreSyncStatus::CoreNotSynced => Ok(VerifyChainLockResult {
CoreSyncStatus::Not => Ok(VerifyChainLockResult {
chain_lock_signature_is_deserializable: true,
found_valid_locally: None,
found_valid_by_core: Some(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::error::Error;
use dpp::dashcore::ChainLock;
use dpp::version::PlatformVersion;
use crate::execution::platform_events::core_chain_lock::make_sure_core_is_synced_to_chain_lock::CoreSyncStatus;
use crate::execution::platform_events::core_chain_lock::make_sure_core_is_synced_to_chain_lock::CoreSyncStatus::{CoreAlmostSynced, CoreIsSynced, CoreNotSynced};

use crate::platform_types::platform::Platform;

Expand All @@ -24,17 +23,17 @@ where

let best_chain_locked_height = self.core_rpc.submit_chain_lock(chain_lock)?;
Ok(if best_chain_locked_height >= given_chain_lock_height {
(true, Some(CoreIsSynced))
(true, Some(CoreSyncStatus::Done))
} else if best_chain_locked_height - given_chain_lock_height
<= platform_version
.drive_abci
.methods
.core_chain_lock
.recent_block_count_amount
{
(true, Some(CoreAlmostSynced))
(true, Some(CoreSyncStatus::Almost))
} else {
(true, Some(CoreNotSynced))
(true, Some(CoreSyncStatus::Not))
})
} else {
Ok((self.core_rpc.verify_chain_lock(chain_lock)?, None))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<C> Platform<C> {
),
]);

for (_, (data_contract, identity_public_keys_set)) in &system_data_contract_types {
for (data_contract, identity_public_keys_set) in system_data_contract_types.values() {
let public_keys = [
(
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ where
self.validate_fees_of_event(&event, block_info, Some(transaction), platform_version)?;

match event {
ExecutionEvent::PaidFromAssetLockDriveEvent {
ExecutionEvent::PaidFromAssetLock {
identity,
operations,
execution_operations,
user_fee_increase,
..
}
| ExecutionEvent::PaidDriveEvent {
| ExecutionEvent::Paid {
identity,
operations,
execution_operations,
Expand Down Expand Up @@ -108,7 +108,7 @@ where
))
}
}
ExecutionEvent::FreeDriveEvent { operations } => {
ExecutionEvent::Free { operations } => {
self.drive
.apply_drive_operations(
operations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ where

StateTransitionExecutionResult::DriveAbciError(format!(
"{} {}",
first_consensus_error.to_string(),
payment_consensus_error.to_string()
first_consensus_error, payment_consensus_error
))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
platform_version: &PlatformVersion,
) -> Result<ConsensusValidationResult<FeeResult>, Error> {
match event {
ExecutionEvent::PaidFromAssetLockDriveEvent {
ExecutionEvent::PaidFromAssetLock {
identity,
added_balance,
operations,
Expand Down Expand Up @@ -94,7 +94,7 @@ where
))
}
}
ExecutionEvent::PaidDriveEvent {
ExecutionEvent::Paid {
identity,
removed_balance,
operations,
Expand Down Expand Up @@ -146,7 +146,7 @@ where
))
}
}
ExecutionEvent::FreeDriveEvent { .. } => Ok(ConsensusValidationResult::new_with_data(
ExecutionEvent::Free { .. } => Ok(ConsensusValidationResult::new_with_data(
FeeResult::default(),
)),
}
Expand Down
Loading

0 comments on commit e831503

Please sign in to comment.