Skip to content

Commit

Permalink
feat(platform)!: matched withdrawal fees to actual processing cost (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer authored Sep 30, 2024
1 parent 404d6d7 commit d805fc7
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
use dpp::block::block_info::BlockInfo;

use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::document::DocumentV0Getters;
use dpp::platform_value::btreemap_extensions::BTreeValueMapHelper;
use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;

use dpp::system_data_contracts::withdrawals_contract;
use dpp::system_data_contracts::withdrawals_contract::v1::document_types::withdrawal;

use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::platform_types::platform_state::PlatformState;
use crate::{
error::{execution::ExecutionError, Error},
platform_types::platform::Platform,
rpc::core::CoreRPCLike,
};
use crate::{error::Error, platform_types::platform::Platform, rpc::core::CoreRPCLike};

impl<C> Platform<C>
where
Expand Down Expand Up @@ -53,20 +42,21 @@ where
mod tests {
use super::*;
use dpp::block::epoch::Epoch;
use itertools::Itertools;

use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::data_contracts::SystemDataContract;
use dpp::identifier::Identifier;
use dpp::identity::core_script::CoreScript;
use dpp::tests::fixtures::get_withdrawal_document_fixture;
use dpp::withdrawal::Pooling;
use drive::util::test_helpers::setup::{setup_document, setup_system_data_contract};
use itertools::Itertools;

use crate::test::helpers::setup::TestPlatformBuilder;
use dpp::document::DocumentV0Getters;
use dpp::platform_value::btreemap_extensions::BTreeValueMapHelper;
use dpp::platform_value::platform_value;
use dpp::system_data_contracts::load_system_data_contract;
use dpp::system_data_contracts::withdrawals_contract::v1::document_types::withdrawal;
use dpp::system_data_contracts::{load_system_data_contract, withdrawals_contract};
use dpp::version::PlatformVersion;
use drive::config::DEFAULT_QUERY_LIMIT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ where
///
/// # Parameters
/// - `block_info`: Information about the current block (e.g., timestamp).
/// - `last_committed_platform_state`: The last committed platform state needed to check active validator set.
/// - `transaction`: The transaction within which the rebroadcast should be executed.
/// - `platform_version`: The version of the platform, used to determine the correct method implementation.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub enum ValidationOperation {
Protocol(ProtocolValidationOperation),
RetrieveIdentity(RetrieveIdentityInfo),
RetrievePrefundedSpecializedBalance,
PerformNetworkThresholdSigning,
SingleSha256(HashBlockCount),
DoubleSha256(HashBlockCount),
ValidateKeyStructure(KeyCount), // This is extremely cheap
Expand Down Expand Up @@ -210,6 +211,19 @@ impl ValidationOperation {
"execution processing fee overflow error",
))?;
}
ValidationOperation::PerformNetworkThresholdSigning => {
let operation_cost = platform_version
.fee_version
.processing
.perform_network_threshold_signing;

fee_result.processing_fee = fee_result
.processing_fee
.checked_add(operation_cost)
.ok_or(ExecutionError::Overflow(
"execution processing fee overflow error",
))?;
}
}
}
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use dpp::state_transition::identity_credit_withdrawal_transition::accessors::Ide
use dpp::state_transition::identity_credit_withdrawal_transition::IdentityCreditWithdrawalTransition;

use crate::error::execution::ExecutionError;
use crate::execution::types::execution_operation::ValidationOperation;

Check warning on line 8 in packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/balance/v0/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused import: `crate::execution::types::execution_operation::ValidationOperation`

