Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Jul 12, 2024
1 parent a079258 commit 91f8952
Show file tree
Hide file tree
Showing 53 changed files with 58 additions and 157 deletions.
6 changes: 4 additions & 2 deletions packages/rs-dpp/src/fee/default_costs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@
//! Fee costs for Known Platform operations
//!
use crate::block::epoch::Epoch;
use std::collections::BTreeMap;
use crate::block::epoch::{Epoch, EpochIndex};
use crate::fee::Credits;
use crate::prelude::CachedEpochIndexFeeVersions;
use platform_version::version::fee::FeeVersion;
use platform_version::version::PlatformVersion;

pub mod constants;

pub type CachedEpochIndexFeeVersions = BTreeMap<EpochIndex, FeeVersion>;

/// A Known Cost Item is an item that changes costs depending on the Epoch
#[derive(Eq, PartialEq, Copy, Clone, Hash)]
pub enum KnownCostItem {
Expand Down
3 changes: 1 addition & 2 deletions packages/rs-dpp/src/fee/fee_result/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
//!
use crate::block::epoch::{Epoch, EpochIndex};
use crate::fee::default_costs::EpochCosts;
use crate::fee::default_costs::{CachedEpochIndexFeeVersions, EpochCosts};
use crate::fee::default_costs::KnownCostItem::StorageDiskUsageCreditPerByte;
use crate::fee::epoch::distribution::calculate_storage_fee_refund_amount_and_leftovers;
use crate::fee::epoch::{BytesPerEpoch, CreditsPerEpoch};
use crate::fee::Credits;
use crate::ProtocolError;
use bincode::{Decode, Encode};

use crate::prelude::CachedEpochIndexFeeVersions;
use platform_value::Identifier;
use serde::{Deserialize, Serialize};
use std::collections::btree_map::Iter;
Expand Down
4 changes: 0 additions & 4 deletions packages/rs-dpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ pub mod prelude {
pub use crate::identity::IdentityPublicKey;
#[cfg(feature = "validation")]
pub use crate::validation::ConsensusValidationResult;
use platform_version::version::fee::FeeVersion;
use std::collections::BTreeMap;

pub type BlockHeight = u64;

Expand All @@ -83,8 +81,6 @@ pub mod prelude {
/// UserFeeIncrease is the additional percentage of the processing fee.
/// A 1 here means we pay 1% more in processing fees. A 100 means we pay 100% more.
pub type UserFeeIncrease = u16;

pub type CachedEpochIndexFeeVersions = BTreeMap<EpochIndex, FeeVersion>;
}

pub use bincode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod v0;

use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;

use drive::grovedb::Transaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
use std::option::Option::None;

use dpp::block::epoch::Epoch;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;
use drive::drive::batch::DriveOperation;
use drive::drive::Drive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::platform_types::platform::Platform;
use crate::rpc::core::CoreRPCLike;
use dpp::block::block_info::BlockInfo;
use dpp::consensus::ConsensusError;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;
use drive::grovedb::Transaction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::platform_types::platform::Platform;
use crate::rpc::core::CoreRPCLike;
use dpp::block::block_info::BlockInfo;
use dpp::consensus::ConsensusError;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;
use dpp::fee::fee_result::FeeResult;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;
use drive::drive::identity::update::apply_balance_change_outcome::ApplyBalanceChangeOutcomeV0Methods;
use drive::grovedb::Transaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ use crate::execution::types::state_transition_container::v0::{
use crate::execution::validation::state_transition::processor::process_state_transition;
use crate::metrics::state_transition_execution_histogram;
use crate::platform_types::event_execution_result::EventExecutionResult;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::util::hash::hash_single;
use dpp::validation::ConsensusValidationResult;
use std::time::Instant;

use dpp::fee::default_costs::CachedEpochIndexFeeVersions;
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::platform_types::state_transitions_processing_result::{
StateTransitionExecutionResult, StateTransitionsProcessingResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use crate::platform_types::platform::Platform;

use crate::rpc::core::CoreRPCLike;
use dpp::block::block_info::BlockInfo;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;
use dpp::fee::fee_result::FeeResult;
use dpp::prelude::{CachedEpochIndexFeeVersions, ConsensusValidationResult};
use dpp::prelude::ConsensusValidationResult;
use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use crate::rpc::core::CoreRPCLike;
use dpp::block::block_info::BlockInfo;
use dpp::consensus::state::identity::IdentityInsufficientBalanceError;
use dpp::consensus::state::state_error::StateError;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;
use dpp::fee::fee_result::FeeResult;

use dpp::prelude::{CachedEpochIndexFeeVersions, ConsensusValidationResult};
use dpp::prelude::ConsensusValidationResult;
use dpp::version::PlatformVersion;

use drive::grovedb::TransactionArg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use crate::config::PlatformConfig;
use crate::error::execution::ExecutionError;
use crate::platform_types::signature_verification_quorum_set::SignatureVerificationQuorumSet;
use dpp::block::block_info::BlockInfo;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::util::hash::hash_double;
use std::collections::BTreeMap;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

/// Platform state
#[derive(Clone, Debug, From)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ use crate::config::PlatformConfig;
use crate::platform_types::signature_verification_quorum_set::{
SignatureVerificationQuorumSet, SignatureVerificationQuorumSetForSaving,
};
use dpp::prelude::CachedEpochIndexFeeVersions;
use itertools::Itertools;
use std::collections::BTreeMap;
use std::fmt::{Debug, Formatter};
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

/// Platform state
#[derive(Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use crate::error::{drive::DriveError, Error};
use dpp::block::block_info::BlockInfo;

use grovedb::TransactionArg;

use dpp::fee::default_costs::CachedEpochIndexFeeVersions;
use dpp::fee::fee_result::FeeResult;
use dpp::prelude::CachedEpochIndexFeeVersions;

use dpp::version::PlatformVersion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use grovedb::batch::KeyInfoPath;
use crate::drive::batch::drive_op_batch::finalize_task::{
DriveOperationFinalizationTasks, DriveOperationFinalizeTask,
};
use dpp::prelude::CachedEpochIndexFeeVersions;
use std::collections::HashMap;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

impl Drive {
/// Applies a list of high level DriveOperations to the drive, and calculates the fee for them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use dpp::block::block_info::BlockInfo;
use dpp::data_contract::DataContract;
use dpp::fee::fee_result::FeeResult;

use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;
use grovedb::batch::KeyInfoPath;
use grovedb::{Element, EstimatedLayerInformation, TransactionArg};
use std::collections::HashMap;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

impl Drive {
/// Updates a data contract.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use dpp::fee::fee_result::FeeResult;
use dpp::data_contract::document_type::methods::DocumentTypeV0Methods;
use dpp::serialization::PlatformSerializableWithPlatformVersion;

use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;
use grovedb::batch::KeyInfoPath;
use grovedb::{Element, EstimatedLayerInformation, TransactionArg};
use std::collections::{HashMap, HashSet};
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

impl Drive {
/// Updates a data contract.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Drive {
transaction: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<Vec<ExtendedEpochInfo>, Error> {
// TODO: We should avoid magic numbers. For now we are good since count refers to the number of epochs to fetch. With 40 epochs/year, this value is way safe atm.
// TODO: We should avoid magic numbers. For now we are good since count refers to the number of epochs to fetch and 16383 is large enough.
if count > 16383 {
return Err(Error::Query(QuerySyntaxError::InvalidLimit(format!(
"get_epochs_infos_v0 count too high {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Drive {
platform_version: &PlatformVersion,
) -> Result<BTreeMap<EpochIndex, ProtocolVersion>, Error> {
if let Some(count) = count {
// TODO: We should avoid magic numbers. For now we are good since count refers to the number of epochs to fetch. With 40 epochs/year, this value is way safe atm.
// TODO: We should avoid magic numbers. For now we are good since count refers to the number of epochs to fetch and 16383 is large enough.
if count > 16383 {
return Err(Error::Query(QuerySyntaxError::InvalidLimit(format!(
"get_epochs_protocol_versions_v0 count too high {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Drive {
transaction: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<Vec<u8>, Error> {
// TODO: We should avoid magic numbers. For now we are good since count refers to the number of epochs to fetch. With 40 epochs/year, this value is way safe atm.
// TODO: We should avoid magic numbers. For now we are good since count refers to the number of epochs to fetch and 16383 is large enough.
if count > 16383 {
return Err(Error::Query(QuerySyntaxError::InvalidLimit(format!(
"get_epochs_infos_v0 count too high {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use dpp::fee::fee_result::FeeResult;
use dpp::version::PlatformVersion;

use dpp::identifier::Identifier;
use dpp::prelude::CachedEpochIndexFeeVersions;
use grovedb::TransactionArg;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

impl Drive {
/// Deletes a document and returns the associated fee.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use dpp::data_contract::DataContract;
use dpp::fee::fee_result::FeeResult;

use dpp::identifier::Identifier;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;
use grovedb::batch::KeyInfoPath;
use grovedb::{EstimatedLayerInformation, TransactionArg};
use std::collections::HashMap;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

impl Drive {
/// Deletes a document and returns the associated fee.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod v0;
use grovedb::TransactionArg;

use dpp::block::block_info::BlockInfo;

use dpp::fee::default_costs::CachedEpochIndexFeeVersions;
use crate::drive::Drive;

use crate::error::drive::DriveError;
Expand All @@ -12,7 +12,6 @@ use crate::error::Error;

use dpp::fee::fee_result::FeeResult;
use dpp::identifier::Identifier;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;

impl Drive {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use grovedb::{EstimatedLayerInformation, TransactionArg};
use std::collections::HashMap;

use dpp::block::block_info::BlockInfo;

use dpp::fee::default_costs::CachedEpochIndexFeeVersions;
use crate::drive::Drive;
use crate::error::document::DocumentError;

Expand All @@ -14,7 +14,6 @@ use crate::fee::op::LowLevelDriveOperation;

use dpp::fee::fee_result::FeeResult;
use dpp::identifier::Identifier;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;

impl Drive {
Expand Down
3 changes: 1 addition & 2 deletions packages/rs-drive/src/drive/document/delete/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ mod tests {
use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::document::serialization_traits::DocumentPlatformConversionMethodsV0;
use dpp::document::Document;
use dpp::fee::default_costs::EpochCosts;
use dpp::fee::default_costs::{CachedEpochIndexFeeVersions, EpochCosts};
use dpp::fee::default_costs::KnownCostItem::StorageDiskUsageCreditPerByte;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::tests::json_document::{json_document_to_contract, json_document_to_document};

use crate::tests::helpers::setup::setup_drive_with_initial_state_structure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::error::Error;
use dpp::block::block_info::BlockInfo;
use dpp::fee::fee_result::FeeResult;

use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;
use grovedb::TransactionArg;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

impl Drive {
/// Adds a document to a contract.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::fee::op::LowLevelDriveOperation;
use dpp::block::block_info::BlockInfo;
use dpp::fee::fee_result::FeeResult;

use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;
use grovedb::TransactionArg;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

impl Drive {
/// Adds a document to a contract.
Expand Down
5 changes: 1 addition & 4 deletions packages/rs-drive/src/drive/document/insert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,9 @@ mod tests {

use crate::drive::object_size_info::DocumentInfo::DocumentRefInfo;
use crate::tests::helpers::setup::setup_drive_with_initial_state_structure;
use dpp::fee::default_costs::EpochCosts;
use dpp::fee::default_costs::{CachedEpochIndexFeeVersions, EpochCosts};
use dpp::fee::default_costs::KnownCostItem::StorageDiskUsageCreditPerByte;
use dpp::fee::fee_result::FeeResult;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::platform_value::{platform_value, BinaryData, Identifier};
use dpp::tests::fixtures::get_dpns_data_contract_fixture;
use dpp::tests::json_document::json_document_to_document;
use dpp::version::PlatformVersion;

Expand Down
3 changes: 1 addition & 2 deletions packages/rs-drive/src/drive/document/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ mod tests {
};
use dpp::document::specialized_document_factory::SpecializedDocumentFactory;
use dpp::document::{Document, DocumentV0Getters, DocumentV0Setters};
use dpp::fee::default_costs::EpochCosts;
use dpp::fee::default_costs::{CachedEpochIndexFeeVersions, EpochCosts};
use dpp::fee::default_costs::KnownCostItem::StorageDiskUsageCreditPerByte;
use dpp::fee::fee_result::FeeResult;
use dpp::platform_value;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::tests::json_document::json_document_to_document;
use once_cell::sync::Lazy;
use platform_version::version::PlatformVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use dpp::fee::fee_result::FeeResult;

use dpp::version::PlatformVersion;

use dpp::prelude::CachedEpochIndexFeeVersions;
use grovedb::TransactionArg;
use std::borrow::Cow;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

impl Drive {
/// Updates a document and returns the associated fee.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use dpp::data_contract::document_type::DocumentTypeRef;
use dpp::data_contract::DataContract;
use dpp::document::Document;
use dpp::fee::fee_result::FeeResult;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;
use grovedb::batch::KeyInfoPath;
use grovedb::{EstimatedLayerInformation, TransactionArg};
use std::borrow::Cow;
use std::collections::HashMap;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

impl Drive {
/// Updates a document and returns the associated fee.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use dpp::fee::fee_result::FeeResult;

use dpp::version::PlatformVersion;

use dpp::prelude::CachedEpochIndexFeeVersions;
use grovedb::TransactionArg;
use std::borrow::Cow;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

impl Drive {
/// Updates a serialized document given a contract id and returns the associated fee.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::document::serialization_traits::DocumentPlatformConversionMethodsV0;
use dpp::document::Document;
use dpp::fee::fee_result::FeeResult;
use dpp::prelude::CachedEpochIndexFeeVersions;
use dpp::version::PlatformVersion;
use grovedb::batch::KeyInfoPath;
use grovedb::{EstimatedLayerInformation, TransactionArg};
use std::borrow::Cow;
use std::collections::HashMap;
use dpp::fee::default_costs::CachedEpochIndexFeeVersions;

impl Drive {
/// Updates a serialized document given a contract id and returns the associated fee.
Expand Down
Loading

0 comments on commit 91f8952

Please sign in to comment.