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

soroban-rpc: preflight: remove key sizes from read_bytes computation #922

Merged
merged 5 commits into from
Sep 5, 2023
Merged
Changes from 2 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
29 changes: 9 additions & 20 deletions cmd/soroban-rpc/lib/preflight/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ pub(crate) fn compute_host_function_transaction_data_and_min_fee(
bucket_list_size: u64,
current_ledger_seq: u32,
) -> Result<(SorobanTransactionData, i64)> {
// TODO: is this OK?
let init_expiration_entries = ExpirationEntryMap::new();
let ledger_changes =
get_ledger_changes(budget, post_storage, pre_storage, init_expiration_entries)?;
get_ledger_changes(budget, post_storage, pre_storage, ExpirationEntryMap::new())?;
let soroban_resources =
calculate_host_function_soroban_resources(&ledger_changes, &post_storage.footprint, budget)
.context("cannot compute host function resources")?;
Expand Down Expand Up @@ -141,22 +139,17 @@ fn calculate_host_function_soroban_resources(
.context("cannot convert storage footprint to ledger footprint")?;
let read_bytes: u32 = ledger_changes
.iter()
.map(
|c| {
let mut size = c.encoded_key.len() as u32 + c.old_entry_size_bytes;
if c.expiration_change.is_some() {
size += EXPIRATION_ENTRY_SIZE;
}
size
}, //size
)
.map(|c| {
c.old_entry_size_bytes
+ c.expiration_change
.as_ref()
.map_or(0, |_| EXPIRATION_ENTRY_SIZE)
})
.sum();

let write_bytes: u32 = ledger_changes
.iter()
.map(|c| {
c.encoded_key.len() as u32 + c.encoded_new_value.as_ref().map_or(0, Vec::len) as u32
})
.map(|c| c.encoded_new_value.as_ref().map_or(0, Vec::len) as u32)
.sum();

// Add a 20% leeway with a minimum of 50k instructions
Expand Down Expand Up @@ -259,15 +252,11 @@ fn calculate_unmodified_ledger_entry_bytes(
) -> Result<u32> {
let mut res: usize = 0;
for lk in ledger_entries {
let key_xdr = lk
.to_xdr()
.with_context(|| format!("cannot marshall ledger key {lk:?}"))?;
let key_size = key_xdr.len();
let entry_xdr = pre_storage
.get_xdr(lk, include_expired)
.with_context(|| format!("cannot get xdr of ledger entry with key {lk:?}"))?;
let entry_size = entry_xdr.len();
res += key_size + entry_size;
res += entry_size;
}
Ok(res as u32)
}
Expand Down