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

Bump env xdr and do the fee library changes corresponding to config changes #965

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ soroban-native-sdk-macros = { version = "0.0.17", path = "soroban-native-sdk-mac
[workspace.dependencies.stellar-xdr]
version = "0.0.17"
git = "https://github.com/stellar/rs-stellar-xdr"
rev = "4eaf2388c1de6fc295ed5f7df8174c199923df5b"
rev = "1c357fc76a03247234f27edad4de6f81f0e157ee"
default-features = false

[workspace.dependencies.wasmi]
Expand Down
26 changes: 11 additions & 15 deletions soroban-env-host/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ pub struct TransactionResources {
pub read_bytes: u32,
/// Number of bytes written to ledger.
pub write_bytes: u32,
/// Size of the metadata that transaction emits. Consists of the size of
/// the events XDR, the size of writeable entries XDR before the transaction
/// is applied, the size of writeable entries XDR after the transaction is
/// applied.
pub metadata_size_bytes: u32,
/// Size of the contract events XDR.
pub contract_events_size_bytes: u32,
/// Size of the transaction XDR.
pub transaction_size_bytes: u32,
}
Expand All @@ -49,11 +46,10 @@ pub struct FeeConfiguration {
/// Fee per 1KB written to history (the history write size is based on
/// transaction size and `TX_BASE_RESULT_SIZE`).
pub fee_per_historical_1kb: i64,
/// Fee per 1KB of metadata written.
pub fee_per_metadata_1kb: i64,
/// Fee per 1KB propagate to the network (the propagated size is equal to
/// the transaction size).
pub fee_per_propagate_1kb: i64,
/// Fee per 1KB of contract events written.
pub fee_per_contract_event_1kb: i64,
/// Fee per 1KB of transaction size.
pub fee_per_transaction_size_1kb: i64,
}

/// Network configuration used to determine the ledger write fee.
Expand Down Expand Up @@ -160,19 +156,19 @@ pub fn compute_transaction_resource_fee(
DATA_SIZE_1KB_INCREMENT,
);

let meta_data_fee = compute_fee_per_increment(
tx_resources.metadata_size_bytes,
fee_config.fee_per_metadata_1kb,
let events_fee = compute_fee_per_increment(
tx_resources.contract_events_size_bytes,
fee_config.fee_per_contract_event_1kb,
DATA_SIZE_1KB_INCREMENT,
);

let bandwidth_fee = compute_fee_per_increment(
tx_resources.transaction_size_bytes,
fee_config.fee_per_propagate_1kb,
fee_config.fee_per_transaction_size_1kb,
DATA_SIZE_1KB_INCREMENT,
);

let refundable_fee = meta_data_fee;
let refundable_fee = events_fee;
let non_refundable_fee = compute_fee
.saturating_add(ledger_read_entry_fee)
.saturating_add(ledger_write_entry_fee)
Expand Down
26 changes: 13 additions & 13 deletions soroban-env-host/tests/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn resource_fee_computation() {
write_entries: 0,
read_bytes: 0,
write_bytes: 0,
metadata_size_bytes: 0,
contract_events_size_bytes: 0,
transaction_size_bytes: 0,
},
&FeeConfiguration {
Expand All @@ -25,8 +25,8 @@ fn resource_fee_computation() {
fee_per_read_1kb: 100,
fee_per_write_1kb: 100,
fee_per_historical_1kb: 100,
fee_per_metadata_1kb: 100,
fee_per_propagate_1kb: 100,
fee_per_contract_event_1kb: 100,
fee_per_transaction_size_1kb: 100,
},
),
// 30 comes from TX_BASE_RESULT_SIZE
Expand All @@ -42,7 +42,7 @@ fn resource_fee_computation() {
write_entries: 1,
read_bytes: 1,
write_bytes: 1,
metadata_size_bytes: 1,
contract_events_size_bytes: 1,
transaction_size_bytes: 1,
},
&FeeConfiguration {
Expand All @@ -52,8 +52,8 @@ fn resource_fee_computation() {
fee_per_read_1kb: 100,
fee_per_write_1kb: 100,
fee_per_historical_1kb: 100,
fee_per_metadata_1kb: 100,
fee_per_propagate_1kb: 100,
fee_per_contract_event_1kb: 100,
fee_per_transaction_size_1kb: 100,
},
),
// 2 entry read + 1 write + 30 from TX_BASE_RESULT_SIZE + 1 for
Expand All @@ -70,7 +70,7 @@ fn resource_fee_computation() {
write_entries: 10,
read_bytes: 25_600,
write_bytes: 10_340,
metadata_size_bytes: 321_654,
contract_events_size_bytes: 321_654,
transaction_size_bytes: 35_721,
},
&FeeConfiguration {
Expand All @@ -80,8 +80,8 @@ fn resource_fee_computation() {
fee_per_read_1kb: 1500,
fee_per_write_1kb: 3000,
fee_per_historical_1kb: 300,
fee_per_metadata_1kb: 200,
fee_per_propagate_1kb: 900,
fee_per_contract_event_1kb: 200,
fee_per_transaction_size_1kb: 900,
},
),
(1_242_089, 62824)
Expand All @@ -96,7 +96,7 @@ fn resource_fee_computation() {
write_entries: u32::MAX,
read_bytes: u32::MAX,
write_bytes: u32::MAX,
metadata_size_bytes: u32::MAX,
contract_events_size_bytes: u32::MAX,
transaction_size_bytes: u32::MAX,
},
&FeeConfiguration {
Expand All @@ -106,11 +106,11 @@ fn resource_fee_computation() {
fee_per_read_1kb: i64::MAX,
fee_per_write_1kb: i64::MAX,
fee_per_historical_1kb: i64::MAX,
fee_per_metadata_1kb: i64::MAX,
fee_per_propagate_1kb: i64::MAX,
fee_per_contract_event_1kb: i64::MAX,
fee_per_transaction_size_1kb: i64::MAX,
},
),
// The refundable (metadata) fee is not i64::MAX because we do division
// The refundable (events) fee is not i64::MAX because we do division
// after multiplication and hence it's i64::MAX / 1024.
// Hitting the integer size limits shouldn't be an issue in practice;
// we need to just make sure there are no overflows.
Expand Down