* Remove pre-charging for code size
* Remove pre charging when reading values of fixed size
* Add new versions of API functions that leave out parameters
* Update CHANGELOG.md
* Apply suggestions from code review
Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
* Add v1 for seal_set_rent_allowance
* Remove unneeded trait bound
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
* Remove unused event_metadata variable
* Eliminate mod_name and use pallet names to name enum variants
* Rename field name `pallet` to `path`
* Use only the pallet name to generate variant names
* Use new naming scheme for Event enum in sudo pallet tests
* Use new naming scheme for Event enum in offences pallet tests
* Use new naming scheme for Event enum in contracts pallet tests
* Use new naming scheme for Event enum in collective pallet tests
* Use new naming scheme for Event enum in bounties pallet tests
* Use new naming scheme for Event enum in balances pallet tests
* Use new naming scheme for Event enum in assets pallet tests
* Use new naming scheme for Event enum in frame support tests
* Use new naming scheme for Event enum in tips pallet tests
* Use new naming scheme for Event enum in transaction payment pallet tests
* Use new naming scheme for GenesisConfig fields in example pallet tests
* Use new naming scheme for GenesisConfig fields in elections pallet tests
* Use new naming scheme for Event enum in election provider multi-phase pallet tests
* Use new naming scheme for Event enum in elections phragmen pallet tests
* Use new naming scheme for GenesisConfig fields in chain spec
* Use new naming scheme for Event enum in staking pallet mock
* Use new naming scheme for GenesisConfig fields in node-template chain spec
* Use new naming scheme for GenesisConfig fields in node-testing chain spec
* Use new naming scheme for Event enum in node executor tests
* Use new naming scheme for GenesisConfig fields in transaction storage pallet mock
* Refactor match conditions
* Add new `seal_call` that offers new features
* Fix doc typo
Co-authored-by: Michael Müller <michi@parity.io>
* Fix doc typos
Co-authored-by: Michael Müller <michi@parity.io>
* Fix comment on assert
* Update CHANGELOG.md
Co-authored-by: Michael Müller <michi@parity.io>
* Fix output of wrongly outputted error
The "Tombstoned a contract that is below the subsistence threshold: {:?}" was
triggered when too few balance was provided. It was a false alarm.
* Fix return of wrong code_len
* Split up `NotCallable` into more fine grained errors
* Fix typos in docs
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
* RentNotPayed -> RentNotPaid
* Fix typo: payed -> paid
It is OK to change the in-storage field name because:
1. The SCALE encoding is not based on names only on position.
2. The struct is not public (only to the crate).
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
* Move public functions up in rent.rs
* Added RentStatus
* Fix test name for consistency
Co-authored-by: Michael Müller <michi@parity.io>
* Mark rent functions as unstable
* Add unstable interfaces to README
* Fix doc typos
Co-authored-by: Andrew Jones <ascjones@gmail.com>
* Use DefaultNoBound
* Simplify calc_share(1)
* Don't output empty debug messages
* Make `seal_debug_message` unstable
Co-authored-by: Michael Müller <michi@parity.io>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
* Move `Schedule` from Storage to Config
* Updated CHANGELOG
* Fix nits from review
* Fix migration
* Print the debug buffer as tracing message
* Use `debug` instead of `trace` and update README
* Add additional assert to test
* Rename `schedule_version` to `instruction_weights_version`
* Fixed typo
* Added more comments to wat fixtures
* Add clarification for the `debug_message` field
* 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>
* contracts: Add RPC that allows instantiating of a contract
* Encode `debug_message` as bytes because usage of `String` is forbidden
* Remove erroneous derive attribute
* Fix rpc tests for new `debug_message` encoding
* Fix typo
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
* Use 'Pallet' struct in construct_runtime.
* Fix genesis and metadata macro.
* Fix 'Pallet' type alias.
* Replace 'Module' with 'Pallet' for all construct_runtime use cases.
* Replace more deprecated 'Module' struct.
* Bring back AllModules and AllPalletsWithSystem type, but deprecate them.
* Replace deprecated 'Module' struct from merge master.
* Minor fix.
* Fix UI tests.
* Revert UI override in derive_no_bound.
* Fix more deprecated 'Module' use from master branch.
* Fix more deprecated 'Module' use from master branch.
* more clear randomness API for BABE
* babe: move randomness utilities to its own file
* node: use babe::RandomnessFromOneEpochAgo in random_seed implementation
* frame-support: annotate randomness trait with block number
* pallet-randomness-collective-flip: fix for new randomness trait
* pallet-society: fix randomness usage
* pallet-lottery: fix randomness usage
* pallet-contracts: fix randomness usage
* pallet-babe: fix randomness usage
we need to track when the current and previous epoch started so that we
know the block number by each existing on-chain was known
* node: fix random_seed
* node-template: fix random_seed
* frame-support: extend docs
* babe: add test for epoch starting block number tracking
* babe: fix epoch randomness docs
* frame: add todos for dealing with randomness api changes
Co-authored-by: André Silva <andrerfosilva@gmail.com>
* contracts: Convert to framev2
* Reduce the API surface of the crate
* Remove unused import
* Merge import block
* Use pallet::metadata to reduce metadata diff
* Remove the explicit "Null" from AccountCounter
* contracts: Consider contract size in weights
* Bump spec version
* Whitespace fix
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
* Correct pre-charged code weight even in the error case
* Use the instrumented code size in weight calculation
* Charge the cost of re-instrumentation from the gas meter
* Fix benchmark
* 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
* Better documentation of return types
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
* Migrate bounties tests to use construct_runtime
* Migrate contracts tests to use construct_runtime
* Migrate democracy tests to use construct_runtime
* review: rename TreasuryEvent -> TreasuryError
* contracts: Implement refcounting for wasm code
* contracts: Charge rent for code storage
* contracts: Fix dispatchables erroneously refunding base costs
* Fixed typos in comments.
Co-authored-by: Andrew Jones <ascjones@gmail.com>
* Remove awkward empty line
* Fix more typos in docs
* Fix typos in docs
Co-authored-by: Andrew Jones <ascjones@gmail.com>
* Split up complicated expression
Co-authored-by: Andrew Jones <ascjones@gmail.com>
* review: Remove unused return value
* Fix typos
Co-authored-by: Andrew Jones <ascjones@gmail.com>
* review: Fix refcount being reset to one on re-instrumentation
* Document evictable_code parameter
* Make Executable::execute consume and store itself
* Added comments about stale values
* Disregard struct size in occupied_storage()
Co-authored-by: Andrew Jones <ascjones@gmail.com>
* Do not evict a contract from within a call stack
We don't want to trigger contract eviction automatically when
a contract is called. This is because those changes can be
reverted due to how storage transactions are used at the moment.
More Information:
https://github.com/paritytech/substrate/issues/6439#issuecomment-648754324
It can be re-introduced once the linked issue is resolved. In the meantime
`claim_surcharge` must be called to evict a contract.
* Lazily delete storage in on_initialize instead of when removing the contract
* Add missing documentation of new error
* Make Module::claim_surcharge public
It being the only dispatchable that is private is an oversight.
* review: Add final newline
* review: Simplify assert statement
* Add test that checks that partial remove of a contract works
* Premote warning to error
* Added missing docs for seal_terminate
* Lazy deletion should only take AVERAGE_ON_INITIALIZE_RATIO of the block
* Added informational about the lazy deletion throughput
* Avoid lazy deletion in case the block is already full
* Prevent queue decoding in case of an already full block
* Add test that checks that on_initialize honors block limits
* pallet-contracts: Fix seal_restore_to to output proper module errors
Those errors where part of the decl_error for some time but where
never actually returned. This allows proper debugging of failed
restorations. Previously, any error did return the misleading
`ContractTrapped`.
* Bind UncheckedFrom<T::Hash> + AsRef<[u8]> everywhere
This allows us to make assumptions about the AccoutId
that are necessary for testing and in order to benchmark
the module properly.
This also groups free standing functions into inherent functions
in order to minimize the places where the new bounds need to
be specified.
* Rework contract address determination
* Do not allow override by runtime author
* Instantiate gained a new parameter "salt"
This change is done now in expecation of the upcoming code rent
which needs to change the instantiation dispatchable and
host function anyways.
The situation in where we have only something that is like CREATE2
makes it impossible for UIs to help the user to create an arbitrary
amount of instantiations from the same code.
With this change we have the same functionality as ethereum with
a CREATE and CREATE2 instantation semantic.
* Remove TrieIdGenerator
The new trait bounds allows us to remove this workaround
from the configuration trait.
* Remove default parameters for config trait
It should be solely the responsiblity to determine proper values for
these parameter. As a matter of fact most runtime weren't using these
values anyways.
* Fix tests for new account id type
Because of the new bounds on the trait tests can't get away by using
u64 as accound id. Replacing the 8 byte value by a 32 byte value
creates out quite a bit of code churn.
* Fix benchmarks
The benchmarks need adaption to the new instantiate semantics.
* Fix compile errors caused by adding new trait bounds
* Fix compile errors caused by renaming storage and rent functions
* Adapt host functions and dispatchables to the new salt
* Add tests for instantiate host functions (was not possible before)
* Add benchmark results
* Adapt to the new WeightInfo
The new benchmarks add a new parameter for salt "s" to the instantiate weights
that needs to be applied.
* Fix deploying_wasm_contract_should_work integration test
This test is adapted to use the new instantiate signature.
* Break overlong line
* Break more long lines
Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
* contracts: Make use of existing type aliases for runtime API types
* contracts: Refactor the contracts call runtime API
* review: Fix comment typo
Co-authored-by: Andrew Jones <ascjones@gmail.com>
* Update frame/contracts/common/src/lib.rs
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
* Update frame/contracts/common/src/lib.rs
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
* Update frame/contracts/common/src/lib.rs
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
* Update frame/contracts/common/src/lib.rs
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
* Update frame/contracts/common/src/lib.rs
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
* Update lib.rs
* review: Group crate imports
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Addie Wagenknecht <addie@nortd.com>
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
* seal: Add capability to put uninstrumented code (for benchmarks)
Benchmarks should only measure the overhead of the API calls itself.
For that reason we want to run them without instrumentation.
* seal: Cap the the data length for deposited events
Data used in events has storage implications for archive nodes.
Those need to keep the events in storage forever. For that reason
we want to limit the amount of storage that can be used inside events.
* seal: Fix error reporting in the case out of bound sandbox access
* seal: Refactor existing benchmarks
* seal: Convert benchmark file to tabs
* seal: Add benchmarks for functions called by contracts
* seal: Create a default schedule from benchmark generated WeightInfo
* seal: Make use of WeightInfo in extrinsic weight annotations
* seal: Replace the old schedule by the benchmark generated one
* Review: Fix copy paste typo in schedule construction
* Review: Fix stale docs
* Fix whitespace errors
Co-authored-by: Sergei Shulepov <sergei@parity.io>
* Review: Use checked_div in order to be more defensive
* Review: Rename no_charge to already_charged
* Review: Whitelist caller of extrinsics
* Review: Remove trailing whitespace
* Review: Remove confusing "self::" syntax
* Review: Add docs for the benchmark prepration submodule
* Review: Move code generation functions to own module
* Review: Refactor and document benchmark helper functions
* Remove additional empty line
* Added missing comment on caller_funding
* Update frame/contracts/src/benchmarking/code.rs
Co-authored-by: Sergei Shulepov <sergei@parity.io>
* Fix missing sp_std::prelude import in code.rs
* 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 --output ./bin/node/runtime/src/weights --header ./HEADER --pallet pallet_contracts --heap-pages 4096
* Use weights from the benchmark machine for the substrate node
* Remove prefixes from Schedule members
* Data lengths in the WeightInfo Trait are specified in kilobytes
* Rename ApiWeights to HostFunctionWeights
Co-authored-by: Sergei Shulepov <sergei@parity.io>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
* seal: Change prefix "ext_" to "seal_" for contract callable functions
The word Ext is a overloaded term in the context of substrate. It usually
is a trait which abstracts away access to external resources usually in order
to mock them away for the purpose of tests. The contract module has its own
`Ext` trait in addition the the substrate `Ext` which makes things even more
confusing.
In order to differentiate the contract callable functions more clearly from
this `Ext` concept we rename them to use the "seal_" prefix instead.
This should change no behaviour at all. This is a pure renaming commit.
* seal: Rename import module from "env" to "seal0"
* seal: Fixup integration test
* seal: Add more tests for new import module names
* seal: Rework ext_transfer, ext_instantiate, ext_call error handling
* Deny calling plain accounts (must use transfer now)
* Return proper module error rather than ad-hoc strings
* Return the correct error codes from call,instantiate (documentation was wrong)
* Make ext_transfer fallible again to make it consistent with ext_call
* seal: Improve error messages on memory access failures
* seal: Convert contract trapped to module error
* seal: Add additional tests for transfer, call, instantiate
These tests verify that those functions return the error types
which are declared in its docs.
* Make it more pronounced that to_execution_result handles trap_reason
* Improve ReturnCode docs
* Fix whitespace issues in wat files
* Improve ReturnCode doc
* Improve ErrorOrigin doc and variant naming
* Improve docs on ExecResult and ExecError
* Encode u32 sentinel value as hex
* with_nested_context no longer accepts an Option for trie
* Fix successful typo
* Rename InvalidContractCalled to NotCallable
* seal: Fail instantiate if new contract is below subsistence threshold
We need each contract that exists to be above the subsistence threshold
in order to keep up the guarantuee that we always leave a tombstone behind
with the exception of a contract that called `ext_terminate`.
* Fixup executor test
* Bump runtime
* seal: Do not allow transfers to bring total balance below subsistence deposit
This also reworks the rent system to take the total balance into account
when evaluating whether the account is above the subsistence deposit.
* Fix nits from review
* Fix typo
* Do not enforce subsistence when called from EOA
* Rename CallOrigin to TransactorKind
* Add debug asserts to check the invariants of a plain account transactor
* Fix typo
Co-authored-by: Sergei Shulepov <sergei@parity.io>
Co-authored-by: Sergei Shulepov <sergei@parity.io>
* Transition getter functions to not use scratch buffer
* Remove scratch buffer from ext_get_storage
* Remove scratch buffer from ext_call
* Remove scratch buffer from ext_instantiate
* Add ext_input and remove scratch buffer
* Rework error handling (changes RPC exposed data)
* ext_return passes a flags field instead of a return code
* Flags is only for seal and not for the caller
* flags: u32 replaced status_code: u8 in RPC exposed type
* API functions use a unified error type (ReturnCode)
* ext_transfer now traps on error to be consistent with call and instantiate
* Remove the no longer used `Dispatched` event
* Updated inline documentation
* Prevent skipping of copying the output for getter API
* Return gas_consumed from the RPC contracts call interface
* Updated COMPLEXTITY.md
* Rename ext_gas_price to ext_weight_to_fee
* Align comments with spaces
* Removed no longer used `ExecError`
* Remove possible panic in `from_typed_value`
* Use a struct as associated data for SpecialTrap::Return
* Fix nits in COMPLEXITY.md
* Renamed SpecialTrap to TrapReason
* Fix test
* Finish renaming special_trap -> trap_reason
* Remove no longer used get_runtime_storage
* fixup! Remove no longer used get_runtime_storage
* Removed tabs for comment aligment
* seal: Refactor ext_gas_price
* Remove seals dependency on pallet_transaction_payment
* Add weight as an argument to ext_gas_price
* Fixed documentation nits from review
* Do not use unchecked math even in test code
* Add a simple direct storage access module
* WIP
* Completely migrate to the transactional system.
* Format
* Fix wasm compilation
* Get rid of account_db module
* Make deposit event eager
* Make restore_to eager
* It almost compiles.
* Make it compile.
* Make the tests compile
* Get rid of account_db
* Drop the result.
* Backport the book keeping.
* Fix all remaining tests.
* Make it compile for std
* Remove a stale TODO marker
* Remove another stale TODO
* Add proof for `terminate`
* Remove a stale comment.
* Make restoration diverging.
* Remove redudnant trait: `ComputeDispatchFee`
* Update frame/contracts/src/exec.rs
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* Introduce proper errors into the storage module.
* Adds comments for contract storage module.
* Inline `ExecutionContext::terminate`.
* Restore_to should not let sacrifice itself if the contract present on the stack.
* Inline `transfer` function
* Update doc - add "if succeeded"
* Adapt to TransactionOutcome changes
* Updates the docs for `ext_restore_to`
* Add a proper assert.
* Update frame/contracts/src/wasm/runtime.rs
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Alexander Theißen <alexander.theissen@parity.io>
With this patch forward this will be the only way for
a contract to destroy itself. This patch therefore changes
the semantics of all other contract initiated balance
transfers to fail if they would bring the caller below the
existential deposit.
* contracts: Add ext_transfer call
This call allows contracts to send balance to any account
contract or not. Previously, the only way to do that was
though ext_call.
* Apply suggestions from code review
Co-Authored-By: Nikolay Volf <nikvolf@gmail.com>
* The define_env! macro does not allow for trailing comma
* Update frame/contracts/src/exec.rs
Co-Authored-By: Nikolay Volf <nikvolf@gmail.com>
* Bump spec version
* Do not use nested gas meter
* Use explicit 0 or 1 as return value
* Remove superflous intermediate binding
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
* Add non-zero ed check on Balances genesis
* Update ED from 0 to 1
* bump impl
* bump spec
* Found remove more ed = 0
* Fix some contract tests
* Use ctx.overlay.set_balance for contracts
* Fix staking test
* Remove obsolete logic
* Allow death of payout account in society
* Update frame/balances/src/lib.rs
Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
* Dont create genesis balances if balance is zero in transaction payment pallet
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Gavin Wood <github@gavwood.com>
* Initially scoping out of the problem
* Remove need for exiry in balance locks.
* Remove expiry from locks.
* Remove supefluous balance test
* Amalgamate pieces of balance module
* Split out vesting
* Fix tests
* Fixes for vesting.
* Docs.
* Weight docs.
* Refactor things in terms of set_balances.
* Switch out ED to be free + reserved.
* Remove on_free_balance_zero and some docs.
* Build fixes
* Update frame/vesting/src/lib.rs
Co-Authored-By: Xiliang Chen <xlchen1291@gmail.com>
* Update frame/vesting/src/lib.rs
Co-Authored-By: Xiliang Chen <xlchen1291@gmail.com>
* Migration
* Remove superfluous code.
* Test fixes
* Fix some tests
* Fix repatriate reserve
* Fixes
* Add test for migration
* Final cleanups
* Fix
* Indentation.
* Undo unneeded referencing
* Bump runtime version
* Fixes
Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>
* contracts: during execution -> contract trapped during execution
This message confused many people so we are improving it to make clear what happened.
* contracts: rename Event::Contract -> Event::ContractExecution
* contracts: fix tests after ContractExecution renaming
* contracts: Add Evicted and Restored events
* fix doc comment
* wrap to not go over (soft) 100 column line limit
* add event deposit for eventual eviction upon pay_rent
* contracts: adjust tests for the new events
* emit Evicted event immediately and add tombstone flag bool