This PR is fixing a bug in the sync mechanism between wasmi and
pallet-contracts. This bug leads to essentially double charging all the
gas that was used during the execution of the host function. When the
`call` host function is used for recursion this will lead to a quadratic
amount of gas consumption with regard to the nesting depth.We also took
the chance to refactor the code in question and improve the rust docs.
The bug was caused by not updating `GasMeter::executor_consumed`
(previously `engine_consumed`) when leaving the host function. This lead
to the value being stale (too low) when entering another host function.
---------
Co-authored-by: PG Herveou <pgherveou@gmail.com>
see #2189
This PR does the following:
- Bring the user api functions into a new pallet-contracts-uapi (They
are currently defined in ink!
[here])(https://github.com/paritytech/ink/blob/master/crates/env/src/engine/on_chain/ext.rs)
- Add older api versions and unstable to the user api trait.
- Remove pallet-contracts-primitives and bring the types it defined in
uapi / pallet-contracts
- Add the infrastructure to build fixtures from Rust files and test it
works by replacing `dummy.wat` and `call.wat`
- Move all the doc from wasm/runtime.rs to pallet-contracts-uapi.
This will be done in a follow up:
- convert the rest of the test from .wat to rust
- bring risc-v uapi up to date with wasm
- finalize the uapi host fns, making sure everything is codegen from the
source host fns in pallet-contracts
---------
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* globally upgrade quote to latest 1.0.x (1.0.26)
* globally upgrade syn to final 1.0.x version (1.0.109)
* globally upgrade proc-macro2 to 1.0.56
* upgrade to syn v2.0.13 and fix everything except NestedMeta
* fix parse nested metadata code in decl_runtime_apis.rs
* Port more stuff to syn 2.0
* Make the rest compile
* Ignore error
* update to syn 2.0.14
---------
Co-authored-by: Bastian Köcher <info@kchr.de>
* Change copyright year to 2023 from 2022
* Fix incorrect update of copyright year
* Remove years from copy right header
* Fix remaining files
* Fix typo in a header and remove update-copyright.sh
* macro to expand traits for host functions documentation
* other way: same Doc trait in seal modules
* added docs for macro, and remove `doc` attribute
* fmt
* Apply suggestions from code review
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* make docs to be generated into re-exported `api_doc` module; fix
unrelated elder docs;
* make it compile without `doc` attr passed to macro
* make alias functions indicated explicitly in docs
* tidy up docs
* refactored a bit
* macro to auto-add doc warning for unstable functions
* invoke macro with no doc generation by default
* addressed review comments
* hide api_doc module behind cfg(doc)
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* works but ugly
* refactored + renamed host fns
* fixed tests
* fix benchmarks
* updated marco docs
* Update frame/contracts/proc-macro/src/lib.rs
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fix for the duplicated prefixed alias bug + test
* refactored a bit
* fix warnings + try to make macro rustdoc compile
* fmt after clearing
* examples update + nocompile
* add seal_ prefixes to unstable host functions
* updated after a review
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* Run cargo fmt on the whole code base
* Second run
* Add CI check
* Fix compilation
* More unnecessary braces
* Handle weights
* Use --all
* Use correct attributes...
* Fix UI tests
* AHHHHHHHHH
* 🤦
* Docs
* Fix compilation
* 🤷
* Please stop
* 🤦 x 2
* More
* make rustfmt.toml consistent with polkadot
Co-authored-by: André Silva <andrerfosilva@gmail.com>
* pallet_contracts: Inline benchmark helper that is only used once
* Move all max_* Schedule items into a new struct
* Limit the number of globals a module can declare
* The current limits are too high for wasmi to even execute
* Limit the amount of parameters any wasm function is allowed to have
* Limit the size the BrTable's immediate value
* Add instruction benchmarks
* Add new benchmarks to the schedule and make use of it
* Add Benchmark Results generated by the bench bot
* Add proc macro that implements `Debug` for `Schedule`
* Add missing imports necessary for no_std build
* Make the WeightDebug macro available for no_std
In this case a dummy implementation is derived in order to not
blow up the code size akin to the RuntimeDebug macro.
* Rework instr_memory_grow benchmark to use only the maximum amount of pages allowed
* Add maximum amount of memory when benching (seal_)call/instantiate
* cargo run --release --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml -- benchmark --chain dev --steps 50 --repeat 20 --extrinsic * --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output ./bin/node/runtime/src/weights --header ./HEADER --pallet pallet_contracts
* Added utility benchmark that allows pretty printing of the real schedule
* review: Add missing header to the proc-macro lib.rs
* review: Clarify why #[allow(dead_code)] attribute is there
* review: Fix pwasm-utils line
* review: Fixup rand usage
* review: Fix typo
* review: Imported -> Exported
* 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
* contracts: Adapt to new weight structure
* contracts: Fixup runtime WeightInfo
* contracts: Remove unneeded fullpath of WeightInfo type
* Apply suggestions from code review
Co-authored-by: Andrew Jones <ascjones@gmail.com>
* Fix typo in schedule.rs
Co-authored-by: Andrew Jones <ascjones@gmail.com>
* Fix docs in schedule.rs
* Apply suggestions from code review
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
* Don't publish proc-macro crate until 3.0.0 is ready
* Optimize imports for less repetition
* Break overlong line
Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>