1. Feb 05, 2021
    • Alexander Theißen's avatar
      contracts: Remove ConfigCache (#8047) · 1b31f7c5
      Alexander Theißen authored
      
      
      * contracts: Remove ConfigCache
      
      * 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
      
      * Fixup test
      
      Co-authored-by: default avatarParity Benchmarking Bot <[email protected]>
      1b31f7c5
  2. Feb 04, 2021
  3. Feb 03, 2021
  4. Feb 02, 2021
  5. Feb 01, 2021
  6. Jan 14, 2021
  7. Jan 06, 2021
  8. Jan 04, 2021
    • Alexander Theißen's avatar
      contracts: Lazy storage removal (#7740) · 3ba8fdfc
      Alexander Theißen authored
      * 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
      3ba8fdfc
    • Alexander Theißen's avatar
      contracts: Allow runtime authors to define a chain extension (#7548) · 51c37ecc
      Alexander Theißen authored
      * Make host functions return TrapReason
      
      This avoids the need to manually store any trap reasons
      to the `Runtime` from the host function. This adds the following
      benefits:
      
      * It properly composes with the upcoming chain extensions
      * Missing to set a trap value is now a compile error
      
      * Add chain extension
      
      The chain extension is a way for the contract author to add new
      host functions for contracts to call.
      
      * Add tests for chain extensions
      
      * Fix regression in set_rent.wat fixture
      
      Not all offsets where properly updated when changing the fixtures
      for the new salt on instantiate.
      
      * Pre-charge a weight amount based off the specified length
      
      * Improve fn write docs
      
      * Renamed state to phantom
      
      * Fix typo
      51c37ecc
    • Bastian Köcher's avatar
      Happy new year (#7814) · e3e651f7
      Bastian Köcher authored
      * Happy new year
      
      Updates the copyright years and fixes wrong license headers.
      
      * Fix the template
      
      * Split HEADER into HEADER-APACHE & HEADER-GPL
      e3e651f7
  9. Dec 29, 2020
  10. Nov 30, 2020
  11. Nov 24, 2020
    • Alexander Theißen's avatar
      contracts: Add `salt` argument to contract instantiation (#7482) · c3ca78fa
      Alexander Theißen authored
      
      
      * 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: default avatarParity Benchmarking Bot <[email protected]>
      c3ca78fa
  12. Nov 09, 2020
    • Alexander Theißen's avatar
      contracts: Add automated weights for wasm instructions (#7361) · 51c67fe8
      Alexander Theißen authored
      
      
      * 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: default avatarAndrew Jones <[email protected]>
      
      * Fix typo in schedule.rs
      
      Co-authored-by: default avatarAndrew Jones <[email protected]>
      
      * Fix docs in schedule.rs
      
      * Apply suggestions from code review
      
      Co-authored-by: default avatarNikolay Volf <[email protected]>
      
      * Don't publish proc-macro crate until 3.0.0 is ready
      
      * Optimize imports for less repetition
      
      * Break overlong line
      
      Co-authored-by: default avatarParity Benchmarking Bot <[email protected]>
      Co-authored-by: default avatarAndrew Jones <[email protected]>
      Co-authored-by: default avatarNikolay Volf <[email protected]>
      51c67fe8
  13. Oct 29, 2020
  14. Oct 08, 2020
    • Alexander Theißen's avatar
      seal: Add automated weights for contract API calls (#7017) · 443725f0
      Alexander Theißen authored
      
      
      * 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: default avatarSergei Shulepov <[email protected]>
      
      * 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: default avatarSergei Shulepov <[email protected]>
      
      * 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: default avatarSergei Shulepov <[email protected]>
      Co-authored-by: default avatarShawn Tabrizi <[email protected]>
      443725f0
  15. Sep 11, 2020
  16. Aug 10, 2020
    • Alexander Theißen's avatar
      seal: Change prefix and module name from "ext_" to "seal_" for contract callable functions (#6798) · 04b185e3
      Alexander Theißen authored
      * 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
      04b185e3
  17. Aug 03, 2020
    • Alexander Theißen's avatar
      seal: Fix and improve error reporting (#6773) · 6671d017
      Alexander Theißen authored
      * 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
      6671d017
  18. Jul 29, 2020
    • Alexander Theißen's avatar
      seal: Add benchmarks for dispatchables (#6715) · a2163420
      Alexander Theißen authored
      * seal: Fix syntax that confuses rust-analyzer
      
      * seal: Add benchmarks for Dispatchables
      
      These are only the benchmarks for the dispatchables of
      the pallet. Those are not listed in the Schedule because
      we do not want to pull the Schedule from storage before
      dispatching.
      
      This OK because those costs are not related to actual contract
      execution. Those costs (instruction costs, ext_* costs) will
      be benchmarked seperatly and entered into the default Schedule.
      
      * seal: Add a maximum code size
      
      * Fix comments from review
      
      * Removed SEED constant
      a2163420
  19. Jul 27, 2020
  20. Jul 21, 2020
  21. Jul 20, 2020
  22. Jul 10, 2020
  23. Jul 09, 2020
    • Alexander Theißen's avatar
      seal: Rework contracts API (#6573) · 25de5b5c
      Alexander Theißen authored
      * 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
      25de5b5c
  24. Jul 07, 2020
  25. Jun 24, 2020
  26. Jun 23, 2020
    • Sergey Pepyakin's avatar
      pallet-contracts: migrate to nested storage transaction mechanism (#6382) · f36b7857
      Sergey Pepyakin authored
      
      
      * 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: default avatarAlexander Theißen <[email protected]>
      
      * 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: default avatarAlexander Theißen <[email protected]>
      
      Co-authored-by: default avatarAlexander Theißen <[email protected]>
      Co-authored-by: default avatarAlexander Theißen <[email protected]>
      f36b7857
  27. Jun 12, 2020
  28. May 28, 2020
  29. May 21, 2020
  30. Apr 25, 2020
    • Shawn Tabrizi's avatar
      Introduce `BlockExecutionWeight` and `ExtrinsicBaseWeight` (#5722) · 8a33c297
      Shawn Tabrizi authored
      
      
      * Introduce `BlockExectionWeight` and `ExtrinsicBaseWeight`
      
      * Add new traits everywhere
      
      * Missed one update
      
      * fix tests
      
      * Update `check_weight` logic
      
      * introduce `max_extrinsic_weight` function
      
      * fix + add tests
      
      * format nits
      
      * remove println
      
      * make test a bit more clear
      
      * Remove minimum weight
      
      * newlines left over from find/replace
      
      * Fix test, improve clarity
      
      * Fix executor tests
      
      * Extrinsic base weight same as old `MINIMUM_WEIGHT`
      
      * fix example test
      
      * Expose constants
      
      * Add test for full block with operational and normal
      
      * Initiate test environment with `BlockExecutionWeight` weight
      
      * format nit
      
      * Update frame/system/src/lib.rs
      
      Co-Authored-By: default avatarKian Paimani <[email protected]>
      
      * Replace `TransactionBaseFee` with `ExtrinsicBaseWeight` (#5761)
      
      * Replace `TransactionBaseFee` with `ExtrinsicBaseFee`
      
      * Fix stuff
      
      * Fix and make tests better
      
      * Forgot to update this test
      
      * Fix priority number in test
      
      * Remove minimum weight from merge
      
      * Fix weight in contracts
      
      * remove `TransactionBaseFee` from contract tests
      
      * Let `register_extra_weight_unchecked` go past `MaximumBlockWeight`
      
      * address feedback
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      8a33c297
  31. Apr 24, 2020
  32. Apr 22, 2020
  33. Apr 20, 2020
  34. Apr 16, 2020
  35. Apr 08, 2020
  36. Mar 26, 2020
    • Kian Paimani's avatar
      Mandate weight annotation (#5357) · a0772117
      Kian Paimani authored
      * Disallow default weight
      
      * Fix build and test
      
      * Fix tests
      
      * Fix another beloved ui test.
      
      * fix beloved trybuild tests
      
      * fix treasury?
      
      * Final test fix
      
      * Fix build
      
      * Fix another one
      
      * Fix
      
      * More doctest fix
      a0772117