contracts: Refactor the exec module (#8604)

* contracts: Add default implementation for Executable::occupied_storage()

* contracts: Refactor the exec module

* Let runtime specify the backing type of the call stack

This removes the need for a runtime check of the specified
`MaxDepth`. We can now garantuee that we don't need to
allocate when a new call frame is pushed.

* Fix doc typo

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_contracts --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/contracts/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Review nits

* Fix defect in contract info caching behaviour

* Add more docs

* Fix wording and typos

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
This commit is contained in:
Alexander Theißen
2021-05-07 14:37:30 +02:00
committed by GitHub
parent 17a1997d18
commit 9e894ce135
15 changed files with 2064 additions and 1862 deletions
@@ -166,16 +166,17 @@ where
/// Store the supplied storage items into this contracts storage.
fn store(&self, items: &Vec<(StorageKey, Vec<u8>)>) -> Result<(), &'static str> {
let info = self.alive_info()?;
let mut info = self.alive_info()?;
for item in items {
Storage::<T>::write(
&self.account_id,
&info.trie_id,
<System<T>>::block_number(),
&mut info,
&item.0,
Some(item.1.clone()),
)
.map_err(|_| "Failed to write storage to restoration dest")?;
}
<ContractInfoOf<T>>::insert(&self.account_id, ContractInfo::Alive(info.clone()));
Ok(())
}
@@ -1148,16 +1149,17 @@ benchmarks! {
.. Default::default()
});
let instance = Contract::<T>::new(code, vec![], Endow::Max)?;
let trie_id = instance.alive_info()?.trie_id;
let mut info = instance.alive_info()?;
for key in keys {
Storage::<T>::write(
&instance.account_id,
&trie_id,
<System<T>>::block_number(),
&mut info,
key.as_slice().try_into().map_err(|e| "Key has wrong length")?,
Some(vec![42; T::MaxValueSize::get() as usize])
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, ContractInfo::Alive(info.clone()));
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::max_value(), vec![])
@@ -1193,16 +1195,17 @@ benchmarks! {
.. Default::default()
});
let instance = Contract::<T>::new(code, vec![], Endow::Max)?;
let trie_id = instance.alive_info()?.trie_id;
let mut info = instance.alive_info()?;
for key in keys {
Storage::<T>::write(
&instance.account_id,
&trie_id,
<System<T>>::block_number(),
&mut info,
key.as_slice().try_into().map_err(|e| "Key has wrong length")?,
Some(vec![])
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, ContractInfo::Alive(info.clone()));
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::max_value(), vec![])
@@ -1238,14 +1241,15 @@ benchmarks! {
.. Default::default()
});
let instance = Contract::<T>::new(code, vec![], Endow::Max)?;
let trie_id = instance.alive_info()?.trie_id;
let mut info = instance.alive_info()?;
Storage::<T>::write(
&instance.account_id,
&trie_id,
<System<T>>::block_number(),
&mut info,
key.as_slice().try_into().map_err(|e| "Key has wrong length")?,
Some(vec![42u8; (n * 1024) as usize])
)
.map_err(|_| "Failed to write to storage during setup.")?;
<ContractInfoOf<T>>::insert(&instance.account_id, ContractInfo::Alive(info.clone()));
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::max_value(), vec![])