Commit Graph

107 Commits

Author SHA1 Message Date
Weiliang Li bff16d906d update tiny-keccak (#4093)
* update tiny-keccak

* fix

* Update Cargo.toml

* update Cargo.lock

* remove keccak-hasher
2019-11-12 09:35:46 +01:00
Bastian Köcher b691cfe093 Substrate runtime interface 2.0 (#4057)
* Adds first version of traits for generating the host functions

* First steps of the procedural macro

* Implements generation of the host extern functions

* Prefix ext host function with snake case trait name

* Implement host functions implementation on the host

* Change `HostFunctions` interface

* Implement `HostFunctions` for tuples

* Make `WasmExecutor` generic over the host functions

* Begin to add a test and make it compile

* Make the test succeed

* Add test to ensure that host functions are not found

* It's alive! Make the `set_storage` test work

* Add test for mutable references

* Code cleanup and documentation etc

* Add marker trait for types that should be passed as SCALE encoded

* Inherit the visibility from the trait and more improvements

* More impls and move them into their own file

* Code simplification by dropping one trait

* Give it a better name

* Implement traits for arrays

* Refactor code to support pass by codec/inner

* Docs

* Implement pass by inner for some crypto types and add a test

* Implement exchangeable function support

* Rewrite sr-io with as runtime interface

* Start reworking after master merge

* Adds `PassByCodec` derive

* Adds `PassByInner` derive

* Fix compilation errors

* More implementations

* Implement runtime interface traits for `str`

* Make `sr-io` compile again

* Fix more compilation errors

* More progress on getting stuff back to compile

* More compilation fixes

* Fix warnings

* Remove le conversions

* Add support for `wasm_only` interfaces

* Implement `Allocator` interface

* Improve error message

* Move `WasmAllocator` to `sr-io` and more clean ups

* Use correct function signature for wasm functions

* Store the host functions with the Wasm runtime

* Docs update

* Fix compilation after master merge

* Remove `sr-io/without_std`

* Make `srml-support` tests run again

* More compilation error fixes

* Use correct doc syntax

* Fix test-runtime

* Fix compilation

* Catch native panics when executing the wasm runtime

As with the native runtime, we now catch all native panics when we
execute the wasm runtime. The panics inside the wasm runtime were
already catched before by the wasm executor automatically, but any panic
in the host functions could bring down the node. The recent switch to
execute the native counterpart of the host function in `sr-io`, makes
this change required. The native `sr-io` functions just `panic` when
something is not provided or any other error occured.

* Fix compilation

* Don't panic in a panic

* Move `sr-sandbox` to new runtime interface

* Fixes tests after sandbox changes

* Make sure we detect invalid utf8

* Fixes after master merge

* Adds pass by enum strategy

* Fix wasmtime integration

* Some macro structure clean up

* Rework and test exchangebale host functions

* PassBy derive macros documentation

* Docs for `runtime_interface` macro

* Support wild card argument names

* Adds ui tests

* Make sure that we are backwards compatible to the old runtime interfaces

* Documentation

* Fixes after latest master merge

* Make `wasmtime` happy

* Make `full_crypto` work

* Make the new interface versionable

* Rename `Sanboxing` to `Sandbox`

* Don't finalize in test while importing

* Fix Performance regression

* Fix test
2019-11-10 21:59:30 +01:00
Jim Posen 8fe64173e8 executor: Move runtime version caching out of WasmRuntime interface. (#3993)
* executor: Move runtime caching out of WasmRuntime interface.

The runtime version is now fetched and cached at a higher level, not
within the WasmRuntime trait implementations.

* executor: Require successful querying of runtime version.
2019-11-01 18:22:28 +01:00
Jim Posen 8676c25ef4 Integrate Wasmtime for runtime execution (#3869)
* executor: Use non wasmi-specific execution in tests.

* executor: Move all runtime execution tests into tests file.

* executor: Use test_case macro to easily execute tests with different
Wasm execution methods.

* executor: Convert errors to strings with Display, not Debug.

* node-executor: Rewrite benchmarks with criterion.

They were not passing compilation before and criterion seems to be more
widely used in Substrate.

* executor: Begin implementation of Wasm runtime.

The implementation demonstrates the outline of the execution, but does
not link against the external host functions.

* executor: Define and implement basic FunctionExecutor.

The SandboxCapabilities::invoke is still left unimplemented.

* executor: Implement host function trampoline generation.

* executor: Instantiate and link runtime module to env module.

* executor: Provide input data during wasmtime execution.

* executor: Implement SandboxCapabilites::invoke for wasmtime executor.

* executor: Integrate and test wasmtime execution method.

* executor: Improve FunctionExecution error messages.

* Scope the unsafe blocks to be smaller.

* Rename TrampolineState to EnvState.

* Let EnvState own its own compiler instead of unsafe lifetime cast.

* Refactor out some common wasmi/wasmtime logic.

* Typos and cosmetic changes.

* More trampoline comments.

* Cargo.lock update.

* cli: CLI option for running Substrate with compiled Wasm execution.

* executor: Switch dependency from fork to official wasmtime repo.

* Quiet down cranelift logs.

* Explicitly catch panics during host calls.

We do this to ensure that panics do not cross language boundaries.

* Additional checks and clarifications in make_trampoline.

* Fixes after merge from master and panic safety for wasmtime
instantiation.
2019-11-01 13:32:14 +01:00
Bastian Köcher 7627428f44 Catch native panics when executing the wasm runtime (#3953)
As with the native runtime, we now catch all native panics when we
execute the wasm runtime. The panics inside the wasm runtime were
already catched before by the wasm executor automatically, but any panic
in the host functions could bring down the node. The recent switch to
execute the native counterpart of the host function in `sr-io`, makes
this change required. The native `sr-io` functions just `panic` when
something is not provided or any other error occured.
2019-10-30 16:34:00 +01:00
Gavin Wood d97775542a Add SECP256k1/ECDSA support for transaction signing (#3861)
* Add SECP256k1/ECDSA support for transaction signing.

* Refactoring and fixes

* Fix for contracts

* Avoid breaking runtime host function

* Build fixes, make subkey work more generaically.

* Fix tests

* Dedpulicate a bit of code, remove unneeded code, docs

* Bump runtime version

* Fix a test and clean up some code.

* Derivation can derive seed.

* Whitespace

* Bump runtime again.

* Update core/primitives/src/crypto.rs

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update core/primitives/src/ecdsa.rs

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Fix AppVerify
2019-10-24 10:59:09 +02:00
Tomasz Drwięga 20a3989785 Runtime logging. (#3821)
* Implement Printable for tuples.

* Add debugging function.

* Add debug 1.

* Implement  for everything.

* RuntimeDebug derive.

* Introduce RuntimeDebug.

* Add some dummy logging.

* Replace RuntimeDebug with Debug.

* Revert "Replace RuntimeDebug with Debug."

This reverts commit bc47070a8cb30241b2b590b2fa29fd195088162f.

* Working on Debug for all.

* Fix bounds.

* Add debug utils.

* Implement runtime logging.

* Add some docs and clean up.

* Clean up derives.

* Fix custom derive impl.

* Bump runtime.

* Fix long lines.

* Fix doc test.

* Use CARGO_CFG_STD.

* Revert "Use CARGO_CFG_STD."

This reverts commit ea429566de18ed0fa052571b359eb9826a64a9f4.

* Use parse_macro_input

* Update lockfile.

* Apply review suggestions.

* Remove stray re-export.

* Add no-std impl.

* Update lockfile.
2019-10-22 14:13:44 +02:00
cheme d9cffa0bb5 Code redundancy between ext implementation and testing. (#3830)
* fix child_storage_hash

* extract common implementation for ext and testing

* cleaning impl.

* replace ExtBasisMut by actual Ext

* remove extbasis.

* Update tests to use Ext from test externalities.

* use Ext constructor for getting ext from TestExternalities.

* Add missing extensions from ext.

* fix wasmi test

* Fix merge error.
2019-10-18 09:52:25 +02:00
Bastian Köcher 81c400e958 Make wasmi_execution public to use it from tests (#3829)
* Make `wasmi_execution` public to use it from tests

* Make `WasmRuntime` accessible as well

* Add `call_in_wasm` instead of making stuff public

* Use `WasmRuntime`

* Move test

* More feedback
2019-10-16 21:00:31 +02:00
Bastian Köcher e3ae647c42 Provide macro for exporting functions from wasm (#3801)
The macro generates the functions with the signature we expect for wasm
functions. This macro is useful for tests where we need to call into
wasm. Parameter passing is done by SCALE encoding the input and output
parameters.
2019-10-14 20:20:07 +02:00
Bastian Köcher 8a39be474e Move Externalities into its own crate (#3775)
* Move `Externalities` into `substrate-externalities`

- `Externalities` now support generic extensions
- Split of `primtives-storage` for storage primitive types

* Move the externalities scoping into `substrate-externalities`

* Fix compilation

* Review feedback

* Adds macro for declaring extensions

* Fix benchmarks

* Introduce `ExtensionStore` trait

* Last review comments

* Implement it for `ExtensionStore`
2019-10-09 15:50:30 +02:00
Jim Posen 6cebbbf8b2 Refactor NativeExecutor to support multiple Wasm execution methods (#3677)
* executor: Move definitions of externals out of wasm_executor module.

* executor: Create WasmRuntime trait.

This will be used to decouple the runtime cache from wasmi execution.

* executor: Remove WasmExecutor and move methods to wasmi_execution.

These will now be crate-internal functions and there is no need
for the struct.

* executor: Set default default_heap_pages in NativeExecutor.

* cli: CLI configuration for Wasm execution method.

* executor: Remove wasmi-specific code from wasm_runtime.

* Respond to review comments.
2019-10-08 12:57:12 +02:00
DemiMarie-parity 62b97a090d Upgrade dependencies whenever “easy” (#3556)
* Update all dependencies

* Upgrade dependencies whenever “easy”

“easy” means that there are no major changes required.

* Fix build and bump paste dependency to 0.1.6

* Remove dead code

* Re-add = dependency for futures-preview

* Add missing std features for runtime-io

* Remove git dependencies

as updated versions have been published to crates.io

* try to debug bug

* For sr-io, "std" should imply "no_oom" and "no_panic_handler".

Otherwise, rustc complains (correctly) about duplicate lang items.

* Add missing "runtime-io/std" features

* Fix compilation errors

* Prevent duplicate lang items

Rust does not allow duplicate lang items.  When compiled without the
`std` feature, `sr-io` defines two lang items.  Therefore, `sr-io`
compiled without `feature = "std"` must not be linked with `std`.

However, `pwasm-utils` and `wasmi-validation` both bring in `std` unless
compiled with `default-features = "false"`.  This caused a duplicate
lang item error.  Building both with `default-features = "false"`
prevents this error.  When building with `feature = "std"`, they should
both be built with the `std` feature, so this feature needs to be
explicitly depended on.

* Bump `impl_version`

* Make tests pass

Three tests used 1 less gas than they had previously.

* Try to un-break build

* Add a Cargo.lock file

* Revert offchain code

* Revert "Revert offchain code"

This reverts commit d216d08cc6ca0344614669c1d24cde3aa5c0d4e2.

* Don’t try to send a body with a GET request

without adding a Transfer-Encoding or Content-Length header.

This has always been wrong, but hyperium/hyper#1925 hid the bug until
hyper was upgraded to 0.12.35.

* Change some more GET requests to POST requests

* Fix excess line width and remove an `extern crate`

* Delete commented-out extern crate

Co-Authored-By: Sergei Pepyakin <sergei@parity.io>

* Fix regression in Cargo.toml files

dev-dependencies need `default-features = false`, too.

* Bump parity-wasm dependency

* Bump `futures-preview`

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update Cargo.lock files

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update core/service/src/chain_ops.rs

Co-Authored-By: Sergei Pepyakin <sergei@parity.io>
2019-10-02 15:23:59 -04:00
Bastian Köcher f6c4c47b50 Give more information why conversion between native and runtime failed (#3720)
* Give more information why conversion between native and runtime failed

This adds the SCALE error description to the error when the conversion
between native and runtime failed.

* Fixes tests
2019-09-30 18:03:13 +02:00
Bastian Köcher ba98168b71 Make TestOffchainExt panic on unknown requests (#3710)
* Make `TestOffchainExt` panic on unknown requests

* Fix test
2019-09-26 23:02:30 +02:00
Caio 0da34de380 Pointer does not implement Display (#3707)
Instead, use `Debug` for `debug_trace!`
2019-09-26 22:21:12 +02:00
Jim Posen 82e7f9e423 Decouple node-executor structures from wasmi (#3610)
* executor: Support non-Wasmi sandbox supervisor environments.

* node-executor: Tests don't reference WasmExecutor directly.

* executor: Simplify encoding of heap metadata.

* executor: Decouple allocator from wasmi::MemoryRef.
2019-09-23 17:38:51 +02:00
Ashley e9c756dced Update parity-wasm to 0.40 (#3631)
* updated direct dependencies to parity-wasm

* fixed tests and incremented impl_version of the runtime

* update wasmi to 0.5.1 in sr-sandbox, bringing all parity-wasm deps up to 0.40
2019-09-18 12:27:59 +02:00
Bastian Köcher 45d64a711c Clean up sr-io (#3609)
* Move trait `Printable` into `sr-primitives`

* Cleanup runtime io trie_root interfaces

* Remove last generic bits from sr-io interface

* Fix srml-sudo after master merge

* Fix benchmarks

* Runtime bump
2019-09-13 16:39:50 +02:00
Michael Müller 5cb8c0dc1c Fixes for allocator + factory + misc improvements (#3534)
* Clear up import/export misunderstandings

* Fetch minimum period from runtime

* Remove unnecessary comment

This variable is already fetched from the runtime
in the line below.

* Fix bug in factory

The `best_block_id` stayed the same, it was always the
genesis hash. This resulted in the factory failing after
4096 blocks, since `client/db` discards hashes (in this
case the genesis hash) after 4096 blocks from the database.

* Fix tense in error message

* Improve allocator documentation

* Fix bug in allocator

Under certain circumstances an invalid pointer was
returned: when the `ptr` was calculated as equal
to the `max_heap_size`. This is an invalid pointer
since there is no access allowed after the heap limit.

The way to provoke this was to repeatedly allocate
with sizes which were previously not allocated and
immediately deallocate right afterwards. What this
did was to increment the `bumper` with each allocation,
whilst keeping the `total_size` of the heap `0`.
If this repeated allocation/deallocation scheme resulted
in `max_heap_size == ptr` the `ptr` was still returned.

The allocator only checked if the `total_size` was
still within the `max_heap_size` limits, and not
if the resulting `ptr` was still within the valid
heap region.

This commit introduces a check to validate if the
calculated `ptr` is within the heap.

* Add test for zero byte allocation and document behavior

* Improve code readability by introducing a const

* Fix error message in test

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Fix code review suggestions

* Replace early return with assertion

* Remove test for zero size allocations

* Shorten test code

* Shorten comment

* Make bump() return Result

* Add comment for bump()

* Remove ambiguous comment

* Replace value with const

* Use proof for panic message

* Fix merge

* Add comment regarding minimum allocation size
2019-09-13 15:47:15 +02:00
Sergei Pepyakin 098d880cf9 read_storage panics (#3589)
* Add a failing test case

* Actual fix

* read_child_storage, fix wasm side

* Bump the impl version.

* Alternative (#3597)

* Update with_std.rs

* Update with_std.rs

* Update wasm_executor.rs

* Update wasm_executor.rs

* Update with_std.rs

* Update wasm_executor.rs
2019-09-11 19:37:19 +02:00
Svyatoslav Nikolsky 010395e620 Never panic during execution proof check (#3504)
* do not panic during execution proof check

* Update core/state-machine/src/lib.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Update core/state-machine/src/lib.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Update core/state-machine/src/lib.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* BackendTrustLevel enum

* up runtime version

* Update core/state-machine/src/lib.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Update core/state-machine/src/lib.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* fixed some grumbles

* Update core/state-machine/src/testing.rs

Co-Authored-By: Gavin Wood <gavin@parity.io>

* Update core/state-machine/src/lib.rs

Co-Authored-By: Gavin Wood <gavin@parity.io>

* mov where

* spaces -> tabs (to restart build)
2019-09-11 10:27:32 +03:00
Bastian Köcher 9607afd629 Cleanup of the state-machine crate (#3524)
* Start refactoring state-machine crate

* More improvement to state-machine

* Fix tests compilation on master and remove warnings

* Fix compilation

* Apply suggestions from code review

Co-Authored-By: Sergei Pepyakin <sergei@parity.io>

* Update core/state-machine/src/basic.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Line width

* Update core/primitives/src/storage.rs

Co-Authored-By: Benjamin Kampmann <ben.kampmann@googlemail.com>

* Update core/state-machine/src/error.rs

Co-Authored-By: Benjamin Kampmann <ben.kampmann@googlemail.com>

* Review feedback
2019-09-10 17:00:00 +02:00
Bastian Köcher 1450719acc First step for generating host externals out of the function definition in sr-io (#3567)
* Adds new wrapper traits for wasm executor

* Add new crate `substrate-wasm-interface`

Thew new crate holds types and traits for the communicating between the
wasm runtime and the host.

* Rewrite externals with new macro etc

* Fix vec initialization

* Make executor tests working

* Remove unused code + warnings

* Introduce `Pointer` and `WordSize` for working with wasm

* Fix tests and compilation

* Fix compilation

* Apply suggestions from code review

Co-Authored-By: Sergei Pepyakin <sergei@parity.io>

* Review feedback

* Remove unused conversions

* Make each host function its own struct

`HostFunctions` now just returns these function structs. Each function
can be executed by using one of the function structs. The inherent host
functions are now moved to the "normal" host functions.

* Remove byteorder

* Add floating point types

* Make pointer interface more safe

* Add type alias for wasm-interface Result

* More review comments
2019-09-10 16:07:25 +02:00
Sergei Pepyakin 4f7e36e072 Update docs for the wasm executor crate (#3569)
* Grammar.

* Update docs for wasm executor.

* Update core/executor/src/lib.rs

Co-Authored-By: André Silva <andre.beat@gmail.com>
2019-09-06 23:08:08 +02:00
Sergei Pepyakin 36ef4c067b Eradicate native_equivalent (#3494)
* Add ability to supply extra storage in test-client

* Don't use native_equivalent in tests.

* Get rid of native_equivalent

* Try to make fields private

* Apply Basti's suggestions

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
2019-08-27 22:20:47 +02:00
Bastian Köcher 3b0af8bbf4 Do not call externalities without Ext being set (#3436)
* Do not call externalities without `Ext` being set

* Fix compare and set

* Bump runtime version.

* Bump hashmap_core
2019-08-19 12:52:39 +02:00
Sergei Pepyakin f735d067c4 Respect heap_pages parameter. (#3420) 2019-08-16 15:33:22 +02:00
Juan Aguilar db5e6712d7 Remove enumerate_trie_root in favour of ordered_trie_root #2382 (#3360) 2019-08-12 16:13:02 +02:00
Bastian Köcher c824c959d7 Adds --no-validator CLI flag (#3348)
* Implement `is_validator` for offchain-workers

* Introduce `--no-validator` flag

* Don't run babe/grandpa/im-online when `--no-validator` is given

* Fixes compilation

* Bump spec version

* Improve error handling in executor

* Add missing extern function

* Revert making error public

* Remove `--no-validator` CLI
2019-08-09 14:24:18 +02:00
cheme b0e1212d48 Child storage tests and genesis fix. (#3185)
* Using child storage, (srml-support only), test failing .

* fix simple tests.

* Enumerable by requiring owned struct (previous form only allow
&'static).
Broken tests are from genesis init.

* implement for_child_keys_with_prefix

* indent

* clear_child_prefix fix.

* clear_child_prefix fix 2.

* fix for storage_impl, if/when allowing child and not child this could be
reverted.

* Fix lot of urlinked child genesis, still need to look upon actual
genesis srml module code.
Probably still a lot of broken code needing debugging.

* switch well_known_key to their associated module child trie.
Fix a genesis init (balance).
Complete some testing.
Comment some tests before using.

* fixing test runtime child keys

* latest commit fix broken genesis init

* fix system balances child name.

* Important fix: storage_root from test externalities need children (it is
already the case for ext).

* executive root with child calculation

* Avoid empty trie on test ext.

* Symetric removal of key for system.

* commenting changes related tests.

* Remove child module specifics.

* fix issues.

* fix some formatting

* fix bench and bump runtime

* Remove extend_storage_overlays, assimilate_storage do the same as is
proper considering srml macro.

* Fix warning for assimilate.

* Removing kill as they do not impact any test cases.

* Use tuple of storage map instead of two parameters. This changes the
behavior of decl_storage genesis build closure (breaking api).

* Do not use build storage before assimilate.

* fix error

* Update core/state-machine/src/backend.rs
2019-08-08 15:05:25 +02:00
Gavin Wood 1a524b8207 Refactor key management (#3296)
* Add Call type to extensible transactions.

Cleanup some naming

* Merge Resource and BlockExhausted into just Exhausted

* Fix

* Another fix

* Call

* Some fixes

* Fix srml tests.

* Fix all tests.

* Refactor crypto so each application of it has its own type.

* Introduce new AuthorityProvider API into Aura

This will eventually allow for dynamic determination of authority
keys and avoid having to set them directly on CLI.

* Introduce authority determinator for Babe.

Experiment with modular consensus API.

* Work in progress to introduce KeyTypeId and avoid polluting API
with validator IDs

* Finish up drafting imonline

* Rework offchain workers API.

* Rework API implementation.

* Make it compile for wasm, simplify app_crypto.

* Fix compilation of im-online.

* Fix compilation of im-online.

* Fix more compilation errors.

* Make it compile.

* Fixing tests.

* Rewrite `keystore`

* Fix session tests

* Bring back `TryFrom`'s'

* Fix `srml-grandpa`

* Fix `srml-aura`

* Fix consensus babe

* More fixes

* Make service generate keys from dev_seed

* Build fixes

* Remove offchain tests

* More fixes and cleanups

* Fixes finality grandpa

* Fix `consensus-aura`

* Fix cli

* Fix `node-cli`

* Fix chain_spec builder

* Fix doc tests

* Add authority getter for grandpa.

* Test fix

* Fixes

* Make keystore accessible from the runtime

* Move app crypto to its own crate

* Update `Cargo.lock`

* Make the crypto stuff usable from the runtime

* Adds some runtime crypto tests

* Use last finalized block for grandpa authority

* Fix warning

* Adds `SessionKeys` runtime api

* Remove `FinalityPair` and `ConsensusPair`

* Minor governance tweaks to get it inline with docs.

* Make the governance be up to date with the docs.

* Build fixes.

* Generate the inital session keys

* Failing keystore is a hard error

* Make babe work again

* Fix grandpa

* Fix tests

* Disable `keystore` in consensus critical stuff

* Build fix.

* ImOnline supports multiple authorities at once.

* Update core/application-crypto/src/ed25519.rs

* Merge branch 'master' into gav-in-progress

* Remove unneeded code for now.

* Some `session` testing

* Support querying the public keys

* Cleanup offchain

* Remove warnings

* More cleanup

* Apply suggestions from code review

Co-Authored-By: Benjamin Kampmann <ben.kampmann@googlemail.com>

* More cleanups

* JSONRPC API for setting keys.

Also, rename traits::KeyStore* -> traits::BareCryptoStore*

* Bad merge

* Fix integration tests

* Fix test build

* Test fix

* Fixes

* Warnings

* Another warning

* Bump version.
2019-08-07 20:47:48 +02:00
thiolliere 4ed67e03a4 Update to parity-scale-codec (#3232)
* WIP: update codec

* WIP

* compiling

* WIP

* rename parity-scale-codec to codec

* WIP

* fix

* remove old comments

* use published crates

* fix expected error msg

* bump version

* fmt and fix

* remove old comment

* fix wrong decoding impl

* implement encode like for structures

* undo removal of old pending changes

* trailingzeroinput

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* update codec

* fmt

* version is 1.0.0

* show more error

* fmt
2019-08-06 19:36:23 +02:00
cheme da8b91ae7b Trie simplification. (#2815)
* switch to simple codec, trie broken for now

* Actualy use trie_root_noext

* align some hash, failing test on EMCH comment

* Fix trie code over layout instead of hash, revert legacy code for legacy
mainnet ??

* stub behind LayOut

* fix no_std

* temp solution for legacy trie behind feature legacy-key in various crate

* use remote project

* rc client db need prefix

* update trie deps

* bum spec runtime version

* Removing legacy as default.

* Switch mode to non legacy.

* bump runtime version

* Remove legacy trie compatibility features.

* fix warning

* bump version

* change hash on new test.

* Move dependency (#11 trie PR) patched to a parity repo.
Bench reverted to correct hasher.
Some renaming and doc improvments.

* ChildBitmap renaming to BitMap.

* Renaming of LayOut to Layout.

* formatting.

* Removing abreviation such as _ix nb_ or bm.

* Update deps and apply renaming 'Buff' -> 'Buffer'.

* Align to latest trie crates naming changes.

* Update trie dependency.

* Update trie dependency.

* change block_import test hash

* update trie deps (trie use new scale codec but it does not seems to be
an issue).

* update to use latest trie version (no mgmt of multiple radix).

* tabify

* Restoring test to 10 000.

* Use published crate, trie bench is currently down until publishing
(require another pr to update version).

* Update trie-bench.
2019-08-02 19:51:59 +02:00
Pierre Krieger cb7383b6b6 Documentation and small cleanup in panic-handler (#3249)
* Documentation and small cleanup in panic-handler

* Apply suggestions from code review

Co-Authored-By: Sergei Pepyakin <s.pepyakin@gmail.com>
2019-08-01 09:53:53 +02:00
Bastian Köcher 9303b9b7df Remove IncrementalInput and fix wasm storage_into* (#3224) 2019-07-29 10:44:40 +02:00
Pierre Krieger ba55d31d44 Minor cleanup in native_executor.rs (#3218)
* Minor cleanup in native_executor.rs

* Fix tests
2019-07-27 15:41:22 +02:00
Michael Müller 23fba990ba Handle local storage race conditions better (#3177)
* Make local_storage_compare_and_set take Option for old_value

* Adapt srml/im-online to API changes

* Bump version

* Bump version again

* Replace match
2019-07-26 07:42:40 +08:00
Sergei Pepyakin af914e9f40 Fair reusing of wasm runtime instances (#3011)
* Add test from original bug report

Original is from @pepyakin in 3d7b27f3421818e8d6de568e02fbc2947a06246b.
I adapted it to work with the latest master.

* No longer cleanup module instance

* Replace runtime cache with synchronous clone

* Fix test

* Preserve initial runtime memory and restore it on fetch

* Remove leftover comment

* Fix style

* Improve variable naming

* Replace get_into() with get()

* Handle missing memory export better

* Return earlier when creating runtime first time

* Improve comments

* fmt

* Fix #2967.

* Eradicate `code` from `Error::InvalidCode`

* tidy

* A state snapshot doc.

* Store multiple runtimes by hash.

* Get rid of deref.

* Docs

* Use Self for instantiate_module

* REVERT ME

* Should be ok

* Commit

* Remove dbg

* Use fast-memory's erase

* Clean and undo hacks.

* Introduce a dedicated error for heap_base

* Ban the start function.

* Clean, docs and refactor

* Add rustflags.

* Update Cargo.lock

* Apply Basti's suggestions

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Rename allocates_huge_stack_array

* Extend TestClientBuilder with set_heap_pages

* Update the test.

* Update core/executor/src/wasm_executor.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update core/executor/src/wasm_runtimes_cache.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update core/executor/src/error.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update core/executor/src/error.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Fix tests.

* Update cargo-lock

* Use wasmi master

* Use master wasmi

* Move tests.

* Use wasmi crates.io

* Update Cargo.lock

* Fix build.rs

* Bump runtime version

* Revert initial_heap_pages renaming

* Bump wasmi up to 0.5.0

* Bump runtime version

* Don't restore an instance every now and then

* Update core/executor/src/wasm_runtimes_cache.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Propagate error in CacheError

* Clarify the get_heap_base call in instantiation

* Supply --export=__heap_base

See https://reviews.llvm.org/D62744

Co-authored-by: Jim Posen <jim.posen@gmail.com>

* Bump version.

* Use combinators for segments.

* Fix build.rs

* Fix build.rs for runtime-test
2019-07-25 16:01:08 +03:00
DemiMarie-parity cfd4ac75ad Include padding in heap size calculation (#3197)
Closes #3005
2019-07-25 10:36:11 +02:00
David Craven a3d19baea3 Refactors the offchain worker api (#3150)
* Update offchain primitives.

* Update offchain worker.

* Update im-online.

* Update service.

* Update node and node-template.

* Update runtime version.

* Fix build.

* Fix offchain worker tests.

* Generalize authority_pubkey.

* Add test.

* Update lib.rs
2019-07-22 17:20:57 +08:00
Michael Müller c70b81444a Introduce srml/im-online (#3079)
* Fix grammar and typo

* Extend network service

* Extend offchain API

* Support creating unsigned UncheckedExtrinsic

* Introduce srml/im-online

* Bump impl and spec version

* Fix web-wasm test

* Apply suggestions from code review

Remove parity-multiaddr dependency

Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>

* Replace transmute with from_raw_parts

* Replace PeerId.to_string() with .to_base58()

Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>

* Update Cargo.lock

* Bump impl and spec version (again)

It was updated in master in the meantime.

* Apply suggestions from code review

Co-Authored-By: Sergei Pepyakin <sergei@parity.io>

* Address comments

* Add public function is_online_in_current_session()

* Bump spec_version

* Fix doc tests

* Improve comments

* Remove superfluous line

* Name parameters consistently

* Implement comments

* Switch From to TryFrom

* Use Vec instead of HashSet

* Fix tests

* Revert me: local testing

* Fix check if already sent during session

We gossip each session, hence we need to check
if already sent in this session (not era).

* Fix typos

* Consistent terminology

* Revert "Revert me: local testing"

This reverts commit 73fbc29ff3e5ed71d99436318260b4f007e837f4.

* Introduce IsMember trait

* Implement misc comments

* Remove unused function

* Fix test

* Fix external_addresses being written

* Fix test

* Add necessary trait bound

* Do not increment version

* Update lib.rs
2019-07-20 09:19:44 +08:00
Tomasz Drwięga e729dbabbe [offchain] Support for sign & verify for crypto keys (#3023)
* Implement sign & verify.

* Use phrases and password.

* Sign & verify with authority keys.

* Fix tests.

* WiP

* WiP

* Allow the caller to decide on 'CryptoKind'.

* Remove TODO.

* Make seed private back.

* Fix non-std build and bump version.

* Use Into<u32> instead of asses.

* Add missing typedef.
2019-07-09 17:09:14 +02:00
Bastian Köcher fe08221479 Build WASM binaries as part of cargo build (#2868)
* Introduce `wasm-builder` and `wasm-builder-runner` to retire `build.sh`

Make use of `wasm-builder` in `test-runtime`.

* Add build script and remove the wasm project

* Port `node-runtime` to new wasm-builder

* Make `substrate-executor` tests work with `wasm-builder`

* Move `node-template` to `wasm-builder`

* Remove `build.sh` :)

* Remove the last include_bytes

* Adds the missing build.rs files

* Remove `build.sh` from CI

* Debug CI

* Make it work in CI

* CI attempt 3

* Make `substrate-runtime-test` compile on stable

* Ahhh, some missed `include_bytes!`

* AHH

* Add suggestions

* Improve search for `Cargo.lock` and don't panic if it is not found

* Searching from manifest path was no good idea

* Make the `wasm-builder` source better configurable

* Expose the bloaty wasm binary as well

* Make sure to rerun WASM recompilation on changes in dependencies

* Introduce new `WASM_BUILD_TYPE` env and make sure to call `build.rs` on
changes to env variables

* Remove `build.sh` from READMEs

* Rename the projects

* Fixes CI

* Update lock file

* Fixes merge-conflict

* Apply suggestions from code review

Co-Authored-By: TriplEight <denis.pisarev@parity.io>

* Try to make windows happy

* Replace all back slashes in paths with slashes

* Apply suggestions from code review

Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>

* Use cargo from `CARGO` env variable

* Fix compilation

* Use `rustup` for running the nightly build

* Make individual projects skipable

* Fix compilation

* Fixes compilation

* Build all WASM projects in one workspace

* Replace more back slashes!

* Remove `inlcude_bytes!`

* Adds some documentation

* Apply suggestions from code review

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Apply suggestions from code review

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* More review comments

* Update `Cargo.lock`

* Set license

* Apply suggestions from code review

Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* More review comments + adds `TRIGGER_WASM_BUILD` env

* Fix doc tests

* Increase version + update README

* Switch crates.io version of `wasm-builder`

* Update README

* Switch to released version of `wasm-builder-runner`
2019-07-04 11:34:06 +02:00
Tomasz Drwięga 2217c1e9a1 Persistent Local Storage for offchain workers. (#2894)
* WiP.

* Implement offchain storage APIs.

* Change compare_and_set to return bool.

* Add offchain http test.

* Fix tests.

* Bump spec version.

* Fix warnings and test.

* Fix compilation.

* Remove unused code.

* Introduce Local (fork-aware) and Persistent storage.

* Fix borked merge.

* Prevent warning on depreacated client.backend

* Fix long lines.

* Clean up dependencies.

* Update core/primitives/src/offchain.rs

Co-Authored-By: André Silva <andre.beat@gmail.com>

* Update core/primitives/src/offchain.rs

Co-Authored-By: André Silva <andre.beat@gmail.com>
2019-07-02 20:11:06 +02:00
kaichao 3e2c77aa21 typo fix in core (#2987) 2019-07-01 19:33:38 +02:00
Bastian Köcher 37acb90847 Remove UserError and switch to error::Error (#2899)
* Remove `UserError` and switch to `error::Error`

* More cleanup

* Update core/executor/src/error.rs

Co-Authored-By: Sergei Pepyakin <s.pepyakin@gmail.com>

* Fix typo

* Update core/executor/src/allocator.rs

Co-Authored-By: Stanislav Tkach <stanislav.tkach@gmail.com>
2019-06-19 15:08:59 +02:00
Gavin Wood bda8641892 New sessions, kill consensus module (#2802)
* Draft of new sessions

* Reintroduce tuple impls

* Move staking module to new session API

* More work on staking and grandpa.

* Use iterator to avoid cloning and tuple macro

* Make runtime build again

* Polish the OpaqueKeys devex

* Move consensus logic into system & aura.

* Fix up system module

* Get build mostly going. Stuck at service.rs

* Building again

* Update srml/staking/src/lib.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Refactoring out Consensus module, AuthorityIdOf, &c.

* Refactored out DigestItem::AuthoritiesChanged. Building.

* Remove tentative code

* Remove invalid comment

* Make Seal opaque and introduce nice methods for handling opaque items.

* Start to use proper digest for Aura authorities tracking.

* Fix up grandpa, remove system::Raw/Log

* Refactor Grandpa to use new logging infrastructure.

Also make authorityid/sessionkey static. Switch over to storing
authorities in a straight Vec.

* Building again

* Tidy up some AuthorityIds

* Expunge most of the rest of the AuthorityKey confusion.

Also, de-generify Babe and re-generify Aura.

* Remove cruft

* Untangle last of the `AuthorityId`s.

* Sort out finality_tracker

* Refactor median getting

* Apply suggestions from code review

Co-Authored-By: Robert Habermeier <rphmeier@gmail.com>

* Session tests works

* Update core/sr-primitives/src/generic/digest.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Session tests works

* Fix for staking from @dvc94ch

* log an error

* fix test runtime build

* Some test fixes

* Staking mock update to new session api.

* Fix build.

* Move OpaqueKeys to primitives.

* Use on_initialize instead of check_rotate_session.

* Update tests to new staking api.

* fixup mock

* Fix bond_extra_and_withdraw_unbonded_works.

* Fix bond_with_little_staked_value_bounded_by_slot_stake.

* Fix bond_with_no_staked_value.

* Fix change_controller_works.

* Fix less_than_needed_candidates_works.

* Fix multi_era_reward_should_work.

* Fix nominating_and_rewards_should_work.

* Fix nominators_also_get_slashed.

* Fix phragmen_large_scale_test.

* Fix phragmen_poc_works.

* Fix phragmen_score_should_be_accurate_on_large_stakes.

* Fix phragmen_should_not_overflow.

* Fix reward_destination_works.

* Fix rewards_should_work.

* Fix sessions_and_eras_should_work.

* Fix slot_stake_is_least_staked_validator.

* Fix too_many_unbond_calls_should_not_work.

* Fix wrong_vote_is_null.

* Fix runtime.

* Fix wasm runtime build.

* Update Cargo.lock

* Fix warnings.

* Fix grandpa tests.

* Fix test-runtime build.

* Fix template node build.

* Fix stuff.

* Update Cargo.lock to fix CI

* Re-add missing AuRa logs

Runtimes are required to know about every digest they receive ― they
panic otherwise.  This re-adds support for AuRa pre-runtime digests.

* Update core/consensus/babe/src/digest.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Kill log trait and all that jazz.

* Refactor staking tests.

* Fix ci runtime wasm check.

* Line length 120.

* Make tests build again

* Remove trailing commas in function declarations

The `extern_functions!` macro doesn’t like them, perhaps due to a bug in
rustc.

* Fix type error

* Fix compilation errors

* Fix a test

* Another couple of fixes

* Fix another test

* More test fixes

* Another test fix

* Bump runtime.

* Wrap long line

* Fix build, remove redundant code.

* Issue to track TODO

* Leave the benchmark code alone.

* Fix missing `std::time::{Instant, Duration}`

* Indentation

* Aura ConsensusLog as enum
2019-06-14 16:34:34 +02:00
Gavin Wood f4afdd2f0b Subkey supports 24-word phrases (#2827)
* Revamp crypto API and make seeds work better in subkey

* Final tweaks

* Update tests

* line spacing

* Avoid escapes in hex constants

* Fix build

* Another fix

* More fixes

* Minor nits
2019-06-13 11:06:30 +02:00
Bastian Köcher 4f888f34d3 Build LongestChain with TestClientBuilder (#2792)
* Switch to `TestClientBuilder` and support generating LongestChain

* Make sure test-client works without the wasm blob

* Use `TestClientBuilder` in more places
2019-06-05 13:45:18 +02:00