Skip to content

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Jul 12, 2024
1 parent 91f8952 commit 86394d4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
15 changes: 8 additions & 7 deletions packages/rs-dpp/src/fee/default_costs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>) -> Credits {
match self {
KnownCostItem::StorageDiskUsageCreditPerByte => {
fee_version.storage.storage_disk_usage_credit_per_byte
Expand All @@ -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
Expand All @@ -133,9 +131,10 @@ impl KnownCostItem {
&self,
epoch: &T,
cached_fee_version: &CachedEpochIndexFeeVersions,
size: Option<usize>,
) -> Credits {
let version = epoch.active_fee_version(cached_fee_version);
self.lookup_cost(&version)
self.lookup_cost(&version, size)
}
}

Expand All @@ -149,6 +148,7 @@ pub trait EpochCosts {
&self,
cached_fee_version: &CachedEpochIndexFeeVersions,
cost_item: KnownCostItem,
size: Option<usize>,
) -> Credits;
}

Expand All @@ -173,7 +173,8 @@ impl EpochCosts for Epoch {
&self,
cached_fee_version: &CachedEpochIndexFeeVersions,
cost_item: KnownCostItem,
size: Option<usize>,
) -> Credits {
cost_item.lookup_cost_on_epoch(self, cached_fee_version)
cost_item.lookup_cost_on_epoch(self, cached_fee_version, size)
}
}
2 changes: 1 addition & 1 deletion packages/rs-dpp/src/fee/fee_result/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions packages/rs-drive/src/drive/document/delete/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions packages/rs-drive/src/drive/document/insert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions packages/rs-drive/src/drive/document/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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 };
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 };
Expand Down

0 comments on commit 86394d4

Please sign in to comment.