Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
eacb017
added [unstable][seal2] call()
agryaznov Mar 7, 2023
b3c9265
updated test to cover new seal_call proof_limit
agryaznov Mar 7, 2023
e226add
docs updated
agryaznov Mar 7, 2023
aba8782
add [seal2][unstable] instantiate() and test
agryaznov Mar 7, 2023
53d8fde
add [seal2][unstable] weight_to_fee() + docs and test
agryaznov Mar 7, 2023
09d1df6
add [seal2][unstable] gas_left() + docs and test
agryaznov Mar 8, 2023
c644fa1
update benchmarks
agryaznov Mar 8, 2023
2cb30c7
add DefaultDepositLimit to pallet Config
agryaznov Mar 8, 2023
a968b29
specify deposit limit for nested call
agryaznov Mar 9, 2023
45b48c2
specify deposit limit for nested instantiate
agryaznov Mar 13, 2023
ec58346
Merge branch 'master' into ag-proof_limit
agryaznov Mar 14, 2023
edf1aac
update benchmarks
agryaznov Mar 14, 2023
2bfb866
added missing fixtures
agryaznov Mar 16, 2023
1ff3f16
fix benches
agryaznov Mar 16, 2023
b0f3103
pass explicit deposit limit to storage bench
agryaznov Mar 16, 2023
3af8712
explicit deposit limit for another set_storage bench
agryaznov Mar 16, 2023
825a6bc
add more deposit limit for storage benches
agryaznov Mar 16, 2023
8f9ea17
moving to simplified benchmarks
agryaznov Mar 16, 2023
6ac5355
Merge branch 'master' into ag-proof_limit
agryaznov Mar 16, 2023
04ead1b
moved to simplified benchmarks
agryaznov Mar 16, 2023
7d1023d
fix seal_weight_to_fee bench
agryaznov Mar 16, 2023
8e6c6d2
fix seal_instantiate benchmark
agryaznov Mar 16, 2023
d618957
Merge branch 'master' into ag-proof_limit
agryaznov Mar 30, 2023
16f0994
doc typo fix
agryaznov Mar 31, 2023
24dcd0e
default dl for benchmarking
agryaznov Mar 31, 2023
d7eab4a
max_runtime_mem to Schedule limits
agryaznov Apr 3, 2023
91fd102
Merge branch 'master' into ag-proof_limit
agryaznov Apr 3, 2023
af1b353
add default deposit limit fallback check to test
agryaznov Apr 12, 2023
04bea78
weight params renaming
agryaznov Apr 12, 2023
c01f166
Merge branch 'master' into ag-proof_limit
agryaznov Apr 12, 2023
50c96da
fmt
agryaznov Apr 12, 2023
95c83ea
Update frame/contracts/src/benchmarking/mod.rs
agryaznov Apr 25, 2023
22c5794
prettify inputs in tests
agryaznov Apr 25, 2023
418aa50
Merge branch 'ag-proof_limit' of github.com:paritytech/substrate into…
agryaznov Apr 25, 2023
0dac6f6
typestate param refactored
agryaznov Apr 25, 2023
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
Prev Previous commit
Next Next commit
specify deposit limit for nested instantiate
save: works with test

cleaned up debugging outputs
  • Loading branch information
agryaznov committed Mar 14, 2023
commit 45b48c2f27f1b8390eab35e8cefaa3dc4f3a06c8
6 changes: 5 additions & 1 deletion frame/contracts/fixtures/caller_contract.wat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(import "seal0" "seal_balance" (func $seal_balance (param i32 i32)))
(import "seal2" "call" (func $seal_call (param i32 i32 i64 i64 i32 i32 i32 i32 i32 i32) (result i32)))
(import "seal2" "instantiate" (func $seal_instantiate
(param i32 i64 i64 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)
(param i32 i64 i64 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)
))
(import "env" "memory" (memory 1 1))

Expand Down Expand Up @@ -45,6 +45,7 @@
(i32.const 24) ;; Pointer to the code hash.
(i64.const 0) ;; How much ref_time weight to devote for the execution. 0 = all.
(i64.const 0) ;; How much proof_size weight to devote for the execution. 0 = all.
(i32.const 0xffffffff) ;; u32 max sentinel value: pass no deposit limit.
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 9) ;; Pointer to input data buffer address
(i32.const 7) ;; Length of input data buffer
Expand All @@ -68,6 +69,7 @@
(i32.const 24) ;; Pointer to the code hash.
(i64.const 1) ;; Supply too little ref_time weight
(i64.const 0) ;; How much proof_size weight to devote for the execution. 0 = all.
(i32.const 0xffffffff) ;; u32 max sentinel value: pass no deposit limit.
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Pointer to input data buffer address
(i32.const 8) ;; Length of input data buffer
Expand All @@ -92,6 +94,7 @@
(i32.const 24) ;; Pointer to the code hash.
(i64.const 0) ;; How much ref_time weight to devote for the execution. 0 = all.
(i64.const 1) ;; Supply too little proof_size weight
(i32.const 0xffffffff) ;; u32 max sentinel value: pass no deposit limit.
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Pointer to input data buffer address
(i32.const 8) ;; Length of input data buffer
Expand Down Expand Up @@ -122,6 +125,7 @@
(i32.const 24) ;; Pointer to the code hash.
(i64.const 0) ;; How much ref_time weight to devote for the execution. 0 = all.
(i64.const 0) ;; How much proof_size weight to devote for the execution. 0 = all.
(i32.const 0xffffffff) ;; u32 max sentinel value: pass no deposit limit.
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Pointer to input data buffer address
(i32.const 8) ;; Length of input data buffer
Expand Down
4 changes: 2 additions & 2 deletions frame/contracts/fixtures/create_storage_and_call.wat
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
(i32.store (i32.const 0) (i32.const 512))

