Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(platform)!: state transition fee increase and priorities #1750

Merged
merged 28 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3016cf8
feat: fee multiplier and priorities
QuantumExplorer Mar 7, 2024
310fff6
fmt
QuantumExplorer Mar 7, 2024
c701280
fee multipler to use u16
QuantumExplorer Mar 7, 2024
015b3c9
Merge branch 'v1.0-dev' into feat/feeMultiplierAndPriorities
QuantumExplorer Mar 7, 2024
af3899a
increased size of state transition
QuantumExplorer Mar 7, 2024
0929e27
Merge branch 'feat/feeMultiplierAndPriorities' of github.com:dashpay/…
QuantumExplorer Mar 7, 2024
e5e35e1
renamed things
QuantumExplorer Mar 8, 2024
4325229
renamed things
QuantumExplorer Mar 8, 2024
e0a3d18
renamed things
QuantumExplorer Mar 8, 2024
b43bd89
changed an add to a saturating add
QuantumExplorer Mar 8, 2024
94180de
renamed things
QuantumExplorer Mar 8, 2024
f6a6c60
renamed things
QuantumExplorer Mar 8, 2024
cb75e18
renamed things
QuantumExplorer Mar 8, 2024
ebe433e
renamed things
QuantumExplorer Mar 8, 2024
e62e7cb
Merge branch 'v1.0-dev' into feat/feeMultiplierAndPriorities
QuantumExplorer Mar 8, 2024
55f6264
Merge branch 'v1.0-dev' into feat/feeMultiplierAndPriorities
QuantumExplorer Mar 8, 2024
69785be
fmt
QuantumExplorer Mar 8, 2024
b4f7c84
Merge branch 'feat/feeMultiplierAndPriorities' of github.com:dashpay/…
QuantumExplorer Mar 8, 2024
266948a
added comment
QuantumExplorer Mar 8, 2024
cc8bfdf
fixed priority test
QuantumExplorer Mar 8, 2024
97d8d5d
Merge branch 'v1.0-dev' into feat/feeMultiplierAndPriorities
QuantumExplorer Mar 8, 2024
668a1de
renamed variable
QuantumExplorer Mar 8, 2024
1469f6c
fmt
QuantumExplorer Mar 8, 2024
a798fac
rename
QuantumExplorer Mar 8, 2024
d8b85c9
rename
QuantumExplorer Mar 8, 2024
1355e5a
rename
QuantumExplorer Mar 8, 2024
aa1b85e
fixed a test
QuantumExplorer Mar 8, 2024
68a07c4
fixed a test
QuantumExplorer Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/rs-dpp/src/document/document_factory/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ impl DocumentFactoryV0 {
Ok(DocumentsBatchTransitionV0 {
owner_id,
transitions,
fee_multiplier: 0,
signature_public_key_id: 0,
signature: Default::default(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ impl SpecializedDocumentFactoryV0 {
Ok(DocumentsBatchTransitionV0 {
owner_id,
transitions,
fee_multiplier: 0,
signature_public_key_id: 0,
signature: Default::default(),
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-dpp/src/fee/default_costs/constants.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::fee::Credits;

pub const BASE_ST_PROCESSING_FEE: Credits = 10000; // 84000
pub const FEE_MULTIPLIER: Credits = 2;
pub const DEFAULT_FEE_MULTIPLIER: Credits = 2;
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
pub const DEFAULT_USER_TIP: Credits = 0;
pub const STORAGE_CREDIT_PER_BYTE: Credits = 5000;
pub const PROCESSING_CREDIT_PER_BYTE: Credits = 12;
Expand Down
14 changes: 14 additions & 0 deletions packages/rs-dpp/src/fee/fee_result/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::consensus::fee::fee_error::FeeError;
use crate::fee::fee_result::refunds::FeeRefunds;
use crate::fee::fee_result::BalanceChange::{AddToBalance, NoBalanceChange, RemoveFromBalance};
use crate::fee::Credits;
use crate::prelude::FeeMultiplier;
use crate::ProtocolError;
use platform_value::Identifier;
use std::cmp::Ordering;
Expand Down Expand Up @@ -192,6 +193,19 @@ impl FeeResult {
removed_bytes_from_system: 0,
}
}

/// Apply a fee multiplier to a fee result
pub fn apply_fee_multiplier(&mut self, fee_multiplier: FeeMultiplier) {
let additional_processing_fee = (self.processing_fee as u128)
.saturating_mul(fee_multiplier as u128)
.saturating_div(100);
if additional_processing_fee > u64::MAX as u128 {
self.processing_fee = u64::MAX;
} else {
self.processing_fee += additional_processing_fee as u64;
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// Convenience method to get total fee
pub fn total_base_fee(&self) -> Credits {
self.storage_fee + self.processing_fee
Expand Down
1 change: 1 addition & 0 deletions packages/rs-dpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub mod prelude {
pub type TimestampMillis = u64;
pub type Revision = u64;
pub type IdentityNonce = u64;
pub type FeeMultiplier = u16;
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
}

pub use bincode;
Expand Down
12 changes: 11 additions & 1 deletion packages/rs-dpp/src/state_transition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use crate::identity::identity_public_key::accessors::v0::IdentityPublicKeyGetter
use crate::identity::signer::Signer;
use crate::identity::state_transition::OptionallyAssetLockProved;
use crate::identity::{IdentityPublicKey, KeyID, KeyType, Purpose, SecurityLevel};
use crate::prelude::AssetLockProof;
use crate::prelude::{AssetLockProof, FeeMultiplier};
pub use state_transitions::*;

use crate::serialization::Signable;
Expand Down Expand Up @@ -301,6 +301,11 @@ impl StateTransition {
call_method!(self, signature)
}

/// returns the fee_multiplier
pub fn fee_multiplier(&self) -> FeeMultiplier {
call_method!(self, fee_multiplier)
}

/// The transaction id is a single hash of the data with the signature
pub fn transaction_id(&self) -> Result<[u8; 32], ProtocolError> {
Ok(hash_single(
Expand Down Expand Up @@ -333,6 +338,11 @@ impl StateTransition {
call_method!(self, set_signature, signature)
}

/// set fee multiplier
pub fn set_fee_multiplier(&mut self, fee_multiplier: FeeMultiplier) {
call_method!(self, set_fee_multiplier, fee_multiplier)
}

/// set a new signature
pub fn set_signature_public_key_id(&mut self, public_key_id: KeyID) {
call_method_identity_signed!(self, set_signature_public_key_id, public_key_id)
Expand Down
5 changes: 5 additions & 0 deletions packages/rs-dpp/src/state_transition/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ mod tests {
let identity_topup_transition = IdentityTopUpTransitionV0 {
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
asset_lock_proof: AssetLockProof::Instant(asset_lock_proof),
identity_id: identity.id(),
fee_multiplier: 0,
signature: [1u8; 65].to_vec().into(),
};
let state_transition: StateTransition = identity_topup_transition.into();
Expand Down Expand Up @@ -125,6 +126,7 @@ mod tests {
add_public_keys: add_public_keys_in_creation,
disable_public_keys: vec![],
public_keys_disabled_at: None,
fee_multiplier: 0,
};

let key_signable_bytes = identity_update_transition
Expand Down Expand Up @@ -192,6 +194,7 @@ mod tests {
add_public_keys: add_public_keys_in_creation,
disable_public_keys: vec![3, 4, 5],
public_keys_disabled_at: Some(15),
fee_multiplier: 0,
};

let key_signable_bytes = identity_update_transition
Expand Down Expand Up @@ -246,6 +249,7 @@ mod tests {
pooling: Pooling::Standard,
output_script: CoreScript::from_bytes((0..23).collect::<Vec<u8>>()),
nonce: 1,
fee_multiplier: 0,
signature_public_key_id: 0,
signature: [1u8; 65].to_vec().into(),
};
Expand Down Expand Up @@ -296,6 +300,7 @@ mod tests {
.data_contract_owned()
.try_into_platform_versioned(platform_version)
.expect("expected a data contract"),
fee_multiplier: 0,
signature_public_key_id: 0,
signature: [1u8; 65].to_vec().into(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ pub mod property_names {
pub const STATE_TRANSITION_PROTOCOL_VERSION: &str = "$version";
pub const IDENTITY_CONTRACT_NONCE: &str = "identityContractNonce";
pub const IDENTITY_NONCE: &str = "identityNonce";

pub const FEE_MULTIPLIER: &str = "feeMultiplier";
pub const SIGNATURE_PUBLIC_KEY_ID: &str = "signaturePublicKeyId";
pub const SIGNATURE: &str = "signature";
pub const TRANSITION_TYPE: &str = "type";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::prelude::FeeMultiplier;
use crate::state_transition::data_contract_create_transition::DataContractCreateTransition;
use crate::state_transition::{StateTransitionLike, StateTransitionType};
use crate::version::FeatureVersion;
Expand Down Expand Up @@ -35,6 +36,21 @@ impl StateTransitionLike for DataContractCreateTransition {
}
}

/// returns the fee multiplier
fn fee_multiplier(&self) -> FeeMultiplier {
match self {
DataContractCreateTransition::V0(transition) => transition.fee_multiplier(),
}
}
/// set a fee multiplier
fn set_fee_multiplier(&mut self, fee_multiplier: FeeMultiplier) {
match self {
DataContractCreateTransition::V0(transition) => {
transition.set_fee_multiplier(fee_multiplier)
}
}
}

fn set_signature_bytes(&mut self, signature: Vec<u8>) {
match self {
DataContractCreateTransition::V0(transition) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{data_contract::DataContract, identity::KeyID, ProtocolError};

use crate::data_contract::created_data_contract::CreatedDataContract;
use crate::data_contract::serialized_version::DataContractInSerializationFormat;
use crate::prelude::IdentityNonce;
use crate::prelude::{FeeMultiplier, IdentityNonce};
use crate::state_transition::data_contract_create_transition::DataContractCreateTransition;
use bincode::{Decode, Encode};
use platform_version::{TryFromPlatformVersioned, TryIntoPlatformVersioned};
Expand All @@ -37,6 +37,7 @@ use crate::version::PlatformVersion;
pub struct DataContractCreateTransitionV0 {
pub data_contract: DataContractInSerializationFormat,
pub identity_nonce: IdentityNonce,
pub fee_multiplier: FeeMultiplier,
#[platform_signable(exclude_from_sig_hash)]
pub signature_public_key_id: KeyID,
#[platform_signable(exclude_from_sig_hash)]
Expand Down Expand Up @@ -67,6 +68,7 @@ impl TryFromPlatformVersioned<DataContract> for DataContractCreateTransitionV0 {
Ok(DataContractCreateTransitionV0 {
data_contract: value.try_into_platform_versioned(platform_version)?,
identity_nonce: Default::default(),
fee_multiplier: 0,
signature_public_key_id: 0,
signature: Default::default(),
})
Expand All @@ -84,6 +86,7 @@ impl TryFromPlatformVersioned<CreatedDataContract> for DataContractCreateTransit
Ok(DataContractCreateTransitionV0 {
data_contract: data_contract.try_into_platform_versioned(platform_version)?,
identity_nonce,
fee_multiplier: 0,
signature_public_key_id: 0,
signature: Default::default(),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use platform_value::BinaryData;

use crate::prelude::FeeMultiplier;
use crate::{
prelude::Identifier,
state_transition::{StateTransitionLike, StateTransitionType},
Expand Down Expand Up @@ -48,4 +49,12 @@ impl StateTransitionLike for DataContractCreateTransitionV0 {
self.data_contract.id()
)]
}

fn fee_multiplier(&self) -> FeeMultiplier {
self.fee_multiplier
}

fn set_fee_multiplier(&mut self, fee_multiplier: FeeMultiplier) {
self.fee_multiplier = fee_multiplier
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl DataContractCreateTransitionMethodsV0 for DataContractCreateTransitionV0 {
let transition = DataContractCreateTransition::V0(DataContractCreateTransitionV0 {
data_contract: data_contract.try_into_platform_versioned(platform_version)?,
identity_nonce,
fee_multiplier: 0,
signature_public_key_id: key_id,
signature: Default::default(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use crate::{data_contract::DataContract, ProtocolError};
use platform_version::TryIntoPlatformVersioned;
use platform_version::version::PlatformVersion;
use crate::data_contract::conversion::value::v0::DataContractValueConversionMethodsV0;
use crate::fee::default_costs::constants::DEFAULT_FEE_MULTIPLIER;
use crate::state_transition::{StateTransitionFieldTypes, StateTransitionValueConvert};
use crate::state_transition::data_contract_create_transition::{DataContractCreateTransitionV0};
use crate::state_transition::data_contract_create_transition::fields::*;
use crate::state_transition::state_transitions::common_fields::property_names::FEE_MULTIPLIER;
use crate::state_transition::state_transitions::contract::data_contract_create_transition::fields::{BINARY_FIELDS, IDENTIFIER_FIELDS, U32_FIELDS};

impl<'a> StateTransitionValueConvert<'a> for DataContractCreateTransitionV0 {
Expand Down Expand Up @@ -41,6 +43,10 @@ impl<'a> StateTransitionValueConvert<'a> for DataContractCreateTransitionV0 {
platform_version,
)?
.try_into_platform_versioned(platform_version)?,
fee_multiplier: raw_object
.get_optional_integer(FEE_MULTIPLIER)
.map_err(ProtocolError::ValueError)?
.unwrap_or_default(),
})
}

Expand Down Expand Up @@ -71,6 +77,10 @@ impl<'a> StateTransitionValueConvert<'a> for DataContractCreateTransitionV0 {
platform_version,
)?
.try_into_platform_versioned(platform_version)?,
fee_multiplier: raw_value_map
.remove_optional_integer(FEE_MULTIPLIER)
.map_err(ProtocolError::ValueError)?
.unwrap_or_default(),
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::state_transition::StateTransition;
use crate::version::FeatureVersion;
use crate::ProtocolError;

use crate::prelude::IdentityNonce;
use crate::prelude::{FeeMultiplier, IdentityNonce};
use platform_version::version::PlatformVersion;

impl DataContractUpdateTransitionMethodsV0 for DataContractUpdateTransition {
Expand All @@ -21,6 +21,7 @@ impl DataContractUpdateTransitionMethodsV0 for DataContractUpdateTransition {
identity: &PartialIdentity,
key_id: KeyID,
identity_contract_nonce: IdentityNonce,
fee_multiplier: FeeMultiplier,
signer: &S,
platform_version: &PlatformVersion,
feature_version: Option<FeatureVersion>,
Expand All @@ -37,6 +38,7 @@ impl DataContractUpdateTransitionMethodsV0 for DataContractUpdateTransition {
identity,
key_id,
identity_contract_nonce,
fee_multiplier,
signer,
platform_version,
feature_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::data_contract::DataContract;
use crate::identity::signer::Signer;
use crate::identity::{KeyID, PartialIdentity};

use crate::prelude::IdentityNonce;
use crate::prelude::{FeeMultiplier, IdentityNonce};
use crate::state_transition::StateTransition;
use crate::version::FeatureVersion;
use crate::ProtocolError;
Expand All @@ -27,6 +27,7 @@ pub trait DataContractUpdateTransitionMethodsV0 {
identity: &PartialIdentity,
key_id: KeyID,
identity_contract_nonce: IdentityNonce,
fee_multiplier: FeeMultiplier,
signer: &S,
platform_version: &PlatformVersion,
feature_version: Option<FeatureVersion>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::prelude::FeeMultiplier;
use crate::state_transition::data_contract_update_transition::DataContractUpdateTransition;
use crate::state_transition::{StateTransitionLike, StateTransitionType};
use crate::version::FeatureVersion;
Expand Down Expand Up @@ -54,4 +55,19 @@ impl StateTransitionLike for DataContractUpdateTransition {
DataContractUpdateTransition::V0(transition) => transition.unique_identifiers(),
}
}

/// returns the fee multiplier
fn fee_multiplier(&self) -> FeeMultiplier {
match self {
DataContractUpdateTransition::V0(transition) => transition.fee_multiplier(),
}
}
/// set a fee multiplier
fn set_fee_multiplier(&mut self, fee_multiplier: FeeMultiplier) {
match self {
DataContractUpdateTransition::V0(transition) => {
transition.set_fee_multiplier(fee_multiplier)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use platform_version::version::PlatformVersion;
use platform_version::{TryFromPlatformVersioned, TryIntoPlatformVersioned};

use crate::data_contract::serialized_version::DataContractInSerializationFormat;
use crate::prelude::IdentityNonce;
use crate::prelude::{FeeMultiplier, IdentityNonce};
use crate::state_transition::data_contract_update_transition::DataContractUpdateTransition;
use crate::state_transition::StateTransition;
use crate::{data_contract::DataContract, identity::KeyID, ProtocolError};
Expand All @@ -37,6 +37,7 @@ pub struct DataContractUpdateTransitionV0 {
)]
pub identity_contract_nonce: IdentityNonce,
pub data_contract: DataContractInSerializationFormat,
pub fee_multiplier: FeeMultiplier,
#[platform_signable(exclude_from_sig_hash)]
pub signature_public_key_id: KeyID,
#[platform_signable(exclude_from_sig_hash)]
Expand All @@ -53,6 +54,7 @@ impl TryFromPlatformVersioned<(DataContract, IdentityNonce)> for DataContractUpd
Ok(DataContractUpdateTransitionV0 {
identity_contract_nonce: value.1,
data_contract: value.0.try_into_platform_versioned(platform_version)?,
fee_multiplier: 0,
signature_public_key_id: 0,
signature: Default::default(),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use platform_value::BinaryData;

use crate::prelude::FeeMultiplier;
use crate::{
prelude::Identifier,
state_transition::{StateTransitionLike, StateTransitionType},
Expand Down Expand Up @@ -49,4 +50,12 @@ impl StateTransitionLike for DataContractUpdateTransitionV0 {
self.identity_contract_nonce
)]
}

fn fee_multiplier(&self) -> FeeMultiplier {
self.fee_multiplier
}

fn set_fee_multiplier(&mut self, fee_multiplier: FeeMultiplier) {
self.fee_multiplier = fee_multiplier
}
}
Loading
Loading