Commit Graph

84 Commits

Author SHA1 Message Date
Gav Wood dcd77a147c Introduce safe types for handling imbalances (#2048)
* Be a little safer with total issuance.

* PairT instead of _Pair

* Remove rev causing upset

* Remove fees stuff.

* Fix build (including tests)

* Update runtime, bump version

* Fix

* Handle gas refunds properly.

* Rename identifier

ala #2025

* Address grumbles

* New not-quite-linear-typing API

* Slimmer API

* More linear-type test fixes

* Fix tests

* Tidy

* Fix some grumbles

* Keep unchecked functions private

* Remove another less-than-safe currency function and ensure that
contracts module can never create cash.

* Address a few grumbles and fix tests
2019-03-20 14:07:28 +01:00
thiolliere d743a8b71f Implement parameterisable modules (#1800)
* first implementation

* remove done comment

* origin done

* impl log for instance

* impl inherent for instance

* Fix wasm build + full example build

this requires parity codec implements codec for core::marker::PhantomData

* patch parity-codec link to github branch

* improve internal names and fix instance prefix

* Fix in macros

* add test modules for support

this allow to test for construct_runtime as well.

The reason to have put that in another crate is:
* if we put test in `tests/` dir of srml/support then decl_storage fails to get
  srml-support access because it believes it is inside srml-support
  crate and so derive access to `quote!{ crate }` but this is wrong
  (and I don't see any way to prevent that, and it only bother us so I
  don't think that matters that much)
* if we put test inside lib.rs then contruct_runtime cannot be used
  because it call some macros that are defined with macros
  (decl_outer_event and decl_outer_origin) and thus rustc complains.

* defaultinstance to its own struct to avoid errors

* enforce <T, I> for Event and Config, impl test

* add origin, log, inherent to test

* test more code generation

* basic storage test

* fix typo

* rename a few imports and field

* delete wip test in example and runtime

* change default prefix to make it backward compatible with test

* rename Instance to I and Instantiable to Instance

note: the name of generic parameter I is only enforce by decl_module!
and this could be rewritten

* doc

* clean old TODOs

* update parity-codec to 3.2

* update node impl version + builds

* fix warning

* fix unrelated grandpa test

* refactor code
2019-03-15 19:25:18 +01:00
Michael Müller c52c528ee8 Add grandpa telemetry (+ other minor improvements) (#1997)
* Support skipping the interactive purge prompt

Skip it via `cargo run -- purge-chain -y`.

* Fix typos

* Add Grandpa telemetry

* Address comments

* Revert unnecessary version bump

* Version bump to make CI run

* Remove unnecessary cast

* Do not bump version
2019-03-15 15:04:01 +01:00
Kian Peymani b86c96ea31 Phragmén Validator Election (#1915)
* adds first draft phragmen with tuned tests and sr-primitives

* fix a few docs and code styles

* clean, organize and finish remaining test cases

* more and more tests

* update edge cases behavior and relavent tests

* fix global test issues

* updated wasm files

* all tests fixed

* cleanup

* fix some global issues

* fix global tests

* bump versions

* fix typo

* first step toward extracting phragmen

* Fix most of the grumbles.

* fix rest of the grumbles

* spaces to tabs

* update wasm

* Removed nightly feature.

* More tests

* Fix broken tests.

* Bump and update wasm.
2019-03-14 12:23:55 +01:00
Gav Wood d7fcf5dc9d Overhaul crypto (Schnorr/Ristretto, HDKD, BIP39) (#1795)
* Rijig to Ristretto

* Rebuild wasm

* adds compatibility test with the wasm module

* Add Ed25519-BIP39 support

* Bump subkey version

* Update CLI output

* New keys.

* Standard phrase/password/path keys.

* Subkey uses S-URI for secrets

* Move everything to use new HDKD crypto.

* Test fixes

* Ignore old test vector.

* fix the ^^ old test vector.

* Fix tests

* Test fixes

* Cleanups

* Fix broken key conversion logic in grandpa

CC @rphmeier

* Remove legacy Keyring usage

* Traitify `Pair`

* Replace Ed25519AuthorityId with ed25519::Public

* Expunge Ed25519AuthorityId type!

* Replace Sr25519AuthorityId with sr25519::Public

* Remove dodgy crypto type-punning conversions

* Fix some tests

* Avoid trait

* Deduplicate DeriveJunction string decode

* Remove cruft code

* Fix test

* Minor removals

* Build fix

* Subkey supports sign and verify

* Inspect works for public key URIs

* Remove more crypto type-punning

* Fix typo

* Fix tests
2019-03-13 14:08:31 +01:00
Bastian Köcher 17f093da13 Make use of assimilate_storage for GenesisConfig (#1982)
* Make use of `assimilate_storage` for `GenesisConfig`

Fixes incorrect initialization of the staking gensis storage.

* Add some documentation
2019-03-13 12:59:07 +01:00
Bastian Köcher 7927054f86 Update copyrights to 2019 (#1932) 2019-03-06 15:04:28 +01:00
Gav Wood ccc11974ee Aggregate all liquidity restrictions in a single place (#1921)
* Clean up session key rotation

* Fix build

* Bump version

* Introduce feature to balances.

* Move staking locking logic over to central point

* ^^^ rest

* First part of assimilation

* More assimilation

* More assimilation

* Fix most tests

* Fix build

* Move Balances to new locking system

* :q!

* Bump runtime version

* Build runtime

* Convenience function

* Test fix.

* Whitespace

* Improve type legibility.

* Fix comment.

* More tests.

* More tests.

* Bump version

* Caps

* Whitespace

* Whitespace

* Remove unneeded function.
2019-03-06 12:46:17 +01:00
Hero Bird 128d164f2b Make use of parity-codec "derive" crate feature (#1919)
* Make use of parity-codec "derive" crate feature

* Bump impl_version

* Update wasm files and Cargo.lock files

* Transferred to parity_codec derive feature for the rest of the crates

* Update wasm binaries and lock files

* Update core and node wasm binaries
2019-03-05 09:00:37 +01:00
Gav Wood 828cd9580a Stash/controller model for staking (#1782)
* First steps to stash/controller separation

* More drafting

* More drafting

* Finish draft.

* Optimisation

* Remove accidental commit

* Make it build.

* Fix linked map for traits.

* Fix Option<_> variant.

*  Improve naming a tad

* Rebuild runtime

* Builds!

* First test.

* Bump RT version

* Minor fix

* Update Mock

* adds the correct reward testcase (+staking eras which was already ok)

* fixes the basic staking testcase to work properly (along with a small fix in the module)

* New logic to avoid controller transferring stash.

* Fix some build issues.

* adding some comments to tests

* Fix impls.

* adds a few more lines to explain the test case

* More fixes.

* gets the basic test up and running again

* Fix rest of build

* Rebuild wasm

* Fix docs.

* fix staking test with new chnages

* updating some tests, pending questions

* More working tests

* adds double staking test

* Docs

* remove invalid slashing test

* Payee stuff.

* Fix build

* Docs

* Fix test

* Fix a couple of tests

* Layout plan for finishing tests before Pragmen

* Add some working tests

* re-build staking and reward tests

* Add more tests

* fix offline grace test

* Nominator should have payee checked for cleanup

* adds more nomination tets

* adds validator prefs tests

* Fix and clean up some TODOs

* Fix a couple of issues

* Fix tests

* noting warnings from tests

* final fix of local tests

* Fix slot_stake bug

* Half baked test

* Add logic to limit `unstake_threshold` set in storage

* Make sure to check before writing!

Almost forgot this one

* Move a couple of comments

* fix last broken slot_stake test

* Ignore broken test
2019-03-02 14:31:48 +01:00
Xiliang Chen fafffdb771 Transaction Fee Module (#1648)
* wip

* Split bytes fee charging and charging by amount into different traits.

* Move to edition 2018.

* Implemented charge fee traits for fees module.

* Implemented 'on_finalise' for fee module.

* Updated fees finalize impl.

* Renaming and documentation update.

* Added overflow & underflow check for fee calculation.

* Added mock and unit tests for fee module.

* More unit tests for fees module.

* Fixed srml-executive unit tests.

* Remove transaction base/bytes fee from balances module, fix unit tests.

* fix compile error

* Fixed unit test.

* Minor fixes.

* Bump spec version.

* Bump spec version.

* Updated fees module and runtime wasm.

* Fees module code style improvement; updated runtime wasm.

* Bump spec and impl version.
2019-02-15 11:21:38 +01:00
Gav Wood a61c218cc3 Introduce Ristretto signing (#1730)
* first draft of ristretto crypto module #1685

* adds better comments and code-style

* remove the last evil unwrap

* remove a mistakenly committed lockfile

* add a fresh new lockfile --will probably need a manual merge later

* fix an invalid old test vector

* Wire in ristretto

* Update comment

* Fix use.

* new Signature type api alias to be compatible with substrate

* Add new keyring, fix node executor tests

* Bump version.

* Remove all hashes.

* Update core/primitives/src/sr25519.rs

Co-Authored-By: gavofyork <github@gavwood.com>

* Revert back to Ed25519 (until JS UI is ready)

* Fix test
2019-02-13 10:10:17 +01:00
Tomasz Drwięga 9e2710246f EnumerableStorageMap (#1763)
* Refactor decl_storage a bit to allow easier impl of linked map.

* A bunch of refactorings for storage generation.

- Rename StorageMap and ChildrenStorageMap to avoid confusion with generator::StorageMap.
- Separate implementation from the procedural macro code to clean it up.
- Make sure that genesis is initialised using the `StorageValue/StorageMap`
  generated implementations instead of going RAW.

* WiP: Writing test.

* Basic implementation.

* Implement enumeration.

* Fix non-std issues.

* fix warning

* Fix test-client.

* Address review grumbles - part 1

* Avoid cloning the key, relax Storage requirements.

* Rebuild runtime.

* Remove dangling todo.
2019-02-13 08:52:52 +01:00
Marcio Diaz b8bd49961a Adds new execution strategy nativeElseWasm (#1546)
* fix: adds new execution strategy nativeElseWasm and replace nativeWhenPossible with it

* feat: adds cmd line params for execution strategies

* fix: uses of cmd line execution strategies

* chore: remove white spaces

* chore: remove println

* chore: remove whitespace

* fix: generating functions with context

* feat: add function to generate with_context declarations

* fix: add implementation for with_context function calls

* fix: add execution context to call_api_at function

* fix: making use of context to select strategy for block_builder

* chore: cleaning up

* fix: merging issues

* fix tests

* add wasm files

* chore: small doc for context fields

* chore: delete redundant docs

* fix: use full path for ExecutionContext

* fix: add context functions from inside fold_item_impl

* chore: remove clone

* fix: moving generative function to utils, remove unused imports

* fix: add missing full path for ExecutionContext

* fix: merge issues

* update wasm files

* fix: update to keep up with changes in master

* chore: remove unused functions, clean up

* fix test

* fix grumbles

* fix: add more tests

* fix: some refactorings

* feat: add execution strategy to call

* chore: small improvements

* fix: add message to panic

* fix tests
2019-02-11 15:22:44 +01:00
Tomasz Drwięga 51a98f5c94 Unify bad signature error (#1717)
* Unify bad signature message.

* Update runtime.
2019-02-09 19:44:52 +01:00
Tomasz Drwięga 83f9e1e720 Allow modules to indicate full block. (#1687)
* Add transaction skipping.

* Update runtime.
2019-02-08 15:35:48 +01:00
Arkadiy Paronyan 091e222d99 Fixed a bunch of warnings (#1740) 2019-02-08 14:55:15 +01:00
Stanislav Tkach 3a4dda7beb Migrate sr-primitives, sr-sandbox, sr-std and sr-version to the 2018 edition (#1694) 2019-02-06 19:04:14 +01:00
Bastian Köcher 567122fab5 Moves node-template into substrate repo (#1637)
* Make runtime macros work without required `macro_use`

* Adds node-template

* Adds node-template-release tool

* Fixes building `node-template` and improve the release

* Add `profile.release` by release script to remove warning

* Adds script for releasing the node template

* Fixes compilation after master merge

* Port node-template to edition 2018

* Remove license

* Fixes compilation after master merge

* Add `node-template-release.sh` into the CI

* WIP Ci integrate node template (#1701)

* copy artifacts to s3 bucket latest path

* typo

* bucket name

* Update wasm files
2019-02-06 17:15:12 +01:00
Gav Wood fa2e323478 Add OnInitialise handler. (#1690)
* Add OnInitialise handler.

Closes #1686

* Fix typo

* Fix wasm build

* Add tests for initialise and finalise.
2019-02-06 10:01:28 +01:00
Tomasz Drwięga ecdd33a367 Allow both consensus and runtime to limit block building (#1581)
* Limit block size in runtime,

* Add test for basic authorship.

* Store length of extrinsics instead of computing it.

* Don't rely on note_extrinsic

* Use hashed version of storage and write test.

* Recompile runtime.
2019-02-01 13:58:23 +01:00
Gav Wood a58de5d0ff Transaction signing payload is hashed first (#1624)
* Transaction signing payload is hashed first

* Fix tests

* Rebuild wasm

* Fix tests

* Only take payload hash when payload.len > 256 bytes.

* Fix tests
2019-01-31 18:39:20 +01:00
Benjamin Kampmann 15ae7cfef6 Document more TODOs as tickets (#1418)
Went through the TODOs, removed a bunch, which are outdated or nothing more than a regular comment, documented a bunch more as actual tickets and made them FIXMEs and unified their structure (`FIXME #TICKETNO DESC` for local tickets, `FIXME: DESC LINK` for external tickets) for easier in-editor support. Further more remove unnecessary remarks and related old code that I noticed in that instance.
2019-01-30 10:29:48 +01:00
Tomasz Drwięga d2cfd7b9dc Allow runtime to return transaction validation error codes (#1534)
* Allow runtime to return more detailed transaction validation errors.

* Re-use ApplyError codes and update test-runtime.

* Fix pool tests.

* Revert using Compact for validity.
2019-01-29 19:06:05 +01:00
thiolliere ecffe0c371 impl Mul + saturating_mul by converting in u64 (#1610) 2019-01-29 13:36:34 +01:00
thiolliere 0078927ac5 update codec and grandpa (#1582)
* update codec

* use new codec

* update grandpa code

* build .lock and binaries
2019-01-28 14:16:17 +01:00
Tomasz Drwięga 2c3c4ac0e8 Add missing docs to sr-primitives. (#1531) 2019-01-24 13:49:39 +01:00
thiolliere c0568ba3c6 update primitive-types and solve break changes (#1535) 2019-01-23 18:26:44 +01:00
Bastian Köcher 70b1af7b1e Rewrite Inherent data (#1488)
* Implement new inherent data

* Fixes compilation on wasm

* Fixes after rebase

* Switch back to generate inherent stuff by macro

* Update after rebase

* Apply suggestions from code review

Co-Authored-By: bkchr <bkchr@users.noreply.github.com>

* Fix compilation after rebase

* Address grumbles

* Remove `InherentDataProviders` from `Client`

* Update wasm files after rebase

* Address grumbles

* Fixes compilation after latest merge

* Last fix
2019-01-22 17:52:08 +01:00
kyegupov 22b65c9cb0 Documentation for the macros that define a Runtime and associated types. (#1516) 2019-01-22 11:09:25 +01:00
Bastian Köcher 010e63116f Make runtime api calls native when possible (#1302)
* Add simple benchmark for the runtime api

* Make the executor support native calls

* Some documentation

* Hide behind `feature = "std"`

* Rework the native calls

* Make all tests compile again

* Make every parameter using the Block serialized/deserialized in the native call

* Forward `UnwindSafe` requirement

* Remove debug stuff

* Add some documentation

* Fixes warnings

* Fixes errors after master rebase

* Fixes compilation after master rebase

* Fixes compilation after rebase
2019-01-21 14:32:53 +01:00
Tomasz Drwięga a69a09a165 Serialize encoded logs. (#1478) 2019-01-19 12:36:14 +01:00
Tomasz Drwięga 34b21d6dd1 Fix serialization of generic unchecked extrinsics. (#1477) 2019-01-19 12:35:30 +01:00
thiolliere beeacf9cfa impl HasCompact for Perbill and Permill (#1411)
* impl Compact<> and HasCompact for Permill Perbill

* update parity-codec to 2.2

* add Cargo.lock

* add lock and build for runtime

* rebuild Cargo.lock after rebase
2019-01-17 11:25:48 +01:00
Gav Wood c9f047fe84 Split Indices module from Balances (#1404)
* Indices module

* Remove indices stuff from balances

* Rejob node, move Lookup into system.

* Fix up some modules.

* Fix democracy tests

* Fix staking tests

* Fix more tests

* Final test fixes

* Bump runtime versions

* Assets uses compact dispatchers

* Contracts module uses indexed addressing

* Democracy has more compact encoding

* Example now demonstrates compact eencoding

* Sudo uses indexed address

* Upgrade key also uses indexed lookups

* Assets more compact types.

* Fix test

* Rebuild runtime, whitespace

* Remove TOODs

* Remove TODOs

* Add a couple of tests back to balances.

* Update lib.rs

* Update lib.rs
2019-01-16 15:57:19 +01:00
Svyatoslav Nikolsky 616716cb4b GRANDPA finality proof draft (#1268)
* grandpa finality proof

* prove GrandpaApi::grandpa_authorities using parent block + some docs

* create justification when consensus data is changed

* generate justifications periodically

* test for ConsensusChanges
2019-01-11 19:25:03 +01:00
Tomasz Drwięga 677b79765b Fix serialization of extrinsics. (#1402) 2019-01-11 19:24:25 +01:00
Tomasz Drwięga cc3748f034 Hex-encode block number. (#1389) 2019-01-11 11:43:58 +01:00
Gav Wood 039741c977 Ensure opaque extr serialise is same as transparent (#1388)
* Ensure opaque extr serialise is same as transparent

Fixes #889

* Fix wasm compile
2019-01-11 11:36:44 +01:00
Tomasz Drwięga 8d4129aa22 Remove unneeded Deserialize impls. (#1370) 2019-01-08 22:44:39 +01:00
Wei Tang 71d889b692 Make AuthorityId generic (#1296)
* BlockAuthorityId convenience type

* Rename AuthorityId -> Ed25519AuthorityId to make it more precise

* Generalize AuthorityId up to substrate-client

* Fix in client-db

* rename: BlockAuthorityId -> AuthorityIdFor

* typo: should be digest item

* Fix test-runtime authorityId mismatch

One states that AuthorityId is u64 while the other states that it's Ed25519AuthorityId.

* Fix more u64 - Ed25519AuthorityId mismatch

* Fix compile of most of the srml modules

* Continue to pin aura and grandpa with ed25519 and fix compile

* Add MaybeHash trait

* Fix node-runtime compile

* Fix network tests
2019-01-08 11:14:18 +01:00
Wei Tang 031826ebdb typo: Hash -> Self::Hash (#1319) 2018-12-22 17:35:49 +01:00
Gav Wood a6c77e4f82 Compact extrinsics (#1314) 2018-12-21 12:55:44 +01:00
Gav Wood 27f69def9a Lock-voting (#1254)
* Optionally long lock voting

* Lock voting.

* Fix tests

* Comment update

* Comments

* Minor grumbles

* Docs.
2018-12-13 18:58:50 +01:00
Robert Habermeier c61d03a86f fix overflow in slashing logic (#1263) 2018-12-13 12:33:03 +01:00
Robert Habermeier 6299b42a4d Punish offline validators, aura-style (#1216)
* make offline-reporting infrastructure more generic

* add a listener-trait for watching when the timestamp has been set

* prevent inclusion of empty offline reports

* add test for exclusion

* generate aura-offline reports

* ability to slash many times for being offline "multiple" times

* Logic for punishing validators for missing aura steps

* stub tests

* pave way for verification of timestamp vs slot

* alter aura import queue to wait for timestamp

* check timestamp matches seal

* do inherent check properly

* service compiles

* all tests compile

* test srml-aura logic

* aura tests pass

* everything builds

* some more final tweaks to block authorship for aura

* switch to manual delays before step

* restore substrate-consensus-aura to always std and address grumbles

* update some state roots in executor tests

* node-executor tests pass

* get most tests passing

* address grumbles
2018-12-10 18:37:08 +01:00
Bastian Köcher 1f6719346f Make runtime api generate version and identifier information (#1226)
* Make `decl_runtime_apis!` implement `RuntimeApiInfo` for all runtime
apis

* Make the runtime side generate the info constants as well

* Make `RuntimeApiInfo` implementation use the correct generics

* Adds a test for the runtime api info stuff

* Remove duplicated code by using block from `test-client`

* Adds `compile_fail` tests for `api_version`

* Adds documentation for `api_version`

* Make `impl_runtime_apis!` generate `RUNTIME_API_VERSIONS`

* Update documentation and tests for `RUNTIME_API_VERSIONS`

* Implement `has_api` by using the `RuntimeApiInfo`

* Make `impl_runtime_apis` check that trait identifiers are unique

* Prefix all runtime api function with the corresponding trait

So `execute_block` will be called `Core_execute_block`.
This makes it possible to have traits implement a function with the
same name.

* Rebase master

* Update after master rebase
2018-12-10 11:48:07 +01:00
André Silva e779eeb2ec Grandpa validator set handoff justification (#1190)
* core: make block justification optional

* runtime: update wasm binaries

* core: optionally pass justification on finalize_block

* finality-grandpa: add channel to trigger authority set changes

this will allow the `BlockImport` to trigger an authority set change when
importing a change block that provides a justification (when syncing)

* finality-grandpa: move finalize_block to free function

* finality-grandpa: add GrandpaOracle for auth set liveness checking

this will be used by `BlockImport` to check whether the authority set for a
given block is still live, if the authority set isn't live then importing a
change block requires a justification.

* finality-grandpa: store justification on finalized transition blocks

* finality-grandpa: check justification on authority set change blocks

* finality-grandpa: poll grandpa liveness oracle every 10 seconds

* finality-grandpa: spawn grandpa oracle in service setup

* core: support multiple subscriptions per consensus gossip topic

* finality-grandpa: create and verify justifications

* finality-grandpa: update to local branch of grandpa

* finality-grandpa: update to finality-grandpa v0.5.0

* finality-grandpa: move grandpa oracle code

* finality-grandpa: fix canonality check

* finality-grandpa: clean up error handling

* finality-grandpa: fix canonical_at_height

* finality-grandpa: fix tests

* runtime: update wasm binaries

* core: add tests for finalizing block with justification

* finality-grandpa: improve validation of justifications

* core: remove unused IncompleteJustification block import error

* core: test multiple subscribers for same consensus gossip topic

* Revert "finality-grandpa: improve validation of justifications"

This reverts commit 51eb2c58c2219801e876af6d6c9371bdd9ff2477.

* finality-grandpa: fix commit validation

* finality-grandpa: fix commit ancestry validation

* finality-grandpa: use grandpa v0.5.1

* finality-grandpa: add docs

* finality-grandpa: fix failing test

* finality-grandpa: only allow a pending authority set change per fork

* finality-grandpa: fix validator set transition test
2018-12-08 13:34:59 +08:00
Robert Habermeier 9bccc9661c CheckInherentError can now report when something would be valid (#1204)
* CheckInherentError can now report when something would be valid

* set timestamp inherent to next valid block time

* return max timestamp for valid-after when checking
2018-12-04 09:19:36 +01:00
Robert Habermeier 63980e3770 make block builder and construct_runtime! generic over inherent-data (#1191)
* make block builder generic over inherent-data

* construct_runtime has you specify inherent data type

* get all tests to compile
2018-12-03 11:49:30 +01:00