warning: unused import: `crate::execution::types::execution_operation::ValidationOperation` --> packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/balance/v0/mod.rs:8:5 | 8 | use crate::execution::types::execution_operation::ValidationOperation; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
use crate::execution::types::state_transition_execution_context::{
StateTransitionExecutionContext, StateTransitionExecutionContextMethodsV0,

Check warning on line 10 in packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/balance/v0/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused imports: `StateTransitionExecutionContextMethodsV0` and `StateTransitionExecutionContext`

warning: unused imports: `StateTransitionExecutionContextMethodsV0` and `StateTransitionExecutionContext` --> packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/balance/v0/mod.rs:10:5 | 10 | StateTransitionExecutionContext, StateTransitionExecutionContextMethodsV0, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
};
use dpp::validation::SimpleConsensusValidationResult;
use dpp::version::PlatformVersion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl StateTransitionActionTransformerV0 for IdentityCreditWithdrawalTransition {
platform: &PlatformRef<C>,
block_info: &BlockInfo,
_validation_mode: ValidationMode,
_execution_context: &mut StateTransitionExecutionContext,
execution_context: &mut StateTransitionExecutionContext,
tx: TransactionArg,
) -> Result<ConsensusValidationResult<StateTransitionAction>, Error> {
let platform_version = platform.state.current_platform_version()?;
Expand All @@ -45,7 +45,13 @@ impl StateTransitionActionTransformerV0 for IdentityCreditWithdrawalTransition {
.identity_credit_withdrawal_state_transition
.transform_into_action
{
0 => self.transform_into_action_v0(platform, block_info, tx, platform_version),
0 => self.transform_into_action_v0(
platform,
block_info,
execution_context,
tx,
platform_version,
),
version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch {
method: "identity credit withdrawal transition: transform_into_action".to_string(),
known_versions: vec![0],
Expand Down Expand Up @@ -94,7 +100,7 @@ impl StateTransitionStateValidationV0 for IdentityCreditWithdrawalTransition {
platform: &PlatformRef<C>,
_validation_mode: ValidationMode,
block_info: &BlockInfo,
_execution_context: &mut StateTransitionExecutionContext,
execution_context: &mut StateTransitionExecutionContext,
tx: TransactionArg,
) -> Result<ConsensusValidationResult<StateTransitionAction>, Error> {
let platform_version = platform.state.current_platform_version()?;
Expand All @@ -106,7 +112,13 @@ impl StateTransitionStateValidationV0 for IdentityCreditWithdrawalTransition {
.identity_credit_withdrawal_state_transition
.state
{
0 => self.validate_state_v0(platform, block_info, tx, platform_version),
0 => self.validate_state_v0(
platform,
block_info,
execution_context,
tx,
platform_version,
),
version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch {
method: "identity credit withdrawal transition: validate_state".to_string(),
known_versions: vec![0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use dpp::prelude::ConsensusValidationResult;
use dpp::state_transition::identity_credit_withdrawal_transition::accessors::IdentityCreditWithdrawalTransitionAccessorsV0;
use dpp::state_transition::identity_credit_withdrawal_transition::IdentityCreditWithdrawalTransition;

use crate::execution::types::execution_operation::ValidationOperation;
use crate::execution::types::state_transition_execution_context::{
StateTransitionExecutionContext, StateTransitionExecutionContextMethodsV0,
};
use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;
use drive::state_transition_action::identity::identity_credit_withdrawal::IdentityCreditWithdrawalTransitionAction;
Expand All @@ -19,6 +23,7 @@ pub(in crate::execution::validation::state_transition::state_transitions::identi
&self,
platform: &PlatformRef<C>,
block_info: &BlockInfo,
execution_context: &mut StateTransitionExecutionContext,
tx: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<ConsensusValidationResult<StateTransitionAction>, Error>;
Expand All @@ -27,6 +32,7 @@ pub(in crate::execution::validation::state_transition::state_transitions::identi
&self,
platform: &PlatformRef<C>,
block_info: &BlockInfo,
execution_context: &mut StateTransitionExecutionContext,
tx: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<ConsensusValidationResult<StateTransitionAction>, Error>;
Expand All @@ -39,6 +45,7 @@ impl IdentityCreditWithdrawalStateTransitionStateValidationV0
&self,
platform: &PlatformRef<C>,
block_info: &BlockInfo,
execution_context: &mut StateTransitionExecutionContext,
tx: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<ConsensusValidationResult<StateTransitionAction>, Error> {
Expand All @@ -65,17 +72,24 @@ impl IdentityCreditWithdrawalStateTransitionStateValidationV0
));
}

self.transform_into_action_v0(platform, block_info, tx, platform_version)
self.transform_into_action_v0(
platform,
block_info,
execution_context,
tx,
platform_version,
)
}

fn transform_into_action_v0<C: CoreRPCLike>(
&self,
platform: &PlatformRef<C>,
block_info: &BlockInfo,
execution_context: &mut StateTransitionExecutionContext,
tx: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<ConsensusValidationResult<StateTransitionAction>, Error> {
Ok(
let consensus_validation_result =
IdentityCreditWithdrawalTransitionAction::try_from_identity_credit_withdrawal(
&platform.drive,
tx,
Expand All @@ -85,7 +99,11 @@ impl IdentityCreditWithdrawalStateTransitionStateValidationV0
)
.map(|consensus_validation_result| {
consensus_validation_result.map(|withdrawal| withdrawal.into())
})?,
)
})?;
if consensus_validation_result.is_valid() {
// If this is valid then we will apply the action and eventually perform network threshold signing
execution_context.add_operation(ValidationOperation::PerformNetworkThresholdSigning);
}
Ok(consensus_validation_result)
}
}
10 changes: 6 additions & 4 deletions packages/rs-platform-version/src/version/fee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ mod tests {
fetch_identity_balance_and_revision_processing_cost: 3,
fetch_identity_cost_per_look_up_key_by_id: 4,
fetch_single_identity_key_processing_cost: 5,
validate_key_structure: 6,
fetch_prefunded_specialized_balance_processing_cost: 7,
perform_network_threshold_signing: 6,
validate_key_structure: 7,
fetch_prefunded_specialized_balance_processing_cost: 8,
},
data_contract: FeeDataContractValidationVersion {
document_type_base_fee: 1,
Expand Down Expand Up @@ -129,8 +130,9 @@ mod tests {
fetch_identity_balance_and_revision_processing_cost: 3,
fetch_identity_cost_per_look_up_key_by_id: 4,
fetch_single_identity_key_processing_cost: 5,
validate_key_structure: 6,
fetch_prefunded_specialized_balance_processing_cost: 7,
perform_network_threshold_signing: 6,
validate_key_structure: 7,
fetch_prefunded_specialized_balance_processing_cost: 8,
},
data_contract: FeeDataContractValidationVersion {
document_type_base_fee: 1,
Expand Down
11 changes: 7 additions & 4 deletions packages/rs-platform-version/src/version/fee/processing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct FeeProcessingVersion {
pub fetch_identity_cost_per_look_up_key_by_id: u64,
pub fetch_prefunded_specialized_balance_processing_cost: u64,
pub fetch_single_identity_key_processing_cost: u64,
pub perform_network_threshold_signing: u64,
pub validate_key_structure: u64,
}

Expand All @@ -26,8 +27,9 @@ mod tests {
fetch_identity_balance_and_revision_processing_cost: 3,
fetch_identity_cost_per_look_up_key_by_id: 4,
fetch_single_identity_key_processing_cost: 5,
validate_key_structure: 6,
fetch_prefunded_specialized_balance_processing_cost: 7,
perform_network_threshold_signing: 6,
validate_key_structure: 7,
fetch_prefunded_specialized_balance_processing_cost: 8,
};

let version2 = FeeProcessingVersion {
Expand All @@ -36,8 +38,9 @@ mod tests {
fetch_identity_balance_and_revision_processing_cost: 3,
fetch_identity_cost_per_look_up_key_by_id: 4,
fetch_single_identity_key_processing_cost: 5,
validate_key_structure: 6,
fetch_prefunded_specialized_balance_processing_cost: 7,
perform_network_threshold_signing: 6,
validate_key_structure: 7,
fetch_prefunded_specialized_balance_processing_cost: 8,
};

// This assertion will check if all fields are considered in the equality comparison
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ pub const FEE_PROCESSING_VERSION1: FeeProcessingVersion = FeeProcessingVersion {
fetch_identity_cost_per_look_up_key_by_id: 9000,
fetch_prefunded_specialized_balance_processing_cost: 10000,
fetch_single_identity_key_processing_cost: 10000,
perform_network_threshold_signing: 100000000, // 1mDash (2.5 cents at 25$/Dash)
validate_key_structure: 50,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::version::fee::state_transition_min_fees::StateTransitionMinFees;

pub const STATE_TRANSITION_MIN_FEES_VERSION1: StateTransitionMinFees = StateTransitionMinFees {
credit_transfer: 100000,
credit_withdrawal: 100000,
credit_withdrawal: 400000000, //credit withdrawals are more expensive that the rest
identity_update: 100000,
document_batch_sub_transition: 100000,
contract_create: 100000,
Expand Down

0 comments on commit d805fc7

Please sign in to comment.