;; copy input at address 4:
;; first 4 bytes for the storage size
;; first 4 bytes for the size of the storage to be created in callee
;; next 32 bytes are for the callee address
;; next bytes for the encoded deposit limit
(call $seal_input (i32.const 4) (i32.const 0))
Expand All @@ -40,7 +40,7 @@
(i32.const 8) ;; Pointer to "callee" address
(i64.const 0) ;; How much ref_time to devote for the execution. 0 = all
(i64.const 0) ;; How much proof_limit to devote for the execution. 0 = all
(i32.const 40) ;; Pointer to storage deposit limit
(i32.const 40) ;; Pointer to the storage deposit limit
(i32.const 512) ;; Pointer to the buffer with value to transfer
(i32.const 4) ;; Pointer to input data buffer address
(i32.const 4) ;; Length of input data buffer
Expand Down
45 changes: 0 additions & 45 deletions frame/contracts/fixtures/store.wat

This file was deleted.

35 changes: 32 additions & 3 deletions frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub trait Ext: sealing::Sealed {
fn instantiate(
&mut self,
gas_limit: Weight,
deposit_limit: BalanceOf<Self::T>,
code: CodeHash<Self::T>,
value: BalanceOf<Self::T>,
input_data: Vec<u8>,
Expand Down Expand Up @@ -895,6 +896,13 @@ where
return Err(Error::<T>::TerminatedInConstructor.into())
}

// If a special limit was set for the sub-call, we enforce it here.
// This is needed because contract constructor might write to storage.
// The sub-call will be rolled back in case the limit is exhausted.
let frame = self.top_frame_mut();
let contract = frame.contract_info.as_contract();
frame.nested_storage.enforce_subcall_limit(contract)?;

// Deposit an instantiation event.
Contracts::<T>::deposit_event(
vec![T::Hashing::hash_of(self.caller()), T::Hashing::hash_of(account_id)],
Expand Down Expand Up @@ -1200,6 +1208,7 @@ where
fn instantiate(
&mut self,
gas_limit: Weight,
deposit_limit: BalanceOf<Self::T>,
code_hash: CodeHash<T>,
value: BalanceOf<T>,
input_data: Vec<u8>,
Expand All @@ -1217,7 +1226,7 @@ where
},
value,
gas_limit,
BalanceOf::<T>::zero(),
deposit_limit,
)?;
let account_id = self.top_frame().account_id.clone();
self.run(executable, input_data).map(|ret| (account_id, ret))
Expand Down Expand Up @@ -2339,6 +2348,7 @@ mod tests {
.ext
.instantiate(
Weight::zero(),
BalanceOf::<Test>::zero(),
dummy_ch,
<Test as Config>::Currency::minimum_balance(),
vec![],
Expand Down Expand Up @@ -2403,6 +2413,7 @@ mod tests {
assert_matches!(
ctx.ext.instantiate(
Weight::zero(),
BalanceOf::<Test>::zero(),
dummy_ch,
<Test as Config>::Currency::minimum_balance(),
vec![],
Expand Down Expand Up @@ -2927,6 +2938,7 @@ mod tests {
ctx.ext
.instantiate(
Weight::zero(),
BalanceOf::<Test>::zero(),
fail_code,
ctx.ext.minimum_balance() * 100,
vec![],
Expand All @@ -2940,6 +2952,7 @@ mod tests {
.ext
.instantiate(
Weight::zero(),
BalanceOf::<Test>::zero(),
success_code,
ctx.ext.minimum_balance() * 100,
vec![],
Expand Down Expand Up @@ -3454,15 +3467,31 @@ mod tests {
assert_eq!(ctx.ext.nonce(), 1);
// Should not change with a failed instantiation
assert_err!(
ctx.ext.instantiate(Weight::zero(), fail_code, 0, vec![], &[],),
ctx.ext.instantiate(
Weight::zero(),
BalanceOf::<Test>::zero(),
fail_code,
0,
vec![],
&[],
),
ExecError {
error: <Error<Test>>::ContractTrapped.into(),
origin: ErrorOrigin::Callee
}
);
assert_eq!(ctx.ext.nonce(), 1);
// Successful instantation increments
ctx.ext.instantiate(Weight::zero(), success_code, 0, vec![], &[]).unwrap();
ctx.ext
.instantiate(
Weight::zero(),
BalanceOf::<Test>::zero(),
success_code,
0,
vec![],
&[],
)
.unwrap();
assert_eq!(ctx.ext.nonce(), 2);
exec_success()
});
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/storage/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ where
self.total_deposit = deposit.clone();
info.storage_base_deposit = deposit.charge_or_zero();

// Usually, deposit charges are deferred to be able to coalesce them with refunds.
// Normally, deposit charges are deferred to be able to coalesce them with refunds.
// However, we need to charge immediately so that the account is created before
// charges possibly below the ed are collected and fail.
E::charge(
Expand Down
Loading