Skip to content

Commit

Permalink
make sure that the hacked resoruces are also returned
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Jul 26, 2023
1 parent b747b77 commit 8677f5f
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions cmd/soroban-rpc/lib/preflight/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ pub(crate) fn compute_host_function_transaction_data_and_min_fee(
events: &Vec<DiagnosticEvent>,
bucket_list_size: u64,
) -> Result<(SorobanTransactionData, i64), Box<dyn error::Error>> {
let soroban_resources =
calculate_host_function_soroban_resources(snapshot_source, storage, budget, events)?;
let soroban_resources = hack_soroban_resources(calculate_host_function_soroban_resources(
snapshot_source,
storage,
budget,
events,
)?);
let fee_configuration = get_fee_configuration(snapshot_source, bucket_list_size)?;

let read_write_entries = u32::try_from(soroban_resources.footprint.read_write.as_vec().len())?;
Expand Down Expand Up @@ -315,13 +319,13 @@ pub(crate) fn compute_bump_footprint_exp_transaction_data_and_min_fee(
snapshot_source,
false,
)?;
let soroban_resources = SorobanResources {
let soroban_resources = hack_soroban_resources(SorobanResources {
footprint,
instructions: 0,
read_bytes,
write_bytes: 0,
extended_meta_data_size_bytes: 2 * read_bytes,
};
});
let transaction_resources = TransactionResources {
instructions: 0,
read_entries: u32::try_from(soroban_resources.footprint.read_only.as_vec().len())?,
Expand Down Expand Up @@ -358,15 +362,15 @@ pub(crate) fn compute_restore_footprint_transaction_data_and_min_fee(
snapshot_source,
true,
)?;
let soroban_resources = SorobanResources {
let soroban_resources = hack_soroban_resources(SorobanResources {
footprint,
instructions: 0,
// FIXME(fons): this seems to be a workaround a bug in code (the fix is to also count bytes read but not written in readBytes).
// we should review it in preview 11.
read_bytes: write_bytes,
write_bytes,
extended_meta_data_size_bytes: 2 * write_bytes,
};
});
let entry_count = u32::try_from(soroban_resources.footprint.read_write.as_vec().len())?;
let transaction_resources = TransactionResources {
instructions: 0,
Expand All @@ -393,27 +397,27 @@ pub(crate) fn compute_restore_footprint_transaction_data_and_min_fee(
Ok((transaction_data, min_fee))
}

fn compute_transaction_resource_fee_wrapper(
tx_resources: &TransactionResources,
fee_config: &FeeConfiguration,
) -> (i64, i64) {
fn hack_soroban_resources(resources: SorobanResources) -> SorobanResources {
// FIXME: Hack suggested by the core team until they include expiration ledger bumps
let resources = TransactionResources {
instructions: tx_resources.instructions,
read_entries: tx_resources.read_entries,
write_entries: tx_resources.read_entries,
return SorobanResources {
footprint: resources.footprint,
instructions: resources.instructions,
read_bytes: max(
tx_resources.read_bytes + 1000,
tx_resources.read_bytes * 120 / 100,
resources.read_bytes + 1000,
resources.read_bytes * 120 / 100,
),
write_bytes: tx_resources.write_bytes,
metadata_size_bytes: max(
tx_resources.metadata_size_bytes + 1000,
tx_resources.metadata_size_bytes * 120 / 100,
write_bytes: resources.write_bytes,
extended_meta_data_size_bytes: max(
resources.extended_meta_data_size_bytes + 1000,
resources.extended_meta_data_size_bytes * 120 / 100,
),
transaction_size_bytes: tx_resources.transaction_size_bytes,
};
}

fn compute_transaction_resource_fee_wrapper(
tx_resources: &TransactionResources,
fee_config: &FeeConfiguration,
) -> (i64, i64) {
let (min_fee, ref_fee) = compute_transaction_resource_fee(&resources, fee_config);
// FIXME: Hack suggested by the core team, until we compute rent fees properly
return (min_fee + 10000, ref_fee + 10000);
Expand Down

0 comments on commit 8677f5f

Please sign in to comment.