From 86394d49fe3e11adf1a71acc72db2458b0433826 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Fri, 12 Jul 2024 16:32:23 +0300 Subject: [PATCH] more work --- packages/rs-dpp/src/fee/default_costs/mod.rs | 15 ++++++++------- packages/rs-dpp/src/fee/fee_result/refunds.rs | 2 +- .../rs-drive/src/drive/document/delete/mod.rs | 3 +++ .../rs-drive/src/drive/document/insert/mod.rs | 10 +++++++--- .../rs-drive/src/drive/document/update/mod.rs | 11 +++++++++++ 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/packages/rs-dpp/src/fee/default_costs/mod.rs b/packages/rs-dpp/src/fee/default_costs/mod.rs index c6c2ecc651f..6875935e237 100644 --- a/packages/rs-dpp/src/fee/default_costs/mod.rs +++ b/packages/rs-dpp/src/fee/default_costs/mod.rs @@ -78,7 +78,7 @@ pub enum KnownCostItem { impl KnownCostItem { #[inline] - pub fn lookup_cost(&self, fee_version: &FeeVersion) -> Credits { + pub fn lookup_cost(&self, fee_version: &FeeVersion, size: Option) -> Credits { match self { KnownCostItem::StorageDiskUsageCreditPerByte => { fee_version.storage.storage_disk_usage_credit_per_byte @@ -104,12 +104,10 @@ impl KnownCostItem { .fetch_single_identity_key_processing_cost } KnownCostItem::Blake3 => { - //TODO: blake3_base or blake3_per_block? - fee_version.hashing.blake3_base + fee_version.hashing.blake3_base + fee_version.hashing.blake3_per_block * size.unwrap_or(0) as u64 } KnownCostItem::SingleSHA256 => { - //TODO: single_sha256_base or single_sha256_per_block? - fee_version.hashing.single_sha256_base + fee_version.hashing.single_sha256_base + fee_version.hashing.sha256_per_block * size.unwrap_or(0) as u64 } KnownCostItem::VerifySignatureEcdsaSecp256k1 => { fee_version.signature.verify_signature_ecdsa_secp256k1 @@ -133,9 +131,10 @@ impl KnownCostItem { &self, epoch: &T, cached_fee_version: &CachedEpochIndexFeeVersions, + size: Option, ) -> Credits { let version = epoch.active_fee_version(cached_fee_version); - self.lookup_cost(&version) + self.lookup_cost(&version, size) } } @@ -149,6 +148,7 @@ pub trait EpochCosts { &self, cached_fee_version: &CachedEpochIndexFeeVersions, cost_item: KnownCostItem, + size: Option, ) -> Credits; } @@ -173,7 +173,8 @@ impl EpochCosts for Epoch { &self, cached_fee_version: &CachedEpochIndexFeeVersions, cost_item: KnownCostItem, + size: Option, ) -> Credits { - cost_item.lookup_cost_on_epoch(self, cached_fee_version) + cost_item.lookup_cost_on_epoch(self, cached_fee_version, size) } } diff --git a/packages/rs-dpp/src/fee/fee_result/refunds.rs b/packages/rs-dpp/src/fee/fee_result/refunds.rs index 750bd368c3e..b4e3ab50482 100644 --- a/packages/rs-dpp/src/fee/fee_result/refunds.rs +++ b/packages/rs-dpp/src/fee/fee_result/refunds.rs @@ -57,7 +57,7 @@ impl FeeRefunds { // TODO We should use multipliers let credits: Credits = (bytes as Credits) - .checked_mul(Epoch::new(current_epoch_index)?.cost_for_known_cost_item(previous_fee_versions, StorageDiskUsageCreditPerByte)) + .checked_mul(Epoch::new(current_epoch_index)?.cost_for_known_cost_item(previous_fee_versions, StorageDiskUsageCreditPerByte, None)) .ok_or(ProtocolError::Overflow("storage written bytes cost overflow"))?; let (amount, _) = calculate_storage_fee_refund_amount_and_leftovers( diff --git a/packages/rs-drive/src/drive/document/delete/mod.rs b/packages/rs-drive/src/drive/document/delete/mod.rs index 10d5326d35e..0fc54c52b27 100644 --- a/packages/rs-drive/src/drive/document/delete/mod.rs +++ b/packages/rs-drive/src/drive/document/delete/mod.rs @@ -829,6 +829,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); // We added 1559 bytes assert_eq!(added_bytes, 1559); @@ -866,6 +867,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); assert!(added_bytes > refund_equivalent_bytes); @@ -929,6 +931,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); // We added 1558 bytes assert_eq!(added_bytes, 1559); diff --git a/packages/rs-drive/src/drive/document/insert/mod.rs b/packages/rs-drive/src/drive/document/insert/mod.rs index 94da6809394..20bf9edf204 100644 --- a/packages/rs-drive/src/drive/document/insert/mod.rs +++ b/packages/rs-drive/src/drive/document/insert/mod.rs @@ -340,7 +340,8 @@ mod tests { storage_fee: 3058 * Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, - StorageDiskUsageCreditPerByte + StorageDiskUsageCreditPerByte, + None ), processing_fee: 2356200, // TODO: Readjust this test when FeeHashingVersion blake3_base, sha256_ripe_md160_base, blake3_per_block values are finalised ..Default::default() @@ -405,7 +406,8 @@ mod tests { storage_fee: 1305 * Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, - StorageDiskUsageCreditPerByte + StorageDiskUsageCreditPerByte, + None ), processing_fee: 1500200, // TODO: Readjust this test when FeeHashingVersion blake3_base, sha256_ripe_md160_base, blake3_per_block values are finalised ..Default::default() @@ -473,6 +475,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); assert_eq!(1305, added_bytes); assert_eq!(144859600, processing_fee); // TODO: Readjust this test when FeeHashingVersion blake3_base, sha256_ripe_md160_base, blake3_per_block values are finalised @@ -703,7 +706,8 @@ mod tests { storage_fee: 1761 * Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, - StorageDiskUsageCreditPerByte + StorageDiskUsageCreditPerByte, + None ), processing_fee: 2095400, // TODO: Readjust this test when FeeHashingVersion blake3_base, sha256_ripe_md160_base, blake3_per_block values are finalised ..Default::default() diff --git a/packages/rs-drive/src/drive/document/update/mod.rs b/packages/rs-drive/src/drive/document/update/mod.rs index e9235abe606..acada22ccc4 100644 --- a/packages/rs-drive/src/drive/document/update/mod.rs +++ b/packages/rs-drive/src/drive/document/update/mod.rs @@ -941,6 +941,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); let expected_added_bytes = if using_history { //Explanation for 1237 @@ -1109,6 +1110,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); assert!(expected_added_bytes > refund_equivalent_bytes); @@ -1129,6 +1131,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); assert_eq!(original_bytes, expected_added_bytes); @@ -1150,6 +1153,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); let expected_added_bytes = if using_history { 313 } else { 1 }; @@ -1222,6 +1226,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); let expected_added_bytes = if using_history { 1238 } else { 962 }; assert_eq!(original_bytes, expected_added_bytes); @@ -1248,6 +1253,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); assert!(expected_added_bytes > refund_equivalent_bytes); @@ -1268,6 +1274,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); assert_eq!(original_bytes, expected_added_bytes); @@ -1289,6 +1296,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None ); let removed_credits = update_fees @@ -1308,6 +1316,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None, ); assert!(expected_added_bytes > refund_equivalent_bytes); @@ -1421,6 +1430,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None, ); let expected_added_bytes = if using_history { //Explanation for 1237 @@ -1581,6 +1591,7 @@ mod tests { / Epoch::new(0).unwrap().cost_for_known_cost_item( &EPOCH_CHANGE_FEE_VERSION_TEST, StorageDiskUsageCreditPerByte, + None, ); let expected_added_bytes = if using_history { 1239 } else { 963 };