Skip to content

Commit

Permalink
fix: add gas cost of consumed by callee instance (#63)
Browse files Browse the repository at this point in the history
* refactor: remove available gas parameter by contract_call

* fix: add gas cost by callee instance

* chore: update prebuilt binaries

* chore: cargo fmt

* chore: update to latest cosmwasm
  • Loading branch information
Jiyong Ha authored May 11, 2022
1 parent ea65d9f commit c8ce5fa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ default = []
backtraces = []

[dependencies]
cosmwasm-std = { git = "https://github.com/line/cosmwasm", rev = "990b9e19728b7e19489df1e5919c8c623b3e7d6e", features = ["iterator","staking","stargate"] }
cosmwasm-vm = { git = "https://github.com/line/cosmwasm", rev = "990b9e19728b7e19489df1e5919c8c623b3e7d6e", features = ["iterator","staking","stargate"] }
cosmwasm-std = { git = "https://github.com/line/cosmwasm", rev = "d81a930ee2d6d92980e2696b9c24bd984a3f71e4", features = ["iterator","staking","stargate"] }
cosmwasm-vm = { git = "https://github.com/line/cosmwasm", rev = "d81a930ee2d6d92980e2696b9c24bd984a3f71e4", features = ["iterator","staking","stargate"] }
errno = "0.2"
serde_json = "1.0"
thiserror = "1.0"
Expand Down
Binary file modified api/libwasmvm.dylib
Binary file not shown.
Binary file modified api/libwasmvm.so
Binary file not shown.
21 changes: 12 additions & 9 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ impl BackendApi for GoApi {
contract_addr: &str,
func_info: &FunctionMetadata,
args: &[WasmerVal],
gas: u64,
) -> BackendResult<Box<[WasmerVal]>>
where
A: BackendApi + 'static,
Expand All @@ -161,7 +160,11 @@ impl BackendApi for GoApi {
&mut used_gas as *mut u64,
)
.into();
let gas_info = GasInfo::with_cost(used_gas);
let mut gas_info = GasInfo::with_cost(used_gas);
let gas_limit = match caller_env.get_gas_left().checked_sub(used_gas) {
Some(renaming) => renaming,
None => return (Err(BackendError::out_of_gas()), gas_info),
};

// return complete error message (reading from buffer for GoResult::Other)
let default = || {
Expand Down Expand Up @@ -195,10 +198,6 @@ impl BackendApi for GoApi {
None => return (Err(BackendError::unknown("invalid checksum")), gas_info),
};
let backend = into_backend(db, *self, querier);
let gas_limit = match gas.checked_sub(used_gas) {
Some(renaming) => renaming,
None => return (Err(BackendError::out_of_gas()), gas_info),
};

let print_debug = false;
let options = InstanceOptions {
Expand All @@ -224,12 +223,16 @@ impl BackendApi for GoApi {
&arg_region_ptrs,
) {
Ok(rets) => {
copy_region_vals_between_env(&callee_instance.env, caller_env, &rets, true).unwrap()
Ok(
copy_region_vals_between_env(&callee_instance.env, caller_env, &rets, true)
.unwrap(),
)
}
Err(e) => return (Err(BackendError::unknown(e.to_string())), gas_info),
Err(e) => Err(BackendError::unknown(e.to_string())),
};
gas_info.cost += callee_instance.create_gas_report().used_internally;

(Ok(call_ret), gas_info)
(call_ret, gas_info)
}
}

Expand Down

0 comments on commit c8ce5fa

Please sign in to comment.