From d2c4b0dbd89d9588adcbe97320e27f49ee251411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 11 Nov 2019 16:26:49 +0100 Subject: [PATCH] Refactor sr-api to not depend on client anymore (#4086) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refactor sr-api to not depend on client anymore * Fix benches * Apply suggestions from code review Co-Authored-By: Tomasz Drwięga * Apply suggestions from code review --- Cargo.lock | 178 +++++++++++---- Cargo.toml | 7 +- core/authority-discovery/Cargo.toml | 1 + .../authority-discovery/primitives/Cargo.toml | 10 +- .../authority-discovery/primitives/src/lib.rs | 3 +- core/authority-discovery/src/lib.rs | 8 +- core/basic-authorship/Cargo.toml | 3 +- core/basic-authorship/src/basic_authorship.rs | 17 +- core/block-builder/Cargo.toml | 14 ++ core/block-builder/runtime-api/Cargo.toml | 20 ++ .../runtime-api/src/lib.rs} | 19 +- .../src/lib.rs} | 91 ++++---- core/client/Cargo.toml | 73 ++----- core/client/src/call_executor.rs | 2 +- core/client/src/client.rs | 65 ++++-- core/client/src/error.rs | 6 + core/client/src/lib.rs | 26 --- core/client/src/light/call_executor.rs | 3 +- core/consensus/aura/Cargo.toml | 4 +- core/consensus/aura/primitives/Cargo.toml | 4 +- core/consensus/aura/primitives/src/lib.rs | 3 +- core/consensus/aura/src/lib.rs | 30 ++- core/consensus/babe/Cargo.toml | 3 + core/consensus/babe/primitives/Cargo.toml | 4 +- core/consensus/babe/primitives/src/lib.rs | 3 +- core/consensus/babe/src/lib.rs | 25 ++- core/consensus/babe/src/tests.rs | 2 +- core/consensus/common/src/error.rs | 2 +- core/consensus/pow/Cargo.toml | 1 + core/consensus/pow/primitives/Cargo.toml | 4 +- core/consensus/pow/primitives/src/lib.rs | 3 +- core/consensus/pow/src/lib.rs | 16 +- core/consensus/slots/src/slots.rs | 2 +- core/finality-grandpa/Cargo.toml | 1 + core/finality-grandpa/primitives/Cargo.toml | 4 +- core/finality-grandpa/primitives/src/lib.rs | 3 +- core/finality-grandpa/src/tests.rs | 9 +- core/inherents/Cargo.toml | 8 +- core/inherents/src/lib.rs | 52 ++++- core/network/Cargo.toml | 1 + core/network/src/test/mod.rs | 2 +- core/offchain/Cargo.toml | 3 +- core/offchain/primitives/Cargo.toml | 4 +- core/offchain/primitives/src/lib.rs | 3 +- core/offchain/src/lib.rs | 10 +- core/primitives/src/lib.rs | 4 +- core/rpc/Cargo.toml | 1 + core/rpc/src/author/mod.rs | 13 +- core/rpc/src/state/mod.rs | 16 +- core/rpc/src/state/state_full.rs | 12 +- core/service/Cargo.toml | 4 +- core/service/src/builder.rs | 16 +- core/service/src/lib.rs | 4 +- core/session/Cargo.toml | 5 +- core/session/src/lib.rs | 29 +-- core/sr-api-macros/Cargo.toml | 37 ---- .../tests/ui/adding_self_parameter.stderr | 5 - .../ui/empty_impl_runtime_apis_call.stderr | 5 - .../ui/impl_incorrect_method_signature.stderr | 64 ------ .../ui/impl_two_traits_with_same_name.stderr | 17 -- .../tests/ui/invalid_api_version_2.stderr | 33 --- .../tests/ui/invalid_api_version_3.stderr | 33 --- .../ui/missing_block_generic_parameter.stderr | 13 -- ...reference_in_impl_runtime_apis_call.stderr | 67 ------ core/sr-api/Cargo.toml | 33 +++ .../benches/bench.rs | 4 +- .../src/runtime_api.rs => sr-api/lib.rs} | 0 core/sr-api/proc-macro/Cargo.toml | 26 +++ .../proc-macro}/src/decl_runtime_apis.rs | 80 ++++--- .../proc-macro}/src/impl_runtime_apis.rs | 84 ++++--- .../proc-macro}/src/lib.rs | 29 +-- .../proc-macro}/src/utils.rs | 13 +- core/sr-api/src/lib.rs | 206 ++++++++++++++++++ core/sr-api/test/Cargo.toml | 21 ++ .../test}/tests/decl_and_impl.rs | 40 ++-- .../test}/tests/runtime_calls.rs | 0 .../test}/tests/trybuild.rs | 0 .../test}/tests/ui/adding_self_parameter.rs | 4 +- .../tests/ui/adding_self_parameter.stderr | 5 + .../tests/ui/changed_in_unknown_version.rs | 3 +- .../ui/changed_in_unknown_version.stderr | 4 +- .../test}/tests/ui/declaring_old_block.rs | 3 +- .../test}/tests/ui/declaring_old_block.stderr | 8 +- ...declaring_own_block_with_different_name.rs | 3 +- ...aring_own_block_with_different_name.stderr | 4 +- .../tests/ui/empty_impl_runtime_apis_call.rs | 5 +- .../ui/empty_impl_runtime_apis_call.stderr | 5 + .../ui/impl_incorrect_method_signature.rs | 7 +- .../ui/impl_incorrect_method_signature.stderr | 70 ++++++ .../ui/impl_two_traits_with_same_name.rs | 5 +- .../ui/impl_two_traits_with_same_name.stderr | 77 +++++++ .../test}/tests/ui/invalid_api_version.rs | 4 +- .../test}/tests/ui/invalid_api_version.stderr | 32 +-- .../test}/tests/ui/invalid_api_version_2.rs | 4 +- .../tests/ui/invalid_api_version_2.stderr | 33 +++ .../test}/tests/ui/invalid_api_version_3.rs | 4 +- .../tests/ui/invalid_api_version_3.stderr | 33 +++ .../ui/missing_block_generic_parameter.rs | 5 +- .../ui/missing_block_generic_parameter.stderr | 11 + .../test}/tests/ui/missing_path_for_trait.rs | 5 +- .../tests/ui/missing_path_for_trait.stderr | 4 +- ...ype_reference_in_impl_runtime_apis_call.rs | 7 +- ...reference_in_impl_runtime_apis_call.stderr | 73 +++++++ core/sr-primitives/Cargo.toml | 2 + core/sr-primitives/src/lib.rs | 13 +- core/sr-primitives/src/traits.rs | 19 ++ core/sr-version/src/lib.rs | 2 +- core/test-runtime/Cargo.toml | 10 +- core/test-runtime/client/Cargo.toml | 12 +- .../client/src/block_builder_ext.rs | 21 +- core/test-runtime/src/lib.rs | 17 +- core/transaction-pool/Cargo.toml | 3 +- core/transaction-pool/runtime-api/Cargo.toml | 14 ++ .../runtime-api/src/lib.rs} | 18 +- core/transaction-pool/src/api.rs | 66 +++--- core/transaction-pool/src/error.rs | 12 +- core/transaction-pool/src/lib.rs | 3 +- node-template/runtime/Cargo.toml | 10 +- node-template/runtime/src/lib.rs | 18 +- node/runtime/Cargo.toml | 10 +- node/runtime/src/lib.rs | 17 +- srml/aura/src/lib.rs | 16 +- srml/authorship/src/lib.rs | 11 +- srml/babe/src/lib.rs | 16 +- srml/contracts/rpc/runtime-api/Cargo.toml | 4 +- srml/contracts/rpc/runtime-api/src/lib.rs | 2 +- srml/finality-tracker/src/lib.rs | 16 +- srml/session/Cargo.toml | 2 +- srml/session/src/lib.rs | 5 +- srml/support/procedural/Cargo.toml | 1 - srml/support/test/tests/instance.rs | 8 +- srml/system/rpc/runtime-api/Cargo.toml | 4 +- srml/system/rpc/runtime-api/src/lib.rs | 2 +- srml/timestamp/src/lib.rs | 18 +- .../rpc/runtime-api/Cargo.toml | 4 +- .../rpc/runtime-api/src/lib.rs | 2 +- test-utils/transaction-factory/Cargo.toml | 2 + .../transaction-factory/src/complex_mode.rs | 7 +- test-utils/transaction-factory/src/lib.rs | 12 +- .../transaction-factory/src/simple_modes.rs | 7 +- 140 files changed, 1510 insertions(+), 980 deletions(-) create mode 100644 core/block-builder/Cargo.toml create mode 100644 core/block-builder/runtime-api/Cargo.toml rename core/{client/src/block_builder/api.rs => block-builder/runtime-api/src/lib.rs} (76%) rename core/{client/src/block_builder/block_builder.rs => block-builder/src/lib.rs} (61%) delete mode 100644 core/sr-api-macros/Cargo.toml delete mode 100644 core/sr-api-macros/tests/ui/adding_self_parameter.stderr delete mode 100644 core/sr-api-macros/tests/ui/empty_impl_runtime_apis_call.stderr delete mode 100644 core/sr-api-macros/tests/ui/impl_incorrect_method_signature.stderr delete mode 100644 core/sr-api-macros/tests/ui/impl_two_traits_with_same_name.stderr delete mode 100644 core/sr-api-macros/tests/ui/invalid_api_version_2.stderr delete mode 100644 core/sr-api-macros/tests/ui/invalid_api_version_3.stderr delete mode 100644 core/sr-api-macros/tests/ui/missing_block_generic_parameter.stderr delete mode 100644 core/sr-api-macros/tests/ui/type_reference_in_impl_runtime_apis_call.stderr create mode 100644 core/sr-api/Cargo.toml rename core/{sr-api-macros => sr-api}/benches/bench.rs (96%) rename core/{client/src/runtime_api.rs => sr-api/lib.rs} (100%) create mode 100644 core/sr-api/proc-macro/Cargo.toml rename core/{sr-api-macros => sr-api/proc-macro}/src/decl_runtime_apis.rs (92%) rename core/{sr-api-macros => sr-api/proc-macro}/src/impl_runtime_apis.rs (87%) rename core/{sr-api-macros => sr-api/proc-macro}/src/lib.rs (91%) rename core/{sr-api-macros => sr-api/proc-macro}/src/utils.rs (93%) create mode 100644 core/sr-api/src/lib.rs create mode 100644 core/sr-api/test/Cargo.toml rename core/{sr-api-macros => sr-api/test}/tests/decl_and_impl.rs (71%) rename core/{sr-api-macros => sr-api/test}/tests/runtime_calls.rs (100%) rename core/{sr-api-macros => sr-api/test}/tests/trybuild.rs (100%) rename core/{sr-api-macros => sr-api/test}/tests/ui/adding_self_parameter.rs (50%) create mode 100644 core/sr-api/test/tests/ui/adding_self_parameter.stderr rename core/{sr-api-macros => sr-api/test}/tests/ui/changed_in_unknown_version.rs (89%) rename core/{sr-api-macros => sr-api/test}/tests/ui/changed_in_unknown_version.stderr (53%) rename core/{sr-api-macros => sr-api/test}/tests/ui/declaring_old_block.rs (67%) rename core/{sr-api-macros => sr-api/test}/tests/ui/declaring_old_block.stderr (80%) rename core/{sr-api-macros => sr-api/test}/tests/ui/declaring_own_block_with_different_name.rs (66%) rename core/{sr-api-macros => sr-api/test}/tests/ui/declaring_own_block_with_different_name.stderr (84%) rename core/{sr-api-macros => sr-api/test}/tests/ui/empty_impl_runtime_apis_call.rs (80%) create mode 100644 core/sr-api/test/tests/ui/empty_impl_runtime_apis_call.stderr rename core/{sr-api-macros => sr-api/test}/tests/ui/impl_incorrect_method_signature.rs (81%) create mode 100644 core/sr-api/test/tests/ui/impl_incorrect_method_signature.stderr rename core/{sr-api-macros => sr-api/test}/tests/ui/impl_two_traits_with_same_name.rs (86%) create mode 100644 core/sr-api/test/tests/ui/impl_two_traits_with_same_name.stderr rename core/{sr-api-macros => sr-api/test}/tests/ui/invalid_api_version.rs (58%) rename core/{sr-api-macros => sr-api/test}/tests/ui/invalid_api_version.stderr (50%) rename core/{sr-api-macros => sr-api/test}/tests/ui/invalid_api_version_2.rs (59%) create mode 100644 core/sr-api/test/tests/ui/invalid_api_version_2.stderr rename core/{sr-api-macros => sr-api/test}/tests/ui/invalid_api_version_3.rs (58%) create mode 100644 core/sr-api/test/tests/ui/invalid_api_version_3.stderr rename core/{sr-api-macros => sr-api/test}/tests/ui/missing_block_generic_parameter.rs (83%) create mode 100644 core/sr-api/test/tests/ui/missing_block_generic_parameter.stderr rename core/{sr-api-macros => sr-api/test}/tests/ui/missing_path_for_trait.rs (83%) rename core/{sr-api-macros => sr-api/test}/tests/ui/missing_path_for_trait.stderr (60%) rename core/{sr-api-macros => sr-api/test}/tests/ui/type_reference_in_impl_runtime_apis_call.rs (82%) create mode 100644 core/sr-api/test/tests/ui/type_reference_in_impl_runtime_apis_call.stderr create mode 100644 core/transaction-pool/runtime-api/Cargo.toml rename core/{client/src/block_builder/mod.rs => transaction-pool/runtime-api/src/lib.rs} (60%) diff --git a/Cargo.lock b/Cargo.lock index 8574c9aa50751..2c3def1e28abc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,7 +125,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -785,7 +785,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1074,7 +1074,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1308,7 +1308,7 @@ dependencies = [ "proc-macro-hack 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1746,7 +1746,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1855,7 +1855,7 @@ dependencies = [ "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2806,6 +2806,7 @@ dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-staking-primitives 2.0.0", @@ -2840,12 +2841,14 @@ dependencies = [ "srml-transaction-payment-rpc-runtime-api 2.0.0", "srml-treasury 2.0.0", "srml-utility 2.0.0", - "substrate-client 2.0.0", + "substrate-block-builder-runtime-api 2.0.0", "substrate-consensus-babe-primitives 2.0.0", + "substrate-inherents 2.0.0", "substrate-keyring 2.0.0", "substrate-offchain-primitives 2.0.0", "substrate-primitives 2.0.0", "substrate-session 2.0.0", + "substrate-transaction-pool-runtime-api 2.0.0", "substrate-wasm-builder-runner 1.0.4", ] @@ -2889,6 +2892,7 @@ dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2904,11 +2908,13 @@ dependencies = [ "srml-system 2.0.0", "srml-timestamp 2.0.0", "srml-transaction-payment 2.0.0", - "substrate-client 2.0.0", + "substrate-block-builder-runtime-api 2.0.0", "substrate-consensus-aura-primitives 2.0.0", + "substrate-inherents 2.0.0", "substrate-offchain-primitives 2.0.0", "substrate-primitives 2.0.0", "substrate-session 2.0.0", + "substrate-transaction-pool-runtime-api 2.0.0", "substrate-wasm-builder-runner 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3274,7 +3280,7 @@ dependencies = [ "proc-macro-hack 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3372,7 +3378,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3382,7 +3388,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3901,7 +3907,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4064,7 +4070,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4228,24 +4234,47 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "sr-api-macros" +name = "sr-api" version = "2.0.0" dependencies = [ - "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api-proc-macro 2.0.0", + "sr-primitives 2.0.0", + "sr-std 2.0.0", + "sr-version 2.0.0", + "substrate-primitives 2.0.0", + "substrate-state-machine 2.0.0", + "substrate-test-runtime-client 2.0.0", +] + +[[package]] +name = "sr-api-proc-macro" +version = "2.0.0" +dependencies = [ + "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", + "sr-primitives 2.0.0", + "sr-version 2.0.0", + "substrate-test-runtime-client 2.0.0", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sr-api-test" +version = "2.0.0" +dependencies = [ + "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustversion 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", "sr-version 2.0.0", - "substrate-client 2.0.0", "substrate-consensus-common 2.0.0", - "substrate-primitives 2.0.0", "substrate-state-machine 2.0.0", "substrate-test-runtime-client 2.0.0", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "trybuild 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4296,6 +4325,7 @@ dependencies = [ "sr-io 2.0.0", "sr-std 2.0.0", "substrate-application-crypto 2.0.0", + "substrate-inherents 2.0.0", "substrate-offchain 2.0.0", "substrate-primitives 2.0.0", ] @@ -4510,9 +4540,9 @@ version = "2.0.0" dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", - "substrate-client 2.0.0", ] [[package]] @@ -4838,7 +4868,7 @@ dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4884,9 +4914,8 @@ version = "2.0.0" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "sr-api-macros 2.0.0", "srml-support-procedural-tools 2.0.0", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4897,7 +4926,7 @@ dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "srml-support-procedural-tools-derive 2.0.0", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4906,7 +4935,7 @@ version = "2.0.0" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4983,7 +5012,7 @@ name = "srml-system-rpc-runtime-api" version = "2.0.0" dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "substrate-client 2.0.0", + "sr-api 2.0.0", ] [[package]] @@ -5039,9 +5068,9 @@ version = "2.0.0" dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", - "substrate-client 2.0.0", ] [[package]] @@ -5136,7 +5165,7 @@ dependencies = [ "proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -5204,6 +5233,7 @@ dependencies = [ "prost 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "prost-build 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", "substrate-authority-discovery-primitives 2.0.0", "substrate-client 2.0.0", @@ -5218,9 +5248,9 @@ name = "substrate-authority-discovery-primitives" version = "2.0.0" dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", - "substrate-client 2.0.0", ] [[package]] @@ -5231,6 +5261,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", + "substrate-block-builder 2.0.0", "substrate-client 2.0.0", "substrate-consensus-common 2.0.0", "substrate-inherents 2.0.0", @@ -5251,6 +5282,28 @@ dependencies = [ "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "substrate-block-builder" +version = "2.0.0" +dependencies = [ + "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", + "sr-primitives 2.0.0", + "substrate-block-builder-runtime-api 2.0.0", + "substrate-primitives 2.0.0", + "substrate-state-machine 2.0.0", +] + +[[package]] +name = "substrate-block-builder-runtime-api" +version = "2.0.0" +dependencies = [ + "sr-api 2.0.0", + "sr-primitives 2.0.0", + "sr-std 2.0.0", + "substrate-inherents 2.0.0", +] + [[package]] name = "substrate-build-script-utils" version = "2.0.0" @@ -5276,7 +5329,7 @@ dependencies = [ "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -5331,10 +5384,11 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sr-api-macros 2.0.0", + "sr-api 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", "sr-version 2.0.0", + "substrate-block-builder 2.0.0", "substrate-client-db 2.0.0", "substrate-consensus-common 2.0.0", "substrate-executor 2.0.0", @@ -5388,12 +5442,14 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-version 2.0.0", "srml-aura 2.0.0", "srml-support 2.0.0", "substrate-application-crypto 2.0.0", + "substrate-block-builder-runtime-api 2.0.0", "substrate-client 2.0.0", "substrate-consensus-aura-primitives 2.0.0", "substrate-consensus-common 2.0.0", @@ -5416,10 +5472,10 @@ name = "substrate-consensus-aura-primitives" version = "2.0.0" dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", "substrate-application-crypto 2.0.0", - "substrate-client 2.0.0", ] [[package]] @@ -5442,12 +5498,15 @@ dependencies = [ "pdqselect 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "schnorrkel 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-version 2.0.0", "srml-babe 2.0.0", "srml-support 2.0.0", "substrate-application-crypto 2.0.0", + "substrate-block-builder 2.0.0", + "substrate-block-builder-runtime-api 2.0.0", "substrate-client 2.0.0", "substrate-consensus-babe-primitives 2.0.0", "substrate-consensus-common 2.0.0", @@ -5473,10 +5532,10 @@ version = "2.0.0" dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "schnorrkel 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", "substrate-application-crypto 2.0.0", - "substrate-client 2.0.0", "substrate-consensus-slots 2.0.0", ] @@ -5509,6 +5568,7 @@ dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "srml-timestamp 2.0.0", + "substrate-block-builder-runtime-api 2.0.0", "substrate-client 2.0.0", "substrate-consensus-common 2.0.0", "substrate-consensus-pow-primitives 2.0.0", @@ -5521,9 +5581,9 @@ name = "substrate-consensus-pow-primitives" version = "2.0.0" dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", - "substrate-client 2.0.0", "substrate-primitives 2.0.0", ] @@ -5588,7 +5648,7 @@ version = "2.0.0" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -5655,6 +5715,7 @@ dependencies = [ "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", "srml-finality-tracker 2.0.0", "substrate-client 2.0.0", @@ -5682,10 +5743,10 @@ version = "2.0.0" dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", "substrate-application-crypto 2.0.0", - "substrate-client 2.0.0", ] [[package]] @@ -5701,10 +5762,11 @@ dependencies = [ name = "substrate-inherents" version = "2.0.0" dependencies = [ + "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sr-primitives 2.0.0", "sr-std 2.0.0", + "substrate-primitives 2.0.0", ] [[package]] @@ -5764,6 +5826,7 @@ dependencies = [ "slog_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", + "substrate-block-builder 2.0.0", "substrate-client 2.0.0", "substrate-consensus-babe-primitives 2.0.0", "substrate-consensus-common 2.0.0", @@ -5799,6 +5862,7 @@ dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", "substrate-client 2.0.0", "substrate-client-db 2.0.0", @@ -5816,8 +5880,8 @@ dependencies = [ name = "substrate-offchain-primitives" version = "2.0.0" dependencies = [ + "sr-api 2.0.0", "sr-primitives 2.0.0", - "substrate-client 2.0.0", ] [[package]] @@ -5920,6 +5984,7 @@ dependencies = [ "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-version 2.0.0", @@ -6011,7 +6076,7 @@ dependencies = [ "rustversion 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-externalities 2.0.0", "substrate-runtime-interface 2.0.0", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "trybuild 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -6065,6 +6130,7 @@ dependencies = [ "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-io 2.0.0", "sr-primitives 2.0.0", "substrate-application-crypto 2.0.0", @@ -6086,6 +6152,7 @@ dependencies = [ "substrate-telemetry 2.0.0", "substrate-test-runtime-client 2.0.0", "substrate-transaction-pool 2.0.0", + "substrate-transaction-pool-runtime-api 2.0.0", "sysinfo 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6116,10 +6183,9 @@ dependencies = [ name = "substrate-session" version = "2.0.0" dependencies = [ + "sr-api 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", - "substrate-client 2.0.0", - "substrate-primitives 2.0.0", ] [[package]] @@ -6199,6 +6265,7 @@ dependencies = [ "memory-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -6210,6 +6277,7 @@ dependencies = [ "srml-system-rpc-runtime-api 2.0.0", "srml-timestamp 2.0.0", "substrate-application-crypto 2.0.0", + "substrate-block-builder-runtime-api 2.0.0", "substrate-client 2.0.0", "substrate-consensus-aura-primitives 2.0.0", "substrate-consensus-babe-primitives 2.0.0", @@ -6222,6 +6290,7 @@ dependencies = [ "substrate-session 2.0.0", "substrate-state-machine 2.0.0", "substrate-test-runtime-client 2.0.0", + "substrate-transaction-pool-runtime-api 2.0.0", "substrate-trie 2.0.0", "substrate-wasm-builder-runner 1.0.4", "trie-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6233,6 +6302,7 @@ version = "2.0.0" dependencies = [ "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", + "substrate-block-builder 2.0.0", "substrate-primitives 2.0.0", "substrate-test-client 2.0.0", "substrate-test-runtime 2.0.0", @@ -6265,12 +6335,22 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", - "substrate-client 2.0.0", "substrate-keyring 2.0.0", "substrate-primitives 2.0.0", "substrate-test-runtime-client 2.0.0", "substrate-transaction-graph 2.0.0", + "substrate-transaction-pool-runtime-api 2.0.0", +] + +[[package]] +name = "substrate-transaction-pool-runtime-api" +version = "2.0.0" +dependencies = [ + "sr-api 2.0.0", + "sr-primitives 2.0.0", + "substrate-primitives 2.0.0", ] [[package]] @@ -6344,7 +6424,7 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6370,7 +6450,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -6444,7 +6524,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -6745,7 +6825,9 @@ version = "0.0.1" dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-api 2.0.0", "sr-primitives 2.0.0", + "substrate-block-builder-runtime-api 2.0.0", "substrate-cli 2.0.0", "substrate-client 2.0.0", "substrate-consensus-common 2.0.0", @@ -7039,7 +7121,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-shared 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -7071,7 +7153,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-backend 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-shared 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -7091,7 +7173,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-backend 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "weedle 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -7889,7 +7971,7 @@ dependencies = [ "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab3af2eb31c42e8f0ccf43548232556c42737e01a96db6e1777b0be108e79799" "checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" -"checksum syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7bedb3320d0f3035594b0b723c8a28d7d336a3eda3881db79e61d676fb644c" +"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92" "checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" "checksum synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f085a5855930c0441ca1288cf044ea4aecf4f43a91668abdb870b4ba546a203" "checksum sysinfo 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d5bd3b813d94552a8033c650691645f8dd5a63d614dddd62428a95d3931ef7b6" diff --git a/Cargo.toml b/Cargo.toml index 8100f2eb80f0a..42f78db493b50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,8 @@ members = [ "core/consensus/slots", "core/consensus/uncles", "core/consensus/pow", + "core/block-builder", + "core/block-builder/runtime-api", "core/executor", "core/executor/runtime-test", "core/externalities", @@ -36,7 +38,9 @@ members = [ "core/service", "core/service/test", "core/session", - "core/sr-api-macros", + "core/sr-api", + "core/sr-api/proc-macro", + "core/sr-api/test", "core/sr-arithmetic", "core/sr-io", "core/sr-primitives", @@ -51,6 +55,7 @@ members = [ "core/test-runtime/client", "core/transaction-pool", "core/transaction-pool/graph", + "core/transaction-pool/runtime-api", "core/trie", "core/utils/fork-tree", "core/utils/wasm-builder", diff --git a/core/authority-discovery/Cargo.toml b/core/authority-discovery/Cargo.toml index 823977668a0e5..c46b815723f62 100644 --- a/core/authority-discovery/Cargo.toml +++ b/core/authority-discovery/Cargo.toml @@ -28,3 +28,4 @@ futures-timer = "0.4" parking_lot = "0.9.0" peerset = { package = "substrate-peerset", path = "../../core/peerset" } test-client = { package = "substrate-test-runtime-client", path = "../../core/test-runtime/client" } +sr-api = { path = "../sr-api" } diff --git a/core/authority-discovery/primitives/Cargo.toml b/core/authority-discovery/primitives/Cargo.toml index 8e9e465a299f6..41d833f58472f 100644 --- a/core/authority-discovery/primitives/Cargo.toml +++ b/core/authority-discovery/primitives/Cargo.toml @@ -7,15 +7,15 @@ edition = "2018" [dependencies] codec = { package = "parity-scale-codec", default-features = false, version = "1.0.3" } -client = { package = "substrate-client", path = "../../client", default-features = false } +sr-api = { path = "../../sr-api", default-features = false } sr-primitives = { path = "../../sr-primitives", default-features = false } rstd = { package = "sr-std", path = "../../sr-std", default-features = false } [features] default = ["std"] std = [ - "rstd/std", - "client/std", - "codec/std", - "sr-primitives/std" + "rstd/std", + "sr-api/std", + "codec/std", + "sr-primitives/std" ] diff --git a/core/authority-discovery/primitives/src/lib.rs b/core/authority-discovery/primitives/src/lib.rs index 7c56dc6ca4ca6..dda2cbc68dba8 100644 --- a/core/authority-discovery/primitives/src/lib.rs +++ b/core/authority-discovery/primitives/src/lib.rs @@ -18,7 +18,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -use client::decl_runtime_apis; use rstd::vec::Vec; use sr_primitives::RuntimeDebug; @@ -29,7 +28,7 @@ pub struct Signature(pub Vec); #[cfg_attr(feature = "std", derive(Hash))] pub struct AuthorityId(pub Vec); -decl_runtime_apis! { +sr_api::decl_runtime_apis! { /// The authority discovery api. /// /// This api is used by the `core/authority-discovery` module to retrieve our diff --git a/core/authority-discovery/src/lib.rs b/core/authority-discovery/src/lib.rs index 35237e251c895..13831be76f8ef 100644 --- a/core/authority-discovery/src/lib.rs +++ b/core/authority-discovery/src/lib.rs @@ -105,7 +105,7 @@ where Block: BlockT + Unpin + 'static, Network: NetworkProvider, Client: ProvideRuntimeApi + Send + Sync + 'static + HeaderBackend, - ::Api: AuthorityDiscoveryApi, + ::Api: AuthorityDiscoveryApi, Self: Future, { /// Return a new authority discovery. @@ -303,7 +303,7 @@ where Block: BlockT + Unpin + 'static, Network: NetworkProvider, Client: ProvideRuntimeApi + Send + Sync + 'static + HeaderBackend, - ::Api: AuthorityDiscoveryApi, + ::Api: AuthorityDiscoveryApi, { type Output = (); @@ -404,7 +404,7 @@ fn hash_authority_id(id: &[u8]) -> Result { #[cfg(test)] mod tests { use super::*; - use client::runtime_api::{ApiExt, Core, RuntimeVersion, StorageProof}; + use sr_api::{ApiExt, Core, RuntimeVersion, StorageProof}; use futures::channel::mpsc::channel; use futures::executor::block_on; use futures::future::poll_fn; @@ -501,6 +501,8 @@ mod tests { } impl ApiExt for RuntimeApi { + type Error = client::error::Error; + fn map_api_result std::result::Result, R, E>( &self, _: F, diff --git a/core/basic-authorship/Cargo.toml b/core/basic-authorship/Cargo.toml index 0a98c151d6eaf..a1f629da8a0de 100644 --- a/core/basic-authorship/Cargo.toml +++ b/core/basic-authorship/Cargo.toml @@ -14,7 +14,8 @@ client = { package = "substrate-client", path = "../../core/client" } consensus_common = { package = "substrate-consensus-common", path = "../../core/consensus/common" } inherents = { package = "substrate-inherents", path = "../inherents" } substrate-telemetry = { path = "../telemetry" } -transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" } +transaction_pool = { package = "substrate-transaction-pool", path = "../transaction-pool" } +block-builder = { package = "substrate-block-builder", path = "../block-builder" } [dev-dependencies] test-client = { package = "substrate-test-runtime-client", path = "../../core/test-runtime/client" } diff --git a/core/basic-authorship/src/basic_authorship.rs b/core/basic-authorship/src/basic_authorship.rs index 7f8b343f6512c..a54c5b52ae9e0 100644 --- a/core/basic-authorship/src/basic_authorship.rs +++ b/core/basic-authorship/src/basic_authorship.rs @@ -20,10 +20,7 @@ // use std::{time, sync::Arc}; -use client::{ - error, Client as SubstrateClient, CallExecutor, - block_builder::api::BlockBuilder as BlockBuilderApi, -}; +use client::{error, Client as SubstrateClient, CallExecutor}; use codec::Decode; use consensus_common::{evaluation}; use inherents::InherentData; @@ -37,6 +34,7 @@ use sr_primitives::{ }; use transaction_pool::txpool::{self, Pool as TransactionPool}; use substrate_telemetry::{telemetry, CONSENSUS_INFO}; +use block_builder::BlockBuilderApi; /// Proposer factory. pub struct ProposerFactory where A: txpool::ChainApi { @@ -55,7 +53,8 @@ where Block: BlockT, RA: Send + Sync + 'static, SubstrateClient: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: BlockBuilderApi, + as ProvideRuntimeApi>::Api: + BlockBuilderApi, { type Proposer = Proposer, A>; type Error = error::Error; @@ -102,7 +101,8 @@ where Block: BlockT, RA: Send + Sync + 'static, SubstrateClient: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: BlockBuilderApi, + as ProvideRuntimeApi>::Api: + BlockBuilderApi, { type Create = futures::future::Ready>; type Error = error::Error; @@ -126,7 +126,8 @@ impl Proposer, A> wh Block: BlockT, RA: Send + Sync + 'static, SubstrateClient: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: BlockBuilderApi, + as ProvideRuntimeApi>::Api: + BlockBuilderApi, { fn propose_with( &self, @@ -167,7 +168,7 @@ impl Proposer, A> wh } trace!("[{:?}] Pushing to the block.", pending.hash); - match client::block_builder::BlockBuilder::push(&mut block_builder, pending.data.clone()) { + match block_builder::BlockBuilder::push(&mut block_builder, pending.data.clone()) { Ok(()) => { debug!("[{:?}] Pushed to the block.", pending.hash); } diff --git a/core/block-builder/Cargo.toml b/core/block-builder/Cargo.toml new file mode 100644 index 0000000000000..e70522e5d5ac3 --- /dev/null +++ b/core/block-builder/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "substrate-block-builder" +version = "2.0.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +state-machine = { package = "substrate-state-machine", path = "../state-machine" } +sr-primitives = { path = "../sr-primitives" } +primitives = { package = "substrate-primitives", path = "../primitives" } +codec = { package = "parity-scale-codec", version = "1.0.6", features = ["derive"] } +runtime_api = { package = "substrate-block-builder-runtime-api", path = "runtime-api" } +sr-api = { path = "../sr-api" } + diff --git a/core/block-builder/runtime-api/Cargo.toml b/core/block-builder/runtime-api/Cargo.toml new file mode 100644 index 0000000000000..48f94ce0ee8e4 --- /dev/null +++ b/core/block-builder/runtime-api/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "substrate-block-builder-runtime-api" +version = "2.0.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +sr-primitives = { path = "../../sr-primitives", default-features = false } +sr-api = { path = "../../sr-api", default-features = false } +rstd = { package = "sr-std", path = "../../sr-std", default-features = false } +inherents = { package = "substrate-inherents", path = "../../inherents", default-features = false } + +[features] +default = [ "std" ] +std = [ + "sr-primitives/std", + "inherents/std", + "sr-api/std", + "rstd/std", +] diff --git a/core/client/src/block_builder/api.rs b/core/block-builder/runtime-api/src/lib.rs similarity index 76% rename from core/client/src/block_builder/api.rs rename to core/block-builder/runtime-api/src/lib.rs index 5bf742a4560d4..6469ac3d9ec62 100644 --- a/core/client/src/block_builder/api.rs +++ b/core/block-builder/runtime-api/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2019 Parity Technologies (UK) Ltd. +// Copyright 2019 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify @@ -14,15 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -//! The runtime api for building blocks. +//! The block builder runtime api. + +#![cfg_attr(not(feature = "std"), no_std)] use sr_primitives::{traits::Block as BlockT, ApplyResult}; -use rstd::vec::Vec; -use sr_api_macros::decl_runtime_apis; -pub use inherents::{InherentData, CheckInherentsResult}; -decl_runtime_apis! { - /// The `BlockBuilder` api trait that provides required functions for building a block for a runtime. +use inherents::{InherentData, CheckInherentsResult}; + +sr_api::decl_runtime_apis! { + /// The `BlockBuilder` api trait that provides the required functionality for building a block. #[api_version(3)] pub trait BlockBuilder { /// Apply the given extrinsics. @@ -31,7 +32,9 @@ decl_runtime_apis! { #[renamed("finalise_block", 3)] fn finalize_block() -> ::Header; /// Generate inherent extrinsics. The inherent data will vary from chain to chain. - fn inherent_extrinsics(inherent: InherentData) -> Vec<::Extrinsic>; + fn inherent_extrinsics( + inherent: InherentData, + ) -> rstd::vec::Vec<::Extrinsic>; /// Check that the inherents are valid. The inherent data will vary from chain to chain. fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult; /// Generate a random seed. diff --git a/core/client/src/block_builder/block_builder.rs b/core/block-builder/src/lib.rs similarity index 61% rename from core/client/src/block_builder/block_builder.rs rename to core/block-builder/src/lib.rs index f5cd6a9f660b0..5a345cbeb62bf 100644 --- a/core/client/src/block_builder/block_builder.rs +++ b/core/block-builder/src/lib.rs @@ -14,59 +14,66 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use super::api::BlockBuilder as BlockBuilderApi; -use std::vec::Vec; +//! Substrate block builder +//! +//! This crate provides the [`BlockBuilder`] utility and the corresponding runtime api +//! [`BlockBuilder`](api::BlockBuilder). +//! +//! The block builder utility is used in the node as an abstraction over the runtime api to +//! initialize a block, to push extrinsics and to finalize a block. + +#![warn(missing_docs)] + use codec::Encode; -use sr_primitives::generic::BlockId; -use sr_primitives::traits::{ - Header as HeaderT, Hash, Block as BlockT, One, HashFor, ProvideRuntimeApi, ApiRef, DigestFor, + +use sr_primitives::{ + generic::BlockId, + traits::{ + Header as HeaderT, Hash, Block as BlockT, HashFor, ProvideRuntimeApi, ApiRef, DigestFor, + NumberFor, One, + }, }; -use primitives::{H256, ExecutionContext}; + +use primitives::ExecutionContext; + use state_machine::StorageProof; -use crate::blockchain::HeaderBackend; -use crate::runtime_api::{Core, ApiExt}; -use crate::error; + +use sr_api::{Core, ApiExt, ApiErrorFor}; + +pub use runtime_api::BlockBuilder as BlockBuilderApi; + +/// Error when the runtime failed to apply an extrinsic. +pub struct ApplyExtrinsicFailed(pub sr_primitives::ApplyError); /// Utility for building new (valid) blocks from a stream of extrinsics. -pub struct BlockBuilder<'a, Block, A: ProvideRuntimeApi> where Block: BlockT { - header: ::Header, - extrinsics: Vec<::Extrinsic>, +pub struct BlockBuilder<'a, Block: BlockT, A: ProvideRuntimeApi> { + header: Block::Header, + extrinsics: Vec, api: ApiRef<'a, A::Api>, block_id: BlockId, } impl<'a, Block, A> BlockBuilder<'a, Block, A> where - Block: BlockT, - A: ProvideRuntimeApi + HeaderBackend + 'a, + Block: BlockT, + A: ProvideRuntimeApi + 'a, A::Api: BlockBuilderApi, + ApiErrorFor: From, { - /// Create a new instance of builder from the given client, building on the - /// latest block. - pub fn new(api: &'a A, inherent_digests: DigestFor) -> error::Result { - Self::at_block(&BlockId::Hash(api.info().best_hash), api, false, inherent_digests) - } - - /// Create a new instance of builder from the given client using a - /// particular block's ID to build upon with optional proof recording enabled. + /// Create a new instance of builder based on the given `parent_hash` and `parent_number`. /// /// While proof recording is enabled, all accessed trie nodes are saved. /// These recorded trie nodes can be used by a third party to prove the /// output of this block builder without having access to the full storage. - pub fn at_block( - block_id: &BlockId, + pub fn new( api: &'a A, + parent_hash: Block::Hash, + parent_number: NumberFor, proof_recording: bool, inherent_digests: DigestFor, - ) -> error::Result { - let number = api.block_number_from_id(block_id)? - .ok_or_else(|| error::Error::UnknownBlock(format!("{}", block_id)))? - + One::one(); - - let parent_hash = api.block_hash_from_id(block_id)? - .ok_or_else(|| error::Error::UnknownBlock(format!("{}", block_id)))?; + ) -> Result> { let header = <::Header as HeaderT>::new( - number, + parent_number + One::one(), Default::default(), Default::default(), parent_hash, @@ -79,22 +86,24 @@ where api.record_proof(); } + let block_id = BlockId::Hash(parent_hash); + api.initialize_block_with_context( - block_id, ExecutionContext::BlockConstruction, &header, + &block_id, ExecutionContext::BlockConstruction, &header, )?; - Ok(BlockBuilder { + Ok(Self { header, extrinsics: Vec::new(), api, - block_id: *block_id, + block_id, }) } /// Push onto the block's list of extrinsics. /// /// This will ensure the extrinsic can be validly executed (by executing it); - pub fn push(&mut self, xt: ::Extrinsic) -> error::Result<()> { + pub fn push(&mut self, xt: ::Extrinsic) -> Result<(), ApiErrorFor> { let block_id = &self.block_id; let extrinsics = &mut self.extrinsics; @@ -109,19 +118,19 @@ where Ok(()) } Err(e) => { - Err(error::Error::ApplyExtrinsicFailed(e)) + Err(ApplyExtrinsicFailed(e))? } } }) } /// Consume the builder to return a valid `Block` containing all pushed extrinsics. - pub fn bake(mut self) -> error::Result { + pub fn bake(mut self) -> Result> { self.bake_impl()?; Ok(::new(self.header, self.extrinsics)) } - fn bake_impl(&mut self) -> error::Result<()> { + fn bake_impl(&mut self) -> Result<(), ApiErrorFor> { self.header = self.api.finalize_block_with_context( &self.block_id, ExecutionContext::BlockConstruction )?; @@ -141,7 +150,9 @@ where /// /// The proof will be `Some(_)`, if proof recording was enabled while creating /// the block builder. - pub fn bake_and_extract_proof(mut self) -> error::Result<(Block, Option)> { + pub fn bake_and_extract_proof(mut self) + -> Result<(Block, Option), ApiErrorFor> + { self.bake_impl()?; let proof = self.api.extract_proof(); diff --git a/core/client/Cargo.toml b/core/client/Cargo.toml index 761b2a9da21b0..ea36b2fc4449c 100644 --- a/core/client/Cargo.toml +++ b/core/client/Cargo.toml @@ -5,29 +5,30 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -derive_more = { version = "0.15.0", optional = true } -fnv = { version = "1.0.6", optional = true } -log = { version = "0.4.8", optional = true } -parking_lot = { version = "0.9.0", optional = true } -hex-literal = { version = "0.2.1", optional = true } -futures = { version = "0.1.29", optional = true } -futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"], optional = true } -consensus = { package = "substrate-consensus-common", path = "../consensus/common", optional = true } -executor = { package = "substrate-executor", path = "../executor", optional = true } -state-machine = { package = "substrate-state-machine", path = "../state-machine", optional = true } -keyring = { package = "substrate-keyring", path = "../keyring", optional = true } -trie = { package = "substrate-trie", path = "../trie", optional = true } -substrate-telemetry = { path = "../telemetry", optional = true } -hash-db = { version = "0.15.2", default-features = false } -kvdb = { git = "https://github.com/paritytech/parity-common", optional = true, rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" } -codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } -primitives = { package = "substrate-primitives", path = "../primitives", default-features = false } -sr-primitives = { path = "../sr-primitives", default-features = false } -runtime-version = { package = "sr-version", path = "../sr-version", default-features = false } -rstd = { package = "sr-std", path = "../sr-std", default-features = false } -inherents = { package = "substrate-inherents", path = "../inherents", default-features = false } -sr-api-macros = { path = "../sr-api-macros" } -header-metadata = { package = "substrate-header-metadata", path = "header-metadata", optional = true } +derive_more = { version = "0.15.0" } +fnv = { version = "1.0.6" } +log = { version = "0.4.8" } +parking_lot = { version = "0.9.0" } +hex-literal = { version = "0.2.1" } +futures = { version = "0.1.29" } +futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] } +consensus = { package = "substrate-consensus-common", path = "../consensus/common" } +executor = { package = "substrate-executor", path = "../executor" } +state-machine = { package = "substrate-state-machine", path = "../state-machine" } +keyring = { package = "substrate-keyring", path = "../keyring" } +trie = { package = "substrate-trie", path = "../trie" } +substrate-telemetry = { path = "../telemetry" } +hash-db = { version = "0.15.2" } +kvdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" } +codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } +primitives = { package = "substrate-primitives", path = "../primitives" } +sr-primitives = { path = "../sr-primitives" } +runtime-version = { package = "sr-version", path = "../sr-version" } +rstd = { package = "sr-std", path = "../sr-std" } +inherents = { package = "substrate-inherents", path = "../inherents" } +sr-api = { path = "../sr-api" } +header-metadata = { package = "substrate-header-metadata", path = "header-metadata" } +block-builder = { package = "substrate-block-builder", path = "../block-builder" } [dev-dependencies] env_logger = "0.7.0" @@ -37,29 +38,3 @@ test-client = { package = "substrate-test-runtime-client", path = "../test-runti kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" } panic-handler = { package = "substrate-panic-handler", path = "../panic-handler" } -[features] -default = ["std"] -std = [ - "rstd/std", - "codec/std", - "primitives/std", - "inherents/std", - "sr-primitives/std", - "runtime-version/std", - "hash-db/std", - "header-metadata", - "consensus", - "parking_lot", - "derive_more", - "fnv", - "log", - "hex-literal", - "futures", - "futures03", - "executor", - "state-machine", - "keyring", - "trie", - "substrate-telemetry", - "kvdb" -] diff --git a/core/client/src/call_executor.rs b/core/client/src/call_executor.rs index e634fcf8faa9f..e25b9e36bb5c4 100644 --- a/core/client/src/call_executor.rs +++ b/core/client/src/call_executor.rs @@ -30,7 +30,7 @@ use primitives::{ traits::{CodeExecutor, KeystoreExt}, }; -use crate::runtime_api::{ProofRecorder, InitializeBlock}; +use sr_api::{ProofRecorder, InitializeBlock}; use crate::backend; use crate::error; diff --git a/core/client/src/client.rs b/core/client/src/client.rs index fdd50b0d01e8b..ac20b8ad39d1a 100644 --- a/core/client/src/client.rs +++ b/core/client/src/client.rs @@ -53,11 +53,10 @@ use consensus::{ }; use header_metadata::{HeaderMetadata, CachedHeaderMetadata}; +use sr_api::{CallRuntimeAt, ConstructRuntimeApi, Core as CoreApi, ProofRecorder, InitializeBlock}; +use block_builder::BlockBuilderApi; + use crate::{ - runtime_api::{ - CallRuntimeAt, ConstructRuntimeApi, Core as CoreApi, ProofRecorder, - InitializeBlock, - }, backend::{ self, BlockImportOperation, PrunableStateChangesTrieStorage, ClientImportOperation, Finalizer, ImportSummary, @@ -70,9 +69,7 @@ use crate::{ call_executor::{CallExecutor, LocalCallExecutor}, notifications::{StorageNotifications, StorageEventStream}, light::{call_executor::prove_execution, fetcher::ChangesProof}, - block_builder::{self, api::BlockBuilder as BlockBuilderAPI}, - error::Error, - cht, error, in_mem, genesis + error::Error, cht, error, in_mem, genesis }; /// Type that implements `futures::Stream` of block import events. @@ -749,9 +746,16 @@ impl Client where E: Clone + Send + Sync, RA: Send + Sync, Self: ProvideRuntimeApi, - ::Api: BlockBuilderAPI + ::Api: BlockBuilderApi { - block_builder::BlockBuilder::new(self, inherent_digests) + let info = self.info(); + block_builder::BlockBuilder::new( + self, + info.chain.best_hash, + info.chain.best_number, + false, + inherent_digests, + ) } /// Create a new block, built on top of `parent`. @@ -763,9 +767,15 @@ impl Client where E: Clone + Send + Sync, RA: Send + Sync, Self: ProvideRuntimeApi, - ::Api: BlockBuilderAPI + ::Api: BlockBuilderApi { - block_builder::BlockBuilder::at_block(parent, &self, false, inherent_digests) + block_builder::BlockBuilder::new( + self, + self.expect_block_hash_from_id(parent)?, + self.expect_block_number_from_id(parent)?, + false, + inherent_digests, + ) } /// Create a new block, built on top of `parent` with proof recording enabled. @@ -781,9 +791,15 @@ impl Client where E: Clone + Send + Sync, RA: Send + Sync, Self: ProvideRuntimeApi, - ::Api: BlockBuilderAPI + ::Api: BlockBuilderApi { - block_builder::BlockBuilder::at_block(parent, &self, true, inherent_digests) + block_builder::BlockBuilder::new( + self, + self.expect_block_hash_from_id(parent)?, + self.expect_block_number_from_id(parent)?, + true, + inherent_digests, + ) } /// Lock the import lock, and run operations inside. @@ -1367,7 +1383,7 @@ impl ChainHeaderBackend for Client wher B: backend::Backend, E: CallExecutor + Send + Sync, Block: BlockT, - RA: Send + Sync + RA: Send + Sync, { fn header(&self, id: BlockId) -> error::Result> { self.backend.blockchain().header(id) @@ -1390,6 +1406,23 @@ impl ChainHeaderBackend for Client wher } } +impl sr_primitives::traits::BlockIdTo for Client where + B: backend::Backend, + E: CallExecutor + Send + Sync, + Block: BlockT, + RA: Send + Sync, +{ + type Error = Error; + + fn to_hash(&self, block_id: &BlockId) -> error::Result> { + self.block_hash_from_id(block_id) + } + + fn to_number(&self, block_id: &BlockId) -> error::Result>> { + self.block_number_from_id(block_id) + } +} + impl ChainHeaderBackend for &Client where B: backend::Backend, E: CallExecutor + Send + Sync, @@ -1444,11 +1477,13 @@ impl CallRuntimeAt for Client where E: CallExecutor + Clone + Send + Sync, Block: BlockT, { + type Error = Error; + fn call_api_at< 'a, R: Encode + Decode + PartialEq, NC: FnOnce() -> result::Result + UnwindSafe, - C: CoreApi, + C: CoreApi, >( &self, core_api: &C, diff --git a/core/client/src/error.rs b/core/client/src/error.rs index 922d122b42a8b..a695e17a4256c 100644 --- a/core/client/src/error.rs +++ b/core/client/src/error.rs @@ -124,6 +124,12 @@ impl<'a> From<&'a str> for Error { } } +impl From for Error { + fn from(err: block_builder::ApplyExtrinsicFailed) -> Self { + Self::ApplyExtrinsicFailed(err.0) + } +} + impl Error { /// Chain a blockchain error. pub fn from_blockchain(e: Box) -> Self { diff --git a/core/client/src/lib.rs b/core/client/src/lib.rs index 57147eb18b181..048af17952c41 100644 --- a/core/client/src/lib.rs +++ b/core/client/src/lib.rs @@ -73,44 +73,25 @@ //! ``` //! -#![cfg_attr(not(feature = "std"), no_std)] #![warn(missing_docs)] #![recursion_limit="128"] -#[macro_use] -pub mod runtime_api; -#[cfg(feature = "std")] pub mod error; -#[cfg(feature = "std")] pub mod blockchain; -#[cfg(feature = "std")] pub mod backend; -#[cfg(feature = "std")] pub mod cht; -#[cfg(feature = "std")] pub mod in_mem; -#[cfg(feature = "std")] pub mod genesis; -pub mod block_builder; -#[cfg(feature = "std")] pub mod light; -#[cfg(feature = "std")] pub mod leaves; -#[cfg(feature = "std")] pub mod children; -#[cfg(feature = "std")] mod call_executor; -#[cfg(feature = "std")] mod client; -#[cfg(feature = "std")] mod notifications; -#[cfg(feature = "std")] pub use crate::blockchain::Info as ChainInfo; -#[cfg(feature = "std")] pub use crate::call_executor::{CallExecutor, LocalCallExecutor}; -#[cfg(feature = "std")] pub use crate::client::{ new_with_backend, new_in_mem, @@ -119,14 +100,7 @@ pub use crate::client::{ LongestChain, BlockOf, ProvideUncles, ForkBlocks, utils, apply_aux, }; -#[cfg(feature = "std")] pub use crate::notifications::{StorageEventStream, StorageChangeSet}; -#[cfg(feature = "std")] pub use state_machine::{ExecutionStrategy, StorageProof}; -#[cfg(feature = "std")] pub use crate::leaves::LeafSet; -#[cfg(feature = "std")] pub use crate::blockchain::well_known_cache_keys; - -#[doc(inline)] -pub use sr_api_macros::{decl_runtime_apis, impl_runtime_apis}; diff --git a/core/client/src/light/call_executor.rs b/core/client/src/light/call_executor.rs index 7f54004ae6722..5544e88e224fa 100644 --- a/core/client/src/light/call_executor.rs +++ b/core/client/src/light/call_executor.rs @@ -33,7 +33,8 @@ use state_machine::{ }; use hash_db::Hasher; -use crate::runtime_api::{ProofRecorder, InitializeBlock}; +use sr_api::{ProofRecorder, InitializeBlock}; + use crate::backend::RemoteBackend; use crate::call_executor::CallExecutor; use crate::error::{Error as ClientError, Result as ClientResult}; diff --git a/core/consensus/aura/Cargo.toml b/core/consensus/aura/Cargo.toml index a09d51095018e..ddef391db1ddf 100644 --- a/core/consensus/aura/Cargo.toml +++ b/core/consensus/aura/Cargo.toml @@ -20,13 +20,15 @@ client = { package = "substrate-client", path = "../../client" } substrate-telemetry = { path = "../../telemetry" } keystore = { package = "substrate-keystore", path = "../../keystore" } consensus_common = { package = "substrate-consensus-common", path = "../common" } -sr-primitives = { path = "../../sr-primitives" } +sr-primitives = { path = "../../sr-primitives" } +sr-api = { path = "../../sr-api" } futures-preview = { version = "0.3.0-alpha.19", features = ["compat"] } futures01 = { package = "futures", version = "0.1" } futures-timer = "0.4.0" parking_lot = "0.9.0" log = "0.4.8" derive_more = "0.15.0" +block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../block-builder/runtime-api" } [dev-dependencies] keyring = { package = "substrate-keyring", path = "../../keyring" } diff --git a/core/consensus/aura/primitives/Cargo.toml b/core/consensus/aura/primitives/Cargo.toml index 7fd3f3d05d9bf..3cd5ff81b9b35 100644 --- a/core/consensus/aura/primitives/Cargo.toml +++ b/core/consensus/aura/primitives/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } -substrate-client = { path = "../../../client", default-features = false } +sr-api = { path = "../../../sr-api", default-features = false } app-crypto = { package = "substrate-application-crypto", path = "../../../application-crypto", default-features = false } rstd = { package = "sr-std", path = "../../../sr-std", default-features = false } sr-primitives = { path = "../../../sr-primitives", default-features = false } @@ -18,6 +18,6 @@ std = [ "rstd/std", "codec/std", "sr-primitives/std", - "substrate-client/std", + "sr-api/std", "app-crypto/std", ] diff --git a/core/consensus/aura/primitives/src/lib.rs b/core/consensus/aura/primitives/src/lib.rs index e4620fcdbfdd4..ccf2d8e5fd52a 100644 --- a/core/consensus/aura/primitives/src/lib.rs +++ b/core/consensus/aura/primitives/src/lib.rs @@ -19,7 +19,6 @@ #![cfg_attr(not(feature = "std"), no_std)] use codec::{Encode, Decode, Codec}; -use substrate_client::decl_runtime_apis; use rstd::vec::Vec; use sr_primitives::ConsensusEngineId; @@ -74,7 +73,7 @@ pub enum ConsensusLog { OnDisabled(AuthorityIndex), } -decl_runtime_apis! { +sr_api::decl_runtime_apis! { /// API necessary for block authorship with aura. pub trait AuraApi { /// Return the slot duration in seconds for Aura. diff --git a/core/consensus/aura/src/lib.rs b/core/consensus/aura/src/lib.rs index 008ad68f81073..0953ea6c973a3 100644 --- a/core/consensus/aura/src/lib.rs +++ b/core/consensus/aura/src/lib.rs @@ -39,16 +39,17 @@ use consensus_common::import_queue::{ Verifier, BasicQueue, BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport, }; use client::{ - block_builder::api::BlockBuilder as BlockBuilderApi, blockchain::ProvideCache, - runtime_api::ApiExt, error::Result as CResult, backend::AuxStore, BlockOf, + blockchain::ProvideCache, error::Result as CResult, backend::AuxStore, BlockOf, well_known_cache_keys::{self, Id as CacheKeyId}, }; +use block_builder_api::BlockBuilder as BlockBuilderApi; + use sr_primitives::{generic::{BlockId, OpaqueDigestItemId}, Justification}; use sr_primitives::traits::{Block as BlockT, Header, DigestItemFor, ProvideRuntimeApi, Zero, Member}; use primitives::crypto::Pair; -use inherents::{InherentDataProviders, InherentData, RuntimeString}; +use inherents::{InherentDataProviders, InherentData}; use futures::prelude::*; use parking_lot::Mutex; @@ -65,6 +66,8 @@ use slots::check_equivocation; use keystore::KeyStorePtr; +use sr_api::ApiExt; + pub use aura_primitives::*; pub use consensus_common::SyncOracle; pub use digest::CompatibleDigestItem; @@ -85,7 +88,7 @@ impl SlotDuration { A: Codec, B: BlockT, C: AuxStore + ProvideRuntimeApi, - C::Api: AuraApi, + C::Api: AuraApi, { slots::SlotDuration::get_or_compute(client, |a, b| a.slot_duration(b)).map(Self) } @@ -332,7 +335,7 @@ enum Error { TooFarInFuture, Client(client::error::Error), DataProvider(String), - Runtime(RuntimeString) + Runtime(String), } fn find_pre_digest(header: &B::Header) -> Result> @@ -438,7 +441,7 @@ impl AuraVerifier inherent_data: InherentData, timestamp_now: u64, ) -> Result<(), Error> - where C: ProvideRuntimeApi, C::Api: BlockBuilderApi + where C: ProvideRuntimeApi, C::Api: BlockBuilderApi { const MAX_TIMESTAMP_DRIFT_SECS: u64 = 60; @@ -471,7 +474,7 @@ impl AuraVerifier thread::sleep(Duration::from_secs(diff)); Ok(()) }, - Some(TIError::Other(e)) => Err(Error::Runtime(e)), + Some(TIError::Other(e)) => Err(Error::Runtime(e.into())), None => Err(Error::DataProvider( self.inherent_data_providers.error_to_string(&i, &e) )), @@ -485,7 +488,7 @@ impl AuraVerifier #[forbid(deprecated)] impl Verifier for AuraVerifier where C: ProvideRuntimeApi + Send + Sync + client::backend::AuxStore + ProvideCache + BlockOf, - C::Api: BlockBuilderApi + AuraApi>, + C::Api: BlockBuilderApi + AuraApi> + ApiExt, DigestItemFor: CompatibleDigestItem

, P: Pair + Send + Sync + 'static, P::Public: Send + Sync + Hash + Eq + Clone + Decode + Encode + Debug + 'static, @@ -499,7 +502,9 @@ impl Verifier for AuraVerifier where justification: Option, mut body: Option>, ) -> Result<(BlockImportParams, Option)>>), String> { - let mut inherent_data = self.inherent_data_providers.create_inherent_data().map_err(String::from)?; + let mut inherent_data = self.inherent_data_providers + .create_inherent_data() + .map_err(|e| e.into_string())?; let (timestamp_now, slot_now, _) = AuraSlotCompatible.extract_timestamp_and_slot(&inherent_data) .map_err(|e| format!("Could not extract timestamp and slot: {:?}", e))?; let hash = header.hash(); @@ -530,7 +535,10 @@ impl Verifier for AuraVerifier where // skip the inherents verification if the runtime API is old. if self.client .runtime_api() - .has_api_with::, _>(&BlockId::Hash(parent_hash), |v| v >= 2) + .has_api_with::, _>( + &BlockId::Hash(parent_hash), + |v| v >= 2, + ) .map_err(|e| format!("{:?}", e))? { self.check_inherents( @@ -667,7 +675,7 @@ pub fn import_queue( ) -> Result, consensus_common::Error> where B: BlockT, C: 'static + ProvideRuntimeApi + BlockOf + ProvideCache + Send + Sync + AuxStore, - C::Api: BlockBuilderApi + AuraApi>, + C::Api: BlockBuilderApi + AuraApi> + ApiExt, DigestItemFor: CompatibleDigestItem

, P: Pair + Send + Sync + 'static, P::Public: Clone + Eq + Send + Sync + Hash + Debug + Encode + Decode, diff --git a/core/consensus/babe/Cargo.toml b/core/consensus/babe/Cargo.toml index 30b7c1f8d6b1c..45dd96a18aa7e 100644 --- a/core/consensus/babe/Cargo.toml +++ b/core/consensus/babe/Cargo.toml @@ -21,6 +21,8 @@ substrate-telemetry = { path = "../../telemetry" } keystore = { package = "substrate-keystore", path = "../../keystore" } srml-babe = { path = "../../../srml/babe" } client = { package = "substrate-client", path = "../../client" } +sr-api = { path = "../../sr-api" } +block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../block-builder/runtime-api" } header-metadata = { package = "substrate-header-metadata", path = "../../client/header-metadata" } consensus-common = { package = "substrate-consensus-common", path = "../common" } uncles = { package = "substrate-consensus-uncles", path = "../uncles" } @@ -44,6 +46,7 @@ substrate-executor = { path = "../../executor" } network = { package = "substrate-network", path = "../../network", features = ["test-helpers"]} service = { package = "substrate-service", path = "../../service" } test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" } +block-builder = { package = "substrate-block-builder", path = "../../block-builder" } tokio = "0.1.22" env_logger = "0.7.0" tempfile = "3.1.0" diff --git a/core/consensus/babe/primitives/Cargo.toml b/core/consensus/babe/primitives/Cargo.toml index 79e817d081028..c74f2bd259c2c 100644 --- a/core/consensus/babe/primitives/Cargo.toml +++ b/core/consensus/babe/primitives/Cargo.toml @@ -6,7 +6,7 @@ description = "Primitives for BABE consensus" edition = "2018" [dependencies] -substrate-client = { path = "../../../client", default-features = false } +sr-api = { path = "../../../sr-api", default-features = false } rstd = { package = "sr-std", path = "../../../sr-std", default-features = false } sr-primitives = { path = "../../../sr-primitives", default-features = false } app-crypto = { package = "substrate-application-crypto", path = "../../../application-crypto", default-features = false } @@ -19,7 +19,7 @@ default = ["std"] std = [ "rstd/std", "sr-primitives/std", - "substrate-client/std", + "sr-api/std", "codec/std", "schnorrkel", "slots", diff --git a/core/consensus/babe/primitives/src/lib.rs b/core/consensus/babe/primitives/src/lib.rs index c464e797d8d58..6ebd2969613b3 100644 --- a/core/consensus/babe/primitives/src/lib.rs +++ b/core/consensus/babe/primitives/src/lib.rs @@ -24,7 +24,6 @@ mod digest; use codec::{Encode, Decode}; use rstd::vec::Vec; use sr_primitives::{ConsensusEngineId, RuntimeDebug}; -use substrate_client::decl_runtime_apis; #[cfg(feature = "std")] pub use digest::{BabePreDigest, CompatibleDigestItem}; @@ -165,7 +164,7 @@ impl slots::SlotData for BabeConfiguration { const SLOT_KEY: &'static [u8] = b"babe_configuration"; } -decl_runtime_apis! { +sr_api::decl_runtime_apis! { /// API necessary for block authorship with BABE. pub trait BabeApi { /// Return the configuration for BABE. Currently, diff --git a/core/consensus/babe/src/lib.rs b/core/consensus/babe/src/lib.rs index 801b47d0ec53d..04d0f5930589a 100644 --- a/core/consensus/babe/src/lib.rs +++ b/core/consensus/babe/src/lib.rs @@ -66,7 +66,7 @@ use consensus_common::ImportResult; use consensus_common::import_queue::{ BoxJustificationImport, BoxFinalityProofImport, }; -use sr_primitives::{generic::{BlockId, OpaqueDigestItemId}, Justification, RuntimeString}; +use sr_primitives::{generic::{BlockId, OpaqueDigestItemId}, Justification}; use sr_primitives::traits::{ Block as BlockT, Header, DigestItemFor, ProvideRuntimeApi, Zero, @@ -75,11 +75,7 @@ use keystore::KeyStorePtr; use parking_lot::Mutex; use primitives::{Blake2Hasher, H256, Pair}; use inherents::{InherentDataProviders, InherentData}; -use substrate_telemetry::{ - telemetry, - CONSENSUS_TRACE, - CONSENSUS_DEBUG, -}; +use substrate_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG}; use consensus_common::{ self, BlockImport, Environment, Proposer, BlockCheckParams, ForkChoiceStrategy, BlockImportParams, BlockOrigin, Error as ConsensusError, @@ -91,11 +87,13 @@ use srml_babe::{ use consensus_common::SelectChain; use consensus_common::import_queue::{Verifier, BasicQueue, CacheKeyId}; use client::{ - block_builder::api::BlockBuilder as BlockBuilderApi, blockchain::{self, HeaderBackend, ProvideCache}, BlockchainEvents, CallExecutor, Client, error::Result as ClientResult, error::Error as ClientError, backend::{AuxStore, Backend}, ProvideUncles, }; + +use block_builder_api::BlockBuilder as BlockBuilderApi; + use slots::{CheckedHeader, check_equivocation}; use futures::prelude::*; use log::{warn, debug, info, trace}; @@ -104,6 +102,8 @@ use epoch_changes::descendent_query; use header_metadata::HeaderMetadata; use schnorrkel::SignatureError; +use sr_api::ApiExt; + mod aux_schema; mod verification; mod epoch_changes; @@ -167,7 +167,7 @@ enum Error { #[display(fmt = "Checking inherents failed: {}", _0)] CheckInherents(String), Client(client::error::Error), - Runtime(RuntimeString), + Runtime(inherents::Error), ForkTree(Box>), } @@ -202,7 +202,7 @@ impl Config { /// Either fetch the slot duration from disk or compute it from the genesis /// state. pub fn get_or_compute(client: &C) -> ClientResult where - C: AuxStore + ProvideRuntimeApi, C::Api: BabeApi, + C: AuxStore + ProvideRuntimeApi, C::Api: BabeApi, { trace!(target: "babe", "Getting slot duration"); match slots::SlotDuration::get_or_compute(client, |a, b| a.configuration(b)).map(Self) { @@ -554,7 +554,7 @@ impl BabeVerifier { block_id: BlockId, inherent_data: InherentData, ) -> Result<(), Error> - where PRA: ProvideRuntimeApi, PRA::Api: BlockBuilderApi + where PRA: ProvideRuntimeApi, PRA::Api: BlockBuilderApi { let inherent_res = self.api.runtime_api().check_inherents( &block_id, @@ -623,7 +623,8 @@ impl Verifier for BabeVerifier + 'static + Clone + Send + Sync, RA: Send + Sync, PRA: ProvideRuntimeApi + Send + Sync + AuxStore + ProvideCache, - PRA::Api: BlockBuilderApi + BabeApi, + PRA::Api: BlockBuilderApi + + BabeApi, { fn verify( &mut self, @@ -1141,7 +1142,7 @@ pub fn import_queue, I, RA, PRA>( E: CallExecutor + Clone + Send + Sync + 'static, RA: Send + Sync + 'static, PRA: ProvideRuntimeApi + ProvideCache + Send + Sync + AuxStore + 'static, - PRA::Api: BlockBuilderApi + BabeApi, + PRA::Api: BlockBuilderApi + BabeApi + ApiExt, { register_babe_inherent_data_provider(&inherent_data_providers, babe_link.config.slot_duration)?; diff --git a/core/consensus/babe/src/tests.rs b/core/consensus/babe/src/tests.rs index 6db4a7284e34f..7fdf70045ec49 100644 --- a/core/consensus/babe/src/tests.rs +++ b/core/consensus/babe/src/tests.rs @@ -23,7 +23,7 @@ use super::*; use authorship::claim_slot; use babe_primitives::{AuthorityPair, SlotNumber}; -use client::block_builder::BlockBuilder; +use block_builder::BlockBuilder; use consensus_common::NoNetwork as DummyOracle; use consensus_common::import_queue::{ BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport, diff --git a/core/consensus/common/src/error.rs b/core/consensus/common/src/error.rs index cb57bb915eb2d..16781b04ff27f 100644 --- a/core/consensus/common/src/error.rs +++ b/core/consensus/common/src/error.rs @@ -36,7 +36,7 @@ pub enum Error { FaultyTimer(std::io::Error), /// Error while working with inherent data. #[display(fmt="InherentData error: {}", _0)] - InherentData(String), + InherentData(inherents::Error), /// Unable to propose a block. #[display(fmt="Unable to create block proposal.")] CannotPropose, diff --git a/core/consensus/pow/Cargo.toml b/core/consensus/pow/Cargo.toml index 86efcbb95da2b..d57881c422a2b 100644 --- a/core/consensus/pow/Cargo.toml +++ b/core/consensus/pow/Cargo.toml @@ -10,6 +10,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive primitives = { package = "substrate-primitives", path = "../../primitives" } sr-primitives = { path = "../../sr-primitives" } client = { package = "substrate-client", path = "../../client" } +block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../block-builder/runtime-api" } srml-timestamp = { path = "../../../srml/timestamp" } inherents = { package = "substrate-inherents", path = "../../inherents" } pow-primitives = { package = "substrate-consensus-pow-primitives", path = "primitives" } diff --git a/core/consensus/pow/primitives/Cargo.toml b/core/consensus/pow/primitives/Cargo.toml index 021e4c80a754c..82a7da90755b6 100644 --- a/core/consensus/pow/primitives/Cargo.toml +++ b/core/consensus/pow/primitives/Cargo.toml @@ -6,7 +6,7 @@ description = "Primitives for Aura consensus" edition = "2018" [dependencies] -substrate-client = { path = "../../../client", default-features = false } +sr-api = { path = "../../../sr-api", default-features = false } rstd = { package = "sr-std", path = "../../../sr-std", default-features = false } sr-primitives = { path = "../../../sr-primitives", default-features = false } primitives = { package = "substrate-primitives", path = "../../../primitives", default-features = false } @@ -16,7 +16,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", default-features = default = ["std"] std = [ "rstd/std", - "substrate-client/std", + "sr-api/std", "sr-primitives/std", "primitives/std", "codec/std", diff --git a/core/consensus/pow/primitives/src/lib.rs b/core/consensus/pow/primitives/src/lib.rs index 2079b1cbe7e88..400ed0594a026 100644 --- a/core/consensus/pow/primitives/src/lib.rs +++ b/core/consensus/pow/primitives/src/lib.rs @@ -21,7 +21,6 @@ use rstd::vec::Vec; use sr_primitives::ConsensusEngineId; use codec::Decode; -use substrate_client::decl_runtime_apis; /// The `ConsensusEngineId` of PoW. pub const POW_ENGINE_ID: ConsensusEngineId = [b'p', b'o', b'w', b'_']; @@ -48,7 +47,7 @@ impl TotalDifficulty for u128 { } } -decl_runtime_apis! { +sr_api::decl_runtime_apis! { /// API necessary for timestamp-based difficulty adjustment algorithms. pub trait TimestampApi { /// Return the timestamp in the current block. diff --git a/core/consensus/pow/src/lib.rs b/core/consensus/pow/src/lib.rs index 5c7716ff8bbb1..b6e94411fdcbf 100644 --- a/core/consensus/pow/src/lib.rs +++ b/core/consensus/pow/src/lib.rs @@ -33,10 +33,10 @@ use std::sync::Arc; use std::thread; use std::collections::HashMap; use client::{ - BlockOf, blockchain::{HeaderBackend, ProvideCache}, - block_builder::api::BlockBuilder as BlockBuilderApi, backend::AuxStore, + BlockOf, blockchain::{HeaderBackend, ProvideCache}, backend::AuxStore, well_known_cache_keys::Id as CacheKeyId, }; +use block_builder_api::BlockBuilder as BlockBuilderApi; use sr_primitives::{Justification, RuntimeString}; use sr_primitives::generic::{BlockId, Digest, DigestItem}; use sr_primitives::traits::{Block as BlockT, Header as HeaderT, ProvideRuntimeApi}; @@ -75,7 +75,7 @@ pub enum Error { #[display(fmt = "Error with block built on {:?}: {:?}", _0, _1)] BlockBuiltError(B::Hash, ConsensusError), #[display(fmt = "Creating inherents failed: {}", _0)] - CreateInherents(RuntimeString), + CreateInherents(inherents::Error), #[display(fmt = "Checking inherents failed: {}", _0)] CheckInherents(String), Client(client::error::Error), @@ -210,7 +210,7 @@ impl, C, S, Algorithm> PowVerifier { inherent_data: InherentData, timestamp_now: u64, ) -> Result<(), Error> where - C: ProvideRuntimeApi, C::Api: BlockBuilderApi + C: ProvideRuntimeApi, C::Api: BlockBuilderApi { const MAX_TIMESTAMP_DRIFT_SECS: u64 = 60; @@ -248,7 +248,7 @@ impl, C, S, Algorithm> PowVerifier { impl, C, S, Algorithm> Verifier for PowVerifier where C: ProvideRuntimeApi + Send + Sync + HeaderBackend + AuxStore + ProvideCache + BlockOf, - C::Api: BlockBuilderApi, + C::Api: BlockBuilderApi, S: SelectChain, Algorithm: PowAlgorithm + Send + Sync, { @@ -260,8 +260,8 @@ impl, C, S, Algorithm> Verifier for PowVerifier>, ) -> Result<(BlockImportParams, Option)>>), String> { let inherent_data = self.inherent_data_providers - .create_inherent_data().map_err(String::from)?; - let timestamp_now = inherent_data.timestamp_inherent_data().map_err(String::from)?; + .create_inherent_data().map_err(|e| e.into_string())?; + let timestamp_now = inherent_data.timestamp_inherent_data().map_err(|e| e.into_string())?; let best_hash = match self.select_chain.as_ref() { Some(select_chain) => select_chain.best_chain() @@ -340,7 +340,7 @@ pub fn import_queue( B: BlockT, C: ProvideRuntimeApi + HeaderBackend + BlockOf + ProvideCache + AuxStore, C: Send + Sync + AuxStore + 'static, - C::Api: BlockBuilderApi, + C::Api: BlockBuilderApi, Algorithm: PowAlgorithm + Send + Sync + 'static, S: SelectChain + 'static, { diff --git a/core/consensus/slots/src/slots.rs b/core/consensus/slots/src/slots.rs index 98310bbf2e27c..0157bc70355d0 100644 --- a/core/consensus/slots/src/slots.rs +++ b/core/consensus/slots/src/slots.rs @@ -146,7 +146,7 @@ impl Stream for Slots { let inherent_data = match self.inherent_data_providers.create_inherent_data() { Ok(id) => id, - Err(err) => return Poll::Ready(Some(Err(consensus_common::Error::InherentData(err.into_owned())))), + Err(err) => return Poll::Ready(Some(Err(consensus_common::Error::InherentData(err)))), }; let result = self.timestamp_extractor.extract_timestamp_and_slot(&inherent_data); let (timestamp, slot_num, offset) = match result { diff --git a/core/finality-grandpa/Cargo.toml b/core/finality-grandpa/Cargo.toml index a4c6a0278a445..d9b7fd176d639 100644 --- a/core/finality-grandpa/Cargo.toml +++ b/core/finality-grandpa/Cargo.toml @@ -38,3 +38,4 @@ state_machine = { package = "substrate-state-machine", path = "../state-machine" env_logger = "0.7.0" tokio = "0.1.22" tempfile = "3.1.0" +sr-api = { path = "../sr-api" } diff --git a/core/finality-grandpa/primitives/Cargo.toml b/core/finality-grandpa/primitives/Cargo.toml index 02439d4150d81..412a36ce7e8ac 100644 --- a/core/finality-grandpa/primitives/Cargo.toml +++ b/core/finality-grandpa/primitives/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -client = { package = "substrate-client", path = "../../client", default-features = false } +sr-api = { path = "../../sr-api", default-features = false } app-crypto = { package = "substrate-application-crypto", path = "../../application-crypto", default-features = false } codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } sr-primitives = { path = "../../sr-primitives", default-features = false } @@ -15,7 +15,7 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] } [features] default = ["std"] std = [ - "client/std", + "sr-api/std", "codec/std", "sr-primitives/std", "rstd/std", diff --git a/core/finality-grandpa/primitives/src/lib.rs b/core/finality-grandpa/primitives/src/lib.rs index e7d399a89200b..ff26b6a68ac2d 100644 --- a/core/finality-grandpa/primitives/src/lib.rs +++ b/core/finality-grandpa/primitives/src/lib.rs @@ -25,7 +25,6 @@ extern crate alloc; use serde::Serialize; use codec::{Encode, Decode, Input, Codec}; use sr_primitives::{ConsensusEngineId, RuntimeDebug}; -use client::decl_runtime_apis; use rstd::borrow::Cow; use rstd::vec::Vec; @@ -211,7 +210,7 @@ impl<'a> Decode for VersionedAuthorityList<'a> { } } -decl_runtime_apis! { +sr_api::decl_runtime_apis! { /// APIs for integrating the GRANDPA finality gadget into runtimes. /// This should be implemented on the runtime side. /// diff --git a/core/finality-grandpa/src/tests.rs b/core/finality-grandpa/src/tests.rs index bdb032df3decf..0e2f2b02b3c94 100644 --- a/core/finality-grandpa/src/tests.rs +++ b/core/finality-grandpa/src/tests.rs @@ -25,11 +25,8 @@ use parking_lot::Mutex; use futures03::{StreamExt as _, TryStreamExt as _}; use tokio::runtime::current_thread; use keyring::Ed25519Keyring; -use client::{ - error::Result, - runtime_api::{Core, RuntimeVersion, ApiExt, StorageProof}, - LongestChain, -}; +use client::{error::Result, LongestChain}; +use sr_api::{Core, RuntimeVersion, ApiExt, StorageProof}; use test_client::{self, runtime::BlockNumber}; use consensus_common::{BlockOrigin, ForkChoiceStrategy, ImportedAux, BlockImportParams, ImportResult}; use consensus_common::import_queue::{BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport}; @@ -244,6 +241,8 @@ impl Core for RuntimeApi { } impl ApiExt for RuntimeApi { + type Error = client::error::Error; + fn map_api_result result::Result, R, E>( &self, _: F diff --git a/core/inherents/Cargo.toml b/core/inherents/Cargo.toml index 45e0b9e828ec7..fbed81150283d 100644 --- a/core/inherents/Cargo.toml +++ b/core/inherents/Cargo.toml @@ -7,8 +7,9 @@ edition = "2018" [dependencies] parking_lot = { version = "0.9.0", optional = true } rstd = { package = "sr-std", path = "../sr-std", default-features = false } -codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } -sr-primitives = { path = "../sr-primitives", default-features = false } +primitives = { package = "substrate-primitives", path = "../primitives", default-features = false } +codec = { package = "parity-scale-codec", version = "1.0.6", default-features = false, features = ["derive"] } +derive_more = { version = "0.15.0", optional = true } [features] default = [ "std" ] @@ -16,5 +17,6 @@ std = [ "parking_lot", "rstd/std", "codec/std", - "sr-primitives/std", + "primitives/std", + "derive_more", ] diff --git a/core/inherents/src/lib.rs b/core/inherents/src/lib.rs index f7363b483bfec..25512f4fcae2a 100644 --- a/core/inherents/src/lib.rs +++ b/core/inherents/src/lib.rs @@ -43,7 +43,37 @@ use parking_lot::RwLock; #[cfg(feature = "std")] use std::{sync::Arc, format}; -pub use sr_primitives::RuntimeString; +/// An error that can occur within the inherent data system. +#[derive(Debug, Encode, Decode, derive_more::Display)] +#[cfg(feature = "std")] +pub struct Error(String); + +#[cfg(feature = "std")] +impl> From for Error { + fn from(data: T) -> Error { + Self(data.into()) + } +} + +#[cfg(feature = "std")] +impl Error { + /// Convert this error into a `String`. + pub fn into_string(self) -> String { + self.0 + } +} + +/// An error that can occur within the inherent data system. +#[derive(Encode, primitives::RuntimeDebug)] +#[cfg(not(feature = "std"))] +pub struct Error(&'static str); + +#[cfg(not(feature = "std"))] +impl From<&'static str> for Error { + fn from(data: &'static str) -> Error { + Self(data) + } +} /// An identifier for an inherent. pub type InherentIdentifier = [u8; 8]; @@ -73,7 +103,7 @@ impl InherentData { &mut self, identifier: InherentIdentifier, inherent: &I, - ) -> Result<(), RuntimeString> { + ) -> Result<(), Error> { match self.data.entry(identifier) { Entry::Vacant(entry) => { entry.insert(inherent.encode()); @@ -106,7 +136,7 @@ impl InherentData { pub fn get_data( &self, identifier: &InherentIdentifier, - ) -> Result, RuntimeString> { + ) -> Result, Error> { match self.data.get(identifier) { Some(inherent) => I::decode(&mut &inherent[..]) @@ -163,7 +193,7 @@ impl CheckInherentsResult { &mut self, identifier: InherentIdentifier, error: &E, - ) -> Result<(), RuntimeString> { + ) -> Result<(), Error> { // Don't accept any other error if self.fatal_error { return Err("No other errors are accepted after an hard error!".into()) @@ -191,7 +221,7 @@ impl CheckInherentsResult { pub fn get_error( &self, identifier: &InherentIdentifier, - ) -> Result, RuntimeString> { + ) -> Result, Error> { self.errors.get_data(identifier) } @@ -245,7 +275,7 @@ impl InherentDataProviders { pub fn register_provider( &self, provider: P, - ) -> Result<(), RuntimeString> { + ) -> Result<(), Error> { if self.has_provider(&provider.inherent_identifier()) { Err( format!( @@ -266,7 +296,7 @@ impl InherentDataProviders { } /// Create inherent data. - pub fn create_inherent_data(&self) -> Result { + pub fn create_inherent_data(&self) -> Result { let mut data = InherentData::new(); self.providers.read().iter().try_for_each(|p| { p.provide_inherent_data(&mut data) @@ -305,7 +335,7 @@ impl InherentDataProviders { pub trait ProvideInherentData { /// Is called when this inherent data provider is registered at the given /// `InherentDataProviders`. - fn on_register(&self, _: &InherentDataProviders) -> Result<(), RuntimeString> { + fn on_register(&self, _: &InherentDataProviders) -> Result<(), Error> { Ok(()) } @@ -315,7 +345,7 @@ pub trait ProvideInherentData { /// Provide inherent data that should be included in a block. /// /// The data should be stored in the given `InherentData` structure. - fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), RuntimeString>; + fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error>; /// Convert the given encoded error to a string. /// @@ -445,7 +475,7 @@ mod tests { const ERROR_TO_STRING: &str = "Found error!"; impl ProvideInherentData for TestInherentDataProvider { - fn on_register(&self, _: &InherentDataProviders) -> Result<(), RuntimeString> { + fn on_register(&self, _: &InherentDataProviders) -> Result<(), Error> { *self.registered.write() = true; Ok(()) } @@ -454,7 +484,7 @@ mod tests { &TEST_INHERENT_0 } - fn provide_inherent_data(&self, data: &mut InherentData) -> Result<(), RuntimeString> { + fn provide_inherent_data(&self, data: &mut InherentData) -> Result<(), Error> { data.put_data(TEST_INHERENT_0, &42) } diff --git a/core/network/Cargo.toml b/core/network/Cargo.toml index 216b898277b4b..56de91b281f6d 100644 --- a/core/network/Cargo.toml +++ b/core/network/Cargo.toml @@ -26,6 +26,7 @@ libp2p = { version = "0.13.0", default-features = false, features = ["libp2p-web fork-tree = { path = "../../core/utils/fork-tree" } consensus = { package = "substrate-consensus-common", path = "../../core/consensus/common" } client = { package = "substrate-client", path = "../../core/client" } +block-builder = { package = "substrate-block-builder", path = "../../core/block-builder" } header_metadata = { package = "substrate-header-metadata", path = "../../core/client/header-metadata" } sr-primitives = { path = "../../core/sr-primitives" } primitives = { package = "substrate-primitives", path = "../../core/primitives" } diff --git a/core/network/src/test/mod.rs b/core/network/src/test/mod.rs index 9365430cb0fba..c292b24be4514 100644 --- a/core/network/src/test/mod.rs +++ b/core/network/src/test/mod.rs @@ -34,7 +34,7 @@ use client::{ error::Result as ClientResult, well_known_cache_keys::{self, Id as CacheKeyId}, }; -use client::block_builder::BlockBuilder; +use block_builder::BlockBuilder; use client::backend::{AuxStore, Backend, Finalizer}; use crate::config::Roles; use consensus::block_validation::DefaultBlockAnnounceValidator; diff --git a/core/offchain/Cargo.toml b/core/offchain/Cargo.toml index 9e16150938f1e..2ca7e32f177fc 100644 --- a/core/offchain/Cargo.toml +++ b/core/offchain/Cargo.toml @@ -8,7 +8,8 @@ edition = "2018" [dependencies] bytes = "0.4.12" -client = { package = "substrate-client", path = "../../core/client" } +client = { package = "substrate-client", path = "../client" } +sr-api = { path = "../sr-api" } fnv = "1.0.6" futures01 = { package = "futures", version = "0.1" } futures-preview = "0.3.0-alpha.19" diff --git a/core/offchain/primitives/Cargo.toml b/core/offchain/primitives/Cargo.toml index c96a579c4446d..80f1313cd41d8 100644 --- a/core/offchain/primitives/Cargo.toml +++ b/core/offchain/primitives/Cargo.toml @@ -7,12 +7,12 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -client = { package = "substrate-client", path = "../../client", default-features = false } +sr-api = { path = "../../sr-api", default-features = false } sr-primitives = { path = "../../sr-primitives", default-features = false } [features] default = ["std"] std = [ - "client/std", + "sr-api/std", "sr-primitives/std" ] diff --git a/core/offchain/primitives/src/lib.rs b/core/offchain/primitives/src/lib.rs index 79fed8cb34150..876fcf49a2e74 100644 --- a/core/offchain/primitives/src/lib.rs +++ b/core/offchain/primitives/src/lib.rs @@ -19,13 +19,12 @@ #![cfg_attr(not(feature = "std"), no_std)] #![warn(missing_docs)] -use client::decl_runtime_apis; use sr_primitives::traits::NumberFor; /// Local Storage Prefix used by the Offchain Worker API to pub const STORAGE_PREFIX: &[u8] = b"storage"; -decl_runtime_apis! { +sr_api::decl_runtime_apis! { /// The offchain worker api. pub trait OffchainWorkerApi { /// Starts the off-chain task for given block number. diff --git a/core/offchain/src/lib.rs b/core/offchain/src/lib.rs index 69147295896ba..345ef17b07ea3 100644 --- a/core/offchain/src/lib.rs +++ b/core/offchain/src/lib.rs @@ -33,15 +33,11 @@ #![warn(missing_docs)] -use std::{ - fmt, - marker::PhantomData, - sync::Arc, -}; +use std::{fmt, marker::PhantomData, sync::Arc}; use parking_lot::Mutex; use threadpool::ThreadPool; -use client::runtime_api::ApiExt; +use sr_api::ApiExt; use futures::future::Future; use log::{debug, warn}; use network::NetworkStateInfo; @@ -106,7 +102,7 @@ impl OffchainWorkers< ) -> impl Future where A: ChainApi + 'static { let runtime = self.client.runtime_api(); let at = BlockId::number(*number); - let has_api = runtime.has_api::>(&at); + let has_api = runtime.has_api::>(&at); debug!("Checking offchain workers at {:?}: {:?}", at, has_api); if has_api.unwrap_or(false) { diff --git a/core/primitives/src/lib.rs b/core/primitives/src/lib.rs index c7b18399b30b2..0bc417fd045a8 100644 --- a/core/primitives/src/lib.rs +++ b/core/primitives/src/lib.rs @@ -38,9 +38,9 @@ use std::borrow::Cow; #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; #[cfg(feature = "std")] -pub use serde;// << for macro +pub use serde; #[doc(hidden)] -pub use codec::{Encode, Decode};// << for macro +pub use codec::{Encode, Decode}; pub use substrate_debug_derive::RuntimeDebug; diff --git a/core/rpc/Cargo.toml b/core/rpc/Cargo.toml index 109db34240ccd..31391568a58e4 100644 --- a/core/rpc/Cargo.toml +++ b/core/rpc/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [dependencies] api = { package = "substrate-rpc-api", path = "./api" } client = { package = "substrate-client", path = "../client" } +sr-api = { path = "../sr-api" } codec = { package = "parity-scale-codec", version = "1.0.0" } futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] } jsonrpc-pubsub = "14.0.3" diff --git a/core/rpc/src/author/mod.rs b/core/rpc/src/author/mod.rs index 82122dcf3d21f..790576710ca18 100644 --- a/core/rpc/src/author/mod.rs +++ b/core/rpc/src/author/mod.rs @@ -23,7 +23,8 @@ use std::{sync::Arc, convert::TryInto}; use futures03::future::{FutureExt, TryFutureExt}; use log::warn; -use client::{self, Client}; +use client::{Client, error::Error as ClientError}; + use rpc::futures::{ Sink, Future, future::result, @@ -87,7 +88,8 @@ impl AuthorApi, BlockHash

> for Author whe P::Error: 'static, RA: Send + Sync + 'static, Client: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: SessionKeys, + as ProvideRuntimeApi>::Api: + SessionKeys, { type Metadata = crate::metadata::Metadata; @@ -131,8 +133,9 @@ impl AuthorApi, BlockHash

> for Author whe Ok(self.pool.ready().map(|tx| tx.data.encode().into()).collect()) } - fn remove_extrinsic(&self, - bytes_or_hash: Vec>> + fn remove_extrinsic( + &self, + bytes_or_hash: Vec>>, ) -> Result>> { let hashes = bytes_or_hash.into_iter() .map(|x| match x { @@ -155,7 +158,7 @@ impl AuthorApi, BlockHash

> for Author whe fn watch_extrinsic(&self, _metadata: Self::Metadata, subscriber: Subscriber, BlockHash

>>, - xt: Bytes + xt: Bytes, ) { let submit = || -> Result<_> { let best_block_hash = self.client.info().chain.best_hash; diff --git a/core/rpc/src/state/mod.rs b/core/rpc/src/state/mod.rs index b922601b0a5b2..91e10c18b32d4 100644 --- a/core/rpc/src/state/mod.rs +++ b/core/rpc/src/state/mod.rs @@ -24,17 +24,10 @@ mod tests; use std::sync::Arc; use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; -use rpc::{ - Result as RpcResult, - futures::Future, -}; +use rpc::{Result as RpcResult, futures::Future}; use api::Subscriptions; -use client::{ - Client, CallExecutor, - runtime_api::Metadata, - light::{blockchain::RemoteBlockchain, fetcher::Fetcher}, -}; +use client::{Client, CallExecutor, light::{blockchain::RemoteBlockchain, fetcher::Fetcher}}; use primitives::{ Blake2Hasher, Bytes, H256, storage::{StorageKey, StorageData, StorageChangeSet}, @@ -44,6 +37,8 @@ use sr_primitives::{ traits::{Block as BlockT, ProvideRuntimeApi}, }; +use sr_api::Metadata; + use self::error::{Error, FutureResult}; pub use api::state::*; @@ -188,7 +183,8 @@ pub fn new_full( E: CallExecutor + Send + Sync + 'static + Clone, RA: Send + Sync + 'static, Client: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: Metadata, + as ProvideRuntimeApi>::Api: + Metadata, { State { backend: Box::new(self::state_full::FullState::new(client, subscriptions)), diff --git a/core/rpc/src/state/state_full.rs b/core/rpc/src/state/state_full.rs index ff4c5e5599a8a..d91a2288954e3 100644 --- a/core/rpc/src/state/state_full.rs +++ b/core/rpc/src/state/state_full.rs @@ -29,8 +29,7 @@ use rpc::{ use api::Subscriptions; use client::{ - Client, CallExecutor, BlockchainEvents, runtime_api::Metadata, - backend::Backend, error::Result as ClientResult, + Client, CallExecutor, BlockchainEvents, backend::Backend, error::Result as ClientResult, }; use primitives::{ H256, Blake2Hasher, Bytes, storage::{well_known_keys, StorageKey, StorageData, StorageChangeSet}, @@ -42,6 +41,8 @@ use sr_primitives::{ traits::{Block as BlockT, Header, NumberFor, ProvideRuntimeApi, SaturatedConversion}, }; +use sr_api::Metadata; + use super::{StateBackend, error::{FutureResult, Error, Result}, client_err}; /// Ranges to query in state_queryStorage. @@ -229,7 +230,8 @@ impl StateBackend for FullState + Send + Sync + 'static + Clone, RA: Send + Sync + 'static, Client: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: Metadata, + as ProvideRuntimeApi>::Api: + Metadata, { fn call( &self, @@ -326,7 +328,9 @@ impl StateBackend for FullState) -> FutureResult { Box::new(result( self.block_or_best(block) - .and_then(|block| self.client.runtime_api().metadata(&BlockId::Hash(block)).map(Into::into)) + .and_then(|block| + self.client.runtime_api().metadata(&BlockId::Hash(block)).map(Into::into) + ) .map_err(client_err))) } diff --git a/core/service/Cargo.toml b/core/service/Cargo.toml index 3d40550c8c5b5..14739b93c5778 100644 --- a/core/service/Cargo.toml +++ b/core/service/Cargo.toml @@ -10,7 +10,7 @@ default = ["rocksdb"] # a path to a database, an error will be produced at runtime. rocksdb = ["client_db/kvdb-rocksdb"] wasmtime = [ - "substrate-executor/wasmtime", + "substrate-executor/wasmtime", ] [dependencies] @@ -38,6 +38,8 @@ consensus_common = { package = "substrate-consensus-common", path = "../../core/ network = { package = "substrate-network", path = "../../core/network" } chain-spec = { package = "substrate-chain-spec", path = "../chain-spec" } client = { package = "substrate-client", path = "../../core/client" } +sr-api = { path = "../sr-api" } +tx-pool-api = { package = "substrate-transaction-pool-runtime-api", path = "../transaction-pool/runtime-api" } client_db = { package = "substrate-client-db", path = "../../core/client/db" } codec = { package = "parity-scale-codec", version = "1.0.0" } substrate-executor = { path = "../../core/executor" } diff --git a/core/service/src/builder.rs b/core/service/src/builder.rs index 9956837e241be..f188f77a4acf6 100644 --- a/core/service/src/builder.rs +++ b/core/service/src/builder.rs @@ -19,8 +19,7 @@ use crate::{SpawnTaskHandle, start_rpc_servers, build_network_future, Transactio use crate::status_sinks; use crate::config::{Configuration, DatabaseConfig}; use client::{ - BlockchainEvents, Client, runtime_api, - backend::RemoteBackend, light::blockchain::RemoteBlockchain, + BlockchainEvents, Client, backend::RemoteBackend, light::blockchain::RemoteBlockchain, }; use chain_spec::{RuntimeGenesis, Extension}; use codec::{Decode, Encode, IoReader}; @@ -757,10 +756,11 @@ ServiceBuilder< > where Client: ProvideRuntimeApi, as ProvideRuntimeApi>::Api: - runtime_api::Metadata + + sr_api::Metadata + offchain::OffchainWorkerApi + - runtime_api::TaggedTransactionQueue + - session::SessionKeys, + tx_pool_api::TaggedTransactionQueue + + session::SessionKeys + + sr_api::ApiExt, TBl: BlockT::Out>, TRtApi: 'static + Send + Sync, TCfg: Default, @@ -808,7 +808,8 @@ ServiceBuilder< session::generate_initial_session_keys( client.clone(), - config.dev_key_seed.clone().map(|s| vec![s]).unwrap_or_default() + &BlockId::Hash(client.info().chain.best_hash), + config.dev_key_seed.clone().map(|s| vec![s]).unwrap_or_default(), )?; let (signal, exit) = exit_future::signal(); @@ -1162,7 +1163,8 @@ pub(crate) fn maintain_transaction_pool( Block: BlockT::Out>, Backend: 'static + client::backend::Backend, Client: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: runtime_api::TaggedTransactionQueue, + as ProvideRuntimeApi>::Api: + tx_pool_api::TaggedTransactionQueue, Executor: 'static + client::CallExecutor, PoolApi: 'static + txpool::ChainApi, Api: 'static, diff --git a/core/service/src/lib.rs b/core/service/src/lib.rs index b267e0a635b23..f45fe0f9641cf 100644 --- a/core/service/src/lib.rs +++ b/core/service/src/lib.rs @@ -36,7 +36,7 @@ use std::time::{Duration, Instant}; use futures::sync::mpsc; use parking_lot::Mutex; -use client::{runtime_api::BlockT, Client}; +use client::Client; use exit_future::Signal; use futures::prelude::*; use futures03::{ @@ -51,7 +51,7 @@ use log::{log, warn, debug, error, Level}; use codec::{Encode, Decode}; use primitives::{Blake2Hasher, H256}; use sr_primitives::generic::BlockId; -use sr_primitives::traits::NumberFor; +use sr_primitives::traits::{NumberFor, Block as BlockT}; pub use self::error::Error; pub use self::builder::{ServiceBuilder, ServiceBuilderExport, ServiceBuilderImport, ServiceBuilderRevert}; diff --git a/core/session/Cargo.toml b/core/session/Cargo.toml index 5d8cb3f0001ba..d1490905c200b 100644 --- a/core/session/Cargo.toml +++ b/core/session/Cargo.toml @@ -5,11 +5,10 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -client = { package = "substrate-client", path = "../client", default-features = false } +sr-api = { path = "../sr-api", default-features = false } rstd = { package = "sr-std", path = "../sr-std", default-features = false } sr-primitives = { path = "../sr-primitives", optional = true } -primitives = { package = "substrate-primitives", path = "../primitives", optional = true } [features] default = [ "std" ] -std = [ "client/std", "rstd/std", "sr-primitives", "primitives" ] +std = [ "sr-api/std", "rstd/std", "sr-primitives" ] diff --git a/core/session/src/lib.rs b/core/session/src/lib.rs index 1b40d2d9ba815..adc7629c36816 100644 --- a/core/session/src/lib.rs +++ b/core/session/src/lib.rs @@ -21,11 +21,9 @@ use rstd::vec::Vec; #[cfg(feature = "std")] -use sr_primitives::traits::{ProvideRuntimeApi, Block as BlockT}; -#[cfg(feature = "std")] -use primitives::{H256, Blake2Hasher}; +use sr_primitives::{generic::BlockId, traits::{ProvideRuntimeApi, Block as BlockT}}; -client::decl_runtime_apis! { +sr_api::decl_runtime_apis! { /// Session keys runtime api. pub trait SessionKeys { /// Generate a set of session keys with optionally using the given seed. @@ -39,28 +37,23 @@ client::decl_runtime_apis! { } } -/// Generate the initial session keys with the given seeds and store them in +/// Generate the initial session keys with the given seeds, at the given block and store them in /// the client's keystore. #[cfg(feature = "std")] -pub fn generate_initial_session_keys( - client: std::sync::Arc>, +pub fn generate_initial_session_keys( + client: std::sync::Arc, + at: &BlockId, seeds: Vec, -) -> Result<(), client::error::Error> +) -> Result<(), <::Api as sr_api::ApiExt>::Error> where - B: client::backend::Backend, - E: client::CallExecutor, - Block: BlockT, - client::Client: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: SessionKeys, + Block: BlockT, + T: ProvideRuntimeApi, + ::Api: SessionKeys, { - let info = client.info().chain; let runtime_api = client.runtime_api(); for seed in seeds { - runtime_api.generate_session_keys( - &sr_primitives::generic::BlockId::Number(info.best_number), - Some(seed.as_bytes().to_vec()), - )?; + runtime_api.generate_session_keys(at, Some(seed.as_bytes().to_vec()))?; } Ok(()) diff --git a/core/sr-api-macros/Cargo.toml b/core/sr-api-macros/Cargo.toml deleted file mode 100644 index ad258fcf67c66..0000000000000 --- a/core/sr-api-macros/Cargo.toml +++ /dev/null @@ -1,37 +0,0 @@ -[package] -name = "sr-api-macros" -version = "2.0.0" -authors = ["Parity Technologies "] -edition = "2018" - -[lib] -proc-macro = true - -[dependencies] -quote = "1.0.2" -syn = { version = "1.0.7", features = [ "full", "fold", "extra-traits", "visit" ] } -proc-macro2 = "1.0.6" -blake2-rfc = "0.2.18" -proc-macro-crate = "0.1.4" - -[dev-dependencies] -client = { package = "substrate-client", path = "../client" } -test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client" } -state_machine = { package = "substrate-state-machine", path = "../state-machine" } -sr-primitives = { path = "../sr-primitives" } -sr-version = { path = "../sr-version" } -primitives = { package = "substrate-primitives", path = "../primitives" } -criterion = "0.3.0" -consensus_common = { package = "substrate-consensus-common", path = "../consensus/common" } -codec = { package = "parity-scale-codec", version = "1.0.0" } -trybuild = "1.0.17" -rustversion = "1.0.0" - -[[bench]] -name = "bench" -harness = false - -# We actually don't need the `std` feature in this crate, but the tests require it. -[features] -default = [ "std" ] -std = [] diff --git a/core/sr-api-macros/tests/ui/adding_self_parameter.stderr b/core/sr-api-macros/tests/ui/adding_self_parameter.stderr deleted file mode 100644 index 34ba4d4a5112f..0000000000000 --- a/core/sr-api-macros/tests/ui/adding_self_parameter.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: `self` as argument not supported. - --> $DIR/adding_self_parameter.rs:5:11 - | -5 | fn test(&self); - | ^ diff --git a/core/sr-api-macros/tests/ui/empty_impl_runtime_apis_call.stderr b/core/sr-api-macros/tests/ui/empty_impl_runtime_apis_call.stderr deleted file mode 100644 index c714df5034cab..0000000000000 --- a/core/sr-api-macros/tests/ui/empty_impl_runtime_apis_call.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: No api implementation given! - --> $DIR/empty_impl_runtime_apis_call.rs:18:1 - | -18 | impl_runtime_apis! {} - | ^^^^^^^^^^^^^^^^^^^^^ in this macro invocation diff --git a/core/sr-api-macros/tests/ui/impl_incorrect_method_signature.stderr b/core/sr-api-macros/tests/ui/impl_incorrect_method_signature.stderr deleted file mode 100644 index 81bbec8645ffd..0000000000000 --- a/core/sr-api-macros/tests/ui/impl_incorrect_method_signature.stderr +++ /dev/null @@ -1,64 +0,0 @@ -error[E0053]: method `test` has an incompatible type for trait - --> $DIR/impl_incorrect_method_signature.rs:20:17 - | -14 | fn test(data: u64); - | --- type in trait -... -20 | fn test(data: String) {} - | ^^^^^^ expected u64, found struct `std::string::String` - | - = note: expected type `fn(u64)` - found type `fn(std::string::String)` - -error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for trait - --> $DIR/impl_incorrect_method_signature.rs:18:1 - | -12 | / decl_runtime_apis! { -13 | | pub trait Api { -14 | | fn test(data: u64); -15 | | } -16 | | } - | |_- type in trait -17 | -18 | impl_runtime_apis! { - | -^^^^^^^^^^^^^^^^^ - | | - | _expected u64, found struct `std::string::String` - | | -19 | | impl self::Api for Runtime { -20 | | fn test(data: String) {} -21 | | } -... | -33 | | } -34 | | } - | |_- in this macro invocation - | - = note: expected type `fn(&RuntimeApiImpl, &sr_primitives::generic::block::BlockId, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::ExecutionContext, std::option::Option, std::vec::Vec) -> std::result::Result, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::error::Error>` - found type `fn(&RuntimeApiImpl, &sr_primitives::generic::block::BlockId, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::ExecutionContext, std::option::Option, std::vec::Vec) -> std::result::Result, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::error::Error>` - -error[E0308]: mismatched types - --> $DIR/impl_incorrect_method_signature.rs:18:1 - | -18 | / impl_runtime_apis! { -19 | | impl self::Api for Runtime { -20 | | fn test(data: String) {} -21 | | } -... | -33 | | } -34 | | } - | | ^ - | | | - | |_expected u64, found struct `std::string::String` - | in this macro invocation - | - = note: expected type `u64` - found type `std::string::String` - -error[E0308]: mismatched types - --> $DIR/impl_incorrect_method_signature.rs:20:11 - | -20 | fn test(data: String) {} - | ^^^^ expected u64, found struct `std::string::String` - | - = note: expected type `u64` - found type `std::string::String` diff --git a/core/sr-api-macros/tests/ui/impl_two_traits_with_same_name.stderr b/core/sr-api-macros/tests/ui/impl_two_traits_with_same_name.stderr deleted file mode 100644 index 4c37b6b716a0a..0000000000000 --- a/core/sr-api-macros/tests/ui/impl_two_traits_with_same_name.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error: Two traits with the same name detected! The trait name is used to generate its ID. Please rename one trait at the declaration! - --> $DIR/impl_two_traits_with_same_name.rs:33:15 - | -33 | impl second::Api for Runtime { - | ^^^ - -error[E0277]: the trait bound `RuntimeApiImpl: sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::Core, substrate_test_runtime::Extrinsic>>` is not satisfied - --> $DIR/impl_two_traits_with_same_name.rs:29:7 - | -29 | impl self::Api for Runtime { - | ^^^^^^^^^^^^^^^^ the trait `sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::Core, substrate_test_runtime::Extrinsic>>` is not implemented for `RuntimeApiImpl` - -error[E0277]: the trait bound `RuntimeApiImpl: sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::Core, substrate_test_runtime::Extrinsic>>` is not satisfied - --> $DIR/impl_two_traits_with_same_name.rs:33:7 - | -33 | impl second::Api for Runtime { - | ^^^^^^^^^^^^^^^^^^ the trait `sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::Core, substrate_test_runtime::Extrinsic>>` is not implemented for `RuntimeApiImpl` diff --git a/core/sr-api-macros/tests/ui/invalid_api_version_2.stderr b/core/sr-api-macros/tests/ui/invalid_api_version_2.stderr deleted file mode 100644 index 39b73938dfac8..0000000000000 --- a/core/sr-api-macros/tests/ui/invalid_api_version_2.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error: can't qualify macro invocation with `pub` - --> $DIR/invalid_api_version_2.rs:3:1 - | -3 | / decl_runtime_apis! { -4 | | #[api_version("1")] -5 | | pub trait Api { -6 | | fn test(data: u64); -7 | | } -8 | | } - | | ^ in this macro invocation - | |_| - | - | - = help: try adjusting the macro to put `pub` inside the invocation - -error: Unexpected `api_version` attribute. The supported format is `api_version(1)` - --> $DIR/invalid_api_version_2.rs:3:1 - | -3 | / decl_runtime_apis! { -4 | | #[api_version("1")] -5 | | pub trait Api { -6 | | fn test(data: u64); -7 | | } -8 | | } - | | ^ in this macro invocation - | |_| - | - -error: Unexpected `api_version` attribute. The supported format is `api_version(1)` - --> $DIR/invalid_api_version_2.rs:4:4 - | -4 | #[api_version("1")] - | ^^^^^^^^^^^ diff --git a/core/sr-api-macros/tests/ui/invalid_api_version_3.stderr b/core/sr-api-macros/tests/ui/invalid_api_version_3.stderr deleted file mode 100644 index d1694458f802e..0000000000000 --- a/core/sr-api-macros/tests/ui/invalid_api_version_3.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error: can't qualify macro invocation with `pub` - --> $DIR/invalid_api_version_3.rs:3:1 - | -3 | / decl_runtime_apis! { -4 | | #[api_version()] -5 | | pub trait Api { -6 | | fn test(data: u64); -7 | | } -8 | | } - | | ^ in this macro invocation - | |_| - | - | - = help: try adjusting the macro to put `pub` inside the invocation - -error: Unexpected `api_version` attribute. The supported format is `api_version(1)` - --> $DIR/invalid_api_version_3.rs:3:1 - | -3 | / decl_runtime_apis! { -4 | | #[api_version()] -5 | | pub trait Api { -6 | | fn test(data: u64); -7 | | } -8 | | } - | | ^ in this macro invocation - | |_| - | - -error: Unexpected `api_version` attribute. The supported format is `api_version(1)` - --> $DIR/invalid_api_version_3.rs:4:4 - | -4 | #[api_version()] - | ^^^^^^^^^^^ diff --git a/core/sr-api-macros/tests/ui/missing_block_generic_parameter.stderr b/core/sr-api-macros/tests/ui/missing_block_generic_parameter.stderr deleted file mode 100644 index 5c8563a8b89d0..0000000000000 --- a/core/sr-api-macros/tests/ui/missing_block_generic_parameter.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: Missing `Block` generic parameter. - --> $DIR/missing_block_generic_parameter.rs:19:13 - | -19 | impl self::Api for Runtime { - | ^^^ - -error[E0107]: wrong number of type arguments: expected 1, found 0 - --> $DIR/missing_block_generic_parameter.rs:19:7 - | -19 | impl self::Api for Runtime { - | ^^^^^^^^^ expected 1 type argument - -For more information about this error, try `rustc --explain E0107`. diff --git a/core/sr-api-macros/tests/ui/type_reference_in_impl_runtime_apis_call.stderr b/core/sr-api-macros/tests/ui/type_reference_in_impl_runtime_apis_call.stderr deleted file mode 100644 index 345389b275f04..0000000000000 --- a/core/sr-api-macros/tests/ui/type_reference_in_impl_runtime_apis_call.stderr +++ /dev/null @@ -1,67 +0,0 @@ -error[E0053]: method `test` has an incompatible type for trait - --> $DIR/type_reference_in_impl_runtime_apis_call.rs:20:17 - | -14 | fn test(data: u64); - | --- type in trait -... -20 | fn test(data: &u64) { - | ^^^^ expected u64, found &u64 - | - = note: expected type `fn(u64)` - found type `fn(&u64)` - -error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for trait - --> $DIR/type_reference_in_impl_runtime_apis_call.rs:18:1 - | -12 | / decl_runtime_apis! { -13 | | pub trait Api { -14 | | fn test(data: u64); -15 | | } -16 | | } - | |_- type in trait -17 | -18 | impl_runtime_apis! { - | -^^^^^^^^^^^^^^^^^ - | | - | _expected u64, found &u64 - | | -19 | | impl self::Api for Runtime { -20 | | fn test(data: &u64) { -21 | | unimplemented!() -... | -35 | | } -36 | | } - | |_- in this macro invocation - | - = note: expected type `fn(&RuntimeApiImpl, &sr_primitives::generic::block::BlockId, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::ExecutionContext, std::option::Option, std::vec::Vec) -> std::result::Result, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::error::Error>` - found type `fn(&RuntimeApiImpl, &sr_primitives::generic::block::BlockId, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::ExecutionContext, std::option::Option<&u64>, std::vec::Vec) -> std::result::Result, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::error::Error>` - -error[E0308]: mismatched types - --> $DIR/type_reference_in_impl_runtime_apis_call.rs:18:1 - | -18 | / impl_runtime_apis! { -19 | | impl self::Api for Runtime { -20 | | fn test(data: &u64) { -21 | | unimplemented!() -... | -35 | | } -36 | | } - | | ^ - | | | - | |_expected u64, found &u64 - | in this macro invocation - | - = note: expected type `u64` - found type `&u64` - -error[E0308]: mismatched types - --> $DIR/type_reference_in_impl_runtime_apis_call.rs:20:11 - | -20 | fn test(data: &u64) { - | ^^^^^^^ - | | - | expected u64, found &u64 - | help: consider removing the borrow: `data` - | - = note: expected type `u64` - found type `&u64` diff --git a/core/sr-api/Cargo.toml b/core/sr-api/Cargo.toml new file mode 100644 index 0000000000000..a2d23e9bbc771 --- /dev/null +++ b/core/sr-api/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "sr-api" +version = "2.0.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } +sr-api-proc-macro = { path = "proc-macro" } +primitives = { package = "substrate-primitives", path = "../primitives", default-features = false } +rstd = { package = "sr-std", path = "../sr-std", default-features = false } +sr-primitives = { path = "../sr-primitives", default-features = false } +sr-version = { path = "../sr-version", default-features = false } +state-machine = { package = "substrate-state-machine", path = "../state-machine", optional = true } + +[dev-dependencies] +criterion = "0.3.0" +test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client" } + +[[bench]] +name = "bench" +harness = false + +[features] +default = [ "std" ] +std = [ + "codec/std", + "primitives/std", + "rstd/std", + "sr-primitives/std", + "state-machine", + "sr-version/std", +] diff --git a/core/sr-api-macros/benches/bench.rs b/core/sr-api/benches/bench.rs similarity index 96% rename from core/sr-api-macros/benches/bench.rs rename to core/sr-api/benches/bench.rs index 9aba38c2d1820..49c8e1e380415 100644 --- a/core/sr-api-macros/benches/bench.rs +++ b/core/sr-api/benches/bench.rs @@ -16,8 +16,8 @@ use criterion::{Criterion, criterion_group, criterion_main}; use test_client::{ - DefaultTestClientBuilderExt, TestClientBuilder, - TestClientBuilderExt, runtime::TestAPI, + DefaultTestClientBuilderExt, TestClientBuilder, + TestClientBuilderExt, runtime::TestAPI, }; use sr_primitives::{generic::BlockId, traits::ProvideRuntimeApi}; use state_machine::ExecutionStrategy; diff --git a/core/client/src/runtime_api.rs b/core/sr-api/lib.rs similarity index 100% rename from core/client/src/runtime_api.rs rename to core/sr-api/lib.rs diff --git a/core/sr-api/proc-macro/Cargo.toml b/core/sr-api/proc-macro/Cargo.toml new file mode 100644 index 0000000000000..fe6a4cc6d6d0d --- /dev/null +++ b/core/sr-api/proc-macro/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "sr-api-proc-macro" +version = "2.0.0" +authors = ["Parity Technologies "] +edition = "2018" + +[lib] +proc-macro = true + +[dependencies] +quote = "1.0.2" +syn = { version = "1.0.8", features = [ "full", "fold", "extra-traits", "visit" ] } +proc-macro2 = "1.0.6" +blake2-rfc = "0.2.18" +proc-macro-crate = "0.1.4" + +[dev-dependencies] +sr-api = { path = ".." } +sr-primitives = { path = "../../sr-primitives" } +sr-version = { path = "../../sr-version" } +test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" } + +# Required for the doc tests +[features] +default = [ "std" ] +std = [] diff --git a/core/sr-api-macros/src/decl_runtime_apis.rs b/core/sr-api/proc-macro/src/decl_runtime_apis.rs similarity index 92% rename from core/sr-api-macros/src/decl_runtime_apis.rs rename to core/sr-api/proc-macro/src/decl_runtime_apis.rs index 778ac910cd93f..bec64b1d9b192 100644 --- a/core/sr-api-macros/src/decl_runtime_apis.rs +++ b/core/sr-api/proc-macro/src/decl_runtime_apis.rs @@ -96,7 +96,7 @@ fn extend_generics_with_block(generics: &mut Generics) { let c = generate_crate_access(HIDDEN_INCLUDES_ID); generics.lt_token = Some(Default::default()); - generics.params.insert(0, parse_quote!( Block: #c::runtime_api::BlockT )); + generics.params.insert(0, parse_quote!( Block: #c::BlockT )); generics.gt_token = Some(Default::default()); } @@ -186,12 +186,12 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result { result.push(quote!( #[cfg(any(feature = "std", test))] fn convert_between_block_types - ( + ( input: &I, error_desc: &'static str, ) -> std::result::Result { - ::decode( - &mut &#crate_::runtime_api::Encode::encode(input)[..], + ::decode( + &mut &#crate_::Encode::encode(input)[..], ).map_err(|e| format!("{} {}", error_desc, e.what())) } )); @@ -272,7 +272,7 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result { result.push(quote!( #[cfg(any(feature = "std", test))] pub fn #fn_name< - 'a, ApiImpl: #trait_ #ty_generics, NodeBlock: #crate_::runtime_api::BlockT + 'a, ApiImpl: #trait_ #ty_generics, NodeBlock: #crate_::BlockT #(, #impl_generics_params)* >( #( #fn_inputs ),* @@ -396,24 +396,24 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result { result.push(quote!( #[cfg(any(feature = "std", test))] pub fn #fn_name< - R: #crate_::runtime_api::Encode + #crate_::runtime_api::Decode + PartialEq, + R: #crate_::Encode + #crate_::Decode + PartialEq, NC: FnOnce() -> std::result::Result + std::panic::UnwindSafe, - Block: #crate_::runtime_api::BlockT, - T: #crate_::runtime_api::CallRuntimeAt, - C: #crate_::runtime_api::Core, + Block: #crate_::BlockT, + T: #crate_::CallRuntimeAt, + C: #crate_::Core, >( call_runtime_at: &T, core_api: &C, - at: &#crate_::runtime_api::BlockId, + at: &#crate_::BlockId, args: Vec, - changes: &std::cell::RefCell<#crate_::runtime_api::OverlayedChanges>, - initialized_block: &std::cell::RefCell>>, + changes: &std::cell::RefCell<#crate_::OverlayedChanges>, + initialized_block: &std::cell::RefCell>>, native_call: Option, - context: #crate_::runtime_api::ExecutionContext, - recorder: &Option>>>, - ) -> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded> { + context: #crate_::ExecutionContext, + recorder: &Option>>>, + ) -> std::result::Result<#crate_::NativeOrEncoded, T::Error> { let version = call_runtime_at.runtime_version_at(at)?; - use #crate_::runtime_api::InitializeBlock; + use #crate_::InitializeBlock; let initialize_block = if #skip_initialize_block { InitializeBlock::Skip } else { @@ -553,7 +553,7 @@ impl<'a> ToClientSideDecl<'a> { fn fold_trait_item_method(&mut self, method: TraitItemMethod) -> (TraitItemMethod, Option, TraitItemMethod) { let crate_ = self.crate_; - let context = quote!( #crate_::runtime_api::ExecutionContext::OffchainCall(None) ); + let context = quote!( #crate_::ExecutionContext::OffchainCall(None) ); let fn_impl = self.create_method_runtime_api_impl(method.clone()); let fn_decl = self.create_method_decl(method.clone(), context); let fn_decl_ctx = self.create_method_decl_with_context(method); @@ -563,7 +563,7 @@ impl<'a> ToClientSideDecl<'a> { fn create_method_decl_with_context(&mut self, method: TraitItemMethod) -> TraitItemMethod { let crate_ = self.crate_; - let context_arg: syn::FnArg = parse_quote!( context: #crate_::runtime_api::ExecutionContext ); + let context_arg: syn::FnArg = parse_quote!( context: #crate_::ExecutionContext ); let mut fn_decl_ctx = self.create_method_decl(method, quote!( context )); fn_decl_ctx.sig.ident = Ident::new(&format!("{}_with_context", &fn_decl_ctx.sig.ident), Span::call_site()); fn_decl_ctx.sig.inputs.insert(2, context_arg); @@ -604,10 +604,10 @@ impl<'a> ToClientSideDecl<'a> { fn #name( &self, at: &#block_id, - context: #crate_::runtime_api::ExecutionContext, + context: #crate_::ExecutionContext, params: Option<( #( #param_types ),* )>, params_encoded: Vec, - ) -> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded<#ret_type>>; + ) -> std::result::Result<#crate_::NativeOrEncoded<#ret_type>, Self::Error>; } ) } @@ -630,7 +630,7 @@ impl<'a> ToClientSideDecl<'a> { let params2 = params.clone(); let ret_type = return_type_extract_type(&method.sig.output); - fold_fn_decl_for_client_side(&mut method.sig, &self.block_id, &self.crate_); + fold_fn_decl_for_client_side(&mut method.sig, &self.block_id); let name_impl = generate_method_runtime_api_impl_name(&self.trait_, &method.sig.ident); let crate_ = self.crate_; @@ -674,7 +674,7 @@ impl<'a> ToClientSideDecl<'a> { parse_quote! { { let runtime_api_impl_params_encoded = - #crate_::runtime_api::Encode::encode(&( #( &#params ),* )); + #crate_::Encode::encode(&( #( &#params ),* )); self.#name_impl( __runtime_api_at_param__, @@ -683,14 +683,16 @@ impl<'a> ToClientSideDecl<'a> { runtime_api_impl_params_encoded, ).and_then(|r| match r { - #crate_::runtime_api::NativeOrEncoded::Native(n) => { + #crate_::NativeOrEncoded::Native(n) => { #native_handling }, - #crate_::runtime_api::NativeOrEncoded::Encoded(r) => { - <#ret_type as #crate_::runtime_api::Decode>::decode(&mut &r[..]) + #crate_::NativeOrEncoded::Encoded(r) => { + <#ret_type as #crate_::Decode>::decode(&mut &r[..]) .map_err(|err| - #crate_::error::Error::CallResultDecode( - #function_name, err + format!( + "Failed to decode result of `{}`: {}", + #function_name, + err.what(), ).into() ) } @@ -720,12 +722,12 @@ impl<'a> Fold for ToClientSideDecl<'a> { 'static + Send + Sync - + #crate_::runtime_api::ApiExt<#block_ident> + + #crate_::ApiExt<#block_ident> ); } else { // Add the `Core` runtime api as super trait. let crate_ = &self.crate_; - input.supertraits.push(parse_quote!( #crate_::runtime_api::Core<#block_ident> )); + input.supertraits.push(parse_quote!( #crate_::Core<#block_ident> )); } // The client side trait is only required when compiling with the feature `std` or `test`. @@ -783,12 +785,24 @@ fn generate_runtime_info_impl(trait_: &ItemTrait, version: u64) -> TokenStream { let crate_ = generate_crate_access(HIDDEN_INCLUDES_ID); let id = generate_runtime_api_id(&trait_name.to_string()); let version = generate_runtime_api_version(version as u32); - let (impl_generics, ty_generics, where_clause) = trait_.generics.split_for_impl(); + + let impl_generics = trait_.generics.type_params().map(|t| { + let ident = &t.ident; + let colon_token = &t.colon_token; + let bounds = &t.bounds; + + quote! { #ident #colon_token #bounds } + }).chain(std::iter::once(quote! { __Sr_Api_Error__ })); + + let ty_generics = trait_.generics.type_params().map(|t| { + let ident = &t.ident; + quote! { #ident } + }).chain(std::iter::once(quote! { Error = __Sr_Api_Error__ })); quote!( #[cfg(any(feature = "std", test))] - impl #impl_generics #crate_::runtime_api::RuntimeApiInfo - for #trait_name #ty_generics #where_clause + impl < #( #impl_generics, )* > #crate_::RuntimeApiInfo + for #trait_name < #( #ty_generics, )* > { #id #version @@ -816,7 +830,7 @@ fn generate_client_side_decls(decls: &[ItemTrait]) -> TokenStream { let decl = decl.clone(); let crate_ = generate_crate_access(HIDDEN_INCLUDES_ID); - let block_id = quote!( #crate_::runtime_api::BlockId ); + let block_id = quote!( #crate_::BlockId ); let mut found_attributes = HashMap::new(); let mut errors = Vec::new(); let trait_ = decl.ident.clone(); diff --git a/core/sr-api-macros/src/impl_runtime_apis.rs b/core/sr-api/proc-macro/src/impl_runtime_apis.rs similarity index 87% rename from core/sr-api-macros/src/impl_runtime_apis.rs rename to core/sr-api/proc-macro/src/impl_runtime_apis.rs index d77d46a43cd44..9a928dab0d53b 100644 --- a/core/sr-api-macros/src/impl_runtime_apis.rs +++ b/core/sr-api/proc-macro/src/impl_runtime_apis.rs @@ -76,7 +76,7 @@ fn generate_impl_call( Ok( quote!( #( - let #pnames : #ptypes = match #c_iter::runtime_api::Decode::decode(&mut #input) { + let #pnames : #ptypes = match #c_iter::Decode::decode(&mut #input) { Ok(input) => input, Err(e) => panic!("Bad input data provided to {}: {}", #fn_name_str, e.what()), }; @@ -175,7 +175,7 @@ fn generate_dispatch_function(impls: &[ItemImpl]) -> Result { .into_iter() .map(|(trait_, fn_name, impl_)| { let name = prefix_function_with_trait(&trait_, &fn_name); - quote!( #name => Some(#c::runtime_api::Encode::encode(&{ #impl_ })), ) + quote!( #name => Some(#c::Encode::encode(&{ #impl_ })), ) }); Ok(quote!( @@ -209,12 +209,12 @@ fn generate_wasm_interface(impls: &[ItemImpl]) -> Result { &[0u8; 0] } else { unsafe { - #c::runtime_api::slice::from_raw_parts(input_data, input_len) + #c::slice::from_raw_parts(input_data, input_len) } }; let output = { #impl_ }; - #c::runtime_api::to_substrate_wasm_fn_return_value(&output) + #c::to_substrate_wasm_fn_return_value(&output) } ) }); @@ -231,8 +231,8 @@ fn generate_block_and_block_id_ty( let trait_ = Ident::new(trait_, Span::call_site()); let assoc_type = Ident::new(assoc_type, Span::call_site()); - let block = quote!( <#runtime as #crate_::runtime_api::#trait_>::#assoc_type ); - let block_id = quote!( #crate_::runtime_api::BlockId<#block> ); + let block = quote!( <#runtime as #crate_::#trait_>::#assoc_type ); + let block_id = quote!( #crate_::BlockId<#block> ); (block, block_id) } @@ -252,30 +252,30 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result + 'static> { + pub struct RuntimeApiImpl + 'static> { call: &'static C, commit_on_success: std::cell::RefCell, initialized_block: std::cell::RefCell>, - changes: std::cell::RefCell<#crate_::runtime_api::OverlayedChanges>, - recorder: Option>>>, + changes: std::cell::RefCell<#crate_::OverlayedChanges>, + recorder: Option>>>, } // `RuntimeApi` itself is not threadsafe. However, an instance is only available in a // `ApiRef` object and `ApiRef` also has an associated lifetime. This lifetimes makes it // impossible to move `RuntimeApi` into another thread. #[cfg(any(feature = "std", test))] - unsafe impl> Send for RuntimeApiImpl {} + unsafe impl> Send for RuntimeApiImpl {} #[cfg(any(feature = "std", test))] - unsafe impl> Sync for RuntimeApiImpl {} + unsafe impl> Sync for RuntimeApiImpl {} #[cfg(any(feature = "std", test))] - impl> #crate_::runtime_api::ApiExt<#block> - for RuntimeApiImpl - { + impl> #crate_::ApiExt<#block> for RuntimeApiImpl { + type Error = C::Error; + fn map_api_result std::result::Result, R, E>( &self, map_call: F - ) -> ::std::result::Result where Self: Sized { + ) -> std::result::Result where Self: Sized { *self.commit_on_success.borrow_mut() = false; let res = map_call(self); *self.commit_on_success.borrow_mut() = true; @@ -288,7 +288,7 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result #crate_::error::Result<#crate_::runtime_api::RuntimeVersion> { + ) -> std::result::Result<#crate_::RuntimeVersion, C::Error> { self.call.runtime_version_at(at) } @@ -296,7 +296,7 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result Option<#crate_::runtime_api::StorageProof> { + fn extract_proof(&mut self) -> Option<#crate_::StorageProof> { self.recorder .take() .map(|recorder| { @@ -306,22 +306,22 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result + 'static> - #crate_::runtime_api::ConstructRuntimeApi<#block, C> for RuntimeApi + impl + 'static> #crate_::ConstructRuntimeApi<#block, C> + for RuntimeApi { type RuntimeApi = RuntimeApiImpl; fn construct_runtime_api<'a>( call: &'a C, - ) -> #crate_::runtime_api::ApiRef<'a, Self::RuntimeApi> { + ) -> #crate_::ApiRef<'a, Self::RuntimeApi> { RuntimeApiImpl { - call: unsafe { ::std::mem::transmute(call) }, + call: unsafe { std::mem::transmute(call) }, commit_on_success: true.into(), initialized_block: None.into(), changes: Default::default(), @@ -331,29 +331,28 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result> RuntimeApiImpl { + impl> RuntimeApiImpl { fn call_api_at< - R: #crate_::runtime_api::Encode + #crate_::runtime_api::Decode + PartialEq, + R: #crate_::Encode + #crate_::Decode + PartialEq, F: FnOnce( &C, &Self, - &std::cell::RefCell<#crate_::runtime_api::OverlayedChanges>, - &std::cell::RefCell>>, - &Option>>>, - ) -> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded>, + &std::cell::RefCell<#crate_::OverlayedChanges>, + &std::cell::RefCell>>, + &Option>>>, + ) -> std::result::Result<#crate_::NativeOrEncoded, E>, + E, >( &self, call_api_at: F, - ) -> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded> { - let res = unsafe { - call_api_at( - &self.call, - self, - &self.changes, - &self.initialized_block, - &self.recorder, - ) - }; + ) -> std::result::Result<#crate_::NativeOrEncoded, E> { + let res = call_api_at( + &self.call, + self, + &self.changes, + &self.initialized_block, + &self.recorder, + ); self.commit_on_ok(&res); res @@ -475,7 +474,7 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> { input.sig.inputs = parse_quote! { &self, at: &#block_id, - context: #crate_::runtime_api::ExecutionContext, + context: #crate_::ExecutionContext, params: Option<( #( #param_types ),* )>, params_encoded: Vec, }; @@ -488,7 +487,7 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> { // Generate the correct return type. input.sig.output = parse_quote!( - -> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded<#ret_type>> + -> std::result::Result<#crate_::NativeOrEncoded<#ret_type>, RuntimeApiImplCall::Error> ); // Generate the new method implementation that calls into the runtime. @@ -535,7 +534,7 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> { let crate_ = generate_crate_access(HIDDEN_INCLUDES_ID); let block = self.node_block; input.generics.params.push( - parse_quote!( RuntimeApiImplCall: #crate_::runtime_api::CallRuntimeAt<#block> + 'static ) + parse_quote!( RuntimeApiImplCall: #crate_::CallRuntimeAt<#block> + 'static ) ); // The implementation for the `RuntimeApiImpl` is only required when compiling with @@ -621,8 +620,7 @@ fn generate_runtime_api_versions(impls: &[ItemImpl]) -> Result { let c = generate_crate_access(HIDDEN_INCLUDES_ID); Ok(quote!( - const RUNTIME_API_VERSIONS: #c::runtime_api::ApisVec = - #c::runtime_api::create_apis_vec!([ #( #result ),* ]); + const RUNTIME_API_VERSIONS: #c::ApisVec = #c::create_apis_vec!([ #( #result ),* ]); )) } diff --git a/core/sr-api-macros/src/lib.rs b/core/sr-api/proc-macro/src/lib.rs similarity index 91% rename from core/sr-api-macros/src/lib.rs rename to core/sr-api/proc-macro/src/lib.rs index d88fb09d1b11a..913e6e9d04bfb 100644 --- a/core/sr-api-macros/src/lib.rs +++ b/core/sr-api/proc-macro/src/lib.rs @@ -44,14 +44,7 @@ mod utils; /// # Example /// /// ```rust -/// #[macro_use] -/// extern crate client; -/// extern crate sr_version as version; -/// -/// use version::create_runtime_str; -/// # extern crate test_client; -/// # extern crate sr_primitives; -/// # extern crate primitives; +/// use sr_version::create_runtime_str; /// # /// # use sr_primitives::traits::GetNodeBlockType; /// # use test_client::runtime::{Block, Header}; @@ -63,7 +56,7 @@ mod utils; /// # type NodeBlock = Block; /// # } /// # -/// # decl_runtime_apis! { +/// # sr_api::decl_runtime_apis! { /// # /// Declare the api trait. /// # pub trait Balance { /// # /// Get the balance. @@ -77,9 +70,9 @@ mod utils; /// # } /// /// /// All runtime api implementations need to be done in one call of the macro! -/// impl_runtime_apis! { -/// # impl client::runtime_api::Core for Runtime { -/// # fn version() -> client::runtime_api::RuntimeVersion { +/// sr_api::impl_runtime_apis! { +/// # impl sr_api::Core for Runtime { +/// # fn version() -> sr_version::RuntimeVersion { /// # unimplemented!() /// # } /// # fn execute_block(_block: Block) {} @@ -103,7 +96,7 @@ mod utils; /// } /// /// /// Runtime version. This needs to be declared for each runtime. -/// pub const VERSION: version::RuntimeVersion = version::RuntimeVersion { +/// pub const VERSION: sr_version::RuntimeVersion = sr_version::RuntimeVersion { /// spec_name: create_runtime_str!("node"), /// impl_name: create_runtime_str!("test-node"), /// authoring_version: 1, @@ -134,10 +127,7 @@ pub fn impl_runtime_apis(input: TokenStream) -> TokenStream { /// # Example /// /// ```rust -/// #[macro_use] -/// extern crate client; -/// -/// decl_runtime_apis! { +/// sr_api::decl_runtime_apis! { /// /// Declare the api trait. /// pub trait Balance { /// /// Get the balance. @@ -169,10 +159,7 @@ pub fn impl_runtime_apis(input: TokenStream) -> TokenStream { /// spec version!). Such a method also does not need to be implemented in the runtime. /// /// ```rust -/// #[macro_use] -/// extern crate client; -/// -/// decl_runtime_apis! { +/// sr_api::decl_runtime_apis! { /// /// Declare the api trait. /// #[api_version(2)] /// pub trait Balance { diff --git a/core/sr-api-macros/src/utils.rs b/core/sr-api/proc-macro/src/utils.rs similarity index 93% rename from core/sr-api-macros/src/utils.rs rename to core/sr-api/proc-macro/src/utils.rs index c627cdacfa982..a46397be1b849 100644 --- a/core/sr-api-macros/src/utils.rs +++ b/core/sr-api/proc-macro/src/utils.rs @@ -37,17 +37,17 @@ fn generate_hidden_includes_mod_name(unique_id: &'static str) -> Ident { /// Generates the hidden includes that are required to make the macro independent from its scope. pub fn generate_hidden_includes(unique_id: &'static str) -> TokenStream { - if env::var("CARGO_PKG_NAME").unwrap() == "substrate-client" { + if env::var("CARGO_PKG_NAME").unwrap() == "sr-api" { TokenStream::new() } else { let mod_name = generate_hidden_includes_mod_name(unique_id); - match crate_name("substrate-client") { + match crate_name("sr-api") { Ok(client_name) => { let client_name = Ident::new(&client_name, Span::call_site()); quote!( #[doc(hidden)] mod #mod_name { - pub extern crate #client_name as sr_api_client; + pub extern crate #client_name as sr_api; } ) }, @@ -62,11 +62,11 @@ pub fn generate_hidden_includes(unique_id: &'static str) -> TokenStream { /// Generates the access to the `substrate_client` crate. pub fn generate_crate_access(unique_id: &'static str) -> TokenStream { - if env::var("CARGO_PKG_NAME").unwrap() == "substrate-client" { + if env::var("CARGO_PKG_NAME").unwrap() == "sr-api" { quote!( crate ) } else { let mod_name = generate_hidden_includes_mod_name(unique_id); - quote!( self::#mod_name::sr_api_client ) + quote!( self::#mod_name::sr_api ) }.into() } @@ -102,7 +102,6 @@ pub fn replace_wild_card_parameter_names(input: &mut Signature) { pub fn fold_fn_decl_for_client_side( input: &mut Signature, block_id: &TokenStream, - crate_: &TokenStream, ) { replace_wild_card_parameter_names(input); @@ -113,7 +112,7 @@ pub fn fold_fn_decl_for_client_side( // Wrap the output in a `Result` input.output = { let ty = return_type_extract_type(&input.output); - parse_quote!( -> std::result::Result<#ty, #crate_::error::Error> ) + parse_quote!( -> std::result::Result<#ty, Self::Error> ) }; } diff --git a/core/sr-api/src/lib.rs b/core/sr-api/src/lib.rs new file mode 100644 index 0000000000000..2a149ffbc9c1a --- /dev/null +++ b/core/sr-api/src/lib.rs @@ -0,0 +1,206 @@ +// Copyright 2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Substrate runtime api +//! +//! The Substrate runtime api is the crucial interface between the node and the runtime. +//! Every call that goes into the runtime is done with a runtime api. The runtime apis are not fixed. +//! Every Substrate user can define its own apis with +//! [`decl_runtime_apis`](macro.decl_runtime_apis.html) and implement them in +//! the runtime with [`impl_runtime_apis`](macro.impl_runtime_apis.html). +//! +//! Every Substrate runtime needs to implement the [`Core`] runtime api. This api provides the basic +//! functionality that every runtime needs to export. +//! +//! Besides the macros and the [`Core`] runtime api, this crates provides the [`Metadata`] runtime +//! api, the [`ApiExt`] trait, the [`CallRuntimeAt`] trait and the [`ConstructRuntimeApi`] trait. + +#![cfg_attr(not(feature = "std"), no_std)] + +#[doc(hidden)] +#[cfg(feature = "std")] +pub use state_machine::{OverlayedChanges, StorageProof}; +#[doc(hidden)] +#[cfg(feature = "std")] +pub use primitives::NativeOrEncoded; +#[doc(hidden)] +#[cfg(not(feature = "std"))] +pub use primitives::to_substrate_wasm_fn_return_value; +#[doc(hidden)] +pub use sr_primitives::{ + traits::{ + Block as BlockT, GetNodeBlockType, GetRuntimeBlockType, + Header as HeaderT, ApiRef, RuntimeApiInfo, Hash as HashT, + }, + generic::BlockId, transaction_validity::TransactionValidity, +}; +#[doc(hidden)] +pub use primitives::{offchain, ExecutionContext}; +#[doc(hidden)] +pub use sr_version::{ApiId, RuntimeVersion, ApisVec, create_apis_vec}; +#[doc(hidden)] +pub use rstd::{slice, mem}; +#[cfg(feature = "std")] +use rstd::result; +#[doc(hidden)] +pub use codec::{Encode, Decode}; +use primitives::OpaqueMetadata; +#[cfg(feature = "std")] +use std::{panic::UnwindSafe, cell::RefCell, rc::Rc}; +#[cfg(feature = "std")] +use primitives::Hasher as HasherT; + +pub use sr_api_proc_macro::{decl_runtime_apis, impl_runtime_apis}; + +#[cfg(feature = "std")] +/// A type that records all accessed trie nodes and generates a proof out of it. +pub type ProofRecorder = state_machine::ProofRecorder< + <<<::Header as HeaderT>::Hashing as HashT>::Hasher as HasherT>::Out +>; + +/// Something that can be constructed to a runtime api. +#[cfg(feature = "std")] +pub trait ConstructRuntimeApi> { + /// The actual runtime api that will be constructed. + type RuntimeApi; + + /// Construct an instance of the runtime api. + fn construct_runtime_api<'a>(call: &'a C) -> ApiRef<'a, Self::RuntimeApi>; +} + +/// An extension for the `RuntimeApi`. +#[cfg(feature = "std")] +pub trait ApiExt { + /// Error type used by the interface. + type Error: std::fmt::Debug + From; + + /// The given closure will be called with api instance. Inside the closure any api call is + /// allowed. After doing the api call, the closure is allowed to map the `Result` to a + /// different `Result` type. This can be important, as the internal data structure that keeps + /// track of modifications to the storage, discards changes when the `Result` is an `Err`. + /// On `Ok`, the structure commits the changes to an internal buffer. + fn map_api_result result::Result, R, E>( + &self, + map_call: F + ) -> result::Result where Self: Sized; + + /// Checks if the given api is implemented and versions match. + fn has_api( + &self, + at: &BlockId + ) -> Result where Self: Sized { + self.runtime_version_at(at).map(|v| v.has_api::()) + } + + /// Check if the given api is implemented and the version passes a predicate. + fn has_api_with bool>( + &self, + at: &BlockId, + pred: P, + ) -> Result where Self: Sized { + self.runtime_version_at(at).map(|v| v.has_api_with::(pred)) + } + + /// Returns the runtime version at the given block id. + fn runtime_version_at(&self, at: &BlockId) -> Result; + + /// Start recording all accessed trie nodes for generating proofs. + fn record_proof(&mut self); + + /// Extract the recorded proof. + /// This stops the proof recording. + fn extract_proof(&mut self) -> Option; +} + +/// Before calling any runtime api function, the runtime need to be initialized +/// at the requested block. However, some functions like `execute_block` or +/// `initialize_block` itself don't require to have the runtime initialized +/// at the requested block. +/// +/// `call_api_at` is instructed by this enum to do the initialization or to skip +/// it. +#[cfg(feature = "std")] +#[derive(Clone, Copy)] +pub enum InitializeBlock<'a, Block: BlockT> { + /// Skip initializing the runtime for a given block. + /// + /// This is used by functions who do the initialization by themselves or don't require it. + Skip, + /// Initialize the runtime for a given block. + /// + /// If the stored `BlockId` is `Some(_)`, the runtime is currently initialized at this block. + Do(&'a RefCell>>), +} + +/// Something that can call into the runtime at a given block. +#[cfg(feature = "std")] +pub trait CallRuntimeAt { + /// Error type used by the interface. + type Error: std::fmt::Debug + From; + + /// Calls the given api function with the given encoded arguments at the given block and returns + /// the encoded result. + fn call_api_at< + 'a, + R: Encode + Decode + PartialEq, + NC: FnOnce() -> result::Result + UnwindSafe, + C: Core, + >( + &self, + core_api: &C, + at: &BlockId, + function: &'static str, + args: Vec, + changes: &RefCell, + initialize_block: InitializeBlock<'a, Block>, + native_call: Option, + context: ExecutionContext, + recorder: &Option>>>, + ) -> Result, Self::Error>; + + /// Returns the runtime version at the given block. + fn runtime_version_at(&self, at: &BlockId) -> Result; +} + +/// Extracts the `Api::Error` for a type that provides a runtime api. +#[cfg(feature = "std")] +pub type ApiErrorFor = < + ::Api as ApiExt +>::Error; + +decl_runtime_apis! { + /// The `Core` runtime api that every Substrate runtime needs to implement. + #[core_trait] + #[api_version(2)] + pub trait Core { + /// Returns the version of the runtime. + fn version() -> RuntimeVersion; + /// Execute the given block. + #[skip_initialize_block] + fn execute_block(block: Block); + /// Initialize a block with the given header. + #[renamed("initialise_block", 2)] + #[skip_initialize_block] + #[initialize_block] + fn initialize_block(header: &::Header); + } + + /// The `Metadata` api trait that returns metadata for the runtime. + pub trait Metadata { + /// Returns the metadata of a runtime. + fn metadata() -> OpaqueMetadata; + } +} diff --git a/core/sr-api/test/Cargo.toml b/core/sr-api/test/Cargo.toml new file mode 100644 index 0000000000000..753ffb2d05b45 --- /dev/null +++ b/core/sr-api/test/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "sr-api-test" +version = "2.0.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +sr-api = { path = "../" } +test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" } +sr-version = { path = "../../sr-version" } +sr-primitives = { path = "../../sr-primitives" } +consensus_common = { package = "substrate-consensus-common", path = "../../consensus/common" } +codec = { package = "parity-scale-codec", version = "1.0.0" } +state-machine = { package = "substrate-state-machine", path = "../../state-machine" } +trybuild = "1.0.17" +rustversion = "1.0.0" + +# We only need this to generate the correct code. +[features] +default = [ "std" ] +std = [] diff --git a/core/sr-api-macros/tests/decl_and_impl.rs b/core/sr-api/test/tests/decl_and_impl.rs similarity index 71% rename from core/sr-api-macros/tests/decl_and_impl.rs rename to core/sr-api/test/tests/decl_and_impl.rs index 314c92e28d02e..91863e186521f 100644 --- a/core/sr-api-macros/tests/decl_and_impl.rs +++ b/core/sr-api/test/tests/decl_and_impl.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use sr_primitives::traits::{GetNodeBlockType, Block as BlockT}; -use sr_primitives::generic::BlockId; -use client::runtime_api::{self, RuntimeApiInfo}; -use client::{error::Result, decl_runtime_apis, impl_runtime_apis}; -use test_client::runtime::Block; +use sr_api::{RuntimeApiInfo, decl_runtime_apis, impl_runtime_apis}; + +use sr_primitives::{traits::{GetNodeBlockType, Block as BlockT}, generic::BlockId}; + +use test_client::{client::error::Result, runtime::Block}; /// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType` /// trait are done by the `construct_runtime!` macro in a real runtime. @@ -67,8 +67,8 @@ impl_runtime_apis! { fn same_name() {} } - impl runtime_api::Core for Runtime { - fn version() -> runtime_api::RuntimeVersion { + impl sr_api::Core for Runtime { + fn version() -> sr_version::RuntimeVersion { unimplemented!() } fn execute_block(_: Block) { @@ -80,7 +80,9 @@ impl_runtime_apis! { } } -type TestClient = client::Client; +type TestClient = test_client::client::Client< + test_client::Backend, test_client::Executor, Block, RuntimeApi +>; #[test] fn test_client_side_function_signature() { @@ -98,15 +100,19 @@ fn test_client_side_function_signature() { #[test] fn check_runtime_api_info() { - assert_eq!(&Api::::ID, &runtime_decl_for_Api::ID); - assert_eq!(Api::::VERSION, runtime_decl_for_Api::VERSION); - assert_eq!(Api::::VERSION, 1); + assert_eq!(&Api::::ID, &runtime_decl_for_Api::ID); + assert_eq!(Api::::VERSION, runtime_decl_for_Api::VERSION); + assert_eq!(Api::::VERSION, 1); assert_eq!( - ApiWithCustomVersion::::VERSION, runtime_decl_for_ApiWithCustomVersion::VERSION + ApiWithCustomVersion::::VERSION, + runtime_decl_for_ApiWithCustomVersion::VERSION, + ); + assert_eq!( + &ApiWithCustomVersion::::ID, + &runtime_decl_for_ApiWithCustomVersion::ID, ); - assert_eq!(&ApiWithCustomVersion::::ID, &runtime_decl_for_ApiWithCustomVersion::ID); - assert_eq!(ApiWithCustomVersion::::VERSION, 2); + assert_eq!(ApiWithCustomVersion::::VERSION, 2); } fn check_runtime_api_versions_contains() { @@ -115,7 +121,7 @@ fn check_runtime_api_versions_contains() { #[test] fn check_runtime_api_versions() { - check_runtime_api_versions_contains::>(); - check_runtime_api_versions_contains::>(); - check_runtime_api_versions_contains::>(); + check_runtime_api_versions_contains::>(); + check_runtime_api_versions_contains::>(); + check_runtime_api_versions_contains::>(); } diff --git a/core/sr-api-macros/tests/runtime_calls.rs b/core/sr-api/test/tests/runtime_calls.rs similarity index 100% rename from core/sr-api-macros/tests/runtime_calls.rs rename to core/sr-api/test/tests/runtime_calls.rs diff --git a/core/sr-api-macros/tests/trybuild.rs b/core/sr-api/test/tests/trybuild.rs similarity index 100% rename from core/sr-api-macros/tests/trybuild.rs rename to core/sr-api/test/tests/trybuild.rs diff --git a/core/sr-api-macros/tests/ui/adding_self_parameter.rs b/core/sr-api/test/tests/ui/adding_self_parameter.rs similarity index 50% rename from core/sr-api-macros/tests/ui/adding_self_parameter.rs rename to core/sr-api/test/tests/ui/adding_self_parameter.rs index fb048211adac3..9195598b5a437 100644 --- a/core/sr-api-macros/tests/ui/adding_self_parameter.rs +++ b/core/sr-api/test/tests/ui/adding_self_parameter.rs @@ -1,6 +1,4 @@ -use client::decl_runtime_apis; - -decl_runtime_apis! { +sr_api::decl_runtime_apis! { pub trait Api { fn test(&self); } diff --git a/core/sr-api/test/tests/ui/adding_self_parameter.stderr b/core/sr-api/test/tests/ui/adding_self_parameter.stderr new file mode 100644 index 0000000000000..894713d35eef8 --- /dev/null +++ b/core/sr-api/test/tests/ui/adding_self_parameter.stderr @@ -0,0 +1,5 @@ +error: `self` as argument not supported. + --> $DIR/adding_self_parameter.rs:3:11 + | +3 | fn test(&self); + | ^ diff --git a/core/sr-api-macros/tests/ui/changed_in_unknown_version.rs b/core/sr-api/test/tests/ui/changed_in_unknown_version.rs similarity index 89% rename from core/sr-api-macros/tests/ui/changed_in_unknown_version.rs rename to core/sr-api/test/tests/ui/changed_in_unknown_version.rs index 127236200517f..1fcb5d4be1e5a 100644 --- a/core/sr-api-macros/tests/ui/changed_in_unknown_version.rs +++ b/core/sr-api/test/tests/ui/changed_in_unknown_version.rs @@ -1,6 +1,5 @@ use sr_primitives::traits::GetNodeBlockType; use test_client::runtime::Block; -use client::decl_runtime_apis; /// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType` /// trait are done by the `construct_runtime!` macro in a real runtime. @@ -9,7 +8,7 @@ impl GetNodeBlockType for Runtime { type NodeBlock = Block; } -decl_runtime_apis! { +sr_api::decl_runtime_apis! { pub trait Api { #[changed_in(2)] fn test(data: u64); diff --git a/core/sr-api-macros/tests/ui/changed_in_unknown_version.stderr b/core/sr-api/test/tests/ui/changed_in_unknown_version.stderr similarity index 53% rename from core/sr-api-macros/tests/ui/changed_in_unknown_version.stderr rename to core/sr-api/test/tests/ui/changed_in_unknown_version.stderr index c62befbab362a..cf03ee4530ab7 100644 --- a/core/sr-api-macros/tests/ui/changed_in_unknown_version.stderr +++ b/core/sr-api/test/tests/ui/changed_in_unknown_version.stderr @@ -1,5 +1,5 @@ error: `changed_in` version can not be greater than the `api_version` - --> $DIR/changed_in_unknown_version.rs:15:3 + --> $DIR/changed_in_unknown_version.rs:14:3 | -15 | fn test(data: u64); +14 | fn test(data: u64); | ^^ diff --git a/core/sr-api-macros/tests/ui/declaring_old_block.rs b/core/sr-api/test/tests/ui/declaring_old_block.rs similarity index 67% rename from core/sr-api-macros/tests/ui/declaring_old_block.rs rename to core/sr-api/test/tests/ui/declaring_old_block.rs index 78d35579fae0c..962aae4506642 100644 --- a/core/sr-api-macros/tests/ui/declaring_old_block.rs +++ b/core/sr-api/test/tests/ui/declaring_old_block.rs @@ -1,7 +1,6 @@ use sr_primitives::traits::Block as BlockT; -use client::decl_runtime_apis; -decl_runtime_apis! { +sr_api::decl_runtime_apis! { pub trait Api { fn test(); } diff --git a/core/sr-api-macros/tests/ui/declaring_old_block.stderr b/core/sr-api/test/tests/ui/declaring_old_block.stderr similarity index 80% rename from core/sr-api-macros/tests/ui/declaring_old_block.stderr rename to core/sr-api/test/tests/ui/declaring_old_block.stderr index 999a50cc96977..e27294692b3e0 100644 --- a/core/sr-api-macros/tests/ui/declaring_old_block.stderr +++ b/core/sr-api/test/tests/ui/declaring_old_block.stderr @@ -1,13 +1,13 @@ error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro! - --> $DIR/declaring_old_block.rs:5:16 + --> $DIR/declaring_old_block.rs:4:16 | -5 | pub trait Api { +4 | pub trait Api { | ^^^^^ error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro! If you try to use a different trait than the substrate `Block` trait, please rename it locally. - --> $DIR/declaring_old_block.rs:5:23 + --> $DIR/declaring_old_block.rs:4:23 | -5 | pub trait Api { +4 | pub trait Api { | ^^^^^^ warning: unused import: `sr_primitives::traits::Block as BlockT` diff --git a/core/sr-api-macros/tests/ui/declaring_own_block_with_different_name.rs b/core/sr-api/test/tests/ui/declaring_own_block_with_different_name.rs similarity index 66% rename from core/sr-api-macros/tests/ui/declaring_own_block_with_different_name.rs rename to core/sr-api/test/tests/ui/declaring_own_block_with_different_name.rs index d63eadc1e4b73..9a47148256493 100644 --- a/core/sr-api-macros/tests/ui/declaring_own_block_with_different_name.rs +++ b/core/sr-api/test/tests/ui/declaring_own_block_with_different_name.rs @@ -1,7 +1,6 @@ use sr_primitives::traits::Block as BlockT; -use client::decl_runtime_apis; -decl_runtime_apis! { +sr_api::decl_runtime_apis! { pub trait Api { fn test(); } diff --git a/core/sr-api-macros/tests/ui/declaring_own_block_with_different_name.stderr b/core/sr-api/test/tests/ui/declaring_own_block_with_different_name.stderr similarity index 84% rename from core/sr-api-macros/tests/ui/declaring_own_block_with_different_name.stderr rename to core/sr-api/test/tests/ui/declaring_own_block_with_different_name.stderr index ec033f2e09d23..88359f19afc72 100644 --- a/core/sr-api-macros/tests/ui/declaring_own_block_with_different_name.stderr +++ b/core/sr-api/test/tests/ui/declaring_own_block_with_different_name.stderr @@ -1,7 +1,7 @@ error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro! If you try to use a different trait than the substrate `Block` trait, please rename it locally. - --> $DIR/declaring_own_block_with_different_name.rs:5:19 + --> $DIR/declaring_own_block_with_different_name.rs:4:19 | -5 | pub trait Api { +4 | pub trait Api { | ^^^^^^ warning: unused import: `sr_primitives::traits::Block as BlockT` diff --git a/core/sr-api-macros/tests/ui/empty_impl_runtime_apis_call.rs b/core/sr-api/test/tests/ui/empty_impl_runtime_apis_call.rs similarity index 80% rename from core/sr-api-macros/tests/ui/empty_impl_runtime_apis_call.rs rename to core/sr-api/test/tests/ui/empty_impl_runtime_apis_call.rs index c9c334f6fdcb5..fee4e475e39aa 100644 --- a/core/sr-api-macros/tests/ui/empty_impl_runtime_apis_call.rs +++ b/core/sr-api/test/tests/ui/empty_impl_runtime_apis_call.rs @@ -1,6 +1,5 @@ use sr_primitives::traits::GetNodeBlockType; use test_client::runtime::Block; -use client::{decl_runtime_apis, impl_runtime_apis}; /// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType` /// trait are done by the `construct_runtime!` macro in a real runtime. @@ -9,12 +8,12 @@ impl GetNodeBlockType for Runtime { type NodeBlock = Block; } -decl_runtime_apis! { +sr_api::decl_runtime_apis! { pub trait Api { fn test(data: u64); } } -impl_runtime_apis! {} +sr_api::impl_runtime_apis! {} fn main() {} diff --git a/core/sr-api/test/tests/ui/empty_impl_runtime_apis_call.stderr b/core/sr-api/test/tests/ui/empty_impl_runtime_apis_call.stderr new file mode 100644 index 0000000000000..e7bf3b8563f93 --- /dev/null +++ b/core/sr-api/test/tests/ui/empty_impl_runtime_apis_call.stderr @@ -0,0 +1,5 @@ +error: No api implementation given! + --> $DIR/empty_impl_runtime_apis_call.rs:17:1 + | +17 | sr_api::impl_runtime_apis! {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation diff --git a/core/sr-api-macros/tests/ui/impl_incorrect_method_signature.rs b/core/sr-api/test/tests/ui/impl_incorrect_method_signature.rs similarity index 81% rename from core/sr-api-macros/tests/ui/impl_incorrect_method_signature.rs rename to core/sr-api/test/tests/ui/impl_incorrect_method_signature.rs index b85431f3ba049..08c3ce8320fb5 100644 --- a/core/sr-api-macros/tests/ui/impl_incorrect_method_signature.rs +++ b/core/sr-api/test/tests/ui/impl_incorrect_method_signature.rs @@ -1,6 +1,5 @@ use sr_primitives::traits::{GetNodeBlockType, Block as BlockT}; use test_client::runtime::Block; -use client::{decl_runtime_apis, impl_runtime_apis, runtime_api}; /// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType` /// trait are done by the `construct_runtime!` macro in a real runtime. @@ -9,18 +8,18 @@ impl GetNodeBlockType for Runtime { type NodeBlock = Block; } -decl_runtime_apis! { +sr_api::decl_runtime_apis! { pub trait Api { fn test(data: u64); } } -impl_runtime_apis! { +sr_api::impl_runtime_apis! { impl self::Api for Runtime { fn test(data: String) {} } - impl runtime_api::Core for Runtime { + impl sr_api::Core for Runtime { fn version() -> runtime_api::RuntimeVersion { unimplemented!() } diff --git a/core/sr-api/test/tests/ui/impl_incorrect_method_signature.stderr b/core/sr-api/test/tests/ui/impl_incorrect_method_signature.stderr new file mode 100644 index 0000000000000..2bf8da343fe6b --- /dev/null +++ b/core/sr-api/test/tests/ui/impl_incorrect_method_signature.stderr @@ -0,0 +1,70 @@ +error[E0433]: failed to resolve: use of undeclared type or module `runtime_api` + --> $DIR/impl_incorrect_method_signature.rs:23:19 + | +23 | fn version() -> runtime_api::RuntimeVersion { + | ^^^^^^^^^^^ use of undeclared type or module `runtime_api` + +error[E0053]: method `test` has an incompatible type for trait + --> $DIR/impl_incorrect_method_signature.rs:19:17 + | +13 | fn test(data: u64); + | --- type in trait +... +19 | fn test(data: String) {} + | ^^^^^^ expected u64, found struct `std::string::String` + | + = note: expected type `fn(u64)` + found type `fn(std::string::String)` + +error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for trait + --> $DIR/impl_incorrect_method_signature.rs:17:1 + | +11 | / sr_api::decl_runtime_apis! { +12 | | pub trait Api { +13 | | fn test(data: u64); +14 | | } +15 | | } + | |_- type in trait +16 | +17 | sr_api::impl_runtime_apis! { + | -^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | _expected u64, found struct `std::string::String` + | | +18 | | impl self::Api for Runtime { +19 | | fn test(data: String) {} +20 | | } +... | +32 | | } +33 | | } + | |_- in this macro invocation + | + = note: expected type `fn(&RuntimeApiImpl, &sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::BlockId, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::ExecutionContext, std::option::Option, std::vec::Vec) -> std::result::Result, , substrate_test_runtime::Extrinsic>>>::Error>` + found type `fn(&RuntimeApiImpl, &sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::BlockId, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::ExecutionContext, std::option::Option, std::vec::Vec) -> std::result::Result, , substrate_test_runtime::Extrinsic>>>::Error>` + +error[E0308]: mismatched types + --> $DIR/impl_incorrect_method_signature.rs:17:1 + | +17 | / sr_api::impl_runtime_apis! { +18 | | impl self::Api for Runtime { +19 | | fn test(data: String) {} +20 | | } +... | +32 | | } +33 | | } + | | ^ + | | | + | |_expected u64, found struct `std::string::String` + | in this macro invocation + | + = note: expected type `u64` + found type `std::string::String` + +error[E0308]: mismatched types + --> $DIR/impl_incorrect_method_signature.rs:19:11 + | +19 | fn test(data: String) {} + | ^^^^ expected u64, found struct `std::string::String` + | + = note: expected type `u64` + found type `std::string::String` diff --git a/core/sr-api-macros/tests/ui/impl_two_traits_with_same_name.rs b/core/sr-api/test/tests/ui/impl_two_traits_with_same_name.rs similarity index 86% rename from core/sr-api-macros/tests/ui/impl_two_traits_with_same_name.rs rename to core/sr-api/test/tests/ui/impl_two_traits_with_same_name.rs index 1664bec577b57..6aee0ec6c2bb4 100644 --- a/core/sr-api-macros/tests/ui/impl_two_traits_with_same_name.rs +++ b/core/sr-api/test/tests/ui/impl_two_traits_with_same_name.rs @@ -1,6 +1,5 @@ use sr_primitives::traits::GetNodeBlockType; use test_client::runtime::Block; -use client::{decl_runtime_apis, impl_runtime_apis}; /// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType` /// trait are done by the `construct_runtime!` macro in a real runtime. @@ -9,7 +8,7 @@ impl GetNodeBlockType for Runtime { type NodeBlock = Block; } -decl_runtime_apis! { +sr_api::decl_runtime_apis! { pub trait Api { fn test(data: u64); } @@ -25,7 +24,7 @@ mod second { } } -impl_runtime_apis! { +sr_api::impl_runtime_apis! { impl self::Api for Runtime { fn test(data: u64) {} } diff --git a/core/sr-api/test/tests/ui/impl_two_traits_with_same_name.stderr b/core/sr-api/test/tests/ui/impl_two_traits_with_same_name.stderr new file mode 100644 index 0000000000000..9aa38805b940f --- /dev/null +++ b/core/sr-api/test/tests/ui/impl_two_traits_with_same_name.stderr @@ -0,0 +1,77 @@ +error: Two traits with the same name detected! The trait name is used to generate its ID. Please rename one trait at the declaration! + --> $DIR/impl_two_traits_with_same_name.rs:32:15 + | +32 | impl second::Api for Runtime { + | ^^^ + +error: cannot find macro `decl_runtime_apis` in this scope + --> $DIR/impl_two_traits_with_same_name.rs:20:2 + | +20 | decl_runtime_apis! { + | ^^^^^^^^^^^^^^^^^ + +error[E0425]: cannot find function `test2_call_api_at` in `second::runtime_decl_for_Api` + --> $DIR/impl_two_traits_with_same_name.rs:27:1 + | +27 | / sr_api::impl_runtime_apis! { +28 | | impl self::Api for Runtime { +29 | | fn test(data: u64) {} +30 | | } +... | +34 | | } +35 | | } + | | ^ + | | | + | |_not found in `second::runtime_decl_for_Api` + | in this macro invocation + +error[E0425]: cannot find function `test2_native_call_generator` in `second::runtime_decl_for_Api` + --> $DIR/impl_two_traits_with_same_name.rs:27:1 + | +27 | / sr_api::impl_runtime_apis! { +28 | | impl self::Api for Runtime { +29 | | fn test(data: u64) {} +30 | | } +... | +34 | | } +35 | | } + | | ^ + | | | + | |_not found in `second::runtime_decl_for_Api` + | in this macro invocation + +error[E0576]: cannot find method or associated constant `test2` in `second::runtime_decl_for_Api::Api` + --> $DIR/impl_two_traits_with_same_name.rs:33:6 + | +33 | fn test2(data: u64) {} + | ^^^^^ not found in `second::runtime_decl_for_Api::Api` + +error[E0603]: module `runtime_decl_for_Api` is private + --> $DIR/impl_two_traits_with_same_name.rs:27:1 + | +27 | / sr_api::impl_runtime_apis! { +28 | | impl self::Api for Runtime { +29 | | fn test(data: u64) {} +30 | | } +... | +34 | | } +35 | | } + | |_^ + +error[E0119]: conflicting implementations of trait `runtime_decl_for_Api::Api, substrate_test_runtime::Extrinsic>>` for type `Runtime`: + --> $DIR/impl_two_traits_with_same_name.rs:32:2 + | +28 | impl self::Api for Runtime { + | --------------------------------- first implementation here +... +32 | impl second::Api for Runtime { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Runtime` + +error[E0119]: conflicting implementations of trait `Api, substrate_test_runtime::Extrinsic>>` for type `RuntimeApiImpl<_>`: + --> $DIR/impl_two_traits_with_same_name.rs:32:2 + | +28 | impl self::Api for Runtime { + | --------------------------------- first implementation here +... +32 | impl second::Api for Runtime { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `RuntimeApiImpl<_>` diff --git a/core/sr-api-macros/tests/ui/invalid_api_version.rs b/core/sr-api/test/tests/ui/invalid_api_version.rs similarity index 58% rename from core/sr-api-macros/tests/ui/invalid_api_version.rs rename to core/sr-api/test/tests/ui/invalid_api_version.rs index b5afa1d6998ef..0b7f5e88ff74b 100644 --- a/core/sr-api-macros/tests/ui/invalid_api_version.rs +++ b/core/sr-api/test/tests/ui/invalid_api_version.rs @@ -1,6 +1,4 @@ -use client::decl_runtime_apis; - -decl_runtime_apis! { +sr_api::decl_runtime_apis! { #[api_version] pub trait Api { fn test(data: u64); diff --git a/core/sr-api-macros/tests/ui/invalid_api_version.stderr b/core/sr-api/test/tests/ui/invalid_api_version.stderr similarity index 50% rename from core/sr-api-macros/tests/ui/invalid_api_version.stderr rename to core/sr-api/test/tests/ui/invalid_api_version.stderr index dcdbded81fe4b..7e63eb8ebf8a4 100644 --- a/core/sr-api-macros/tests/ui/invalid_api_version.stderr +++ b/core/sr-api/test/tests/ui/invalid_api_version.stderr @@ -1,12 +1,12 @@ error: can't qualify macro invocation with `pub` - --> $DIR/invalid_api_version.rs:3:1 + --> $DIR/invalid_api_version.rs:1:1 | -3 | / decl_runtime_apis! { -4 | | #[api_version] -5 | | pub trait Api { -6 | | fn test(data: u64); -7 | | } -8 | | } +1 | / sr_api::decl_runtime_apis! { +2 | | #[api_version] +3 | | pub trait Api { +4 | | fn test(data: u64); +5 | | } +6 | | } | | ^ in this macro invocation | |_| | @@ -14,20 +14,20 @@ error: can't qualify macro invocation with `pub` = help: try adjusting the macro to put `pub` inside the invocation error: Unexpected `api_version` attribute. The supported format is `api_version(1)` - --> $DIR/invalid_api_version.rs:3:1 + --> $DIR/invalid_api_version.rs:1:1 | -3 | / decl_runtime_apis! { -4 | | #[api_version] -5 | | pub trait Api { -6 | | fn test(data: u64); -7 | | } -8 | | } +1 | / sr_api::decl_runtime_apis! { +2 | | #[api_version] +3 | | pub trait Api { +4 | | fn test(data: u64); +5 | | } +6 | | } | | ^ in this macro invocation | |_| | error: Unexpected `api_version` attribute. The supported format is `api_version(1)` - --> $DIR/invalid_api_version.rs:4:4 + --> $DIR/invalid_api_version.rs:2:4 | -4 | #[api_version] +2 | #[api_version] | ^^^^^^^^^^^ diff --git a/core/sr-api-macros/tests/ui/invalid_api_version_2.rs b/core/sr-api/test/tests/ui/invalid_api_version_2.rs similarity index 59% rename from core/sr-api-macros/tests/ui/invalid_api_version_2.rs rename to core/sr-api/test/tests/ui/invalid_api_version_2.rs index b8870838009bf..4e29d36e1ba2f 100644 --- a/core/sr-api-macros/tests/ui/invalid_api_version_2.rs +++ b/core/sr-api/test/tests/ui/invalid_api_version_2.rs @@ -1,6 +1,4 @@ -use client::decl_runtime_apis; - -decl_runtime_apis! { +sr_api::decl_runtime_apis! { #[api_version("1")] pub trait Api { fn test(data: u64); diff --git a/core/sr-api/test/tests/ui/invalid_api_version_2.stderr b/core/sr-api/test/tests/ui/invalid_api_version_2.stderr new file mode 100644 index 0000000000000..e080b2dd1a0d6 --- /dev/null +++ b/core/sr-api/test/tests/ui/invalid_api_version_2.stderr @@ -0,0 +1,33 @@ +error: can't qualify macro invocation with `pub` + --> $DIR/invalid_api_version_2.rs:1:1 + | +1 | / sr_api::decl_runtime_apis! { +2 | | #[api_version("1")] +3 | | pub trait Api { +4 | | fn test(data: u64); +5 | | } +6 | | } + | | ^ in this macro invocation + | |_| + | + | + = help: try adjusting the macro to put `pub` inside the invocation + +error: Unexpected `api_version` attribute. The supported format is `api_version(1)` + --> $DIR/invalid_api_version_2.rs:1:1 + | +1 | / sr_api::decl_runtime_apis! { +2 | | #[api_version("1")] +3 | | pub trait Api { +4 | | fn test(data: u64); +5 | | } +6 | | } + | | ^ in this macro invocation + | |_| + | + +error: Unexpected `api_version` attribute. The supported format is `api_version(1)` + --> $DIR/invalid_api_version_2.rs:2:4 + | +2 | #[api_version("1")] + | ^^^^^^^^^^^ diff --git a/core/sr-api-macros/tests/ui/invalid_api_version_3.rs b/core/sr-api/test/tests/ui/invalid_api_version_3.rs similarity index 58% rename from core/sr-api-macros/tests/ui/invalid_api_version_3.rs rename to core/sr-api/test/tests/ui/invalid_api_version_3.rs index 6f365b146b222..bafe566840d25 100644 --- a/core/sr-api-macros/tests/ui/invalid_api_version_3.rs +++ b/core/sr-api/test/tests/ui/invalid_api_version_3.rs @@ -1,6 +1,4 @@ -use client::decl_runtime_apis; - -decl_runtime_apis! { +sr_api::decl_runtime_apis! { #[api_version()] pub trait Api { fn test(data: u64); diff --git a/core/sr-api/test/tests/ui/invalid_api_version_3.stderr b/core/sr-api/test/tests/ui/invalid_api_version_3.stderr new file mode 100644 index 0000000000000..fd6e15852f74b --- /dev/null +++ b/core/sr-api/test/tests/ui/invalid_api_version_3.stderr @@ -0,0 +1,33 @@ +error: can't qualify macro invocation with `pub` + --> $DIR/invalid_api_version_3.rs:1:1 + | +1 | / sr_api::decl_runtime_apis! { +2 | | #[api_version()] +3 | | pub trait Api { +4 | | fn test(data: u64); +5 | | } +6 | | } + | | ^ in this macro invocation + | |_| + | + | + = help: try adjusting the macro to put `pub` inside the invocation + +error: Unexpected `api_version` attribute. The supported format is `api_version(1)` + --> $DIR/invalid_api_version_3.rs:1:1 + | +1 | / sr_api::decl_runtime_apis! { +2 | | #[api_version()] +3 | | pub trait Api { +4 | | fn test(data: u64); +5 | | } +6 | | } + | | ^ in this macro invocation + | |_| + | + +error: Unexpected `api_version` attribute. The supported format is `api_version(1)` + --> $DIR/invalid_api_version_3.rs:2:4 + | +2 | #[api_version()] + | ^^^^^^^^^^^ diff --git a/core/sr-api-macros/tests/ui/missing_block_generic_parameter.rs b/core/sr-api/test/tests/ui/missing_block_generic_parameter.rs similarity index 83% rename from core/sr-api-macros/tests/ui/missing_block_generic_parameter.rs rename to core/sr-api/test/tests/ui/missing_block_generic_parameter.rs index 99755144f7556..d35253a7219a4 100644 --- a/core/sr-api-macros/tests/ui/missing_block_generic_parameter.rs +++ b/core/sr-api/test/tests/ui/missing_block_generic_parameter.rs @@ -1,6 +1,5 @@ use sr_primitives::traits::GetNodeBlockType; use test_client::runtime::Block; -use client::{decl_runtime_apis, impl_runtime_apis}; /// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType` /// trait are done by the `construct_runtime!` macro in a real runtime. @@ -9,13 +8,13 @@ impl GetNodeBlockType for Runtime { type NodeBlock = Block; } -decl_runtime_apis! { +sr_api::decl_runtime_apis! { pub trait Api { fn test(data: u64); } } -impl_runtime_apis! { +sr_api::impl_runtime_apis! { impl self::Api for Runtime { fn test(data: u64) { unimplemented!() diff --git a/core/sr-api/test/tests/ui/missing_block_generic_parameter.stderr b/core/sr-api/test/tests/ui/missing_block_generic_parameter.stderr new file mode 100644 index 0000000000000..61311c14b882d --- /dev/null +++ b/core/sr-api/test/tests/ui/missing_block_generic_parameter.stderr @@ -0,0 +1,11 @@ +error: Missing `Block` generic parameter. + --> $DIR/missing_block_generic_parameter.rs:18:13 + | +18 | impl self::Api for Runtime { + | ^^^ + +error[E0107]: wrong number of type arguments: expected 1, found 0 + --> $DIR/missing_block_generic_parameter.rs:18:7 + | +18 | impl self::Api for Runtime { + | ^^^^^^^^^ expected 1 type argument diff --git a/core/sr-api-macros/tests/ui/missing_path_for_trait.rs b/core/sr-api/test/tests/ui/missing_path_for_trait.rs similarity index 83% rename from core/sr-api-macros/tests/ui/missing_path_for_trait.rs rename to core/sr-api/test/tests/ui/missing_path_for_trait.rs index f6f6e3dfb3c43..fb78374ebdf70 100644 --- a/core/sr-api-macros/tests/ui/missing_path_for_trait.rs +++ b/core/sr-api/test/tests/ui/missing_path_for_trait.rs @@ -1,6 +1,5 @@ use sr_primitives::traits::GetNodeBlockType; use test_client::runtime::Block; -use client::{decl_runtime_apis, impl_runtime_apis}; /// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType` /// trait are done by the `construct_runtime!` macro in a real runtime. @@ -9,13 +8,13 @@ impl GetNodeBlockType for Runtime { type NodeBlock = Block; } -decl_runtime_apis! { +sr_api::decl_runtime_apis! { pub trait Api { fn test(data: u64); } } -impl_runtime_apis! { +sr_api::impl_runtime_apis! { impl Api for Runtime { fn test(data: u64) { unimplemented!() diff --git a/core/sr-api-macros/tests/ui/missing_path_for_trait.stderr b/core/sr-api/test/tests/ui/missing_path_for_trait.stderr similarity index 60% rename from core/sr-api-macros/tests/ui/missing_path_for_trait.stderr rename to core/sr-api/test/tests/ui/missing_path_for_trait.stderr index 4018712e3f5b3..729ff0bad18d8 100644 --- a/core/sr-api-macros/tests/ui/missing_path_for_trait.stderr +++ b/core/sr-api/test/tests/ui/missing_path_for_trait.stderr @@ -1,5 +1,5 @@ error: The implemented trait has to be referenced with a path, e.g. `impl client::Core for Runtime`. - --> $DIR/missing_path_for_trait.rs:19:7 + --> $DIR/missing_path_for_trait.rs:18:7 | -19 | impl Api for Runtime { +18 | impl Api for Runtime { | ^^^ diff --git a/core/sr-api-macros/tests/ui/type_reference_in_impl_runtime_apis_call.rs b/core/sr-api/test/tests/ui/type_reference_in_impl_runtime_apis_call.rs similarity index 82% rename from core/sr-api-macros/tests/ui/type_reference_in_impl_runtime_apis_call.rs rename to core/sr-api/test/tests/ui/type_reference_in_impl_runtime_apis_call.rs index 20f114c6bb29e..41bbd8a9eee53 100644 --- a/core/sr-api-macros/tests/ui/type_reference_in_impl_runtime_apis_call.rs +++ b/core/sr-api/test/tests/ui/type_reference_in_impl_runtime_apis_call.rs @@ -1,6 +1,5 @@ use sr_primitives::traits::{GetNodeBlockType, Block as BlockT}; use test_client::runtime::Block; -use client::{decl_runtime_apis, impl_runtime_apis, runtime_api}; /// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType` /// trait are done by the `construct_runtime!` macro in a real runtime. @@ -9,20 +8,20 @@ impl GetNodeBlockType for Runtime { type NodeBlock = Block; } -decl_runtime_apis! { +sr_api::decl_runtime_apis! { pub trait Api { fn test(data: u64); } } -impl_runtime_apis! { +sr_api::impl_runtime_apis! { impl self::Api for Runtime { fn test(data: &u64) { unimplemented!() } } - impl runtime_api::Core for Runtime { + impl sr_api::Core for Runtime { fn version() -> runtime_api::RuntimeVersion { unimplemented!() } diff --git a/core/sr-api/test/tests/ui/type_reference_in_impl_runtime_apis_call.stderr b/core/sr-api/test/tests/ui/type_reference_in_impl_runtime_apis_call.stderr new file mode 100644 index 0000000000000..4614fe89b8cea --- /dev/null +++ b/core/sr-api/test/tests/ui/type_reference_in_impl_runtime_apis_call.stderr @@ -0,0 +1,73 @@ +error[E0433]: failed to resolve: use of undeclared type or module `runtime_api` + --> $DIR/type_reference_in_impl_runtime_apis_call.rs:25:19 + | +25 | fn version() -> runtime_api::RuntimeVersion { + | ^^^^^^^^^^^ use of undeclared type or module `runtime_api` + +error[E0053]: method `test` has an incompatible type for trait + --> $DIR/type_reference_in_impl_runtime_apis_call.rs:19:17 + | +13 | fn test(data: u64); + | --- type in trait +... +19 | fn test(data: &u64) { + | ^^^^ expected u64, found &u64 + | + = note: expected type `fn(u64)` + found type `fn(&u64)` + +error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for trait + --> $DIR/type_reference_in_impl_runtime_apis_call.rs:17:1 + | +11 | / sr_api::decl_runtime_apis! { +12 | | pub trait Api { +13 | | fn test(data: u64); +14 | | } +15 | | } + | |_- type in trait +16 | +17 | sr_api::impl_runtime_apis! { + | -^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | _expected u64, found &u64 + | | +18 | | impl self::Api for Runtime { +19 | | fn test(data: &u64) { +20 | | unimplemented!() +... | +34 | | } +35 | | } + | |_- in this macro invocation + | + = note: expected type `fn(&RuntimeApiImpl, &sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::BlockId, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::ExecutionContext, std::option::Option, std::vec::Vec) -> std::result::Result, , substrate_test_runtime::Extrinsic>>>::Error>` + found type `fn(&RuntimeApiImpl, &sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::BlockId, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::ExecutionContext, std::option::Option<&u64>, std::vec::Vec) -> std::result::Result, , substrate_test_runtime::Extrinsic>>>::Error>` + +error[E0308]: mismatched types + --> $DIR/type_reference_in_impl_runtime_apis_call.rs:17:1 + | +17 | / sr_api::impl_runtime_apis! { +18 | | impl self::Api for Runtime { +19 | | fn test(data: &u64) { +20 | | unimplemented!() +... | +34 | | } +35 | | } + | | ^ + | | | + | |_expected u64, found &u64 + | in this macro invocation + | + = note: expected type `u64` + found type `&u64` + +error[E0308]: mismatched types + --> $DIR/type_reference_in_impl_runtime_apis_call.rs:19:11 + | +19 | fn test(data: &u64) { + | ^^^^^^^ + | | + | expected u64, found &u64 + | help: consider removing the borrow: `data` + | + = note: expected type `u64` + found type `&u64` diff --git a/core/sr-primitives/Cargo.toml b/core/sr-primitives/Cargo.toml index 1b1434b91930d..5785a17e6874c 100644 --- a/core/sr-primitives/Cargo.toml +++ b/core/sr-primitives/Cargo.toml @@ -16,6 +16,7 @@ log = { version = "0.4.8", optional = true } paste = "0.1.6" rand = { version = "0.7.2", optional = true } impl-trait-for-tuples = "0.1.3" +inherents = { package = "substrate-inherents", path = "../inherents", default-features = false } [dev-dependencies] serde_json = "1.0.41" @@ -35,4 +36,5 @@ std = [ "rstd/std", "runtime_io/std", "serde", + "inherents/std", ] diff --git a/core/sr-primitives/src/lib.rs b/core/sr-primitives/src/lib.rs index 4213f152e9386..f072661d611aa 100644 --- a/core/sr-primitives/src/lib.rs +++ b/core/sr-primitives/src/lib.rs @@ -45,12 +45,11 @@ use rstd::convert::TryFrom; use primitives::{crypto, ed25519, sr25519, ecdsa, hash::{H256, H512}}; use codec::{Encode, Decode}; -#[cfg(feature = "std")] -pub mod testing; - pub mod curve; pub mod generic; pub mod offchain; +#[cfg(feature = "std")] +pub mod testing; pub mod traits; pub mod transaction_validity; pub mod weights; @@ -93,19 +92,19 @@ impl TypeId for ModuleId { /// A String that is a `&'static str` on `no_std` and a `Cow<'static, str>` on `std`. #[cfg(feature = "std")] -pub type RuntimeString = ::std::borrow::Cow<'static, str>; +pub type RuntimeString = std::borrow::Cow<'static, str>; /// A String that is a `&'static str` on `no_std` and a `Cow<'static, str>` on `std`. #[cfg(not(feature = "std"))] pub type RuntimeString = &'static str; -/// Create a const [RuntimeString]. +/// Create a const [`RuntimeString`]. #[cfg(feature = "std")] #[macro_export] macro_rules! create_runtime_str { - ( $y:expr ) => {{ ::std::borrow::Cow::Borrowed($y) }} + ( $y:expr ) => {{ std::borrow::Cow::Borrowed($y) }} } -/// Create a const [RuntimeString]. +/// Create a const [`RuntimeString`]. #[cfg(not(feature = "std"))] #[macro_export] macro_rules! create_runtime_str { diff --git a/core/sr-primitives/src/traits.rs b/core/sr-primitives/src/traits.rs index 8805611d1435b..edddaf035aa95 100644 --- a/core/sr-primitives/src/traits.rs +++ b/core/sr-primitives/src/traits.rs @@ -1250,6 +1250,25 @@ impl Printable for Tuple { } } +/// Something that can convert a [`BlockId`] to a number or a hash. +#[cfg(feature = "std")] +pub trait BlockIdTo { + /// The error type that will be returned by the functions. + type Error: std::fmt::Debug; + + /// Convert the given `block_id` to the corresponding block hash. + fn to_hash( + &self, + block_id: &crate::generic::BlockId, + ) -> Result, Self::Error>; + + /// Convert the given `block_id` to the corresponding block number. + fn to_number( + &self, + block_id: &crate::generic::BlockId, + ) -> Result>, Self::Error>; +} + #[cfg(test)] mod tests { use super::AccountIdConversion; diff --git a/core/sr-version/src/lib.rs b/core/sr-version/src/lib.rs index 24c54a739a2e0..f342c25217926 100644 --- a/core/sr-version/src/lib.rs +++ b/core/sr-version/src/lib.rs @@ -49,7 +49,7 @@ pub type ApisVec = &'static [(ApiId, u32)]; #[macro_export] #[cfg(feature = "std")] macro_rules! create_apis_vec { - ( $y:expr ) => { ::std::borrow::Cow::Borrowed(& $y) } + ( $y:expr ) => { std::borrow::Cow::Borrowed(& $y) } } #[macro_export] #[cfg(not(feature = "std"))] diff --git a/core/test-runtime/Cargo.toml b/core/test-runtime/Cargo.toml index 189a46eb7eebe..022b6d8c196ea 100644 --- a/core/test-runtime/Cargo.toml +++ b/core/test-runtime/Cargo.toml @@ -10,7 +10,8 @@ log = { version = "0.4.8", optional = true } serde = { version = "1.0.101", optional = true, features = ["derive"] } codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } keyring = { package = "substrate-keyring", path = "../keyring", optional = true } -substrate-client = { path = "../client", default-features = false } +sr-api = { path = "../sr-api", default-features = false } +substrate-client = { path = "../client", optional = true } primitives = { package = "substrate-primitives", path = "../primitives", default-features = false } app-crypto = { package = "substrate-application-crypto", path = "../application-crypto", default-features = false } inherents = { package = "substrate-inherents", path = "../inherents", default-features = false } @@ -33,6 +34,8 @@ srml-babe = { path = "../../srml/babe", default-features = false } srml-timestamp = { path = "../../srml/timestamp", default-features = false } srml-system = { path = "../../srml/system", default-features = false } srml-system-rpc-runtime-api = { path = "../../srml/system/rpc/runtime-api", default-features = false } +transaction-pool-api = { package = "substrate-transaction-pool-runtime-api", path = "../transaction-pool/runtime-api", default-features = false } +block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../block-builder/runtime-api", default-features = false } [dev-dependencies] substrate-executor = { path = "../executor" } @@ -49,7 +52,7 @@ default = [ std = [ "log", "serde", - "substrate-client/std", + "sr-api/std", "keyring", "codec/std", "rstd/std", @@ -74,4 +77,7 @@ std = [ "app-crypto/std", "session/std", "runtime-interface/std", + "transaction-pool-api/std", + "block-builder-api/std", + "substrate-client", ] diff --git a/core/test-runtime/client/Cargo.toml b/core/test-runtime/client/Cargo.toml index 6545048759687..c2f8b4346bef9 100644 --- a/core/test-runtime/client/Cargo.toml +++ b/core/test-runtime/client/Cargo.toml @@ -7,14 +7,8 @@ edition = "2018" [dependencies] generic-test-client = { package = "substrate-test-client", path = "../../test-client" } primitives = { package = "substrate-primitives", path = "../../primitives" } -runtime = { package = "substrate-test-runtime", path = "../../test-runtime", default-features = false } +block-builder = { package = "substrate-block-builder", path = "../../block-builder" } +runtime = { package = "substrate-test-runtime", path = "../../test-runtime" } sr-primitives = { path = "../../sr-primitives" } -codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.0.0" } -[features] -default = [ - "std", -] -std = [ - "runtime/std", -] diff --git a/core/test-runtime/client/src/block_builder_ext.rs b/core/test-runtime/client/src/block_builder_ext.rs index c389a946bab86..6bd3ed18ebeb6 100644 --- a/core/test-runtime/client/src/block_builder_ext.rs +++ b/core/test-runtime/client/src/block_builder_ext.rs @@ -19,25 +19,34 @@ use runtime; use sr_primitives::traits::ProvideRuntimeApi; use generic_test_client::client; -use generic_test_client::client::block_builder::api::BlockBuilder; + +use block_builder::BlockBuilderApi; /// Extension trait for test block builder. pub trait BlockBuilderExt { /// Add transfer extrinsic to the block. fn push_transfer(&mut self, transfer: runtime::Transfer) -> Result<(), client::error::Error>; /// Add storage change extrinsic to the block. - fn push_storage_change(&mut self, key: Vec, value: Option>) -> Result<(), client::error::Error>; + fn push_storage_change( + &mut self, + key: Vec, + value: Option>, + ) -> Result<(), client::error::Error>; } -impl<'a, A> BlockBuilderExt for client::block_builder::BlockBuilder<'a, runtime::Block, A> where - A: ProvideRuntimeApi + client::blockchain::HeaderBackend + 'a, - A::Api: BlockBuilder +impl<'a, A> BlockBuilderExt for block_builder::BlockBuilder<'a, runtime::Block, A> where + A: ProvideRuntimeApi + 'a, + A::Api: BlockBuilderApi, { fn push_transfer(&mut self, transfer: runtime::Transfer) -> Result<(), client::error::Error> { self.push(transfer.into_signed_tx()) } - fn push_storage_change(&mut self, key: Vec, value: Option>) -> Result<(), client::error::Error> { + fn push_storage_change( + &mut self, + key: Vec, + value: Option>, + ) -> Result<(), client::error::Error> { self.push(runtime::Extrinsic::StorageChange(key, value)) } } diff --git a/core/test-runtime/src/lib.rs b/core/test-runtime/src/lib.rs index 24443233720a1..2bd6cc6bcbd1c 100644 --- a/core/test-runtime/src/lib.rs +++ b/core/test-runtime/src/lib.rs @@ -32,10 +32,7 @@ use trie_db::{TrieMut, Trie}; use substrate_trie::PrefixedMemoryDB; use substrate_trie::trie_types::{TrieDB, TrieDBMut}; -use substrate_client::{ - runtime_api as client_api, block_builder::api as block_builder_api, decl_runtime_apis, - impl_runtime_apis, -}; +use sr_api::{decl_runtime_apis, impl_runtime_apis}; use sr_primitives::{ ApplyResult, create_runtime_str, Perbill, impl_opaque_keys, transaction_validity::{ @@ -460,7 +457,7 @@ static mut MUTABLE_STATIC: u64 = 32; cfg_if! { if #[cfg(feature = "std")] { impl_runtime_apis! { - impl client_api::Core for Runtime { + impl sr_api::Core for Runtime { fn version() -> RuntimeVersion { version() } @@ -474,13 +471,13 @@ cfg_if! { } } - impl client_api::Metadata for Runtime { + impl sr_api::Metadata for Runtime { fn metadata() -> OpaqueMetadata { unimplemented!() } } - impl client_api::TaggedTransactionQueue for Runtime { + impl transaction_pool_api::TaggedTransactionQueue for Runtime { fn validate_transaction(utx: ::Extrinsic) -> TransactionValidity { if let Extrinsic::IncludeData(data) = utx { return Ok(ValidTransaction { @@ -645,7 +642,7 @@ cfg_if! { } } else { impl_runtime_apis! { - impl client_api::Core for Runtime { + impl sr_api::Core for Runtime { fn version() -> RuntimeVersion { version() } @@ -659,13 +656,13 @@ cfg_if! { } } - impl client_api::Metadata for Runtime { + impl sr_api::Metadata for Runtime { fn metadata() -> OpaqueMetadata { unimplemented!() } } - impl client_api::TaggedTransactionQueue for Runtime { + impl transaction_pool_api::TaggedTransactionQueue for Runtime { fn validate_transaction(utx: ::Extrinsic) -> TransactionValidity { if let Extrinsic::IncludeData(data) = utx { return Ok(ValidTransaction{ diff --git a/core/transaction-pool/Cargo.toml b/core/transaction-pool/Cargo.toml index 60803fd42a9c3..c0222f9a00db3 100644 --- a/core/transaction-pool/Cargo.toml +++ b/core/transaction-pool/Cargo.toml @@ -11,9 +11,10 @@ futures = { version = "0.3.0", features = ["thread-pool"] } codec = { package = "parity-scale-codec", version = "1.0.0" } parking_lot = "0.9.0" sr-primitives = { path = "../sr-primitives" } -client = { package = "substrate-client", path = "../client" } primitives = { package = "substrate-primitives", path = "../primitives" } txpool = { package = "substrate-transaction-graph", path = "./graph" } +tx-runtime-api = { package = "substrate-transaction-pool-runtime-api", path = "runtime-api" } +sr-api = { path = "../sr-api" } [dev-dependencies] keyring = { package = "substrate-keyring", path = "../../core/keyring" } diff --git a/core/transaction-pool/runtime-api/Cargo.toml b/core/transaction-pool/runtime-api/Cargo.toml new file mode 100644 index 0000000000000..087d4644fd6a8 --- /dev/null +++ b/core/transaction-pool/runtime-api/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "substrate-transaction-pool-runtime-api" +version = "2.0.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +sr-primitives = { path = "../../sr-primitives", default-features = false } +primitives = { package = "substrate-primitives", path = "../../primitives", default-features = false } +sr-api = { path = "../../sr-api", default-features = false } + +[features] +default = [ "std" ] +std = [ "sr-primitives/std", "primitives/std", "sr-api/std" ] diff --git a/core/client/src/block_builder/mod.rs b/core/transaction-pool/runtime-api/src/lib.rs similarity index 60% rename from core/client/src/block_builder/mod.rs rename to core/transaction-pool/runtime-api/src/lib.rs index 7f617044a42cf..48d0f8a85dd31 100644 --- a/core/client/src/block_builder/mod.rs +++ b/core/transaction-pool/runtime-api/src/lib.rs @@ -14,10 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -//! Utility struct to build a block. +//! Substrate runtime api for the transaction queue. -#[cfg(feature = "std")] -mod block_builder; -#[cfg(feature = "std")] -pub use self::block_builder::*; -pub mod api; +#![cfg_attr(not(feature = "std"), no_std)] + +use sr_primitives::{transaction_validity::TransactionValidity, traits::Block as BlockT}; + +sr_api::decl_runtime_apis! { + /// The `TaggedTransactionQueue` api trait for interfering with the transaction queue. + pub trait TaggedTransactionQueue { + /// Validate the given transaction. + fn validate_transaction(tx: ::Extrinsic) -> TransactionValidity; + } +} diff --git a/core/transaction-pool/src/api.rs b/core/transaction-pool/src/api.rs index 7f88ab99b96d5..28681fb11ba8a 100644 --- a/core/transaction-pool/src/api.rs +++ b/core/transaction-pool/src/api.rs @@ -16,31 +16,19 @@ //! Chain api required for the transaction pool. -use std::{ - marker::PhantomData, - pin::Pin, - sync::Arc, -}; -use client::{runtime_api::TaggedTransactionQueue, blockchain::HeaderBackend}; +use std::{marker::PhantomData, pin::Pin, sync::Arc}; + use codec::Encode; -use futures::{ - channel::oneshot, - executor::{ThreadPool, ThreadPoolBuilder}, - future::Future, -}; -use txpool; -use primitives::{ - H256, - Blake2Hasher, - Hasher, -}; -use sr_primitives::{ - generic::BlockId, - traits, - transaction_validity::TransactionValidity, -}; - -use crate::error; + +use futures::{channel::oneshot, executor::{ThreadPool, ThreadPoolBuilder}, future::Future}; + +use primitives::{H256, Blake2Hasher, Hasher}; + +use sr_primitives::{generic::BlockId, traits, transaction_validity::TransactionValidity}; + +use tx_runtime_api::TaggedTransactionQueue; + +use crate::error::{self, Error}; /// The transaction pool logic pub struct FullChainApi { @@ -51,7 +39,7 @@ pub struct FullChainApi { impl FullChainApi where Block: traits::Block, - T: traits::ProvideRuntimeApi + HeaderBackend { + T: traits::ProvideRuntimeApi + traits::BlockIdTo { /// Create new transaction pool logic. pub fn new(client: Arc) -> Self { FullChainApi { @@ -67,14 +55,15 @@ impl FullChainApi where } impl txpool::ChainApi for FullChainApi where - Block: traits::Block, - T: traits::ProvideRuntimeApi + HeaderBackend + 'static, - T::Api: TaggedTransactionQueue + Block: traits::Block, + T: traits::ProvideRuntimeApi + traits::BlockIdTo + 'static + Send + Sync, + T::Api: TaggedTransactionQueue, + sr_api::ApiErrorFor: Send, { type Block = Block; type Hash = H256; type Error = error::Error; - type ValidationFuture = Pin> + Send>>; + type ValidationFuture = Pin> + Send>>; fn validate_transaction( &self, @@ -86,7 +75,8 @@ impl txpool::ChainApi for FullChainApi where let at = at.clone(); self.pool.spawn_ok(async move { - let res = client.runtime_api().validate_transaction(&at, uxt).map_err(Into::into); + let res = client.runtime_api().validate_transaction(&at, uxt) + .map_err(|e| Error::RuntimeApi(format!("{:?}", e))); if let Err(e) = tx.send(res) { log::warn!("Unable to send a validate transaction result: {:?}", e); } @@ -95,17 +85,23 @@ impl txpool::ChainApi for FullChainApi where Box::pin(async move { match rx.await { Ok(r) => r, - Err(e) => Err(client::error::Error::Msg(format!("{}", e)))?, + Err(_) => Err(Error::RuntimeApi("Validation was canceled".into())), } }) } - fn block_id_to_number(&self, at: &BlockId) -> error::Result>> { - Ok(self.client.block_number_from_id(at)?) + fn block_id_to_number( + &self, + at: &BlockId, + ) -> error::Result>> { + self.client.to_number(at).map_err(|e| Error::BlockIdConversion(format!("{:?}", e))) } - fn block_id_to_hash(&self, at: &BlockId) -> error::Result>> { - Ok(self.client.block_hash_from_id(at)?) + fn block_id_to_hash( + &self, + at: &BlockId, + ) -> error::Result>> { + self.client.to_hash(at).map_err(|e| Error::BlockIdConversion(format!("{:?}", e))) } fn hash_and_length(&self, ex: &txpool::ExtrinsicFor) -> (Self::Hash, usize) { diff --git a/core/transaction-pool/src/error.rs b/core/transaction-pool/src/error.rs index f3641aa8ecee3..ae0a058e5cc37 100644 --- a/core/transaction-pool/src/error.rs +++ b/core/transaction-pool/src/error.rs @@ -16,26 +16,26 @@ //! Transaction pool error. -use client; -use txpool; - /// Transaction pool result. pub type Result = std::result::Result; /// Transaction pool error type. #[derive(Debug, derive_more::Display, derive_more::From)] pub enum Error { - /// Client error. - Client(client::error::Error), /// Pool error. Pool(txpool::error::Error), + /// Error while converting a `BlockId`. + BlockIdConversion(String), + /// Error while calling the runtime api. + RuntimeApi(String), } impl std::error::Error for Error { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { - Error::Client(ref err) => Some(err), Error::Pool(ref err) => Some(err), + Error::BlockIdConversion(_) => None, + Error::RuntimeApi(_) => None, } } } diff --git a/core/transaction-pool/src/lib.rs b/core/transaction-pool/src/lib.rs index 6938166299d85..d7703de65285d 100644 --- a/core/transaction-pool/src/lib.rs +++ b/core/transaction-pool/src/lib.rs @@ -20,10 +20,9 @@ #![warn(unused_extern_crates)] mod api; +pub mod error; #[cfg(test)] mod tests; -pub mod error; - pub use api::FullChainApi; pub use txpool; diff --git a/node-template/runtime/Cargo.toml b/node-template/runtime/Cargo.toml index ff2e3eb2b1676..217202b390c1d 100644 --- a/node-template/runtime/Cargo.toml +++ b/node-template/runtime/Cargo.toml @@ -26,8 +26,11 @@ timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default sudo = { package = "srml-sudo", path = "../../srml/sudo", default_features = false } transaction-payment = { package = "srml-transaction-payment", path = "../../srml/transaction-payment", default_features = false } sr-primitives = { path = "../../core/sr-primitives", default_features = false } -client = { package = "substrate-client", path = "../../core/client", default_features = false } +sr-api = { path = "../../core/sr-api", default_features = false } offchain-primitives = { package = "substrate-offchain-primitives", path = "../../core/offchain/primitives", default-features = false } +block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../core/block-builder/runtime-api", default-features = false } +tx-pool-api = { package = "substrate-transaction-pool-runtime-api", path = "../../core/transaction-pool/runtime-api", default-features = false } +inherents = { package = "substrate-inherents", path = "../../core/inherents", default-features = false } [build-dependencies] wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.4" } @@ -36,7 +39,7 @@ wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1. default = ["std"] std = [ "codec/std", - "client/std", + "sr-api/std", "rstd/std", "runtime-io/std", "support/std", @@ -58,4 +61,7 @@ std = [ "safe-mix/std", "offchain-primitives/std", "substrate-session/std", + "block-builder-api/std", + "tx-pool-api/std", + "inherents/std", ] diff --git a/node-template/runtime/src/lib.rs b/node-template/runtime/src/lib.rs index 512f0020a5967..4b7a572da2337 100644 --- a/node-template/runtime/src/lib.rs +++ b/node-template/runtime/src/lib.rs @@ -18,10 +18,7 @@ use sr_primitives::traits::{ NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto, IdentifyAccount }; use sr_primitives::weights::Weight; -use client::{ - block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api}, - runtime_api as client_api, impl_runtime_apis -}; +use sr_api::impl_runtime_apis; use aura_primitives::sr25519::AuthorityId as AuraId; use grandpa::AuthorityList as GrandpaAuthorityList; use grandpa::fg_primitives; @@ -283,7 +280,7 @@ pub type CheckedExtrinsic = generic::CheckedExtrinsic, Runtime, AllModules>; impl_runtime_apis! { - impl client_api::Core for Runtime { + impl sr_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION } @@ -297,7 +294,7 @@ impl_runtime_apis! { } } - impl client_api::Metadata for Runtime { + impl sr_api::Metadata for Runtime { fn metadata() -> OpaqueMetadata { Runtime::metadata().into() } @@ -312,11 +309,14 @@ impl_runtime_apis! { Executive::finalize_block() } - fn inherent_extrinsics(data: InherentData) -> Vec<::Extrinsic> { + fn inherent_extrinsics(data: inherents::InherentData) -> Vec<::Extrinsic> { data.create_extrinsics() } - fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult { + fn check_inherents( + block: Block, + data: inherents::InherentData, + ) -> inherents::CheckInherentsResult { data.check_extrinsics(&block) } @@ -325,7 +325,7 @@ impl_runtime_apis! { } } - impl client_api::TaggedTransactionQueue for Runtime { + impl tx_pool_api::TaggedTransactionQueue for Runtime { fn validate_transaction(tx: ::Extrinsic) -> TransactionValidity { Executive::validate_transaction(tx) } diff --git a/node/runtime/Cargo.toml b/node/runtime/Cargo.toml index 5f450601246e9..2b1c817d7bbc3 100644 --- a/node/runtime/Cargo.toml +++ b/node/runtime/Cargo.toml @@ -22,7 +22,10 @@ sr-primitives = { path = "../../core/sr-primitives", default-features = false } sr-staking-primitives = { path = "../../core/sr-staking-primitives", default-features = false } # core dependencies -client = { package = "substrate-client", path = "../../core/client", default-features = false } +sr-api = { path = "../../core/sr-api", default-features = false } +inherents = { package = "substrate-inherents", path = "../../core/inherents", default-features = false } +block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../core/block-builder/runtime-api", default-features = false } +tx-pool-api = { package = "substrate-transaction-pool-runtime-api", path = "../../core/transaction-pool/runtime-api", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } version = { package = "sr-version", path = "../../core/sr-version", default-features = false } substrate-session = { path = "../../core/session", default-features = false } @@ -72,7 +75,7 @@ std = [ "babe-primitives/std", "babe/std", "balances/std", - "client/std", + "sr-api/std", "codec/std", "collective/std", "contracts/std", @@ -111,4 +114,7 @@ std = [ "transaction-payment/std", "transaction-payment-rpc-runtime-api/std", "version/std", + "block-builder-api/std", + "tx-pool-api/std", + "inherents/std", ] diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index 344c7ef731fcb..42ae8063b3572 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -25,14 +25,8 @@ use support::{ construct_runtime, parameter_types, traits::{SplitTwoWays, Currency, Randomness} }; use primitives::u32_trait::{_1, _2, _3, _4}; -use node_primitives::{ - AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, - Moment, Signature, -}; -use client::{ - block_builder::api::{self as block_builder_api, InherentData, CheckInherentsResult}, - runtime_api as client_api, impl_runtime_apis -}; +use node_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Moment, Signature}; +use sr_api::impl_runtime_apis; use sr_primitives::{Permill, Perbill, ApplyResult, impl_opaque_keys, generic, create_runtime_str}; use sr_primitives::curve::PiecewiseLinear; use sr_primitives::transaction_validity::TransactionValidity; @@ -51,6 +45,7 @@ use im_online::sr25519::{AuthorityId as ImOnlineId}; use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo; use contracts_rpc_runtime_api::ContractExecResult; use system::offchain::TransactionSubmitter; +use inherents::{InherentData, CheckInherentsResult}; #[cfg(any(feature = "std", test))] pub use sr_primitives::BuildStorage; @@ -562,7 +557,7 @@ pub type CheckedExtrinsic = generic::CheckedExtrinsic, Runtime, AllModules>; impl_runtime_apis! { - impl client_api::Core for Runtime { + impl sr_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION } @@ -576,7 +571,7 @@ impl_runtime_apis! { } } - impl client_api::Metadata for Runtime { + impl sr_api::Metadata for Runtime { fn metadata() -> OpaqueMetadata { Runtime::metadata().into() } @@ -604,7 +599,7 @@ impl_runtime_apis! { } } - impl client_api::TaggedTransactionQueue for Runtime { + impl tx_pool_api::TaggedTransactionQueue for Runtime { fn validate_transaction(tx: ::Extrinsic) -> TransactionValidity { Executive::validate_transaction(tx) } diff --git a/srml/aura/src/lib.rs b/srml/aura/src/lib.rs index f27cb98c0131d..7e459fde0486b 100644 --- a/srml/aura/src/lib.rs +++ b/srml/aura/src/lib.rs @@ -60,7 +60,7 @@ use sr_primitives::{ use timestamp::OnTimestampSet; #[cfg(feature = "std")] use timestamp::TimestampInherentData; -use inherents::{RuntimeString, InherentIdentifier, InherentData, ProvideInherent, MakeFatalError}; +use inherents::{InherentIdentifier, InherentData, ProvideInherent, MakeFatalError}; #[cfg(feature = "std")] use inherents::{InherentDataProviders, ProvideInherentData}; use substrate_consensus_aura_primitives::{AURA_ENGINE_ID, ConsensusLog, AuthorityIndex}; @@ -77,13 +77,13 @@ pub type InherentType = u64; /// Auxiliary trait to extract Aura inherent data. pub trait AuraInherentData { /// Get aura inherent data. - fn aura_inherent_data(&self) -> result::Result; + fn aura_inherent_data(&self) -> result::Result; /// Replace aura inherent data. fn aura_replace_inherent_data(&mut self, new: InherentType); } impl AuraInherentData for InherentData { - fn aura_inherent_data(&self) -> result::Result { + fn aura_inherent_data(&self) -> result::Result { self.get_data(&INHERENT_IDENTIFIER) .and_then(|r| r.ok_or_else(|| "Aura inherent data not found".into())) } @@ -113,7 +113,7 @@ impl ProvideInherentData for InherentDataProvider { fn on_register( &self, providers: &InherentDataProviders, - ) -> result::Result<(), RuntimeString> { + ) -> result::Result<(), inherents::Error> { if !providers.has_provider(×tamp::INHERENT_IDENTIFIER) { // Add the timestamp inherent data provider, as we require it. providers.register_provider(timestamp::InherentDataProvider) @@ -129,14 +129,14 @@ impl ProvideInherentData for InherentDataProvider { fn provide_inherent_data( &self, inherent_data: &mut InherentData, - ) -> result::Result<(), RuntimeString> { + ) -> result::Result<(), inherents::Error> { let timestamp = inherent_data.timestamp_inherent_data()?; let slot_num = timestamp / self.slot_duration; inherent_data.put_data(INHERENT_IDENTIFIER, &slot_num) } fn error_to_string(&self, error: &[u8]) -> Option { - RuntimeString::decode(&mut &error[..]).map(Into::into).ok() + inherents::Error::decode(&mut &error[..]).map(|e| e.into_string()).ok() } } @@ -279,7 +279,7 @@ impl OnTimestampSet for Module { impl ProvideInherent for Module { type Call = timestamp::Call; - type Error = MakeFatalError; + type Error = MakeFatalError; const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER; fn create_inherent(_: &InherentData) -> Option { @@ -300,7 +300,7 @@ impl ProvideInherent for Module { if timestamp_based_slot == seal_slot { Ok(()) } else { - Err(RuntimeString::from("timestamp set in block doesn't match slot in seal").into()) + Err(inherents::Error::from("timestamp set in block doesn't match slot in seal").into()) } } } diff --git a/srml/authorship/src/lib.rs b/srml/authorship/src/lib.rs index 173af5f729cbb..795b0f7940e11 100644 --- a/srml/authorship/src/lib.rs +++ b/srml/authorship/src/lib.rs @@ -29,10 +29,7 @@ use codec::{Encode, Decode}; use system::ensure_none; use sr_primitives::traits::{Header as HeaderT, One, Zero}; use sr_primitives::weights::SimpleDispatchInfo; -use inherents::{ - RuntimeString, InherentIdentifier, ProvideInherent, - InherentData, MakeFatalError, -}; +use inherents::{InherentIdentifier, ProvideInherent, InherentData, MakeFatalError}; /// The identifier for the `uncles` inherent. pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"uncles00"; @@ -40,11 +37,11 @@ pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"uncles00"; /// Auxiliary trait to extract uncles inherent data. pub trait UnclesInherentData { /// Get uncles. - fn uncles(&self) -> Result, RuntimeString>; + fn uncles(&self) -> Result, inherents::Error>; } impl UnclesInherentData for InherentData { - fn uncles(&self) -> Result, RuntimeString> { + fn uncles(&self) -> Result, inherents::Error> { Ok(self.get_data(&INHERENT_IDENTIFIER)?.unwrap_or_default()) } } @@ -71,7 +68,7 @@ where F: Fn() -> Vec &INHERENT_IDENTIFIER } - fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), RuntimeString> { + fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), inherents::Error> { let uncles = (self.inner)(); if !uncles.is_empty() { inherent_data.put_data(INHERENT_IDENTIFIER, &uncles) diff --git a/srml/babe/src/lib.rs b/srml/babe/src/lib.rs index c5541258db6cf..17ce12c716359 100644 --- a/srml/babe/src/lib.rs +++ b/srml/babe/src/lib.rs @@ -34,7 +34,7 @@ use sr_staking_primitives::{ #[cfg(feature = "std")] use timestamp::TimestampInherentData; use codec::{Encode, Decode}; -use inherents::{RuntimeString, InherentIdentifier, InherentData, ProvideInherent, MakeFatalError}; +use inherents::{InherentIdentifier, InherentData, ProvideInherent, MakeFatalError}; #[cfg(feature = "std")] use inherents::{InherentDataProviders, ProvideInherentData}; use babe_primitives::{ @@ -57,13 +57,13 @@ pub type InherentType = u64; /// Auxiliary trait to extract BABE inherent data. pub trait BabeInherentData { /// Get BABE inherent data. - fn babe_inherent_data(&self) -> result::Result; + fn babe_inherent_data(&self) -> result::Result; /// Replace BABE inherent data. fn babe_replace_inherent_data(&mut self, new: InherentType); } impl BabeInherentData for InherentData { - fn babe_inherent_data(&self) -> result::Result { + fn babe_inherent_data(&self) -> result::Result { self.get_data(&INHERENT_IDENTIFIER) .and_then(|r| r.ok_or_else(|| "BABE inherent data not found".into())) } @@ -94,7 +94,7 @@ impl ProvideInherentData for InherentDataProvider { fn on_register( &self, providers: &InherentDataProviders, - ) -> result::Result<(), RuntimeString> { + ) -> result::Result<(), inherents::Error> { if !providers.has_provider(×tamp::INHERENT_IDENTIFIER) { // Add the timestamp inherent data provider, as we require it. providers.register_provider(timestamp::InherentDataProvider) @@ -110,14 +110,14 @@ impl ProvideInherentData for InherentDataProvider { fn provide_inherent_data( &self, inherent_data: &mut InherentData, - ) -> result::Result<(), RuntimeString> { + ) -> result::Result<(), inherents::Error> { let timestamp = inherent_data.timestamp_inherent_data()?; let slot_number = timestamp / self.slot_duration; inherent_data.put_data(INHERENT_IDENTIFIER, &slot_number) } fn error_to_string(&self, error: &[u8]) -> Option { - RuntimeString::decode(&mut &error[..]).map(Into::into).ok() + inherents::Error::decode(&mut &error[..]).map(|e| e.into_string()).ok() } } @@ -602,7 +602,7 @@ fn compute_randomness( impl ProvideInherent for Module { type Call = timestamp::Call; - type Error = MakeFatalError; + type Error = MakeFatalError; const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER; fn create_inherent(_: &InherentData) -> Option { @@ -621,7 +621,7 @@ impl ProvideInherent for Module { if timestamp_based_slot == seal_slot { Ok(()) } else { - Err(RuntimeString::from("timestamp set in block doesn't match slot in seal").into()) + Err(inherents::Error::from("timestamp set in block doesn't match slot in seal").into()) } } } diff --git a/srml/contracts/rpc/runtime-api/Cargo.toml b/srml/contracts/rpc/runtime-api/Cargo.toml index 2a36ed2c96cc4..e37d476860395 100644 --- a/srml/contracts/rpc/runtime-api/Cargo.toml +++ b/srml/contracts/rpc/runtime-api/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -client = { package = "substrate-client", path = "../../../../core/client", default-features = false } +sr-api = { path = "../../../../core/sr-api", default-features = false } codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../../../core/sr-std", default-features = false } serde = { version = "1.0.101", optional = true, features = ["derive"] } @@ -14,7 +14,7 @@ sr-primitives = { path = "../../../../core/sr-primitives", default-features = fa [features] default = ["std"] std = [ - "client/std", + "sr-api/std", "codec/std", "rstd/std", "serde", diff --git a/srml/contracts/rpc/runtime-api/src/lib.rs b/srml/contracts/rpc/runtime-api/src/lib.rs index 054f110beb4d0..6d9c4a27b1feb 100644 --- a/srml/contracts/rpc/runtime-api/src/lib.rs +++ b/srml/contracts/rpc/runtime-api/src/lib.rs @@ -59,7 +59,7 @@ pub enum GetStorageError { IsTombstone, } -client::decl_runtime_apis! { +sr_api::decl_runtime_apis! { /// The API to interact with contracts without using executive. pub trait ContractsApi where AccountId: Codec, diff --git a/srml/finality-tracker/src/lib.rs b/srml/finality-tracker/src/lib.rs index 5e973cd43235d..b5c01c3c8733f 100644 --- a/srml/finality-tracker/src/lib.rs +++ b/srml/finality-tracker/src/lib.rs @@ -18,10 +18,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use inherents::{ - RuntimeString, InherentIdentifier, ProvideInherent, - InherentData, MakeFatalError, -}; +use inherents::{InherentIdentifier, ProvideInherent, InherentData, MakeFatalError}; use sr_primitives::traits::{One, Zero, SaturatedConversion}; use rstd::{prelude::*, result, cmp, vec}; use codec::Decode; @@ -38,11 +35,11 @@ pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"finalnum"; /// Auxiliary trait to extract finalized inherent data. pub trait FinalizedInherentData { /// Get finalized inherent data. - fn finalized_number(&self) -> Result; + fn finalized_number(&self) -> Result; } impl FinalizedInherentData for InherentData { - fn finalized_number(&self) -> Result { + fn finalized_number(&self) -> Result { self.get_data(&INHERENT_IDENTIFIER) .and_then(|r| r.ok_or_else(|| "Finalized number inherent data not found".into())) } @@ -64,13 +61,16 @@ impl InherentDataProvider { #[cfg(feature = "std")] impl inherents::ProvideInherentData for InherentDataProvider - where F: Fn() -> Result + where F: Fn() -> Result { fn inherent_identifier(&self) -> &'static InherentIdentifier { &INHERENT_IDENTIFIER } - fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), RuntimeString> { + fn provide_inherent_data( + &self, + inherent_data: &mut InherentData, + ) -> Result<(), inherents::Error> { (self.inner)() .and_then(|n| inherent_data.put_data(INHERENT_IDENTIFIER, &n)) } diff --git a/srml/session/Cargo.toml b/srml/session/Cargo.toml index 1346867910313..d9a95100aae58 100644 --- a/srml/session/Cargo.toml +++ b/srml/session/Cargo.toml @@ -15,7 +15,7 @@ support = { package = "srml-support", path = "../support", default-features = fa system = { package = "srml-system", path = "../system", default-features = false } timestamp = { package = "srml-timestamp", path = "../timestamp", default-features = false } substrate-trie = { path = "../../core/trie", default-features = false, optional = true } -runtime-io ={ package = "sr-io", path = "../../core/sr-io", default-features = false } +runtime-io = { package = "sr-io", path = "../../core/sr-io", default-features = false } impl-trait-for-tuples = "0.1.3" [dev-dependencies] diff --git a/srml/session/src/lib.rs b/srml/session/src/lib.rs index 42324d387f69e..aa86dedd987f4 100644 --- a/srml/session/src/lib.rs +++ b/srml/session/src/lib.rs @@ -125,10 +125,7 @@ use sr_primitives::{KeyTypeId, Perbill, RuntimeAppPublic, BoundToRuntimeAppPubli use sr_primitives::weights::SimpleDispatchInfo; use sr_primitives::traits::{Convert, Zero, Member, OpaqueKeys}; use sr_staking_primitives::SessionIndex; -use support::{ - dispatch::Result, ConsensusEngineId, decl_module, decl_event, - decl_storage, -}; +use support::{dispatch::Result, ConsensusEngineId, decl_module, decl_event, decl_storage}; use support::{ensure, traits::{OnFreeBalanceZero, Get, FindAuthor}, Parameter}; use system::{self, ensure_signed}; diff --git a/srml/support/procedural/Cargo.toml b/srml/support/procedural/Cargo.toml index b891e7b46ff7f..59025800ec615 100644 --- a/srml/support/procedural/Cargo.toml +++ b/srml/support/procedural/Cargo.toml @@ -9,7 +9,6 @@ proc-macro = true [dependencies] srml-support-procedural-tools = { package = "srml-support-procedural-tools", path = "./tools" } -sr-api-macros = { path = "../../../core/sr-api-macros" } proc-macro2 = "1.0.6" quote = "1.0.2" diff --git a/srml/support/test/tests/instance.rs b/srml/support/test/tests/instance.rs index 80e7e526e596d..dc4fded17edc7 100644 --- a/srml/support/test/tests/instance.rs +++ b/srml/support/test/tests/instance.rs @@ -25,9 +25,7 @@ use support::{ }, StorageValue, StorageMap, StorageLinkedMap, StorageDoubleMap, }; -use inherents::{ - ProvideInherent, InherentData, InherentIdentifier, RuntimeString, MakeFatalError -}; +use inherents::{ProvideInherent, InherentData, InherentIdentifier, MakeFatalError}; use primitives::{H256, sr25519}; mod system; @@ -100,7 +98,7 @@ mod module1 { T::BlockNumber: From { type Call = Call; - type Error = MakeFatalError; + type Error = MakeFatalError; const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER; fn create_inherent(_data: &InherentData) -> Option { @@ -160,7 +158,7 @@ mod module2 { impl, I: Instance> ProvideInherent for Module { type Call = Call; - type Error = MakeFatalError; + type Error = MakeFatalError; const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER; fn create_inherent(_data: &InherentData) -> Option { diff --git a/srml/system/rpc/runtime-api/Cargo.toml b/srml/system/rpc/runtime-api/Cargo.toml index fc525d8fce2ad..19a3ac10ce2fe 100644 --- a/srml/system/rpc/runtime-api/Cargo.toml +++ b/srml/system/rpc/runtime-api/Cargo.toml @@ -5,12 +5,12 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -client = { package = "substrate-client", path = "../../../../core/client", default-features = false } +sr-api = { path = "../../../../core/sr-api", default-features = false } codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } [features] default = ["std"] std = [ - "client/std", + "sr-api/std", "codec/std", ] diff --git a/srml/system/rpc/runtime-api/src/lib.rs b/srml/system/rpc/runtime-api/src/lib.rs index 45af0241e0836..5c8c64902b0da 100644 --- a/srml/system/rpc/runtime-api/src/lib.rs +++ b/srml/system/rpc/runtime-api/src/lib.rs @@ -22,7 +22,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -client::decl_runtime_apis! { +sr_api::decl_runtime_apis! { /// The API to query account nonce (aka transaction index). pub trait AccountNonceApi where AccountId: codec::Codec, diff --git a/srml/timestamp/src/lib.rs b/srml/timestamp/src/lib.rs index 5f0ec8d443b26..8271c6e0e5795 100644 --- a/srml/timestamp/src/lib.rs +++ b/srml/timestamp/src/lib.rs @@ -98,12 +98,15 @@ use codec::Decode; use inherents::ProvideInherentData; use support::{Parameter, decl_storage, decl_module}; use support::traits::{Time, Get}; -use sr_primitives::traits::{ - SimpleArithmetic, Zero, SaturatedConversion, Scale +use sr_primitives::{ + RuntimeString, + traits::{ + SimpleArithmetic, Zero, SaturatedConversion, Scale + } }; use sr_primitives::weights::SimpleDispatchInfo; use system::ensure_none; -use inherents::{RuntimeString, InherentIdentifier, ProvideInherent, IsFatalError, InherentData}; +use inherents::{InherentIdentifier, ProvideInherent, IsFatalError, InherentData}; /// The identifier for the `timestamp` inherent. pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"timstap0"; @@ -145,11 +148,11 @@ impl InherentError { /// Auxiliary trait to extract timestamp inherent data. pub trait TimestampInherentData { /// Get timestamp inherent data. - fn timestamp_inherent_data(&self) -> Result; + fn timestamp_inherent_data(&self) -> Result; } impl TimestampInherentData for InherentData { - fn timestamp_inherent_data(&self) -> Result { + fn timestamp_inherent_data(&self) -> Result { self.get_data(&INHERENT_IDENTIFIER) .and_then(|r| r.ok_or_else(|| "Timestamp inherent data not found".into())) } @@ -164,7 +167,10 @@ impl ProvideInherentData for InherentDataProvider { &INHERENT_IDENTIFIER } - fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), RuntimeString> { + fn provide_inherent_data( + &self, + inherent_data: &mut InherentData, + ) -> Result<(), inherents::Error> { use std::time::SystemTime; let now = SystemTime::now(); diff --git a/srml/transaction-payment/rpc/runtime-api/Cargo.toml b/srml/transaction-payment/rpc/runtime-api/Cargo.toml index c26f295f4bec3..2ef5e3acf6252 100644 --- a/srml/transaction-payment/rpc/runtime-api/Cargo.toml +++ b/srml/transaction-payment/rpc/runtime-api/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -client = { package = "substrate-client", path = "../../../../core/client", default-features = false } +sr-api = { path = "../../../../core/sr-api", default-features = false } codec = { package = "parity-scale-codec", version = "1.0.6", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../../../core/sr-std", default-features = false } sr-primitives = { path = "../../../../core/sr-primitives", default-features = false } @@ -15,7 +15,7 @@ sr-primitives = { path = "../../../../core/sr-primitives", default-features = fa default = ["std"] std = [ "serde", - "client/std", + "sr-api/std", "codec/std", "rstd/std", "sr-primitives/std", diff --git a/srml/transaction-payment/rpc/runtime-api/src/lib.rs b/srml/transaction-payment/rpc/runtime-api/src/lib.rs index dc6360ca88d76..1254d5acb98f6 100644 --- a/srml/transaction-payment/rpc/runtime-api/src/lib.rs +++ b/srml/transaction-payment/rpc/runtime-api/src/lib.rs @@ -37,7 +37,7 @@ pub struct RuntimeDispatchInfo { pub partial_fee: Balance, } -client::decl_runtime_apis! { +sr_api::decl_runtime_apis! { pub trait TransactionPaymentApi where Balance: Codec, Extrinsic: Codec, diff --git a/test-utils/transaction-factory/Cargo.toml b/test-utils/transaction-factory/Cargo.toml index e53972eec65c5..ce32708ebf4ef 100644 --- a/test-utils/transaction-factory/Cargo.toml +++ b/test-utils/transaction-factory/Cargo.toml @@ -7,6 +7,8 @@ edition = "2018" [dependencies] cli = { package = "substrate-cli", path = "../../core/cli" } client = { package = "substrate-client", path = "../../core/client" } +sr-api = { path = "../../core/sr-api" } +block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../core/block-builder/runtime-api" } consensus_common = { package = "substrate-consensus-common", path = "../../core/consensus/common" } log = "0.4.8" codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } diff --git a/test-utils/transaction-factory/src/complex_mode.rs b/test-utils/transaction-factory/src/complex_mode.rs index ed76a66b09083..5e68a05c7ddbf 100644 --- a/test-utils/transaction-factory/src/complex_mode.rs +++ b/test-utils/transaction-factory/src/complex_mode.rs @@ -42,8 +42,8 @@ use std::sync::Arc; use log::info; use client::Client; -use client::block_builder::api::BlockBuilder; -use client::runtime_api::ConstructRuntimeApi; +use block_builder_api::BlockBuilder; +use sr_api::ConstructRuntimeApi; use primitives::{Blake2Hasher, Hasher}; use sr_primitives::generic::BlockId; use sr_primitives::traits::{Block as BlockT, ProvideRuntimeApi, One, Zero}; @@ -63,7 +63,8 @@ where Exec: client::CallExecutor + Send + Sync + Clone, Backend: client::backend::Backend + Send, Client: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: BlockBuilder, + as ProvideRuntimeApi>::Api: + BlockBuilder, RtApi: ConstructRuntimeApi> + Send + Sync, RA: RuntimeAdapter, { diff --git a/test-utils/transaction-factory/src/lib.rs b/test-utils/transaction-factory/src/lib.rs index d1526cc8bb972..93ee0d608b734 100644 --- a/test-utils/transaction-factory/src/lib.rs +++ b/test-utils/transaction-factory/src/lib.rs @@ -26,7 +26,9 @@ use std::fmt::Display; use log::info; -use client::{Client, block_builder::api::BlockBuilder, runtime_api::ConstructRuntimeApi}; +use client::Client; +use block_builder_api::BlockBuilder; +use sr_api::ConstructRuntimeApi; use consensus_common::{ BlockOrigin, BlockImportParams, InherentData, ForkChoiceStrategy, SelectChain @@ -102,7 +104,8 @@ where Exec: client::CallExecutor + Send + Sync + Clone, Backend: client::backend::Backend + Send, Client: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: BlockBuilder, + as ProvideRuntimeApi>::Api: + BlockBuilder, RtApi: ConstructRuntimeApi> + Send + Sync, Sc: SelectChain, RA: RuntimeAdapter, @@ -161,7 +164,8 @@ where Backend: client::backend::Backend + Send, Client: ProvideRuntimeApi, RtApi: ConstructRuntimeApi> + Send + Sync, - as ProvideRuntimeApi>::Api: BlockBuilder, + as ProvideRuntimeApi>::Api: + BlockBuilder, RA: RuntimeAdapter, { let mut block = client.new_block(Default::default()).expect("Failed to create new block"); @@ -180,7 +184,7 @@ where fn import_block( client: &Arc>, block: Block -) -> () where +) -> () where Block: BlockT::Out>, Exec: client::CallExecutor + Send + Sync + Clone, Backend: client::backend::Backend + Send, diff --git a/test-utils/transaction-factory/src/simple_modes.rs b/test-utils/transaction-factory/src/simple_modes.rs index bcbb91200657f..827561c204e8e 100644 --- a/test-utils/transaction-factory/src/simple_modes.rs +++ b/test-utils/transaction-factory/src/simple_modes.rs @@ -37,8 +37,8 @@ use std::sync::Arc; use log::info; use client::Client; -use client::block_builder::api::BlockBuilder; -use client::runtime_api::ConstructRuntimeApi; +use block_builder_api::BlockBuilder; +use sr_api::ConstructRuntimeApi; use primitives::{Blake2Hasher, Hasher}; use sr_primitives::traits::{Block as BlockT, ProvideRuntimeApi, One}; use sr_primitives::generic::BlockId; @@ -58,7 +58,8 @@ where Exec: client::CallExecutor + Send + Sync + Clone, Backend: client::backend::Backend + Send, Client: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: BlockBuilder, + as ProvideRuntimeApi>::Api: + BlockBuilder, RtApi: ConstructRuntimeApi> + Send + Sync, RA: RuntimeAdapter, {