Skip to content

Commit

Permalink
Fix rent changes extraction bug (#1043)
Browse files Browse the repository at this point in the history
* wip: fix rent charge and add test contract

* clean up test changes

* Revert "clean up test changes"

This reverts commit 0ea35f4.

* storage contract: replace "increase size" fn with `replace_with_bytes_and_bump`

* Clean up invocation test
  • Loading branch information
jayz22 authored Sep 8, 2023
1 parent 0c613eb commit 880afe7
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 7 deletions.
3 changes: 2 additions & 1 deletion soroban-env-host/src/e2e_invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ pub fn extract_rent_changes(ledger_changes: &Vec<LedgerEntryChange>) -> Vec<Ledg
&entry_change.expiration_change,
&entry_change.encoded_new_value,
) {
// Skip non-bumped entries as well.
// Skip the entry if 1. it is not bumped and 2. the entry size has not increased
if expiration_change.old_expiration_ledger
>= expiration_change.new_expiration_ledger
&& entry_change.old_entry_size_bytes >= encoded_new_value.len() as u32
{
return None;
}
Expand Down
46 changes: 40 additions & 6 deletions soroban-test-wasms/wasm-workspace/contract_data/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]
use soroban_sdk::{contract, contractimpl, Env, Symbol};
use soroban_sdk::{contract, contractimpl, Bytes, Env, Symbol};

#[contract]
pub struct Contract;
Expand All @@ -22,8 +22,15 @@ impl Contract {
e.storage().persistent().get(&key).unwrap()
}

pub fn bump_persistent(e: Env, key: Symbol, low_expiration_watermark: u32, high_expiration_watermark: u32) {
e.storage().persistent().bump(&key, low_expiration_watermark, high_expiration_watermark)
pub fn bump_persistent(
e: Env,
key: Symbol,
low_expiration_watermark: u32,
high_expiration_watermark: u32,
) {
e.storage()
.persistent()
.bump(&key, low_expiration_watermark, high_expiration_watermark)
}

pub fn put_temporary(e: Env, key: Symbol, val: u64) {
Expand All @@ -42,8 +49,15 @@ impl Contract {
e.storage().temporary().get(&key).unwrap()
}

pub fn bump_temporary(e: Env, key: Symbol, low_expiration_watermark: u32, high_expiration_watermark: u32) {
e.storage().temporary().bump(&key, low_expiration_watermark, high_expiration_watermark)
pub fn bump_temporary(
e: Env,
key: Symbol,
low_expiration_watermark: u32,
high_expiration_watermark: u32,
) {
e.storage()
.temporary()
.bump(&key, low_expiration_watermark, high_expiration_watermark)
}

pub fn put_instance(e: Env, key: Symbol, val: u64) {
Expand All @@ -63,6 +77,26 @@ impl Contract {
}

pub fn bump_instance(e: Env, low_expiration_watermark: u32, high_expiration_watermark: u32) {
e.storage().instance().bump(low_expiration_watermark, high_expiration_watermark)
e.storage()
.instance()
.bump(low_expiration_watermark, high_expiration_watermark)
}

pub fn replace_with_bytes_and_bump(
e: Env,
key: Symbol,
num_kilo_bytes: u32,
low_expiration_watermark: u32,
high_expiration_watermark: u32,
) {
let slice = [0_u8; 1024];
let mut bytes = Bytes::new(&e);
for _ in 0..num_kilo_bytes {
bytes.extend_from_slice(&slice);
}
e.storage().persistent().set(&key, &bytes);
e.storage()
.persistent()
.bump(&key, low_expiration_watermark, high_expiration_watermark)
}
}
Binary file modified soroban-test-wasms/wasm-workspace/opt/auth_test_contract.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_add_f32.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_add_i32.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_alloc.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_complex.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_contract_data.wasm
Binary file not shown.
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_err.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_fannkuch.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_fib.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_hostile.wasm
Binary file not shown.
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_linear_memory.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_vec.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 880afe7

Please sign in to comment.