From 69037db735c1b560d3211f23e975b0296d76a9ba Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Tue, 5 Sep 2023 00:07:46 +0200 Subject: [PATCH 1/3] host: fix EXPIRATION_ENTRY_SIZE constant --- soroban-env-host/src/fees.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/soroban-env-host/src/fees.rs b/soroban-env-host/src/fees.rs index 8745cb969..2b0d5c307 100644 --- a/soroban-env-host/src/fees.rs +++ b/soroban-env-host/src/fees.rs @@ -7,9 +7,8 @@ /// Rough estimate of the base size of any transaction result in the archives /// (independent of the transaction envelope size). pub const TX_BASE_RESULT_SIZE: u32 = 300; -/// Estimate for any `ExpirationEntry` ledger entry, consisting of a 32-byte -/// hash of the corresponding entry and 4 bytes for expiration ledger. -pub const EXPIRATION_ENTRY_SIZE: u32 = 32 + 4; +/// Estimate for any `ExpirationEntry` ledger entry +pub const EXPIRATION_ENTRY_SIZE: u32 = 48; const INSTRUCTIONS_INCREMENT: i64 = 10000; const DATA_SIZE_1KB_INCREMENT: i64 = 1024; From 42138d4efd9dd4c236ccdd8a06bf60ca3d2f5311 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Tue, 5 Sep 2023 00:28:14 +0200 Subject: [PATCH 2/3] Fix tests --- soroban-env-host/tests/fees.rs | 52 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/soroban-env-host/tests/fees.rs b/soroban-env-host/tests/fees.rs index a9e1ca0af..9bef7d335 100644 --- a/soroban-env-host/tests/fees.rs +++ b/soroban-env-host/tests/fees.rs @@ -141,9 +141,9 @@ fn test_rent_bump_fees_with_only_bump() { 50_000, ), // Rent: ceil(1 * 1000 * 200_000 / (10_000 * 1024)) (=20) + - // Expiration entry write bytes: ceil(1000 * 36 / 1024) (=36) + + // Expiration entry write bytes: ceil(1000 * 48 / 1024) (=47) + // Expiration entry write: 10 - 20 + 36 + 10 + 20 + 47 + 10 ); // Minimal ledgers @@ -160,8 +160,8 @@ fn test_rent_bump_fees_with_only_bump() { 50_000, ), // Rent: ceil(10 * 1024 * 1000 * 1 / (10_000 * 1024)) (=1) + - // Expiration entry write entry/bytes: 46 - 1 + 46 + // Expiration entry write entry/bytes: 57 + 1 + 57 ); // Minimal ledgers & size @@ -178,8 +178,8 @@ fn test_rent_bump_fees_with_only_bump() { 50_000, ), // Rent: ceil(1 * 1000 * 1 / (10_000 * 1024)) - // Expiration entry write entry/bytes: 46 - 1 + 46 + // Expiration entry write entry/bytes: 57 + 1 + 57 ); // No size change @@ -196,8 +196,8 @@ fn test_rent_bump_fees_with_only_bump() { 50_000, ), // Rent: ceil(10 * 1024 * 1000 * 200_000 / (10_000 * 1024)) (=200_000) - // Expiration entry write entry/bytes: 46 - 200_000 + 46 + // Expiration entry write entry/bytes: 57 + 200_000 + 57 ); // Size decrease @@ -214,8 +214,8 @@ fn test_rent_bump_fees_with_only_bump() { 50_000, ), // Rent: ceil(5 * 1024 * 1000 * 200_000 / (10_000 * 1024)) (=100_000) + - // Expiration entry write entry/bytes: 46 - 100_000 + 46 + // Expiration entry write entry/bytes: 57 + 100_000 + 57 ); // Temp storage rate @@ -232,8 +232,8 @@ fn test_rent_bump_fees_with_only_bump() { 50_000, ), // Rent: ceil(10 * 1024 * 1000 * 200_000 / (100_000 * 1024)) (=20_000) + - // Expiration entry write entry/bytes: 46 - 20_000 + 46 + // Expiration entry write entry/bytes: 57 + 20_000 + 57 ); // Multiple entries @@ -287,9 +287,9 @@ fn test_rent_bump_fees_with_only_bump() { 50_000, ), // Rent: 20_000 + 200_000 + 1 + 20 + 200_000 + 20_000 (=440_021) + - // Expiration entry write bytes: ceil(6 * 1000 * 36 / 1024) (=211) + + // Expiration entry write bytes: ceil(6 * 1000 * 48 / 1024) (=282) + // Expiration entry write: 10 * 6 - 440_021 + 211 + 60 + 440_021 + 282 + 60 ); } @@ -421,8 +421,8 @@ fn test_rent_bump_with_size_change_and_bump() { ), // Rent: 100_000 * 1000 * 200_000 / (10_000 * 1024) + // 99_999 * 1000 * (100_000 - 25_000 + 1) / (10_000 * 1024) - // Expiration entry write entry/bytes: 46 - 2_685_550 + 46 + // Expiration entry write entry/bytes: 57 + 2_685_550 + 57 ); // Temp entry @@ -440,8 +440,8 @@ fn test_rent_bump_with_size_change_and_bump() { ), // Rent: 100_000 * 1000 * 200_000 / (10_000 * 1024) + // 99_999 * 1000 * (100_000 - 25_000 + 1) / (10_000 * 1024) - // Expiration entry write entry/bytes: 46 - 268_556 + 46 + // Expiration entry write entry/bytes: 57 + 268_556 + 57 ); // Multiple entries @@ -467,9 +467,9 @@ fn test_rent_bump_with_size_change_and_bump() { 25_000, ), // Rent: 2_685_550 + 268_556 - // Expiration entry write bytes: ceil(2 * 1000 * 36 / 1024) (=71) + + // Expiration entry write bytes: ceil(2 * 1000 * 48 / 1024) (=94) + // Expiration entry write: 10 * 2 - 2_954_106 + 71 + 20 + 2_954_106 + 94 + 20 ); // Small increments @@ -487,8 +487,8 @@ fn test_rent_bump_with_size_change_and_bump() { ), // Rent: ceil(2 * 1000 * 1 / (10_000 * 1024)) + // ceil(1 * 1000 * (100_000 - 99_999 + 1) / (10_000 * 1024)) (=2) - // Expiration entry write entry/bytes: 46 - 2 + 46 + // Expiration entry write entry/bytes: 57 + 2 + 57 ); } @@ -515,8 +515,8 @@ fn test_rent_bump_without_old_entry() { 25_000, ), // Rent: 100_000 * 1000 * (100_000 - 25_000) / (10_000 * 1024) - // Expiration entry write entry/bytes: 46 - 732_432 + 46 + // Expiration entry write entry/bytes: 57 + 732_432 + 57 ); // Temp storage @@ -533,8 +533,8 @@ fn test_rent_bump_without_old_entry() { 25_000, ), // Rent: 100_000 * 1000 * (100_000 - 25_000) / (10_000 * 1024) - // Expiration entry write entry/bytes: 46 - 73_244 + 46 + // Expiration entry write entry/bytes: 57 + 73_244 + 57 ); } From 3eb3c3190359a085bd16adcaf35863ff8fd6bad8 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Tue, 5 Sep 2023 02:53:20 +0200 Subject: [PATCH 3/3] Add test to check EXPIRATION_ENTRY_SIZE --- soroban-env-host/tests/fees.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/soroban-env-host/tests/fees.rs b/soroban-env-host/tests/fees.rs index 9bef7d335..63992d00f 100644 --- a/soroban-env-host/tests/fees.rs +++ b/soroban-env-host/tests/fees.rs @@ -1,8 +1,26 @@ +use soroban_env_common::xdr::{Hash, LedgerEntry, LedgerEntryData, LedgerEntryExt, WriteXdr}; use soroban_env_host::fees::{ compute_rent_fee, compute_transaction_resource_fee, compute_write_fee_per_1kb, FeeConfiguration, LedgerEntryRentChange, RentFeeConfiguration, TransactionResources, - WriteFeeConfiguration, + WriteFeeConfiguration, EXPIRATION_ENTRY_SIZE, }; +use soroban_env_host::xdr::ExpirationEntry; + +#[test] +fn expiration_entry_size() { + let expiration_entry = LedgerEntry { + last_modified_ledger_seq: 0, + data: LedgerEntryData::Expiration(ExpirationEntry { + key_hash: Hash([0; 32]), + expiration_ledger_seq: 0, + }), + ext: LedgerEntryExt::V0, + }; + assert_eq!( + EXPIRATION_ENTRY_SIZE, + expiration_entry.to_xdr().unwrap().len() as u32 + ); +} #[test] fn resource_fee_computation() {