From 5852886fe451e81e68f7cc5dd611067005244dac Mon Sep 17 00:00:00 2001 From: haerdib Date: Tue, 28 Mar 2023 17:11:04 +0200 Subject: [PATCH 01/32] update to v0.9.0 tag --- Cargo.lock | 496 ++++++++++++++++-- cli/Cargo.toml | 4 +- core-primitives/extrinsics-factory/Cargo.toml | 2 +- .../node-api/api-client-extensions/Cargo.toml | 2 +- .../node-api/api-client-types/Cargo.toml | 2 +- core-primitives/node-api/metadata/Cargo.toml | 2 +- core-primitives/stf-executor/Cargo.toml | 2 +- .../indirect-calls-executor/Cargo.toml | 2 +- core/rpc-client/Cargo.toml | 2 +- enclave-runtime/Cargo.lock | 59 ++- enclave-runtime/Cargo.toml | 2 +- service/Cargo.toml | 2 +- 12 files changed, 490 insertions(+), 87 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6dcd5c74fd..68cb2818ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,8 +14,8 @@ dependencies = [ [[package]] name = "ac-compose-macros" -version = "0.2.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.7.0#84af198434ea210eb0cd90cb8239748c376a079a" +version = "0.2.2" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" dependencies = [ "ac-primitives", "log 0.4.17", @@ -23,21 +23,18 @@ dependencies = [ "sp-application-crypto", "sp-core", "sp-runtime", - "sp-std", ] [[package]] name = "ac-node-api" -version = "0.2.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.7.0#84af198434ea210eb0cd90cb8239748c376a079a" +version = "0.2.2" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" dependencies = [ "ac-primitives", "bitvec", "derive_more", "either", - "frame-metadata 15.0.0 (git+https://github.com/integritee-network/frame-metadata)", - "frame-support", - "frame-system", + "frame-metadata 15.0.0 (git+https://github.com/paritytech/frame-metadata)", "hex", "log 0.4.17", "parity-scale-codec", @@ -48,19 +45,29 @@ dependencies = [ "sp-core", "sp-runtime", "sp-runtime-interface", - "sp-std", ] [[package]] name = "ac-primitives" -version = "0.2.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.7.0#84af198434ea210eb0cd90cb8239748c376a079a" +version = "0.4.0" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" dependencies = [ + "frame-system", "hex", + "impl-serde", + "pallet-assets", + "pallet-balances", + "pallet-contracts", + "pallet-staking", "parity-scale-codec", + "primitive-types", + "scale-info", + "serde 1.0.158", + "serde_json 1.0.94", "sp-core", "sp-runtime", - "sp-std", + "sp-staking", + "sp-version", ] [[package]] @@ -216,6 +223,15 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +[[package]] +name = "async-lock" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7" +dependencies = [ + "event-listener", +] + [[package]] name = "async-trait" version = "0.1.68" @@ -322,6 +338,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" + [[package]] name = "base64ct" version = "1.6.0" @@ -1378,6 +1400,12 @@ dependencies = [ "uint", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "evm" version = "0.37.0" @@ -1663,6 +1691,34 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "frame-election-provider-solution-type" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#1837f423b494254e1d27834b1c9da34b2c0c2375" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "frame-election-provider-support" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#1837f423b494254e1d27834b1c9da34b2c0c2375" +dependencies = [ + "frame-election-provider-solution-type", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-arithmetic", + "sp-core", + "sp-npos-elections", + "sp-runtime", + "sp-std", +] + [[package]] name = "frame-executive" version = "4.0.0-dev" @@ -1694,7 +1750,7 @@ dependencies = [ [[package]] name = "frame-metadata" version = "15.0.0" -source = "git+https://github.com/integritee-network/frame-metadata#3b43da9821238681f9431276d55b92a079142083" +source = "git+https://github.com/paritytech/frame-metadata#040a53c63af277e280282028b73b992eac9c35a2" dependencies = [ "cfg-if 1.0.0", "parity-scale-codec", @@ -2457,9 +2513,9 @@ dependencies = [ "hyper", "log 0.4.17", "rustls 0.19.1", - "rustls-native-certs", + "rustls-native-certs 0.5.0", "tokio", - "tokio-rustls", + "tokio-rustls 0.22.0", "webpki 0.21.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2580,6 +2636,12 @@ dependencies = [ "serde 1.0.158", ] +[[package]] +name = "indexmap-nostd" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e04e2fd2b8188ea827b32ef11de88377086d690286ab35747ef7f9bf3ccb590" + [[package]] name = "instant" version = "0.1.12" @@ -2719,7 +2781,7 @@ dependencies = [ "its-rpc-handler", "its-storage", "its-test", - "jsonrpsee", + "jsonrpsee 0.2.0", "lazy_static", "log 0.4.17", "mockall", @@ -3135,7 +3197,7 @@ dependencies = [ "its-rpc-handler", "its-storage", "its-test", - "jsonrpsee", + "jsonrpsee 0.2.0", "log 0.4.17", "parity-scale-codec", "serde_json 1.0.94", @@ -3880,7 +3942,7 @@ dependencies = [ "its-rpc-handler", "its-storage", "its-test", - "jsonrpsee", + "jsonrpsee 0.2.0", "log 0.4.17", "serde 1.0.158", "serde_json 1.0.94", @@ -4058,12 +4120,66 @@ dependencies = [ "jsonrpsee-http-client", "jsonrpsee-http-server", "jsonrpsee-proc-macros", - "jsonrpsee-types", + "jsonrpsee-types 0.2.0", "jsonrpsee-utils", "jsonrpsee-ws-client", "jsonrpsee-ws-server", ] +[[package]] +name = "jsonrpsee" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d291e3a5818a2384645fd9756362e6d89cf0541b0b916fa7702ea4a9833608e" +dependencies = [ + "jsonrpsee-client-transport", + "jsonrpsee-core", + "jsonrpsee-types 0.16.2", +] + +[[package]] +name = "jsonrpsee-client-transport" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "965de52763f2004bc91ac5bcec504192440f0b568a5d621c59d9dbd6f886c3fb" +dependencies = [ + "futures-util 0.3.27", + "http 0.2.9", + "jsonrpsee-core", + "jsonrpsee-types 0.16.2", + "pin-project", + "rustls-native-certs 0.6.2", + "soketto 0.7.1", + "thiserror 1.0.40", + "tokio", + "tokio-rustls 0.23.4", + "tokio-util 0.7.7", + "tracing", + "webpki-roots 0.22.6", +] + +[[package]] +name = "jsonrpsee-core" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4e70b4439a751a5de7dd5ed55eacff78ebf4ffe0fc009cb1ebb11417f5b536b" +dependencies = [ + "anyhow", + "async-lock", + "async-trait", + "beef", + "futures-channel 0.3.27", + "futures-timer", + "futures-util 0.3.27", + "jsonrpsee-types 0.16.2", + "rustc-hash", + "serde 1.0.158", + "serde_json 1.0.94", + "thiserror 1.0.40", + "tokio", + "tracing", +] + [[package]] name = "jsonrpsee-http-client" version = "0.2.0" @@ -4074,7 +4190,7 @@ dependencies = [ "fnv 1.0.7", "hyper", "hyper-rustls", - "jsonrpsee-types", + "jsonrpsee-types 0.2.0", "jsonrpsee-utils", "log 0.4.17", "serde 1.0.158", @@ -4093,7 +4209,7 @@ dependencies = [ "futures-util 0.3.27", "globset", "hyper", - "jsonrpsee-types", + "jsonrpsee-types 0.2.0", "jsonrpsee-utils", "lazy_static", "log 0.4.17", @@ -4132,10 +4248,24 @@ dependencies = [ "log 0.4.17", "serde 1.0.158", "serde_json 1.0.94", - "soketto", + "soketto 0.5.0", "thiserror 1.0.40", ] +[[package]] +name = "jsonrpsee-types" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bd522fe1ce3702fd94812965d7bb7a3364b1c9aba743944c5a00529aae80f8c" +dependencies = [ + "anyhow", + "beef", + "serde 1.0.158", + "serde_json 1.0.94", + "thiserror 1.0.40", + "tracing", +] + [[package]] name = "jsonrpsee-utils" version = "0.2.0" @@ -4145,7 +4275,7 @@ dependencies = [ "futures-channel 0.3.27", "futures-util 0.3.27", "hyper", - "jsonrpsee-types", + "jsonrpsee-types 0.2.0", "log 0.4.17", "parking_lot 0.11.2", "rand 0.8.5", @@ -4164,17 +4294,17 @@ dependencies = [ "async-trait", "fnv 1.0.7", "futures 0.3.27", - "jsonrpsee-types", + "jsonrpsee-types 0.2.0", "log 0.4.17", "pin-project", "rustls 0.19.1", - "rustls-native-certs", + "rustls-native-certs 0.5.0", "serde 1.0.158", "serde_json 1.0.94", - "soketto", + "soketto 0.5.0", "thiserror 1.0.40", "tokio", - "tokio-rustls", + "tokio-rustls 0.22.0", "tokio-util 0.6.10", "url 2.3.1", ] @@ -4187,13 +4317,13 @@ checksum = "b512c3c679a89d20f97802f69188a2d01f6234491b7513076e21e8424efccafe" dependencies = [ "futures-channel 0.3.27", "futures-util 0.3.27", - "jsonrpsee-types", + "jsonrpsee-types 0.2.0", "jsonrpsee-utils", "log 0.4.17", "rustc-hash", "serde 1.0.158", "serde_json 1.0.94", - "soketto", + "soketto 0.5.0", "thiserror 1.0.40", "tokio", "tokio-stream", @@ -4237,7 +4367,7 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" dependencies = [ - "spin", + "spin 0.5.2", ] [[package]] @@ -5120,6 +5250,21 @@ version = "6.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" +[[package]] +name = "pallet-assets" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#1837f423b494254e1d27834b1c9da34b2c0c2375" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-aura" version = "4.0.0-dev" @@ -5183,6 +5328,57 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-contracts" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#1837f423b494254e1d27834b1c9da34b2c0c2375" +dependencies = [ + "bitflags", + "frame-benchmarking", + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "log 0.4.17", + "pallet-contracts-primitives", + "pallet-contracts-proc-macro", + "parity-scale-codec", + "rand 0.8.5", + "scale-info", + "serde 1.0.158", + "smallvec 1.10.0", + "sp-api", + "sp-core", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39)", + "sp-runtime", + "sp-std", + "wasm-instrument", + "wasmi 0.20.0", + "wasmparser-nostd", +] + +[[package]] +name = "pallet-contracts-primitives" +version = "7.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#1837f423b494254e1d27834b1c9da34b2c0c2375" +dependencies = [ + "bitflags", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", + "sp-weights", +] + +[[package]] +name = "pallet-contracts-proc-macro" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#1837f423b494254e1d27834b1c9da34b2c0c2375" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "pallet-evm" version = "6.0.0-dev" @@ -5367,6 +5563,28 @@ dependencies = [ "teerex-primitives", ] +[[package]] +name = "pallet-staking" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#1837f423b494254e1d27834b1c9da34b2c0c2375" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log 0.4.17", + "pallet-authorship", + "pallet-session", + "parity-scale-codec", + "scale-info", + "serde 1.0.158", + "sp-application-crypto", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39)", + "sp-runtime", + "sp-staking", + "sp-std", +] + [[package]] name = "pallet-sudo" version = "4.0.0-dev" @@ -6239,7 +6457,7 @@ source = "git+https://github.com/mesalock-linux/ring-sgx?tag=v0.16.5#844efe271ed dependencies = [ "cc", "sgx_tstd", - "spin", + "spin 0.5.2", "untrusted", ] @@ -6252,7 +6470,7 @@ dependencies = [ "cc", "libc", "once_cell 1.17.1", - "spin", + "spin 0.5.2", "untrusted", "web-sys", "winapi 0.3.9", @@ -6268,7 +6486,7 @@ dependencies = [ "log 0.4.17", "once_cell 1.17.1", "rkyv", - "spin", + "spin 0.5.2", "untrusted", "winapi 0.3.9", "xous", @@ -6450,6 +6668,18 @@ dependencies = [ "webpki 0.21.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustls" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +dependencies = [ + "log 0.4.17", + "ring 0.16.20 (registry+https://github.com/rust-lang/crates.io-index)", + "sct 0.7.0", + "webpki 0.22.0", +] + [[package]] name = "rustls-native-certs" version = "0.5.0" @@ -6462,6 +6692,18 @@ dependencies = [ "security-framework", ] +[[package]] +name = "rustls-native-certs" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50" +dependencies = [ + "openssl-probe", + "rustls-pemfile 1.0.2", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "0.2.1" @@ -6471,6 +6713,15 @@ dependencies = [ "base64 0.13.1", ] +[[package]] +name = "rustls-pemfile" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" +dependencies = [ + "base64 0.21.0", +] + [[package]] name = "rustversion" version = "1.0.12" @@ -6633,6 +6884,16 @@ dependencies = [ "untrusted", ] +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring 0.16.20 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted", +] + [[package]] name = "sec1" version = "0.3.0" @@ -7241,6 +7502,21 @@ dependencies = [ "sha-1 0.9.8", ] +[[package]] +name = "soketto" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" +dependencies = [ + "base64 0.13.1", + "bytes 1.4.0", + "futures 0.3.27", + "httparse 1.8.0", + "log 0.4.17", + "rand 0.8.5", + "sha-1 0.9.8", +] + [[package]] name = "sp-api" version = "4.0.0-dev" @@ -7565,6 +7841,20 @@ dependencies = [ "zstd", ] +[[package]] +name = "sp-npos-elections" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#1837f423b494254e1d27834b1c9da34b2c0c2375" +dependencies = [ + "parity-scale-codec", + "scale-info", + "serde 1.0.158", + "sp-arithmetic", + "sp-core", + "sp-runtime", + "sp-std", +] + [[package]] name = "sp-offchain" version = "4.0.0-dev" @@ -7585,16 +7875,6 @@ dependencies = [ "regex 1.7.3", ] -[[package]] -name = "sp-rpc" -version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#1837f423b494254e1d27834b1c9da34b2c0c2375" -dependencies = [ - "rustc-hash", - "serde 1.0.158", - "sp-core", -] - [[package]] name = "sp-runtime" version = "7.0.0" @@ -7808,7 +8088,7 @@ dependencies = [ "log 0.4.17", "parity-scale-codec", "sp-std", - "wasmi", + "wasmi 0.13.2", "wasmtime", ] @@ -7833,6 +8113,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spin" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0959fd6f767df20b231736396e4f602171e00d95205676286e79d4a4eb67bef" + [[package]] name = "spki" version = "0.6.0" @@ -7906,30 +8192,26 @@ dependencies = [ [[package]] name = "substrate-api-client" -version = "0.7.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.7.0#84af198434ea210eb0cd90cb8239748c376a079a" +version = "0.9.0" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" dependencies = [ "ac-compose-macros", "ac-node-api", "ac-primitives", - "frame-metadata 15.0.0 (git+https://github.com/integritee-network/frame-metadata)", + "frame-metadata 15.0.0 (git+https://github.com/paritytech/frame-metadata)", "frame-support", - "frame-system", + "futures 0.3.27", "hex", + "jsonrpsee 0.16.2", "log 0.4.17", - "pallet-balances", - "pallet-transaction-payment", "parity-scale-codec", - "primitive-types", "serde 1.0.158", "serde_json 1.0.94", "sp-core", - "sp-rpc", "sp-runtime", "sp-runtime-interface", - "sp-std", - "sp-version", - "thiserror 1.0.40", + "thiserror-core", + "url 2.3.1", "ws", ] @@ -7949,7 +8231,7 @@ dependencies = [ [[package]] name = "substrate-client-keystore" version = "0.7.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.7.0#84af198434ea210eb0cd90cb8239748c376a079a" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" dependencies = [ "async-trait", "hex", @@ -8133,6 +8415,26 @@ dependencies = [ "thiserror-impl 1.0.40", ] +[[package]] +name = "thiserror-core" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d97345f6437bb2004cd58819d8a9ef8e36cdd7661c2abc4bbde0a7c40d9f497" +dependencies = [ + "thiserror-core-impl", +] + +[[package]] +name = "thiserror-core-impl" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10ac1c5050e43014d16b2f94d0d2ce79e65ffdd8b38d8048f9c8f6a8a6da62ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "thiserror-impl" version = "1.0.9" @@ -8270,6 +8572,17 @@ dependencies = [ "webpki 0.21.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls 0.20.8", + "tokio", + "webpki 0.22.0", +] + [[package]] name = "tokio-stream" version = "0.1.12" @@ -8316,6 +8629,7 @@ checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" dependencies = [ "bytes 1.4.0", "futures-core 0.3.27", + "futures-io 0.3.27", "futures-sink 0.3.27", "pin-project-lite", "tokio", @@ -8781,7 +9095,7 @@ dependencies = [ "multipart", "percent-encoding 2.2.0", "pin-project", - "rustls-pemfile", + "rustls-pemfile 0.2.1", "scoped-tls", "serde 1.0.158", "serde_json 1.0.94", @@ -8866,6 +9180,15 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +[[package]] +name = "wasm-instrument" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a47ecb37b9734d1085eaa5ae1a81e60801fd8c28d4cabdd8aedb982021918bc" +dependencies = [ + "parity-wasm", +] + [[package]] name = "wasm-opt" version = "0.111.0" @@ -8915,7 +9238,19 @@ checksum = "06c326c93fbf86419608361a2c925a31754cf109da1b8b55737070b4d6669422" dependencies = [ "parity-wasm", "wasmi-validation", - "wasmi_core", + "wasmi_core 0.2.1", +] + +[[package]] +name = "wasmi" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01bf50edb2ea9d922aa75a7bf3c15e26a6c9e2d18c56e862b49737a582901729" +dependencies = [ + "spin 0.9.7", + "wasmi_arena", + "wasmi_core 0.5.0", + "wasmparser-nostd", ] [[package]] @@ -8927,6 +9262,12 @@ dependencies = [ "parity-wasm", ] +[[package]] +name = "wasmi_arena" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ea379cbb0b41f3a9f0bf7b47036d036aae7f43383d8cc487d4deccf40dee0a" + [[package]] name = "wasmi_core" version = "0.2.1" @@ -8940,6 +9281,17 @@ dependencies = [ "num-traits 0.2.15", ] +[[package]] +name = "wasmi_core" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5bf998ab792be85e20e771fe14182b4295571ad1d4f89d3da521c1bef5f597a" +dependencies = [ + "downcast-rs", + "libm", + "num-traits 0.2.15", +] + [[package]] name = "wasmparser" version = "0.100.0" @@ -8950,6 +9302,15 @@ dependencies = [ "url 2.3.1", ] +[[package]] +name = "wasmparser-nostd" +version = "0.91.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c37f310b5a62bfd5ae7c0f1d8e6f98af16a5d6d84ba764e9c36439ec14e318b" +dependencies = [ + "indexmap-nostd", +] + [[package]] name = "wasmtime" version = "6.0.1" @@ -9122,6 +9483,16 @@ dependencies = [ "untrusted", ] +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring 0.16.20 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted", +] + [[package]] name = "webpki-roots" version = "0.21.0" @@ -9149,6 +9520,15 @@ dependencies = [ "webpki 0.21.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "webpki-roots" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +dependencies = [ + "webpki 0.22.0", +] + [[package]] name = "wide" version = "0.7.8" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4191fd3056..3aa4d5667b 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -25,8 +25,8 @@ ws = { version = "0.9.1", features = ["ssl"] } # scs / integritee my-node-runtime = { package = "integritee-node-runtime", git = "https://github.com/integritee-network/integritee-node.git", branch = "polkadot-v0.9.39" } pallet-evm = { optional = true, git = "https://github.com/integritee-network/frontier.git", branch = "polkadot-v0.9.39" } -substrate-api-client = { features = ["ws-client"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" } -substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" } +substrate-api-client = { features = ["ws-client"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } +substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } teerex-primitives = { git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v0.9.39" } # substrate dependencies diff --git a/core-primitives/extrinsics-factory/Cargo.toml b/core-primitives/extrinsics-factory/Cargo.toml index 07e2b72fec..b6d97e3175 100644 --- a/core-primitives/extrinsics-factory/Cargo.toml +++ b/core-primitives/extrinsics-factory/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" # sgx dependencies sgx_tstd = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true } sgx_types = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git" } -substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" } +substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } # local dependencies itp-node-api = { path = "../node-api", default-features = false } diff --git a/core-primitives/node-api/api-client-extensions/Cargo.toml b/core-primitives/node-api/api-client-extensions/Cargo.toml index 497506ac52..2824d0ab27 100644 --- a/core-primitives/node-api/api-client-extensions/Cargo.toml +++ b/core-primitives/node-api/api-client-extensions/Cargo.toml @@ -15,7 +15,7 @@ sp-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", bra sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } # scs -substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" } +substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } # local deps itp-types = { path = "../../types" } diff --git a/core-primitives/node-api/api-client-types/Cargo.toml b/core-primitives/node-api/api-client-types/Cargo.toml index 974556b34c..5dd80a8fbc 100644 --- a/core-primitives/node-api/api-client-types/Cargo.toml +++ b/core-primitives/node-api/api-client-types/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] # scs -substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" } +substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } # substrate sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } diff --git a/core-primitives/node-api/metadata/Cargo.toml b/core-primitives/node-api/metadata/Cargo.toml index a971b03497..3d6dd1874e 100644 --- a/core-primitives/node-api/metadata/Cargo.toml +++ b/core-primitives/node-api/metadata/Cargo.toml @@ -13,7 +13,7 @@ derive_more = { version = "0.99.5" } sp-core = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.39" } # scs -substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" } +substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } [features] default = ["std"] diff --git a/core-primitives/stf-executor/Cargo.toml b/core-primitives/stf-executor/Cargo.toml index 3837369960..0459301d11 100644 --- a/core-primitives/stf-executor/Cargo.toml +++ b/core-primitives/stf-executor/Cargo.toml @@ -26,7 +26,7 @@ itp-top-pool-author = { path = "../top-pool-author", default-features = false } itp-types = { path = "../types", default-features = false } # scs -substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" } +substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } # sgx enabled external libraries thiserror_sgx = { optional = true, package = "thiserror", git = "https://github.com/mesalock-linux/thiserror-sgx", tag = "sgx_1.1.3" } diff --git a/core/parentchain/indirect-calls-executor/Cargo.toml b/core/parentchain/indirect-calls-executor/Cargo.toml index 16f4642f84..e27228660b 100644 --- a/core/parentchain/indirect-calls-executor/Cargo.toml +++ b/core/parentchain/indirect-calls-executor/Cargo.toml @@ -38,7 +38,7 @@ sp-core = { default-features = false, features = ["full_crypto"], git = "https:/ sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } # scs/integritee -substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0", default-features = false } +substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0", default-features = false } [dev-dependencies] env_logger = "0.9.0" diff --git a/core/rpc-client/Cargo.toml b/core/rpc-client/Cargo.toml index 27db112f83..a5b2f0a421 100644 --- a/core/rpc-client/Cargo.toml +++ b/core/rpc-client/Cargo.toml @@ -13,7 +13,7 @@ parking_lot = "0.12.1" serde_derive = "1.0" serde_json = "1.0" sgx_crypto_helper = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git" } -substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" } +substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } thiserror = { version = "1.0" } url = { version = "2.0.0" } ws = { version = "0.9.1", features = ["ssl"] } diff --git a/enclave-runtime/Cargo.lock b/enclave-runtime/Cargo.lock index 21da067ef1..55cc2af1c4 100644 --- a/enclave-runtime/Cargo.lock +++ b/enclave-runtime/Cargo.lock @@ -14,8 +14,8 @@ dependencies = [ [[package]] name = "ac-compose-macros" -version = "0.2.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.7.0#84af198434ea210eb0cd90cb8239748c376a079a" +version = "0.2.2" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" dependencies = [ "ac-primitives", "log", @@ -23,21 +23,18 @@ dependencies = [ "sp-application-crypto", "sp-core", "sp-runtime", - "sp-std", ] [[package]] name = "ac-node-api" -version = "0.2.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.7.0#84af198434ea210eb0cd90cb8239748c376a079a" +version = "0.2.2" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" dependencies = [ "ac-primitives", "bitvec", "derive_more", "either", - "frame-metadata 15.0.0 (git+https://github.com/integritee-network/frame-metadata)", - "frame-support", - "frame-system", + "frame-metadata 15.0.0 (git+https://github.com/paritytech/frame-metadata)", "hex", "log", "parity-scale-codec", @@ -48,19 +45,24 @@ dependencies = [ "sp-core", "sp-runtime", "sp-runtime-interface", - "sp-std", ] [[package]] name = "ac-primitives" -version = "0.2.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.7.0#84af198434ea210eb0cd90cb8239748c376a079a" +version = "0.4.0" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" dependencies = [ "hex", + "impl-serde", "parity-scale-codec", + "primitive-types", + "scale-info", + "serde 1.0.158", + "serde_json 1.0.94", "sp-core", "sp-runtime", - "sp-std", + "sp-staking", + "sp-version", ] [[package]] @@ -976,7 +978,7 @@ dependencies = [ [[package]] name = "frame-metadata" version = "15.0.0" -source = "git+https://github.com/integritee-network/frame-metadata#3b43da9821238681f9431276d55b92a079142083" +source = "git+https://github.com/paritytech/frame-metadata#040a53c63af277e280282028b73b992eac9c35a2" dependencies = [ "cfg-if 1.0.0", "parity-scale-codec", @@ -4349,21 +4351,22 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "substrate-api-client" -version = "0.7.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.7.0#84af198434ea210eb0cd90cb8239748c376a079a" +version = "0.9.0" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" dependencies = [ "ac-compose-macros", "ac-node-api", "ac-primitives", - "frame-metadata 15.0.0 (git+https://github.com/integritee-network/frame-metadata)", - "frame-support", + "frame-metadata 15.0.0 (git+https://github.com/paritytech/frame-metadata)", "hex", "log", "parity-scale-codec", + "serde 1.0.158", + "serde_json 1.0.94", "sp-core", "sp-runtime", "sp-runtime-interface", - "sp-std", + "thiserror-core", ] [[package]] @@ -4456,6 +4459,26 @@ dependencies = [ "thiserror-impl 1.0.40", ] +[[package]] +name = "thiserror-core" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d97345f6437bb2004cd58819d8a9ef8e36cdd7661c2abc4bbde0a7c40d9f497" +dependencies = [ + "thiserror-core-impl", +] + +[[package]] +name = "thiserror-core-impl" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10ac1c5050e43014d16b2f94d0d2ce79e65ffdd8b38d8048f9c8f6a8a6da62ac" +dependencies = [ + "proc-macro2", + "quote 1.0.26", + "syn 1.0.109", +] + [[package]] name = "thiserror-impl" version = "1.0.9" diff --git a/enclave-runtime/Cargo.toml b/enclave-runtime/Cargo.toml index c41ca899df..908b6bd7b4 100644 --- a/enclave-runtime/Cargo.toml +++ b/enclave-runtime/Cargo.toml @@ -69,7 +69,7 @@ primitive-types = { version = "0.12.1", default-features = false, features = ["c # scs / integritee jsonrpc-core = { default-features = false, git = "https://github.com/scs/jsonrpc", branch = "no_std_v18" } -substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" } +substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } # mesalock env_logger = { git = "https://github.com/integritee-network/env_logger-sgx" } diff --git a/service/Cargo.toml b/service/Cargo.toml index 96b1739556..9fea393138 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -60,7 +60,7 @@ its-storage = { path = "../sidechain/storage" } my-node-runtime = { package = "integritee-node-runtime", git = "https://github.com/integritee-network/integritee-node.git", branch = "polkadot-v0.9.39" } sgx-verify = { git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v0.9.39" } -substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" } +substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } teerex-primitives = { git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v0.9.39" } # Substrate dependencies From 8610d5faa581dcc415b717b457f94f38f10b4e2a Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 29 Mar 2023 08:58:21 +0200 Subject: [PATCH 02/32] fix api-types --- Cargo.lock | 2 ++ cli/src/base_cli/mod.rs | 2 +- cli/src/trusted_operation.rs | 16 ++++++++------ .../api-client-extensions/src/account.rs | 15 ++++++++----- .../node-api/api-client-types/Cargo.toml | 8 +++++++ .../node-api/api-client-types/src/lib.rs | 15 ++++++++----- core-primitives/node-api/metadata/src/lib.rs | 3 +++ core-primitives/types/src/lib.rs | 1 + core-primitives/types/src/parentchain.rs | 22 +++++++++++++++++++ core/rpc-client/Cargo.toml | 4 ++++ core/rpc-client/src/direct_client.rs | 11 ++++++---- 11 files changed, 75 insertions(+), 24 deletions(-) create mode 100644 core-primitives/types/src/parentchain.rs diff --git a/Cargo.lock b/Cargo.lock index 68cb2818ad..6c43da37f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3164,6 +3164,7 @@ name = "itc-rpc-client" version = "0.9.0" dependencies = [ "env_logger 0.9.3", + "frame-metadata 15.0.0 (git+https://github.com/paritytech/frame-metadata)", "itc-tls-websocket-server", "itp-networking-utils", "itp-rpc", @@ -3274,6 +3275,7 @@ dependencies = [ name = "itp-api-client-types" version = "0.9.0" dependencies = [ + "integritee-node-runtime", "sp-core", "sp-runtime", "substrate-api-client", diff --git a/cli/src/base_cli/mod.rs b/cli/src/base_cli/mod.rs index 03b370ac99..65e61bc840 100644 --- a/cli/src/base_cli/mod.rs +++ b/cli/src/base_cli/mod.rs @@ -110,7 +110,7 @@ fn list_accounts() { } fn print_metadata(cli: &Cli) { - let meta = get_chain_api(cli).get_metadata().unwrap(); + let meta = get_chain_api(cli).metadata(); println!("Metadata:\n {}", Metadata::pretty_format(&meta).unwrap()); } diff --git a/cli/src/trusted_operation.rs b/cli/src/trusted_operation.rs index a042c6efa0..b20e49470a 100644 --- a/cli/src/trusted_operation.rs +++ b/cli/src/trusted_operation.rs @@ -115,14 +115,16 @@ fn send_request( let arg_signer = &trusted_args.xt_signer; let signer = get_pair_from_str(arg_signer); - let _chain_api = chain_api.set_signer(sr25519_core::Pair::from(signer)); + chain_api.set_signer(sr25519_core::Pair::from(signer)); let request = Request { shard, cyphertext: call_encrypted }; - let xt = compose_extrinsic!(_chain_api, TEEREX, "call_worker", request); + let xt = compose_extrinsic!(&chain_api, TEEREX, "call_worker", request); // send and watch extrinsic until block is executed - let block_hash = - _chain_api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap().unwrap(); + let block_hash = _chain_api + .submit_and_watch_extrinsic_until(xt.encode(), XtStatus::InBlock) + .unwrap() + .unwrap(); info!( "Trusted call extrinsic sent and successfully included in parentchain block with hash {:?}.", @@ -130,15 +132,15 @@ fn send_request( ); info!("Waiting for execution confirmation from enclave..."); let (events_in, events_out) = channel(); - _chain_api.subscribe_events(events_in).unwrap(); + chain_api.subscribe_events(events_in).unwrap(); loop { let ret: ProcessedParentchainBlockArgs = - _chain_api.wait_for_event::(&events_out).unwrap(); + chain_api.wait_for_event::(&events_out).unwrap(); info!("Confirmation of ProcessedParentchainBlock received"); debug!("Expected block Hash: {:?}", block_hash); debug!("Confirmed stf block Hash: {:?}", ret.block_hash); - match _chain_api.get_header::
(Some(block_hash)) { + match chain_api.get_header::
(Some(block_hash)) { Ok(option) => { match option { None => { diff --git a/core-primitives/node-api/api-client-extensions/src/account.rs b/core-primitives/node-api/api-client-extensions/src/account.rs index 4703223328..e13bff927b 100644 --- a/core-primitives/node-api/api-client-extensions/src/account.rs +++ b/core-primitives/node-api/api-client-extensions/src/account.rs @@ -16,20 +16,23 @@ */ use crate::ApiResult; -use itp_types::AccountId; +use itp_types::parentchain::{AccountId, Balance, Index}; use sp_core::crypto::Pair; use sp_runtime::MultiSignature; -use substrate_api_client::{Api, ExtrinsicParams, RpcClient}; +use substrate_api_client::{Api, ExtrinsicParams, Request}; /// ApiClient extension that contains some convenience methods around accounts. pub trait AccountApi { - fn get_nonce_of(&self, who: &AccountId) -> ApiResult; - fn get_free_balance(&self, who: &AccountId) -> ApiResult; + fn get_nonce_of(&self, who: &AccountId) -> ApiResult; + fn get_free_balance(&self, who: &AccountId) -> ApiResult; } -impl AccountApi for Api +impl AccountApi + for Api where - MultiSignature: From, + Signer: Pair, + Client: Request, + MultiSignature: From, { fn get_nonce_of(&self, who: &AccountId) -> ApiResult { Ok(self.get_account_info(who)?.map_or_else(|| 0, |info| info.nonce)) diff --git a/core-primitives/node-api/api-client-types/Cargo.toml b/core-primitives/node-api/api-client-types/Cargo.toml index 5dd80a8fbc..5b4ef4b97a 100644 --- a/core-primitives/node-api/api-client-types/Cargo.toml +++ b/core-primitives/node-api/api-client-types/Cargo.toml @@ -5,6 +5,8 @@ authors = ["Integritee AG "] edition = "2021" [dependencies] +# integritee-node +my-node-runtime = { package = "integritee-node-runtime", optional = true, git = "https://github.com/integritee-network/integritee-node.git", branch = "polkadot-v0.9.39" } # scs substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } @@ -13,11 +15,17 @@ substrate-api-client = { default-features = false, git = "https://github.com/scs sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } +# local +itp-types = { default-features = false, path = "../types" } + + [features] default = ["std"] std = [ + "itp-types/std", "substrate-api-client/std", "substrate-api-client/ws-client", "sp-core/std", "sp-runtime/std", + "my-node-runtime", ] diff --git a/core-primitives/node-api/api-client-types/src/lib.rs b/core-primitives/node-api/api-client-types/src/lib.rs index 67dbf17360..d4d7585be6 100644 --- a/core-primitives/node-api/api-client-types/src/lib.rs +++ b/core-primitives/node-api/api-client-types/src/lib.rs @@ -22,6 +22,7 @@ #![cfg_attr(not(feature = "std"), no_std)] +pub use itp_types::parentchain::{Balance, Index}; pub use sp_runtime::MultiSignature; pub use substrate_api_client::{ CallIndex, GenericAddress, PlainTip, PlainTipExtrinsicParams, PlainTipExtrinsicParamsBuilder, @@ -31,17 +32,17 @@ pub use substrate_api_client::{ /// Configuration for the ExtrinsicParams. /// /// Valid for the default integritee node -pub type ParentchainExtrinsicParams = PlainTipExtrinsicParams; -pub type ParentchainExtrinsicParamsBuilder = PlainTipExtrinsicParamsBuilder; +pub type ParentchainExtrinsicParams = PlainTipExtrinsicParams; +pub type ParentchainExtrinsicParamsBuilder = PlainTipExtrinsicParamsBuilder; // Pay in asset fees. // // This needs to be used if the node uses the `pallet_asset_tx_payment`. -//pub type ParentchainExtrinsicParams = AssetTipExtrinsicParams; -//pub type ParentchainExtrinsicParamsBuilder = AssetTipExtrinsicParamsBuilder; +//pub type ParentchainExtrinsicParams = AssetTipExtrinsicParams; +//pub type ParentchainExtrinsicParamsBuilder = AssetTipExtrinsicParamsBuilder; pub type ParentchainUncheckedExtrinsic = UncheckedExtrinsicV4; -pub type ParentchainSignedExtra = SubstrateDefaultSignedExtra; +pub type ParentchainSignedExtra = SubstrateDefaultSignedExtra, Index>; pub type ParentchainSignature = Signature; /// Signature type of the [UncheckedExtrinsicV4]. @@ -55,7 +56,9 @@ mod api { use super::ParentchainExtrinsicParams; use substrate_api_client::Api; + pub use my_node_runtime::Runtime; pub use substrate_api_client::{rpc::WsRpcClient, ApiClientError}; - pub type ParentchainApi = Api; + pub type ParentchainApi = + Api, Runtime>; } diff --git a/core-primitives/node-api/metadata/src/lib.rs b/core-primitives/node-api/metadata/src/lib.rs index 396c06a30a..98470e62e3 100644 --- a/core-primitives/node-api/metadata/src/lib.rs +++ b/core-primitives/node-api/metadata/src/lib.rs @@ -98,6 +98,7 @@ impl NodeMetadata { None => Err(Error::MetadataNotSet), Some(m) => m .storage_value_key(storage_prefix, storage_key_name) + .map(|key| key.into()) .map_err(Error::NodeMetadata), } } @@ -112,6 +113,7 @@ impl NodeMetadata { None => Err(Error::MetadataNotSet), Some(m) => m .storage_map_key::(storage_prefix, storage_key_name, map_key) + .map(|key| key.into()) .map_err(Error::NodeMetadata), } } @@ -127,6 +129,7 @@ impl NodeMetadata { None => Err(Error::MetadataNotSet), Some(m) => m .storage_double_map_key(storage_prefix, storage_key_name, first, second) + .map(|key| key.into()) .map_err(Error::NodeMetadata), } } diff --git a/core-primitives/types/src/lib.rs b/core-primitives/types/src/lib.rs index 14b50b726e..fa1d22f5a7 100644 --- a/core-primitives/types/src/lib.rs +++ b/core-primitives/types/src/lib.rs @@ -24,6 +24,7 @@ use codec::{Decode, Encode}; use sgx_tstd as std; use sp_std::vec::Vec; +pub mod parentchain; pub mod storage; /// Substrate runtimes provide no string type. Hence, for arbitrary data of varying length the diff --git a/core-primitives/types/src/parentchain.rs b/core-primitives/types/src/parentchain.rs new file mode 100644 index 0000000000..81ca3819d2 --- /dev/null +++ b/core-primitives/types/src/parentchain.rs @@ -0,0 +1,22 @@ +/* + Copyright 2021 Integritee AG and Supercomputing Systems AG + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +// Node specific params. Be sure to change them if your node uses different types. +pub type AccountId = sp_core::crypto::AccountId; +pub type Index = u32; +pub type Balance = u128; +pub type Hash = sp_core::H256; diff --git a/core/rpc-client/Cargo.toml b/core/rpc-client/Cargo.toml index a5b2f0a421..4dd93ef238 100644 --- a/core/rpc-client/Cargo.toml +++ b/core/rpc-client/Cargo.toml @@ -18,6 +18,10 @@ thiserror = { version = "1.0" } url = { version = "2.0.0" } ws = { version = "0.9.1", features = ["ssl"] } +# parity +frame-metadata = { git = "https://github.com/paritytech/frame-metadata", features = ["v14"] } + + # local itp-rpc = { path = "../../core-primitives/rpc" } itp-types = { path = "../../core-primitives/types" } diff --git a/core/rpc-client/src/direct_client.rs b/core/rpc-client/src/direct_client.rs index 1a761de286..b5f47d572f 100644 --- a/core/rpc-client/src/direct_client.rs +++ b/core/rpc-client/src/direct_client.rs @@ -19,6 +19,7 @@ use crate::ws_client::{WsClient, WsClientControl}; use codec::Decode; +use frame_metadata::RuntimeMetadataPrefixed; use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue}; use itp_types::DirectRequestStatus; use itp_utils::FromHexPrefixed; @@ -32,7 +33,7 @@ use std::{ thread, thread::JoinHandle, }; -use substrate_api_client::RuntimeMetadataPrefixed; +use substrate_api_client::metadata::Metadata; pub use crate::error::{Error, Result}; @@ -49,7 +50,7 @@ pub trait DirectApi { fn get_rsa_pubkey(&self) -> Result; fn get_mu_ra_url(&self) -> Result; fn get_untrusted_worker_url(&self) -> Result; - fn get_state_metadata(&self) -> Result; + fn get_state_metadata(&self) -> Result; fn send(&self, request: &str) -> Result<()>; /// Close any open websocket connection. @@ -136,7 +137,7 @@ impl DirectApi for DirectClient { Ok(untrusted_url) } - fn get_state_metadata(&self) -> Result { + fn get_state_metadata(&self) -> Result { let jsonrpc_call: String = RpcRequest::compose_jsonrpc_call("state_getMetadata".to_string(), Default::default())?; @@ -150,8 +151,10 @@ impl DirectApi for DirectClient { // Decode Metadata. let metadata = RuntimeMetadataPrefixed::decode(&mut rpc_return_value.value.as_slice())?; - println!("[+] Got metadata of enclave runtime"); + metadata = Metadata::try_from(metadata).map_err(|e| e.into()) + + Ok(metadata) } From 9d9e0f1a1c1e59eefa8273a16604c0d874f26098 Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 29 Mar 2023 09:30:24 +0200 Subject: [PATCH 03/32] some more changes --- Cargo.lock | 1 + cli/src/base_cli/commands/faucet.rs | 5 +++-- cli/src/base_cli/commands/shield_funds.rs | 4 ++-- cli/src/base_cli/commands/transfer.rs | 3 ++- cli/src/oracle/commands/add_to_whitelist.rs | 13 +++++++++---- .../api-client-extensions/src/account.rs | 19 ++++++++----------- .../api-client-extensions/src/chain.rs | 4 ++-- .../node-api/api-client-extensions/src/lib.rs | 4 ++-- .../src/pallet_teerex.rs | 4 ++-- .../node-api/api-client-types/Cargo.toml | 2 +- core-primitives/types/src/parentchain.rs | 2 +- core/rpc-client/src/direct_client.rs | 3 +-- enclave-runtime/Cargo.lock | 1 + 13 files changed, 35 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c43da37f9..977640af4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3276,6 +3276,7 @@ name = "itp-api-client-types" version = "0.9.0" dependencies = [ "integritee-node-runtime", + "itp-types", "sp-core", "sp-runtime", "substrate-api-client", diff --git a/cli/src/base_cli/commands/faucet.rs b/cli/src/base_cli/commands/faucet.rs index 18dd16f0ae..226a95ab19 100644 --- a/cli/src/base_cli/commands/faucet.rs +++ b/cli/src/base_cli/commands/faucet.rs @@ -36,13 +36,14 @@ pub struct FaucetCommand { impl FaucetCommand { pub(crate) fn run(&self, cli: &Cli) { - let api = get_chain_api(cli).set_signer(AccountKeyring::Alice.pair()); + let mut api = get_chain_api(cli); + api.set_signer(sr25519_core::Pair::from(AccountKeyring::Alice.pair())); let mut nonce = api.get_nonce().unwrap(); for account in &self.accounts { let to = get_accountid_from_str(account); #[allow(clippy::redundant_clone)] let xt: UncheckedExtrinsicV4<_, _> = compose_extrinsic_offline!( - api.clone().signer.unwrap(), + &api.signer().unwrap(), RuntimeCall::Balances(BalancesCall::transfer { dest: MultiAddress::Id(to.clone()), value: PREFUNDING_AMOUNT diff --git a/cli/src/base_cli/commands/shield_funds.rs b/cli/src/base_cli/commands/shield_funds.rs index e80a43c0b9..5be2453a92 100644 --- a/cli/src/base_cli/commands/shield_funds.rs +++ b/cli/src/base_cli/commands/shield_funds.rs @@ -46,7 +46,7 @@ pub struct ShieldFundsCommand { impl ShieldFundsCommand { pub(crate) fn run(&self, cli: &Cli) { - let chain_api = get_chain_api(cli); + let mut chain_api = get_chain_api(cli); let shard_opt = match self.shard.from_base58() { Ok(s) => ShardIdentifier::decode(&mut &s[..]), @@ -60,7 +60,7 @@ impl ShieldFundsCommand { // get the sender let from = get_pair_from_str(&self.from); - let chain_api = chain_api.set_signer(sr25519_core::Pair::from(from)); + chain_api.set_signer(sr25519_core::Pair::from(from)); // get the recipient let to = get_accountid_from_str(&self.to); diff --git a/cli/src/base_cli/commands/transfer.rs b/cli/src/base_cli/commands/transfer.rs index 781d9407e8..288f9185c1 100644 --- a/cli/src/base_cli/commands/transfer.rs +++ b/cli/src/base_cli/commands/transfer.rs @@ -42,7 +42,8 @@ impl TransferCommand { let to_account = get_accountid_from_str(&self.to); info!("from ss58 is {}", from_account.public().to_ss58check()); info!("to ss58 is {}", to_account.to_ss58check()); - let api = get_chain_api(cli).set_signer(sr25519_core::Pair::from(from_account)); + let mut api = get_chain_api(cli); + api.set_signer(sr25519_core::Pair::from(from_account)); let xt = api.balance_transfer(GenericAddress::Id(to_account.clone()), self.amount); let tx_hash = api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap(); println!("[+] TrustedOperation got finalized. Hash: {:?}\n", tx_hash); diff --git a/cli/src/oracle/commands/add_to_whitelist.rs b/cli/src/oracle/commands/add_to_whitelist.rs index 38eaf05eb4..50ba3ce915 100644 --- a/cli/src/oracle/commands/add_to_whitelist.rs +++ b/cli/src/oracle/commands/add_to_whitelist.rs @@ -39,16 +39,21 @@ pub struct AddToWhitelistCmd { impl AddToWhitelistCmd { pub fn run(&self, cli: &Cli) { - let api = get_chain_api(cli); + let mut api = get_chain_api(cli); let mrenclave = mrenclave_from_base58(&self.mrenclave); let from = get_pair_from_str(&self.from); let market_data_source = self.source.clone(); - let api = api.set_signer(from.into()); + api.set_signer(from.into()); - let call = - compose_call!(api.metadata, TEERACLE, ADD_TO_WHITELIST, market_data_source, mrenclave); + let call = compose_call!( + api.metadata(), + TEERACLE, + ADD_TO_WHITELIST, + market_data_source, + mrenclave + ); // compose the extrinsic let xt: UncheckedExtrinsicV4<_, _> = compose_extrinsic!(api, "Sudo", "sudo", call); diff --git a/core-primitives/node-api/api-client-extensions/src/account.rs b/core-primitives/node-api/api-client-extensions/src/account.rs index e13bff927b..b9811d1acf 100644 --- a/core-primitives/node-api/api-client-extensions/src/account.rs +++ b/core-primitives/node-api/api-client-extensions/src/account.rs @@ -16,10 +16,10 @@ */ use crate::ApiResult; -use itp_types::parentchain::{AccountId, Balance, Index}; +use itp_types::parentchain::{AccountData, AccountId, Balance, Hash, Index}; use sp_core::crypto::Pair; use sp_runtime::MultiSignature; -use substrate_api_client::{Api, ExtrinsicParams, Request}; +use substrate_api_client::GetAccountInformation; /// ApiClient extension that contains some convenience methods around accounts. pub trait AccountApi { @@ -27,18 +27,15 @@ pub trait AccountApi { fn get_free_balance(&self, who: &AccountId) -> ApiResult; } -impl AccountApi - for Api +impl AccountApi for Api where - Signer: Pair, - Client: Request, - MultiSignature: From, + Api: GetAccountInformation, { - fn get_nonce_of(&self, who: &AccountId) -> ApiResult { - Ok(self.get_account_info(who)?.map_or_else(|| 0, |info| info.nonce)) + fn get_nonce_of(&self, who: &AccountId) -> ApiResult { + Ok(self.get_account_info(who)?.map_or_else(|| 0, |info| info.nonce.into())) } - fn get_free_balance(&self, who: &AccountId) -> ApiResult { - Ok(self.get_account_data(who)?.map_or_else(|| 0, |data| data.free)) + fn get_free_balance(&self, who: &AccountId) -> ApiResult { + Ok(self.get_account_info(who)?.map_or_else(|| 0, |info| info.data.free.into())) } } diff --git a/core-primitives/node-api/api-client-extensions/src/chain.rs b/core-primitives/node-api/api-client-extensions/src/chain.rs index 39b9b785e6..917696529d 100644 --- a/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -20,7 +20,7 @@ use itp_types::{Header, SignedBlock}; use sp_core::{storage::StorageKey, Pair, H256}; use sp_finality_grandpa::{AuthorityList, VersionedAuthorityList, GRANDPA_AUTHORITIES_KEY}; use sp_runtime::MultiSignature; -use substrate_api_client::{Api, ExtrinsicParams, RpcClient}; +use substrate_api_client::{rpc::Request, Api, ExtrinsicParams}; pub type StorageProof = Vec>; @@ -39,7 +39,7 @@ pub trait ChainApi { fn grandpa_authorities_proof(&self, hash: Option) -> ApiResult; } -impl ChainApi for Api +impl ChainApi for Api where MultiSignature: From, { diff --git a/core-primitives/node-api/api-client-extensions/src/lib.rs b/core-primitives/node-api/api-client-extensions/src/lib.rs index 08004fa99f..72ab2edeae 100644 --- a/core-primitives/node-api/api-client-extensions/src/lib.rs +++ b/core-primitives/node-api/api-client-extensions/src/lib.rs @@ -17,7 +17,7 @@ //! Some substrate-api-client extension traits. -pub use substrate_api_client::{rpc::WsRpcClient, Api, ApiClientError}; +pub use substrate_api_client::{rpc::WsRpcClient, Api, Error}; pub mod account; pub mod chain; @@ -30,4 +30,4 @@ pub use chain::*; pub use pallet_teeracle::*; pub use pallet_teerex::*; -pub type ApiResult = Result; +pub type ApiResult = Result; diff --git a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs index 4405f8169f..60587e67b3 100644 --- a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs +++ b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs @@ -19,7 +19,7 @@ use crate::ApiResult; use itp_types::{Enclave, IpfsHash, ShardIdentifier}; use sp_core::{Pair, H256 as Hash}; use sp_runtime::MultiSignature; -use substrate_api_client::{Api, ExtrinsicParams, RpcClient}; +use substrate_api_client::{rpc::Request, Api, ExtrinsicParams}; pub const TEEREX: &str = "Teerex"; pub const SIDECHAIN: &str = "Sidechain"; @@ -41,7 +41,7 @@ pub trait PalletTeerexApi { ) -> ApiResult>; } -impl PalletTeerexApi for Api +impl PalletTeerexApi for Api where MultiSignature: From, { diff --git a/core-primitives/node-api/api-client-types/Cargo.toml b/core-primitives/node-api/api-client-types/Cargo.toml index 5b4ef4b97a..205ce327c4 100644 --- a/core-primitives/node-api/api-client-types/Cargo.toml +++ b/core-primitives/node-api/api-client-types/Cargo.toml @@ -16,7 +16,7 @@ sp-core = { default-features = false, git = "https://github.com/paritytech/subst sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } # local -itp-types = { default-features = false, path = "../types" } +itp-types = { default-features = false, path = "../../types" } [features] diff --git a/core-primitives/types/src/parentchain.rs b/core-primitives/types/src/parentchain.rs index 81ca3819d2..3db396a592 100644 --- a/core-primitives/types/src/parentchain.rs +++ b/core-primitives/types/src/parentchain.rs @@ -16,7 +16,7 @@ */ // Node specific params. Be sure to change them if your node uses different types. -pub type AccountId = sp_core::crypto::AccountId; +pub type AccountId = sp_core::crypto::AccountId32; pub type Index = u32; pub type Balance = u128; pub type Hash = sp_core::H256; diff --git a/core/rpc-client/src/direct_client.rs b/core/rpc-client/src/direct_client.rs index b5f47d572f..e1327b6fee 100644 --- a/core/rpc-client/src/direct_client.rs +++ b/core/rpc-client/src/direct_client.rs @@ -152,8 +152,7 @@ impl DirectApi for DirectClient { // Decode Metadata. let metadata = RuntimeMetadataPrefixed::decode(&mut rpc_return_value.value.as_slice())?; println!("[+] Got metadata of enclave runtime"); - metadata = Metadata::try_from(metadata).map_err(|e| e.into()) - + let metadata = Metadata::try_from(metadata).map_err(|e| e.into()); Ok(metadata) } diff --git a/enclave-runtime/Cargo.lock b/enclave-runtime/Cargo.lock index 55cc2af1c4..e19aae974f 100644 --- a/enclave-runtime/Cargo.lock +++ b/enclave-runtime/Cargo.lock @@ -1798,6 +1798,7 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" name = "itp-api-client-types" version = "0.9.0" dependencies = [ + "itp-types", "sp-core", "sp-runtime", "substrate-api-client", From 613a7117902bfb09b457ce0dd1e3d11f1551ad02 Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 29 Mar 2023 10:50:29 +0200 Subject: [PATCH 04/32] fix metadata --- .../api-client-extensions/src/chain.rs | 53 ++++++++++--------- .../node-api/api-client-extensions/src/lib.rs | 4 +- .../src/pallet_teerex.rs | 10 ++-- .../node-api/api-client-types/src/lib.rs | 2 +- core-primitives/node-api/factory/src/lib.rs | 11 ++-- core-primitives/types/src/parentchain.rs | 30 ++++++++++- core/rpc-client/src/direct_client.rs | 4 +- core/rpc-client/src/error.rs | 2 + 8 files changed, 75 insertions(+), 41 deletions(-) diff --git a/core-primitives/node-api/api-client-extensions/src/chain.rs b/core-primitives/node-api/api-client-extensions/src/chain.rs index 917696529d..39b82f0d4e 100644 --- a/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -16,54 +16,57 @@ */ use crate::ApiResult; -use itp_types::{Header, SignedBlock}; -use sp_core::{storage::StorageKey, Pair, H256}; +use itp_types::parentchain::{Block, BlockNumber, Hash, Header, SignedBlock, StorageProof}; use sp_finality_grandpa::{AuthorityList, VersionedAuthorityList, GRANDPA_AUTHORITIES_KEY}; -use sp_runtime::MultiSignature; -use substrate_api_client::{rpc::Request, Api, ExtrinsicParams}; - -pub type StorageProof = Vec>; +use sp_runtime::{traits::GetRuntimeBlockType, DeserializeOwned}; +use substrate_api_client::{ + error::NoBlockHash, primitives::StorageKey, rpc::Request, Api, ExtrinsicParams, + FrameSystemConfig, GetBlock, GetHeader, GetStorage, +}; /// ApiClient extension that simplifies chain data access. pub trait ChainApi { fn last_finalized_block(&self) -> ApiResult>; - fn signed_block(&self, hash: Option) -> ApiResult>; - fn get_genesis_hash(&self) -> ApiResult; - fn get_header(&self, header_hash: Option) -> ApiResult>; + fn signed_block(&self, hash: Option) -> ApiResult>; + fn get_genesis_hash(&self) -> ApiResult; + fn get_header(&self, header_hash: Option) -> ApiResult>; /// Fetch blocks from parentchain with blocknumber from until to, including both boundaries. /// Returns a vector with one element if from equals to. /// Returns an empty vector if from is greater than to. - fn get_blocks(&self, from: u32, to: u32) -> ApiResult>; + fn get_blocks(&self, from: BlockNumber, to: BlockNumber) -> ApiResult>; fn is_grandpa_available(&self) -> ApiResult; - fn grandpa_authorities(&self, hash: Option) -> ApiResult; - fn grandpa_authorities_proof(&self, hash: Option) -> ApiResult; + fn grandpa_authorities(&self, hash: Option) -> ApiResult; + fn grandpa_authorities_proof(&self, hash: Option) -> ApiResult; } -impl ChainApi for Api +impl ChainApi for Api where - MultiSignature: From, + Api: GetHeader, + Api: GetBlock, { fn last_finalized_block(&self) -> ApiResult> { self.get_finalized_head()? .map_or_else(|| Ok(None), |hash| self.signed_block(Some(hash))) } - fn signed_block(&self, hash: Option) -> ApiResult> { - // Even though this is only a wrapper here, we want to have this in the trait - // to be able to be generic over the trait and mock the `signed_block` method - // in tests. - self.get_signed_block(hash) + fn signed_block(&self, hash: Option) -> ApiResult> { + // Convert the substrate-api-clients `SignedBlock` redefinition into ours. + Ok(self.get_signed_block(hash)?.map(Into::into)) } - fn get_genesis_hash(&self) -> ApiResult { - self.get_genesis_hash() + fn get_genesis_hash(&self) -> ApiResult { + if let Some(hash) = self.get_block_hash(Some(0u32.into()))? { + Ok(hash) + } else { + Err(NoBlockHash) + } } - fn get_header(&self, header_hash: Option) -> ApiResult> { + fn get_header(&self, header_hash: Option) -> ApiResult> { self.get_header(header_hash) } - fn get_blocks(&self, from: u32, to: u32) -> ApiResult> { + fn get_blocks(&self, from: BlockNumber, to: BlockNumber) -> ApiResult> { let mut blocks = Vec::::new(); for n in from..=to { @@ -83,14 +86,14 @@ where .unwrap_or(false)) } - fn grandpa_authorities(&self, at_block: Option) -> ApiResult { + fn grandpa_authorities(&self, at_block: Option) -> ApiResult { Ok(self .get_storage_by_key_hash(StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec()), at_block)? .map(|g: VersionedAuthorityList| g.into()) .unwrap_or_default()) } - fn grandpa_authorities_proof(&self, at_block: Option) -> ApiResult { + fn grandpa_authorities_proof(&self, at_block: Option) -> ApiResult { Ok(self .get_storage_proof_by_keys( vec![StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec())], diff --git a/core-primitives/node-api/api-client-extensions/src/lib.rs b/core-primitives/node-api/api-client-extensions/src/lib.rs index 72ab2edeae..4265e33393 100644 --- a/core-primitives/node-api/api-client-extensions/src/lib.rs +++ b/core-primitives/node-api/api-client-extensions/src/lib.rs @@ -17,7 +17,7 @@ //! Some substrate-api-client extension traits. -pub use substrate_api_client::{rpc::WsRpcClient, Api, Error}; +pub use substrate_api_client::{api::Error as ApiClientError, rpc::WsRpcClient, Api}; pub mod account; pub mod chain; @@ -30,4 +30,4 @@ pub use chain::*; pub use pallet_teeracle::*; pub use pallet_teerex::*; -pub type ApiResult = Result; +pub type ApiResult = Result; diff --git a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs index 60587e67b3..5c4e6166f6 100644 --- a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs +++ b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs @@ -16,10 +16,10 @@ */ use crate::ApiResult; -use itp_types::{Enclave, IpfsHash, ShardIdentifier}; -use sp_core::{Pair, H256 as Hash}; +use itp_types::{parentchain::Hash, Enclave, IpfsHash, ShardIdentifier}; +use sp_core::Pair; use sp_runtime::MultiSignature; -use substrate_api_client::{rpc::Request, Api, ExtrinsicParams}; +use substrate_api_client::{rpc::Request, Api, ExtrinsicParams, GetStorage}; pub const TEEREX: &str = "Teerex"; pub const SIDECHAIN: &str = "Sidechain"; @@ -41,9 +41,9 @@ pub trait PalletTeerexApi { ) -> ApiResult>; } -impl PalletTeerexApi for Api +impl PalletTeerexApi for Api where - MultiSignature: From, + Api: GetStorage, { fn enclave(&self, index: u64, at_block: Option) -> ApiResult> { self.get_storage_map(TEEREX, "EnclaveRegistry", index, at_block) diff --git a/core-primitives/node-api/api-client-types/src/lib.rs b/core-primitives/node-api/api-client-types/src/lib.rs index d4d7585be6..7403900193 100644 --- a/core-primitives/node-api/api-client-types/src/lib.rs +++ b/core-primitives/node-api/api-client-types/src/lib.rs @@ -57,7 +57,7 @@ mod api { use substrate_api_client::Api; pub use my_node_runtime::Runtime; - pub use substrate_api_client::{rpc::WsRpcClient, ApiClientError}; + pub use substrate_api_client::{api::Error as ApiClientError, rpc::WsRpcClient, rpc::Error as RpcClientError}; pub type ParentchainApi = Api, Runtime>; diff --git a/core-primitives/node-api/factory/src/lib.rs b/core-primitives/node-api/factory/src/lib.rs index 3c15d66aec..fb37dc6ec2 100644 --- a/core-primitives/node-api/factory/src/lib.rs +++ b/core-primitives/node-api/factory/src/lib.rs @@ -27,6 +27,8 @@ pub trait CreateNodeApi { /// Node API factory error. #[derive(Debug, thiserror::Error)] pub enum NodeApiFactoryError { + #[error("Could not connect to node with rpc client: {0}")] + FailedToCreateRpcClient(#[from] itp_api_client_types::RpcClientError), #[error("Failed to create a node API: {0}")] FailedToCreateNodeApi(#[from] itp_api_client_types::ApiClientError), #[error(transparent)] @@ -49,8 +51,11 @@ impl NodeApiFactory { impl CreateNodeApi for NodeApiFactory { fn create_api(&self) -> Result { - ParentchainApi::new(WsRpcClient::new(self.node_url.as_str())) - .map_err(NodeApiFactoryError::FailedToCreateNodeApi) - .map(|a| a.set_signer(self.signer.clone())) + let rpc_client = WsRpcClient::new(self.node_url.as_str()) + .map_err(NodeApiFactoryError::FailedToCreateRpcClient)?; + let mut api = + ParentchainApi::new(rpc_client).map_err(NodeApiFactoryError::FailedToCreateNodeApi)?; + api.set_signer(self.signer.clone()); + Ok(api) } } diff --git a/core-primitives/types/src/parentchain.rs b/core-primitives/types/src/parentchain.rs index 3db396a592..bbdc47409b 100644 --- a/core-primitives/types/src/parentchain.rs +++ b/core-primitives/types/src/parentchain.rs @@ -15,8 +15,34 @@ */ -// Node specific params. Be sure to change them if your node uses different types. -pub type AccountId = sp_core::crypto::AccountId32; +//! Parentchain specific params. Be sure to change them if your node uses different types. + +use sp_runtime::{ + generic::{self, Block as BlockG, SignedBlock as SignedBlockG}, + traits::{BlakeTwo256, IdentifyAccount, Verify}, + MultiSignature, OpaqueExtrinsic, +}; + +// Basic Types. pub type Index = u32; pub type Balance = u128; pub type Hash = sp_core::H256; + +// Account Types. +pub type AccountId = sp_core::crypto::AccountId32; +pub type AccountData = pallet_balances::AccountData; +pub type AccountInfo = frame_system::AccountInfo; +pub type AccountIndex = u32; +pub type Address = sp_runtime::MultiAddress; + +// Block Types +pub type BlockNumber = u32; +pub type Header = generic::Header; +pub type Block = BlockG; +pub type SignedBlock = SignedBlockG; +pub type BlockHash = sp_core::H256; + +/// Alias to 512-bit hash when used in the context of a transaction signature on the chain. +pub type Signature = MultiSignature; + +pub type StorageProof = Vec>; diff --git a/core/rpc-client/src/direct_client.rs b/core/rpc-client/src/direct_client.rs index e1327b6fee..281e592f5c 100644 --- a/core/rpc-client/src/direct_client.rs +++ b/core/rpc-client/src/direct_client.rs @@ -152,9 +152,7 @@ impl DirectApi for DirectClient { // Decode Metadata. let metadata = RuntimeMetadataPrefixed::decode(&mut rpc_return_value.value.as_slice())?; println!("[+] Got metadata of enclave runtime"); - let metadata = Metadata::try_from(metadata).map_err(|e| e.into()); - - Ok(metadata) + Metadata::try_from(metadata).map_err(|e| e.into()) } fn send(&self, request: &str) -> Result<()> { diff --git a/core/rpc-client/src/error.rs b/core/rpc-client/src/error.rs index 5fc5a298da..411ac97890 100644 --- a/core/rpc-client/src/error.rs +++ b/core/rpc-client/src/error.rs @@ -34,6 +34,8 @@ pub enum Error { WsClientError(#[from] WsClientError), #[error("Faulty channel: {0}")] MspcReceiver(#[from] RecvError), + #[error("InvalidMetadata: {0}")] + InvalidMetadata(#[from] substrate_api_client::metadata::InvalidMetadataError), #[error("Custom Error: {0}")] Custom(Box), } From 563e525a129b949073334f635a9762680ae3814e Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 29 Mar 2023 10:57:46 +0200 Subject: [PATCH 05/32] fix it all --- .../node-api/api-client-extensions/src/chain.rs | 5 +++-- core/rpc-client/src/error.rs | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core-primitives/node-api/api-client-extensions/src/chain.rs b/core-primitives/node-api/api-client-extensions/src/chain.rs index 39b82f0d4e..6746b4d501 100644 --- a/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -20,7 +20,7 @@ use itp_types::parentchain::{Block, BlockNumber, Hash, Header, SignedBlock, Stor use sp_finality_grandpa::{AuthorityList, VersionedAuthorityList, GRANDPA_AUTHORITIES_KEY}; use sp_runtime::{traits::GetRuntimeBlockType, DeserializeOwned}; use substrate_api_client::{ - error::NoBlockHash, primitives::StorageKey, rpc::Request, Api, ExtrinsicParams, + api::Error::NoBlockHash, primitives::StorageKey, rpc::Request, Api, ExtrinsicParams, FrameSystemConfig, GetBlock, GetHeader, GetStorage, }; @@ -43,6 +43,7 @@ impl ChainApi for Api where Api: GetHeader, Api: GetBlock, + Api: GetStorage, { fn last_finalized_block(&self) -> ApiResult> { self.get_finalized_head()? @@ -71,7 +72,7 @@ where for n in from..=to { if let Some(block) = self.get_signed_block_by_num(Some(n))? { - blocks.push(block); + blocks.push(block.into()); } } Ok(blocks) diff --git a/core/rpc-client/src/error.rs b/core/rpc-client/src/error.rs index 411ac97890..5f4d0d5d1d 100644 --- a/core/rpc-client/src/error.rs +++ b/core/rpc-client/src/error.rs @@ -17,6 +17,7 @@ use codec::Error as CodecError; use serde_json::Error as JsonError; use std::{boxed::Box, sync::mpsc::RecvError}; +use substrate_api_client::metadata::InvalidMetadataError; use thiserror; use ws::Error as WsClientError; @@ -34,8 +35,14 @@ pub enum Error { WsClientError(#[from] WsClientError), #[error("Faulty channel: {0}")] MspcReceiver(#[from] RecvError), - #[error("InvalidMetadata: {0}")] - InvalidMetadata(#[from] substrate_api_client::metadata::InvalidMetadataError), + #[error("InvalidMetadata: {0:?}")] + InvalidMetadata(InvalidMetadataError), #[error("Custom Error: {0}")] Custom(Box), } + +impl From for Error { + fn from(error: InvalidMetadataError) -> Self { + Error::InvalidMetadata(error) + } +} From 9bd6a9669bdeee6c0bf1a2618e361f30fcf3b012 Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 29 Mar 2023 11:15:57 +0200 Subject: [PATCH 06/32] fix submit extrinsic --- .../node-api/api-client-types/src/lib.rs | 24 ++++++++----- service/src/account_funding.rs | 14 +++++--- service/src/error.rs | 10 ++++-- service/src/main.rs | 34 +++++++++---------- 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/core-primitives/node-api/api-client-types/src/lib.rs b/core-primitives/node-api/api-client-types/src/lib.rs index 7403900193..45fd157616 100644 --- a/core-primitives/node-api/api-client-types/src/lib.rs +++ b/core-primitives/node-api/api-client-types/src/lib.rs @@ -22,27 +22,30 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub use itp_types::parentchain::{Balance, Index}; +pub use itp_types::parentchain::{Balance, Hash, Index}; pub use sp_runtime::MultiSignature; pub use substrate_api_client::{ - CallIndex, GenericAddress, PlainTip, PlainTipExtrinsicParams, PlainTipExtrinsicParamsBuilder, + AssetTip, BaseExtrinsicParams, BaseExtrinsicParamsBuilder, CallIndex, GenericAddress, PlainTip, SubstrateDefaultSignedExtra, UncheckedExtrinsicV4, }; +pub type ParentchainPlainTip = PlainTip; +pub type ParentchainAssetTip = AssetTip; + /// Configuration for the ExtrinsicParams. /// /// Valid for the default integritee node -pub type ParentchainExtrinsicParams = PlainTipExtrinsicParams; -pub type ParentchainExtrinsicParamsBuilder = PlainTipExtrinsicParamsBuilder; +pub type ParentchainExtrinsicParams = BaseExtrinsicParams; +pub type ParentchainExtrinsicParamsBuilder = BaseExtrinsicParamsBuilder; // Pay in asset fees. // // This needs to be used if the node uses the `pallet_asset_tx_payment`. -//pub type ParentchainExtrinsicParams = AssetTipExtrinsicParams; -//pub type ParentchainExtrinsicParamsBuilder = AssetTipExtrinsicParamsBuilder; +//pub type ParentchainExtrinsicParams = BaseExtrinsicParams; +//pub type ParentchainExtrinsicParamsBuilder = BaseExtrinsicParamsBuilder; pub type ParentchainUncheckedExtrinsic = UncheckedExtrinsicV4; -pub type ParentchainSignedExtra = SubstrateDefaultSignedExtra, Index>; +pub type ParentchainSignedExtra = SubstrateDefaultSignedExtra; pub type ParentchainSignature = Signature; /// Signature type of the [UncheckedExtrinsicV4]. @@ -57,8 +60,11 @@ mod api { use substrate_api_client::Api; pub use my_node_runtime::Runtime; - pub use substrate_api_client::{api::Error as ApiClientError, rpc::WsRpcClient, rpc::Error as RpcClientError}; + pub use substrate_api_client::{ + api::Error as ApiClientError, + rpc::{Error as RpcClientError, WsRpcClient}, + }; pub type ParentchainApi = - Api, Runtime>; + Api; } diff --git a/service/src/account_funding.rs b/service/src/account_funding.rs index 586c4f1ff1..b9ce8f971c 100644 --- a/service/src/account_funding.rs +++ b/service/src/account_funding.rs @@ -21,13 +21,14 @@ use itp_node_api::api_client::{AccountApi, ParentchainApi}; use itp_settings::worker::{ EXISTENTIAL_DEPOSIT_FACTOR_FOR_INIT_FUNDS, REGISTERING_FEE_FACTOR_FOR_INIT_FUNDS, }; +use itp_types::parentchain::Balance; use log::*; use sp_core::{ crypto::{AccountId32, Ss58Codec}, Pair, }; use sp_keyring::AccountKeyring; -use substrate_api_client::{Balance, GenericAddress, XtStatus}; +use substrate_api_client::{GenericAddress, XtStatus}; /// Information about the enclave on-chain account. pub trait EnclaveAccountInfo { @@ -54,7 +55,7 @@ impl EnclaveAccountInfoProvider { pub fn setup_account_funding( api: &ParentchainApi, accountid: &AccountId32, - extrinsic_prefix: &str, + encoded_extrinsic: Vec, is_development_mode: bool, ) -> ServiceResult<()> { // Account funds @@ -63,7 +64,7 @@ pub fn setup_account_funding( ensure_account_has_funds(api, accountid)?; } else { // Production mode, there is no faucet. - let registration_fees = enclave_registration_fees(api, extrinsic_prefix)?; + let registration_fees = enclave_registration_fees(api, encoded_extrinsic)?; info!("Registration fees = {:?}", registration_fees); let free_balance = api.get_free_balance(accountid)?; info!("TEE's free balance = {:?}", free_balance); @@ -107,8 +108,11 @@ fn ensure_account_has_funds(api: &ParentchainApi, accountid: &AccountId32) -> Re Ok(()) } -fn enclave_registration_fees(api: &ParentchainApi, xthex_prefixed: &str) -> Result { - let reg_fee_details = api.get_fee_details(xthex_prefixed, None)?; +fn enclave_registration_fees( + api: &ParentchainApi, + encoded_extrinsic: Vec, +) -> Result { + let reg_fee_details = api.get_fee_details(encoded_extrinsic, None)?; match reg_fee_details { Some(details) => match details.inclusion_fee { Some(fee) => Ok(fee.inclusion_fee()), diff --git a/service/src/error.rs b/service/src/error.rs index 8dea96c1d1..e8878f1aad 100644 --- a/service/src/error.rs +++ b/service/src/error.rs @@ -15,8 +15,8 @@ */ use codec::Error as CodecError; +use itp_node_api::api_client::ApiClientError; use itp_types::ShardIdentifier; -use substrate_api_client::ApiClientError; pub type ServiceResult = Result; @@ -25,7 +25,7 @@ pub enum Error { #[error("{0}")] Codec(#[from] CodecError), #[error("{0}")] - ApiClient(#[from] ApiClientError), + ApiClient(ApiClientError), #[error("Node API terminated subscription unexpectedly: {0}")] ApiSubscriptionDisconnected(#[from] std::sync::mpsc::RecvError), #[error("Enclave API error: {0}")] @@ -53,3 +53,9 @@ pub enum Error { #[error("{0}")] Custom(Box), } + +impl From for Error { + fn from(error: ApiClientError) -> Self { + Error::ApiClient(error) + } +} diff --git a/service/src/main.rs b/service/src/main.rs index b767071a3f..46faf01494 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -81,6 +81,7 @@ use sgx_verify::extract_tcb_info_from_raw_dcap_quote; use sp_core::crypto::{AccountId32, Ss58Codec}; use sp_keyring::AccountKeyring; +use sp_runtime::traits::Header as HeaderTrait; use std::{ path::PathBuf, str, @@ -91,7 +92,7 @@ use std::{ thread, time::Duration, }; -use substrate_api_client::{utils::FromHexString, Header as HeaderTrait, XtStatus}; +use substrate_api_client::{utils::FromHexString, XtStatus}; use teerex_primitives::ShardIdentifier; mod account_funding; @@ -421,9 +422,9 @@ fn start_worker( .set_nonce(nonce) .expect("Could not set nonce of enclave. Returning here..."); - let metadata = node_api.metadata.clone(); - let runtime_spec_version = node_api.runtime_version.spec_version; - let runtime_transaction_version = node_api.runtime_version.transaction_version; + let metadata = node_api.metadata().clone(); + let runtime_spec_version = node_api.runtime_version().spec_version; + let runtime_transaction_version = node_api.runtime_version().transaction_version; enclave .set_node_metadata( NodeMetadata::new(metadata, runtime_spec_version, runtime_transaction_version).encode(), @@ -459,11 +460,11 @@ fn start_worker( println!("[!] creating remote attestation report and create enclave register extrinsic."); }; #[cfg(not(feature = "dcap"))] - let uxt = enclave.generate_ias_ra_extrinsic(&trusted_url, skip_ra).unwrap(); + let xt = enclave.generate_ias_ra_extrinsic(&trusted_url, skip_ra).unwrap(); #[cfg(feature = "dcap")] - let uxt = enclave.generate_dcap_ra_extrinsic(&trusted_url, skip_ra).unwrap(); + let xt = enclave.generate_dcap_ra_extrinsic(&trusted_url, skip_ra).unwrap(); let register_enclave_xt_hash = - send_extrinsic(&uxt, &node_api, &tee_accountid, is_development_mode); + send_extrinsic(xt, &node_api, &tee_accountid, is_development_mode); let register_enclave_xt_header = node_api.get_header(register_enclave_xt_hash).unwrap().unwrap(); @@ -767,8 +768,8 @@ fn register_quotes_from_marblerun( for quote in quotes { match enclave.generate_dcap_ra_extrinsic_from_quote(url.clone(), "e) { - Ok(xts) => { - send_extrinsic(&xts, api, accountid, is_development_mode); + Ok(xt) => { + send_extrinsic(xt, api, accountid, is_development_mode); }, Err(e) => { error!("Extracting information from quote failed: {}", e) @@ -787,29 +788,28 @@ fn register_collateral( let dcap_quote = enclave.generate_dcap_ra_quote(skip_ra).unwrap(); let (fmspc, _tcb_info) = extract_tcb_info_from_raw_dcap_quote(&dcap_quote).unwrap(); - let uxt = enclave.generate_register_quoting_enclave_extrinsic(fmspc).unwrap(); - send_extrinsic(&uxt, api, accountid, is_development_mode); + let xt = enclave.generate_register_quoting_enclave_extrinsic(fmspc).unwrap(); + send_extrinsic(xt, api, accountid, is_development_mode); - let uxt = enclave.generate_register_tcb_info_extrinsic(fmspc).unwrap(); - send_extrinsic(&uxt, api, accountid, is_development_mode); + let xt = enclave.generate_register_tcb_info_extrinsic(fmspc).unwrap(); + send_extrinsic(xt, api, accountid, is_development_mode); } fn send_extrinsic( - extrinsic: &[u8], + extrinsic: Vec, api: &ParentchainApi, accountid: &AccountId32, is_development_mode: bool, ) -> Option { - let xthex = hex_encode(extrinsic); // Account funds - if let Err(x) = setup_account_funding(api, accountid, &xthex, is_development_mode) { + if let Err(x) = setup_account_funding(api, accountid, extrinsic.clone(), is_development_mode) { error!("Starting worker failed: {:?}", x); // Return without registering the enclave. This will fail and the transaction will be banned for 30min. return None } println!("[>] Register the TCB info (send the extrinsic)"); - let register_qe_xt_hash = api.send_extrinsic(xthex, XtStatus::Finalized).unwrap(); + let register_qe_xt_hash = api.submit_extrinsic(extrinsic, XtStatus::Finalized).unwrap(); println!("[<] Extrinsic got finalized. Hash: {:?}\n", register_qe_xt_hash); register_qe_xt_hash } From 51de119673517154d02205ff820ac622f282cac4 Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 29 Mar 2023 14:39:25 +0200 Subject: [PATCH 07/32] fix palletteerex api --- Cargo.lock | 1 + .../src/pallet_teerex.rs | 19 +++-- .../src/pallet_teerex_api_mock.rs | 2 +- core-primitives/types/Cargo.toml | 4 + core-primitives/types/src/parentchain.rs | 82 ++++++++++++++----- service/src/main.rs | 1 - .../src/ocall_bridge/worker_on_chain_ocall.rs | 2 +- service/src/sync_state.rs | 1 + 8 files changed, 81 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 977640af4d..97b4bdd94d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3766,6 +3766,7 @@ version = "0.9.0" dependencies = [ "chrono 0.4.24", "frame-system", + "integritee-node-runtime", "itp-sgx-runtime-primitives", "pallet-balances", "parity-scale-codec", diff --git a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs index 5c4e6166f6..4aad08dd8e 100644 --- a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs +++ b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs @@ -19,7 +19,7 @@ use crate::ApiResult; use itp_types::{parentchain::Hash, Enclave, IpfsHash, ShardIdentifier}; use sp_core::Pair; use sp_runtime::MultiSignature; -use substrate_api_client::{rpc::Request, Api, ExtrinsicParams, GetStorage}; +use substrate_api_client::{rpc::Request, Api, ExtrinsicParams, FrameSystemConfig, GetStorage}; pub const TEEREX: &str = "Teerex"; pub const SIDECHAIN: &str = "Sidechain"; @@ -41,16 +41,21 @@ pub trait PalletTeerexApi { ) -> ApiResult>; } -impl PalletTeerexApi for Api +impl PalletTeerexApi for Api where - Api: GetStorage, + Client: Request, + Runtime: FrameSystemConfig, + Params: ExtrinsicParams, + Runtime::Hash: From, { fn enclave(&self, index: u64, at_block: Option) -> ApiResult> { - self.get_storage_map(TEEREX, "EnclaveRegistry", index, at_block) + self.get_storage_map(TEEREX, "EnclaveRegistry", index, at_block.map(|b| b.into())) } fn enclave_count(&self, at_block: Option) -> ApiResult { - Ok(self.get_storage_value(TEEREX, "EnclaveCount", at_block)?.unwrap_or(0u64)) + Ok(self + .get_storage_value(TEEREX, "EnclaveCount", at_block.map(|b| b.into()))? + .unwrap_or(0u64)) } fn all_enclaves(&self, at_block: Option) -> ApiResult> { @@ -67,7 +72,7 @@ where shard: &ShardIdentifier, at_block: Option, ) -> ApiResult> { - self.get_storage_map(SIDECHAIN, "WorkerForShard", shard, at_block)? + self.get_storage_map(SIDECHAIN, "WorkerForShard", shard, at_block.map(|b| b.into()))? .map_or_else(|| Ok(None), |w_index| self.enclave(w_index, at_block)) } @@ -76,6 +81,6 @@ where shard: &ShardIdentifier, at_block: Option, ) -> ApiResult> { - self.get_storage_map(TEEREX, "LatestIPFSHash", shard, at_block) + self.get_storage_map(TEEREX, "LatestIPFSHash", shard, at_block.map(|b| b.into())) } } diff --git a/core-primitives/node-api/api-client-extensions/src/pallet_teerex_api_mock.rs b/core-primitives/node-api/api-client-extensions/src/pallet_teerex_api_mock.rs index 867b7ee5ff..06da958b9d 100644 --- a/core-primitives/node-api/api-client-extensions/src/pallet_teerex_api_mock.rs +++ b/core-primitives/node-api/api-client-extensions/src/pallet_teerex_api_mock.rs @@ -16,7 +16,7 @@ */ use crate::{pallet_teerex::PalletTeerexApi, ApiResult}; -use itp_types::{Enclave, IpfsHash, ShardIdentifier, H256 as Hash}; +use itp_types::{parentchain::Hash, Enclave, IpfsHash, ShardIdentifier}; #[derive(Default)] pub struct PalletTeerexApiMock { diff --git a/core-primitives/types/Cargo.toml b/core-primitives/types/Cargo.toml index 0829be85c8..63ff06ea7c 100644 --- a/core-primitives/types/Cargo.toml +++ b/core-primitives/types/Cargo.toml @@ -24,11 +24,15 @@ sp-core = { default-features = false, features = ["full_crypto"], git = "https:/ sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } +# integritee-node +my-node-runtime = { package = "integritee-node-runtime", optional = true, git = "https://github.com/integritee-network/integritee-node.git", branch = "polkadot-v0.9.39" } + [features] default = ["std"] std = [ "codec/std", "chrono/std", + "my-node-runtime", "serde/std", "serde_json/std", "primitive-types/std", diff --git a/core-primitives/types/src/parentchain.rs b/core-primitives/types/src/parentchain.rs index bbdc47409b..31faf7535b 100644 --- a/core-primitives/types/src/parentchain.rs +++ b/core-primitives/types/src/parentchain.rs @@ -18,31 +18,71 @@ //! Parentchain specific params. Be sure to change them if your node uses different types. use sp_runtime::{ - generic::{self, Block as BlockG, SignedBlock as SignedBlockG}, + generic::{self, Block as BlockG, SignedBlock as SignedBlockG, UncheckedExtrinsic}, traits::{BlakeTwo256, IdentifyAccount, Verify}, - MultiSignature, OpaqueExtrinsic, + MultiSignature, }; -// Basic Types. -pub type Index = u32; -pub type Balance = u128; -pub type Hash = sp_core::H256; +pub type StorageProof = Vec>; -// Account Types. -pub type AccountId = sp_core::crypto::AccountId32; -pub type AccountData = pallet_balances::AccountData; -pub type AccountInfo = frame_system::AccountInfo; -pub type AccountIndex = u32; -pub type Address = sp_runtime::MultiAddress; +#[cfg(not(feature = "std"))] +pub use no_std::*; -// Block Types -pub type BlockNumber = u32; -pub type Header = generic::Header; -pub type Block = BlockG; -pub type SignedBlock = SignedBlockG; -pub type BlockHash = sp_core::H256; +#[cfg(feature = "std")] +pub use runtime_types::*; -/// Alias to 512-bit hash when used in the context of a transaction signature on the chain. -pub type Signature = MultiSignature; +#[cfg(not(feature = "std"))] +pub mod no_std { + use super::*; -pub type StorageProof = Vec>; + // Basic Types. + pub type Index = u32; + pub type Balance = u128; + pub type Hash = sp_core::H256; + + // Account Types. + pub type AccountId = sp_core::crypto::AccountId32; + pub type AccountData = pallet_balances::AccountData; + pub type AccountInfo = frame_system::AccountInfo; + pub type Address = sp_runtime::MultiAddress; + + // Block Types + pub type BlockNumber = u32; + pub type Header = generic::Header; + pub type Block = BlockG; + pub type SignedBlock = SignedBlockG>; + pub type BlockHash = sp_core::H256; + + /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. + pub type Signature = MultiSignature; +} + +#[cfg(feature = "std")] +pub mod runtime_types { + use super::*; + use frame_system::Config as FrameSystemConfig; + use my_node_runtime::Runtime; + use pallet_balances::Config as BalancesConfig; + + // Basic Types. + pub type Index = ::Index; + pub type Balance = ::Balance; + pub type Hash = ::Hash; + + // Account Types. + pub type AccountId = ::AccountId; + pub type AccountData = ::AccountData; + pub type AccountInfo = frame_system::AccountInfo; + pub type Address = my_node_runtime::Address; + + // Block Types + pub type BlockNumber = ::BlockNumber; + pub type Header = ::Header; + pub type UncheckedExtrinsic = my_node_runtime::UncheckedExtrinsic; + pub type Block = my_node_runtime::Block; + pub type SignedBlock = SignedBlockG; + pub type BlockHash = ::Hash; + + /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. + pub type Signature = my_node_runtime::Signature; +} diff --git a/service/src/main.rs b/service/src/main.rs index 46faf01494..047d046a45 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -66,7 +66,6 @@ use itp_settings::{ files::SIDECHAIN_STORAGE_PATH, worker_mode::{ProvideWorkerMode, WorkerMode, WorkerModeProvider}, }; -use itp_utils::hex::hex_encode; use its_peer_fetch::{ block_fetch_client::BlockFetcher, untrusted_peer_fetch::UntrustedPeerFetcher, }; diff --git a/service/src/ocall_bridge/worker_on_chain_ocall.rs b/service/src/ocall_bridge/worker_on_chain_ocall.rs index 102e91cc38..2e4b6568d1 100644 --- a/service/src/ocall_bridge/worker_on_chain_ocall.rs +++ b/service/src/ocall_bridge/worker_on_chain_ocall.rs @@ -25,7 +25,7 @@ use log::*; use sp_core::storage::StorageKey; use sp_runtime::OpaqueExtrinsic; use std::{sync::Arc, vec::Vec}; -use substrate_api_client::XtStatus; +use substrate_api_client::{GetStorage, XtStatus}; pub struct WorkerOnChainOCall { node_api_factory: Arc, diff --git a/service/src/sync_state.rs b/service/src/sync_state.rs index 0a924662ba..9702596cf4 100644 --- a/service/src/sync_state.rs +++ b/service/src/sync_state.rs @@ -28,6 +28,7 @@ use itp_settings::worker_mode::{ProvideWorkerMode, WorkerMode}; use itp_types::ShardIdentifier; use sgx_types::sgx_quote_sign_type_t; use std::string::String; +use substrate_api_client::FrameSystemConfig; pub(crate) fn sync_state< E: TlsRemoteAttestation + EnclaveBase, From 0724b4391685c073f5cbad72051d78e17e0f6fa0 Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 29 Mar 2023 17:12:50 +0200 Subject: [PATCH 08/32] one step further --- Cargo.lock | 11 +- .../node-api/api-client-extensions/Cargo.toml | 1 + .../api-client-extensions/src/account.rs | 34 ++++- .../api-client-extensions/src/chain.rs | 64 +++++++--- .../node-api/api-client-types/src/lib.rs | 5 +- core-primitives/types/src/parentchain.rs | 120 +++++++++--------- service/src/account_funding.rs | 11 +- service/src/main.rs | 10 +- .../src/ocall_bridge/worker_on_chain_ocall.rs | 6 +- service/src/parentchain_handler.rs | 2 +- 10 files changed, 163 insertions(+), 101 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 97b4bdd94d..3175a88fc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,7 +15,7 @@ dependencies = [ [[package]] name = "ac-compose-macros" version = "0.2.2" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c4d3f110b94e25d5ce52d5bb64d0c778c4c7f2da" dependencies = [ "ac-primitives", "log 0.4.17", @@ -28,7 +28,7 @@ dependencies = [ [[package]] name = "ac-node-api" version = "0.2.2" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c4d3f110b94e25d5ce52d5bb64d0c778c4c7f2da" dependencies = [ "ac-primitives", "bitvec", @@ -50,7 +50,7 @@ dependencies = [ [[package]] name = "ac-primitives" version = "0.4.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c4d3f110b94e25d5ce52d5bb64d0c778c4c7f2da" dependencies = [ "frame-system", "hex", @@ -3262,6 +3262,7 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" name = "itp-api-client-extensions" version = "0.9.0" dependencies = [ + "itp-api-client-types", "itp-types", "parity-scale-codec", "sp-core", @@ -8197,7 +8198,7 @@ dependencies = [ [[package]] name = "substrate-api-client" version = "0.9.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c4d3f110b94e25d5ce52d5bb64d0c778c4c7f2da" dependencies = [ "ac-compose-macros", "ac-node-api", @@ -8235,7 +8236,7 @@ dependencies = [ [[package]] name = "substrate-client-keystore" version = "0.7.0" -source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c952d689bfd6469432f92b10ca351876bd5ac51a" +source = "git+https://github.com/scs/substrate-api-client.git?branch=polkadot-v0.9.39-tag-v0.9.0#c4d3f110b94e25d5ce52d5bb64d0c778c4c7f2da" dependencies = [ "async-trait", "hex", diff --git a/core-primitives/node-api/api-client-extensions/Cargo.toml b/core-primitives/node-api/api-client-extensions/Cargo.toml index 2824d0ab27..cba2802052 100644 --- a/core-primitives/node-api/api-client-extensions/Cargo.toml +++ b/core-primitives/node-api/api-client-extensions/Cargo.toml @@ -19,6 +19,7 @@ substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git" # local deps itp-types = { path = "../../types" } +itp-api-client-types = { path = "../api-client-types" } [features] # used for unit testing only! diff --git a/core-primitives/node-api/api-client-extensions/src/account.rs b/core-primitives/node-api/api-client-extensions/src/account.rs index b9811d1acf..8544560b2f 100644 --- a/core-primitives/node-api/api-client-extensions/src/account.rs +++ b/core-primitives/node-api/api-client-extensions/src/account.rs @@ -17,9 +17,11 @@ use crate::ApiResult; use itp_types::parentchain::{AccountData, AccountId, Balance, Hash, Index}; -use sp_core::crypto::Pair; +use sp_core::Pair; use sp_runtime::MultiSignature; -use substrate_api_client::GetAccountInformation; +use substrate_api_client::{ + rpc::Request, Api, ExtrinsicParams, FrameSystemConfig, GetAccountInformation, +}; /// ApiClient extension that contains some convenience methods around accounts. pub trait AccountApi { @@ -27,15 +29,35 @@ pub trait AccountApi { fn get_free_balance(&self, who: &AccountId) -> ApiResult; } -impl AccountApi for Api +impl AccountApi for Api where - Api: GetAccountInformation, + Signer: Pair, + MultiSignature: From, + Client: Request, + Runtime: FrameSystemConfig, + Params: ExtrinsicParams, + Runtime::AccountId: From, + Runtime::Index: Into, + Runtime::AccountData: Into, { fn get_nonce_of(&self, who: &AccountId) -> ApiResult { - Ok(self.get_account_info(who)?.map_or_else(|| 0, |info| info.nonce.into())) + let account_id = who.clone().into(); + Ok(self.get_account_info(&account_id)?.map_or_else(|| 0, |info| info.nonce.into())) } fn get_free_balance(&self, who: &AccountId) -> ApiResult { - Ok(self.get_account_info(who)?.map_or_else(|| 0, |info| info.data.free.into())) + let account_id = who.clone().into(); + let maybe_account_info = self.get_account_info(&account_id)?; + + let free_balance = match maybe_account_info { + Some(account_info) => { + let data: AccountData = account_info.data.into(); + data.free + }, + None => 0, + }; + + //maybe_account_info.map_or_else(|| 0, |info| info.data.free.into()) + Ok(free_balance) } } diff --git a/core-primitives/node-api/api-client-extensions/src/chain.rs b/core-primitives/node-api/api-client-extensions/src/chain.rs index 6746b4d501..0f83c3e5e3 100644 --- a/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -16,9 +16,11 @@ */ use crate::ApiResult; -use itp_types::parentchain::{Block, BlockNumber, Hash, Header, SignedBlock, StorageProof}; +use itp_api_client_types::{Block, SignedBlock}; +use itp_types::parentchain::{BlockNumber, Hash, Header, StorageProof}; +use sp_core::Pair; use sp_finality_grandpa::{AuthorityList, VersionedAuthorityList, GRANDPA_AUTHORITIES_KEY}; -use sp_runtime::{traits::GetRuntimeBlockType, DeserializeOwned}; +use sp_runtime::{traits::GetRuntimeBlockType, DeserializeOwned, MultiSignature}; use substrate_api_client::{ api::Error::NoBlockHash, primitives::StorageKey, rpc::Request, Api, ExtrinsicParams, FrameSystemConfig, GetBlock, GetHeader, GetStorage, @@ -29,7 +31,7 @@ pub trait ChainApi { fn last_finalized_block(&self) -> ApiResult>; fn signed_block(&self, hash: Option) -> ApiResult>; fn get_genesis_hash(&self) -> ApiResult; - fn get_header(&self, header_hash: Option) -> ApiResult>; + fn header(&self, header_hash: Option) -> ApiResult>; /// Fetch blocks from parentchain with blocknumber from until to, including both boundaries. /// Returns a vector with one element if from equals to. /// Returns an empty vector if from is greater than to. @@ -39,40 +41,49 @@ pub trait ChainApi { fn grandpa_authorities_proof(&self, hash: Option) -> ApiResult; } -impl ChainApi for Api +impl ChainApi for Api where - Api: GetHeader, - Api: GetBlock, - Api: GetStorage, + Client: Request, + Runtime: FrameSystemConfig + GetRuntimeBlockType, + Params: ExtrinsicParams, + Runtime::Header: DeserializeOwned + Into
, + Runtime::Hash: From + Into, + Runtime::RuntimeBlock: DeserializeOwned + Into, + Runtime::BlockNumber: Into, { fn last_finalized_block(&self) -> ApiResult> { self.get_finalized_head()? - .map_or_else(|| Ok(None), |hash| self.signed_block(Some(hash))) + .map_or_else(|| Ok(None), |hash| self.signed_block(Some(hash.into()))) } fn signed_block(&self, hash: Option) -> ApiResult> { // Convert the substrate-api-clients `SignedBlock` redefinition into ours. - Ok(self.get_signed_block(hash)?.map(Into::into)) + let maybe_signed_block = self.get_signed_block(hash.map(|h| h.into()))?; + let maybe_converted_block = match maybe_signed_block { + Some(block) => Some(convert_signed_block::(block)), + None => None, + }; + Ok(maybe_converted_block) } fn get_genesis_hash(&self) -> ApiResult { if let Some(hash) = self.get_block_hash(Some(0u32.into()))? { - Ok(hash) + Ok(hash.into()) } else { Err(NoBlockHash) } } - fn get_header(&self, header_hash: Option) -> ApiResult> { - self.get_header(header_hash) + fn header(&self, header_hash: Option) -> ApiResult> { + Ok(self.get_header(header_hash.map(|h| h.into()))?.map(Into::into)) } fn get_blocks(&self, from: BlockNumber, to: BlockNumber) -> ApiResult> { let mut blocks = Vec::::new(); for n in from..=to { - if let Some(block) = self.get_signed_block_by_num(Some(n))? { - blocks.push(block.into()); + if let Some(block) = self.get_signed_block_by_num(Some(n.into()))? { + blocks.push(convert_signed_block::(block)); } } Ok(blocks) @@ -81,7 +92,10 @@ where fn is_grandpa_available(&self) -> ApiResult { let genesis_hash = Some(self.get_genesis_hash().expect("Failed to get genesis hash")); Ok(self - .get_storage_by_key_hash(StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec()), genesis_hash)? + .get_storage_by_key_hash( + StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec()), + genesis_hash.map(|b| b.into()), + )? .map(|v: VersionedAuthorityList| v.into()) .map(|v: AuthorityList| !v.is_empty()) .unwrap_or(false)) @@ -89,7 +103,10 @@ where fn grandpa_authorities(&self, at_block: Option) -> ApiResult { Ok(self - .get_storage_by_key_hash(StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec()), at_block)? + .get_storage_by_key_hash( + StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec()), + at_block.map(|b| b.into()), + )? .map(|g: VersionedAuthorityList| g.into()) .unwrap_or_default()) } @@ -98,9 +115,22 @@ where Ok(self .get_storage_proof_by_keys( vec![StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec())], - at_block, + at_block.map(|b| b.into()), )? .map(|read_proof| read_proof.proof.into_iter().map(|bytes| bytes.0).collect()) .unwrap_or_default()) } } + +fn convert_signed_block( + signed_block: substrate_api_client::SignedBlock, +) -> SignedBlock +where + Runtime: GetRuntimeBlockType, + Runtime::RuntimeBlock: Into, +{ + SignedBlock { + block: signed_block.block.into(), + justifications: signed_block.justifications.map(|justifactions| justifactions.into()), + } +} diff --git a/core-primitives/node-api/api-client-types/src/lib.rs b/core-primitives/node-api/api-client-types/src/lib.rs index 45fd157616..405dbb4f2e 100644 --- a/core-primitives/node-api/api-client-types/src/lib.rs +++ b/core-primitives/node-api/api-client-types/src/lib.rs @@ -59,7 +59,10 @@ mod api { use super::ParentchainExtrinsicParams; use substrate_api_client::Api; - pub use my_node_runtime::Runtime; + pub use my_node_runtime::{Block, Runtime, UncheckedExtrinsic}; + + pub type SignedBlock = sp_runtime::generic::SignedBlock; + pub use substrate_api_client::{ api::Error as ApiClientError, rpc::{Error as RpcClientError, WsRpcClient}, diff --git a/core-primitives/types/src/parentchain.rs b/core-primitives/types/src/parentchain.rs index 31faf7535b..93ab34e21f 100644 --- a/core-primitives/types/src/parentchain.rs +++ b/core-primitives/types/src/parentchain.rs @@ -25,64 +25,62 @@ use sp_runtime::{ pub type StorageProof = Vec>; -#[cfg(not(feature = "std"))] -pub use no_std::*; - -#[cfg(feature = "std")] -pub use runtime_types::*; - -#[cfg(not(feature = "std"))] -pub mod no_std { - use super::*; - - // Basic Types. - pub type Index = u32; - pub type Balance = u128; - pub type Hash = sp_core::H256; - - // Account Types. - pub type AccountId = sp_core::crypto::AccountId32; - pub type AccountData = pallet_balances::AccountData; - pub type AccountInfo = frame_system::AccountInfo; - pub type Address = sp_runtime::MultiAddress; - - // Block Types - pub type BlockNumber = u32; - pub type Header = generic::Header; - pub type Block = BlockG; - pub type SignedBlock = SignedBlockG>; - pub type BlockHash = sp_core::H256; - - /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. - pub type Signature = MultiSignature; -} - -#[cfg(feature = "std")] -pub mod runtime_types { - use super::*; - use frame_system::Config as FrameSystemConfig; - use my_node_runtime::Runtime; - use pallet_balances::Config as BalancesConfig; - - // Basic Types. - pub type Index = ::Index; - pub type Balance = ::Balance; - pub type Hash = ::Hash; - - // Account Types. - pub type AccountId = ::AccountId; - pub type AccountData = ::AccountData; - pub type AccountInfo = frame_system::AccountInfo; - pub type Address = my_node_runtime::Address; - - // Block Types - pub type BlockNumber = ::BlockNumber; - pub type Header = ::Header; - pub type UncheckedExtrinsic = my_node_runtime::UncheckedExtrinsic; - pub type Block = my_node_runtime::Block; - pub type SignedBlock = SignedBlockG; - pub type BlockHash = ::Hash; - - /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. - pub type Signature = my_node_runtime::Signature; -} +// #[cfg(not(feature = "std"))] +// pub use no_std::*; +// +// #[cfg(feature = "std")] +// pub use runtime_types::*; +// +// #[cfg(not(feature = "std"))] +// pub mod no_std { +// use super::*; + +// Basic Types. +pub type Index = u32; +pub type Balance = u128; +pub type Hash = sp_core::H256; + +// Account Types. +pub type AccountId = sp_core::crypto::AccountId32; +pub type AccountData = pallet_balances::AccountData; +pub type AccountInfo = frame_system::AccountInfo; +pub type Address = sp_runtime::MultiAddress; + +// Block Types +pub type BlockNumber = u32; +pub type Header = generic::Header; +pub type BlockHash = sp_core::H256; + +/// Alias to 512-bit hash when used in the context of a transaction signature on the chain. +pub type Signature = MultiSignature; +// } + +// #[cfg(feature = "std")] +// pub mod runtime_types { +// use super::*; +// use frame_system::Config as FrameSystemConfig; +// use my_node_runtime::Runtime; +// use pallet_balances::Config as BalancesConfig; +// +// // Basic Types. +// pub type Index = ::Index; +// pub type Balance = ::Balance; +// pub type Hash = ::Hash; +// +// // Account Types. +// pub type AccountId = ::AccountId; +// pub type AccountData = ::AccountData; +// pub type AccountInfo = frame_system::AccountInfo; +// pub type Address = my_node_runtime::Address; +// +// // Block Types +// pub type BlockNumber = ::BlockNumber; +// pub type Header = ::Header; +// pub type UncheckedExtrinsic = my_node_runtime::UncheckedExtrinsic; +// pub type Block = my_node_runtime::Block; +// pub type SignedBlock = SignedBlockG; +// pub type BlockHash = ::Hash; +// +// /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. +// pub type Signature = my_node_runtime::Signature; +// } diff --git a/service/src/account_funding.rs b/service/src/account_funding.rs index b9ce8f971c..c2af2e23da 100644 --- a/service/src/account_funding.rs +++ b/service/src/account_funding.rs @@ -28,7 +28,9 @@ use sp_core::{ Pair, }; use sp_keyring::AccountKeyring; -use substrate_api_client::{GenericAddress, XtStatus}; +use substrate_api_client::{ + GenericAddress, GetBalance, GetTransactionPayment, SubmitAndWatch, SubmitExtrinsic, XtStatus, +}; /// Information about the enclave on-chain account. pub trait EnclaveAccountInfo { @@ -150,13 +152,14 @@ fn bootstrap_funds_from_alice( } let mut alice_signer_api = api.clone(); - alice_signer_api.signer = Some(alice); + api.set_signer(alice); println!("[+] bootstrap funding Enclave from Alice's funds"); let xt = alice_signer_api.balance_transfer(GenericAddress::Id(accountid.clone()), funding_amount); - let xt_hash = alice_signer_api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock)?; - info!("[<] Extrinsic got included in a block. Hash: {:?}\n", xt_hash); + let xt_report = + alice_signer_api.submit_and_watch_extrinsic_until(xt.encode(), XtStatus::InBlock)?; + info!("[<] Extrinsic got included in a block. Extrinsic Hash: {:?}\n", xt_hash.extrinsic_hash); // Verify funds have arrived. let free_balance = alice_signer_api.get_free_balance(accountid); diff --git a/service/src/main.rs b/service/src/main.rs index 047d046a45..a697be2020 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -74,6 +74,7 @@ use its_storage::{interface::FetchBlocks, BlockPruner, SidechainStorageLock}; use log::*; use my_node_runtime::{Hash, Header, RuntimeEvent}; use sgx_types::*; +use substrate_api_client::{GetHeader, SubmitExtrinsic, SubscribeChain}; #[cfg(feature = "dcap")] use sgx_verify::extract_tcb_info_from_raw_dcap_quote; @@ -799,7 +800,7 @@ fn send_extrinsic( api: &ParentchainApi, accountid: &AccountId32, is_development_mode: bool, -) -> Option { +) -> Hash { // Account funds if let Err(x) = setup_account_funding(api, accountid, extrinsic.clone(), is_development_mode) { error!("Starting worker failed: {:?}", x); @@ -808,8 +809,11 @@ fn send_extrinsic( } println!("[>] Register the TCB info (send the extrinsic)"); - let register_qe_xt_hash = api.submit_extrinsic(extrinsic, XtStatus::Finalized).unwrap(); - println!("[<] Extrinsic got finalized. Hash: {:?}\n", register_qe_xt_hash); + let register_qe_xt_hash = api + .submit_and_watch_extrinsic_until(extrinsic, XtStatus::Finalized) + .unwrap() + .extrinsic_hash; + println!("[<] Extrinsic got finalized. Extrinsic hash: {:?}\n", register_qe_xt_hash); register_qe_xt_hash } diff --git a/service/src/ocall_bridge/worker_on_chain_ocall.rs b/service/src/ocall_bridge/worker_on_chain_ocall.rs index 2e4b6568d1..60987f0f19 100644 --- a/service/src/ocall_bridge/worker_on_chain_ocall.rs +++ b/service/src/ocall_bridge/worker_on_chain_ocall.rs @@ -22,10 +22,10 @@ use itp_node_api::node_api_factory::CreateNodeApi; use itp_types::{WorkerRequest, WorkerResponse}; use itp_utils::ToHexPrefixed; use log::*; -use sp_core::storage::StorageKey; use sp_runtime::OpaqueExtrinsic; use std::{sync::Arc, vec::Vec}; -use substrate_api_client::{GetStorage, XtStatus}; +use substrate_api_client::{GetStorage, StorageKey, XtStatus}; +use substrate_api_client::SubmitExtrinsic; pub struct WorkerOnChainOCall { node_api_factory: Arc, @@ -89,7 +89,7 @@ where debug!("Enclave wants to send {} extrinsics", extrinsics.len()); let api = self.node_api_factory.create_api()?; for call in extrinsics.into_iter() { - if let Err(e) = api.send_extrinsic(call.to_hex(), XtStatus::Ready) { + if let Err(e) = api.submit_extrinsic(call.encode()) { error!("Could not send extrsinic to node: {:?}", e); } } diff --git a/service/src/parentchain_handler.rs b/service/src/parentchain_handler.rs index 2ddabea56b..e232e19440 100644 --- a/service/src/parentchain_handler.rs +++ b/service/src/parentchain_handler.rs @@ -23,7 +23,7 @@ use itc_parentchain::{ }; use itp_enclave_api::{enclave_base::EnclaveBase, sidechain::Sidechain}; use itp_node_api::api_client::ChainApi; -use itp_types::SignedBlock; +use itp_types::parentchain::SignedBlock; use log::*; use my_node_runtime::Header; use sp_finality_grandpa::VersionedAuthorityList; From 0329f1b2853621ba862b440f81a0b795246317f7 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 08:12:47 +0200 Subject: [PATCH 09/32] some more uptadates --- .../api-client-extensions/src/account.rs | 2 +- .../api-client-extensions/src/chain.rs | 3 +- service/src/account_funding.rs | 5 +- service/src/error.rs | 4 +- service/src/main.rs | 68 +++++++++---------- service/src/parentchain_handler.rs | 8 +-- 6 files changed, 42 insertions(+), 48 deletions(-) diff --git a/core-primitives/node-api/api-client-extensions/src/account.rs b/core-primitives/node-api/api-client-extensions/src/account.rs index 8544560b2f..7d6947bf40 100644 --- a/core-primitives/node-api/api-client-extensions/src/account.rs +++ b/core-primitives/node-api/api-client-extensions/src/account.rs @@ -16,7 +16,7 @@ */ use crate::ApiResult; -use itp_types::parentchain::{AccountData, AccountId, Balance, Hash, Index}; +use itp_types::parentchain::{AccountData, AccountId, Balance, Index}; use sp_core::Pair; use sp_runtime::MultiSignature; use substrate_api_client::{ diff --git a/core-primitives/node-api/api-client-extensions/src/chain.rs b/core-primitives/node-api/api-client-extensions/src/chain.rs index 0f83c3e5e3..1987ba0891 100644 --- a/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -18,9 +18,8 @@ use crate::ApiResult; use itp_api_client_types::{Block, SignedBlock}; use itp_types::parentchain::{BlockNumber, Hash, Header, StorageProof}; -use sp_core::Pair; use sp_finality_grandpa::{AuthorityList, VersionedAuthorityList, GRANDPA_AUTHORITIES_KEY}; -use sp_runtime::{traits::GetRuntimeBlockType, DeserializeOwned, MultiSignature}; +use sp_runtime::{traits::GetRuntimeBlockType, DeserializeOwned}; use substrate_api_client::{ api::Error::NoBlockHash, primitives::StorageKey, rpc::Request, Api, ExtrinsicParams, FrameSystemConfig, GetBlock, GetHeader, GetStorage, diff --git a/service/src/account_funding.rs b/service/src/account_funding.rs index c2af2e23da..b3fc68d7c1 100644 --- a/service/src/account_funding.rs +++ b/service/src/account_funding.rs @@ -159,7 +159,10 @@ fn bootstrap_funds_from_alice( alice_signer_api.balance_transfer(GenericAddress::Id(accountid.clone()), funding_amount); let xt_report = alice_signer_api.submit_and_watch_extrinsic_until(xt.encode(), XtStatus::InBlock)?; - info!("[<] Extrinsic got included in a block. Extrinsic Hash: {:?}\n", xt_hash.extrinsic_hash); + info!( + "[<] Extrinsic got included in a block. Extrinsic Hash: {:?}\n", + xt_report.extrinsic_hash + ); // Verify funds have arrived. let free_balance = alice_signer_api.get_free_balance(accountid); diff --git a/service/src/error.rs b/service/src/error.rs index e8878f1aad..8703b243eb 100644 --- a/service/src/error.rs +++ b/service/src/error.rs @@ -26,8 +26,8 @@ pub enum Error { Codec(#[from] CodecError), #[error("{0}")] ApiClient(ApiClientError), - #[error("Node API terminated subscription unexpectedly: {0}")] - ApiSubscriptionDisconnected(#[from] std::sync::mpsc::RecvError), + #[error("Node API terminated subscription unexpectedly")] + ApiSubscriptionDisconnected, #[error("Enclave API error: {0}")] EnclaveApi(#[from] itp_enclave_api::error::Error), #[error("Trusted Rpc Client error: {0}")] diff --git a/service/src/main.rs b/service/src/main.rs index a697be2020..e6819f791b 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -74,7 +74,10 @@ use its_storage::{interface::FetchBlocks, BlockPruner, SidechainStorageLock}; use log::*; use my_node_runtime::{Hash, Header, RuntimeEvent}; use sgx_types::*; -use substrate_api_client::{GetHeader, SubmitExtrinsic, SubscribeChain}; +use substrate_api_client::{ + primitives::StorageChangeSet, rpc::HandleSubscription, GetHeader, SubmitAndWatchUntilSuccess, + SubmitExtrinsic, SubscribeChain, SubscribeFrameSystem, +}; #[cfg(feature = "dcap")] use sgx_verify::extract_tcb_info_from_raw_dcap_quote; @@ -463,11 +466,11 @@ fn start_worker( let xt = enclave.generate_ias_ra_extrinsic(&trusted_url, skip_ra).unwrap(); #[cfg(feature = "dcap")] let xt = enclave.generate_dcap_ra_extrinsic(&trusted_url, skip_ra).unwrap(); - let register_enclave_xt_hash = + let register_enclave_block_hash = send_extrinsic(xt, &node_api, &tee_accountid, is_development_mode); let register_enclave_xt_header = - node_api.get_header(register_enclave_xt_hash).unwrap().unwrap(); + node_api.get_header(register_enclave_block_hash).unwrap().unwrap(); let we_are_primary_validateer = we_are_primary_validateer(&node_api, ®ister_enclave_xt_header).unwrap(); @@ -534,23 +537,14 @@ fn start_worker( } // ------------------------------------------------------------------------ - // subscribe to events and react on firing + // Subscribe to events and print them. println!("*** Subscribing to events"); - let (sender, receiver) = channel(); - let sender2 = sender.clone(); - let _eventsubscriber = thread::Builder::new() - .name("eventsubscriber".to_owned()) - .spawn(move || { - node_api.subscribe_events(sender2).unwrap(); - }) - .unwrap(); - + let subscription = node_api.subscribe_system_events().unwrap(); println!("[+] Subscribed to events. waiting..."); - let timeout = Duration::from_millis(10); loop { - if let Ok(msg) = receiver.recv_timeout(timeout) { - if let Ok(events) = parse_events(msg.clone()) { - print_events(events, sender.clone()) + if let Some(Ok(storage_change_set)) = subscription.next() { + if let Ok(events) = parse_events(storage_change_set) { + print_events(events) } } } @@ -586,13 +580,12 @@ fn spawn_worker_for_shard_polling( type Events = Vec>; -fn parse_events(event: String) -> Result { - let _unhex = Vec::from_hex(event).map_err(|_| "Decoding Events Failed".to_string())?; - let mut _er_enc = _unhex.as_slice(); - Events::decode(&mut _er_enc).map_err(|_| "Decoding Events Failed".to_string()) +fn parse_events(change_set: StorageChangeSet) -> Result { + let event_bytes = change_set[0].1.clone().map_err("Retrieving Events Failed".to_string())?.0; + Events::decode(&mut event_bytes.as_slice()).map_err(|_| "Decoding Events Failed".to_string()) } -fn print_events(events: Events, _sender: Sender) { +fn print_events(events: Events) { for evr in &events { debug!("Decoded: phase = {:?}, event = {:?}", evr.phase, evr.event); match &evr.event { @@ -800,7 +793,7 @@ fn send_extrinsic( api: &ParentchainApi, accountid: &AccountId32, is_development_mode: bool, -) -> Hash { +) -> Option { // Account funds if let Err(x) = setup_account_funding(api, accountid, extrinsic.clone(), is_development_mode) { error!("Starting worker failed: {:?}", x); @@ -809,12 +802,12 @@ fn send_extrinsic( } println!("[>] Register the TCB info (send the extrinsic)"); - let register_qe_xt_hash = api - .submit_and_watch_extrinsic_until(extrinsic, XtStatus::Finalized) + let register_qe_block_hash = api + .submit_and_watch_extrinsic_until_success(extrinsic, true) .unwrap() - .extrinsic_hash; - println!("[<] Extrinsic got finalized. Extrinsic hash: {:?}\n", register_qe_xt_hash); - register_qe_xt_hash + .block_hash; + println!("[<] Extrinsic got finalized. Block hash: {:?}\n", register_qe_block_hash); + register_qe_block_hash } /// Subscribe to the node API finalized heads stream and trigger a parent chain sync @@ -823,19 +816,20 @@ fn subscribe_to_parentchain_new_headers( parentchain_handler: Arc>, mut last_synced_header: Header, ) -> Result<(), Error> { - let (sender, receiver) = channel(); - //TODO: this should be implemented by parentchain_handler directly, and not via - // exposed parentchain_api. Blocked by https://github.com/scs/substrate-api-client/issues/267. - parentchain_handler + let subscription = parentchain_handler .parentchain_api() - .subscribe_finalized_heads(sender) + .subscribe_finalized_heads() .map_err(Error::ApiClient)?; loop { - let new_header: Header = match receiver.recv() { - Ok(header_str) => serde_json::from_str(&header_str).map_err(Error::Serialization), - Err(e) => Err(Error::ApiSubscriptionDisconnected(e)), - }?; + let new_header = subscription + .next() + .ok_or(Error::ApiSubscriptionDisconnected)? + .map_err(|e| Error::ApiClientError(e.into()))?; + // { + // Ok(header_str) => serde_json::from_str(&header_str).map_err(Error::Serialization), + // Err(e) => Err(Error::ApiSubscriptionDisconnected(e)), + // }?; println!( "[+] Received finalized header update ({}), syncing parent chain...", diff --git a/service/src/parentchain_handler.rs b/service/src/parentchain_handler.rs index e232e19440..3a64aaaf0b 100644 --- a/service/src/parentchain_handler.rs +++ b/service/src/parentchain_handler.rs @@ -23,7 +23,6 @@ use itc_parentchain::{ }; use itp_enclave_api::{enclave_base::EnclaveBase, sidechain::Sidechain}; use itp_node_api::api_client::ChainApi; -use itp_types::parentchain::SignedBlock; use log::*; use my_node_runtime::Header; use sp_finality_grandpa::VersionedAuthorityList; @@ -79,9 +78,8 @@ where enclave_api: Arc, ) -> ServiceResult { let genesis_hash = parentchain_api.get_genesis_hash()?; - let genesis_header: Header = parentchain_api - .get_header(Some(genesis_hash))? - .ok_or(Error::MissingGenesisHeader)?; + let genesis_header = + parentchain_api.header(Some(genesis_hash))?.ok_or(Error::MissingGenesisHeader)?; let parentchain_init_params: ParentchainInitParams = if parentchain_api .is_grandpa_available()? @@ -125,7 +123,7 @@ where fn sync_parentchain(&self, last_synced_header: Header) -> ServiceResult
{ trace!("Getting current head"); - let curr_block: SignedBlock = self + let curr_block = self .parentchain_api .last_finalized_block()? .ok_or(Error::MissingLastFinalizedBlock)?; From d531a65812c1389ed2a2732ad5fed224116e806a Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 08:37:52 +0200 Subject: [PATCH 10/32] seems to work --- .../src/pallet_teerex.rs | 2 - core-primitives/types/src/parentchain.rs | 51 ++----------------- service/src/account_funding.rs | 4 +- service/src/main.rs | 27 +++------- .../src/ocall_bridge/worker_on_chain_ocall.rs | 3 +- service/src/sync_state.rs | 1 - 6 files changed, 13 insertions(+), 75 deletions(-) diff --git a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs index 4aad08dd8e..0f6e2f8c21 100644 --- a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs +++ b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs @@ -17,8 +17,6 @@ use crate::ApiResult; use itp_types::{parentchain::Hash, Enclave, IpfsHash, ShardIdentifier}; -use sp_core::Pair; -use sp_runtime::MultiSignature; use substrate_api_client::{rpc::Request, Api, ExtrinsicParams, FrameSystemConfig, GetStorage}; pub const TEEREX: &str = "Teerex"; diff --git a/core-primitives/types/src/parentchain.rs b/core-primitives/types/src/parentchain.rs index 93ab34e21f..47772baf19 100644 --- a/core-primitives/types/src/parentchain.rs +++ b/core-primitives/types/src/parentchain.rs @@ -17,24 +17,10 @@ //! Parentchain specific params. Be sure to change them if your node uses different types. -use sp_runtime::{ - generic::{self, Block as BlockG, SignedBlock as SignedBlockG, UncheckedExtrinsic}, - traits::{BlakeTwo256, IdentifyAccount, Verify}, - MultiSignature, -}; +use sp_runtime::{generic::Header as HeaderG, traits::BlakeTwo256, MultiAddress, MultiSignature}; pub type StorageProof = Vec>; -// #[cfg(not(feature = "std"))] -// pub use no_std::*; -// -// #[cfg(feature = "std")] -// pub use runtime_types::*; -// -// #[cfg(not(feature = "std"))] -// pub mod no_std { -// use super::*; - // Basic Types. pub type Index = u32; pub type Balance = u128; @@ -44,43 +30,12 @@ pub type Hash = sp_core::H256; pub type AccountId = sp_core::crypto::AccountId32; pub type AccountData = pallet_balances::AccountData; pub type AccountInfo = frame_system::AccountInfo; -pub type Address = sp_runtime::MultiAddress; +pub type Address = MultiAddress; // Block Types pub type BlockNumber = u32; -pub type Header = generic::Header; +pub type Header = HeaderG; pub type BlockHash = sp_core::H256; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. pub type Signature = MultiSignature; -// } - -// #[cfg(feature = "std")] -// pub mod runtime_types { -// use super::*; -// use frame_system::Config as FrameSystemConfig; -// use my_node_runtime::Runtime; -// use pallet_balances::Config as BalancesConfig; -// -// // Basic Types. -// pub type Index = ::Index; -// pub type Balance = ::Balance; -// pub type Hash = ::Hash; -// -// // Account Types. -// pub type AccountId = ::AccountId; -// pub type AccountData = ::AccountData; -// pub type AccountInfo = frame_system::AccountInfo; -// pub type Address = my_node_runtime::Address; -// -// // Block Types -// pub type BlockNumber = ::BlockNumber; -// pub type Header = ::Header; -// pub type UncheckedExtrinsic = my_node_runtime::UncheckedExtrinsic; -// pub type Block = my_node_runtime::Block; -// pub type SignedBlock = SignedBlockG; -// pub type BlockHash = ::Hash; -// -// /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. -// pub type Signature = my_node_runtime::Signature; -// } diff --git a/service/src/account_funding.rs b/service/src/account_funding.rs index b3fc68d7c1..d1aae3f93a 100644 --- a/service/src/account_funding.rs +++ b/service/src/account_funding.rs @@ -29,7 +29,7 @@ use sp_core::{ }; use sp_keyring::AccountKeyring; use substrate_api_client::{ - GenericAddress, GetBalance, GetTransactionPayment, SubmitAndWatch, SubmitExtrinsic, XtStatus, + GenericAddress, GetBalance, GetTransactionPayment, SubmitAndWatch, XtStatus, }; /// Information about the enclave on-chain account. @@ -152,7 +152,7 @@ fn bootstrap_funds_from_alice( } let mut alice_signer_api = api.clone(); - api.set_signer(alice); + alice_signer_api.set_signer(alice); println!("[+] bootstrap funding Enclave from Alice's funds"); let xt = diff --git a/service/src/main.rs b/service/src/main.rs index e6819f791b..c8a45de722 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -76,7 +76,7 @@ use my_node_runtime::{Hash, Header, RuntimeEvent}; use sgx_types::*; use substrate_api_client::{ primitives::StorageChangeSet, rpc::HandleSubscription, GetHeader, SubmitAndWatchUntilSuccess, - SubmitExtrinsic, SubscribeChain, SubscribeFrameSystem, + SubscribeChain, SubscribeFrameSystem, }; #[cfg(feature = "dcap")] @@ -85,17 +85,7 @@ use sgx_verify::extract_tcb_info_from_raw_dcap_quote; use sp_core::crypto::{AccountId32, Ss58Codec}; use sp_keyring::AccountKeyring; use sp_runtime::traits::Header as HeaderTrait; -use std::{ - path::PathBuf, - str, - sync::{ - mpsc::{channel, Sender}, - Arc, - }, - thread, - time::Duration, -}; -use substrate_api_client::{utils::FromHexString, XtStatus}; +use std::{path::PathBuf, str, sync::Arc, thread, time::Duration}; use teerex_primitives::ShardIdentifier; mod account_funding; @@ -539,7 +529,7 @@ fn start_worker( // ------------------------------------------------------------------------ // Subscribe to events and print them. println!("*** Subscribing to events"); - let subscription = node_api.subscribe_system_events().unwrap(); + let mut subscription = node_api.subscribe_system_events().unwrap(); println!("[+] Subscribed to events. waiting..."); loop { if let Some(Ok(storage_change_set)) = subscription.next() { @@ -581,7 +571,8 @@ fn spawn_worker_for_shard_polling( type Events = Vec>; fn parse_events(change_set: StorageChangeSet) -> Result { - let event_bytes = change_set[0].1.clone().map_err("Retrieving Events Failed".to_string())?.0; + let event_bytes = + change_set.changes[0].1.clone().ok_or("Retrieving Events Failed".to_string())?.0; Events::decode(&mut event_bytes.as_slice()).map_err(|_| "Decoding Events Failed".to_string()) } @@ -816,7 +807,7 @@ fn subscribe_to_parentchain_new_headers( parentchain_handler: Arc>, mut last_synced_header: Header, ) -> Result<(), Error> { - let subscription = parentchain_handler + let mut subscription = parentchain_handler .parentchain_api() .subscribe_finalized_heads() .map_err(Error::ApiClient)?; @@ -825,11 +816,7 @@ fn subscribe_to_parentchain_new_headers( let new_header = subscription .next() .ok_or(Error::ApiSubscriptionDisconnected)? - .map_err(|e| Error::ApiClientError(e.into()))?; - // { - // Ok(header_str) => serde_json::from_str(&header_str).map_err(Error::Serialization), - // Err(e) => Err(Error::ApiSubscriptionDisconnected(e)), - // }?; + .map_err(|e| Error::ApiClient(e.into()))?; println!( "[+] Received finalized header update ({}), syncing parent chain...", diff --git a/service/src/ocall_bridge/worker_on_chain_ocall.rs b/service/src/ocall_bridge/worker_on_chain_ocall.rs index 60987f0f19..28220d193b 100644 --- a/service/src/ocall_bridge/worker_on_chain_ocall.rs +++ b/service/src/ocall_bridge/worker_on_chain_ocall.rs @@ -20,11 +20,10 @@ use crate::ocall_bridge::bridge_api::{OCallBridgeError, OCallBridgeResult, Worke use codec::{Decode, Encode}; use itp_node_api::node_api_factory::CreateNodeApi; use itp_types::{WorkerRequest, WorkerResponse}; -use itp_utils::ToHexPrefixed; use log::*; use sp_runtime::OpaqueExtrinsic; use std::{sync::Arc, vec::Vec}; -use substrate_api_client::{GetStorage, StorageKey, XtStatus}; +use substrate_api_client::{GetStorage, StorageKey}; use substrate_api_client::SubmitExtrinsic; pub struct WorkerOnChainOCall { diff --git a/service/src/sync_state.rs b/service/src/sync_state.rs index 9702596cf4..0a924662ba 100644 --- a/service/src/sync_state.rs +++ b/service/src/sync_state.rs @@ -28,7 +28,6 @@ use itp_settings::worker_mode::{ProvideWorkerMode, WorkerMode}; use itp_types::ShardIdentifier; use sgx_types::sgx_quote_sign_type_t; use std::string::String; -use substrate_api_client::FrameSystemConfig; pub(crate) fn sync_state< E: TlsRemoteAttestation + EnclaveBase, From f9fee4347fe8dcc5d71d6852996050b66c9fc2dd Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 09:36:18 +0200 Subject: [PATCH 11/32] oh yes --- cli/src/base_cli/commands/balance.rs | 1 + cli/src/base_cli/commands/faucet.rs | 7 ++++--- cli/src/base_cli/commands/listen.rs | 19 +++++++++---------- cli/src/base_cli/commands/shield_funds.rs | 6 ++++-- cli/src/base_cli/commands/transfer.rs | 5 +++-- cli/src/base_cli/mod.rs | 4 ++-- cli/src/command_utils.rs | 2 +- cli/src/trusted_operation.rs | 17 ++++++++++------- 8 files changed, 34 insertions(+), 27 deletions(-) diff --git a/cli/src/base_cli/commands/balance.rs b/cli/src/base_cli/commands/balance.rs index 74ad9264cd..752190d425 100644 --- a/cli/src/base_cli/commands/balance.rs +++ b/cli/src/base_cli/commands/balance.rs @@ -19,6 +19,7 @@ use crate::{ command_utils::{get_accountid_from_str, get_chain_api}, Cli, }; +use substrate_api_client::GetAccountInformation; #[derive(Parser)] pub struct BalanceCommand { diff --git a/cli/src/base_cli/commands/faucet.rs b/cli/src/base_cli/commands/faucet.rs index 226a95ab19..691b72c851 100644 --- a/cli/src/base_cli/commands/faucet.rs +++ b/cli/src/base_cli/commands/faucet.rs @@ -19,11 +19,12 @@ use crate::{ command_utils::{get_accountid_from_str, get_chain_api}, Cli, }; +use codec::Encode; use my_node_runtime::{BalancesCall, RuntimeCall}; use sp_keyring::AccountKeyring; use sp_runtime::MultiAddress; use std::vec::Vec; -use substrate_api_client::{compose_extrinsic_offline, UncheckedExtrinsicV4, XtStatus}; +use substrate_api_client::{compose_extrinsic_offline, SubmitExtrinsic, UncheckedExtrinsicV4}; const PREFUNDING_AMOUNT: u128 = 1_000_000_000; @@ -37,7 +38,7 @@ pub struct FaucetCommand { impl FaucetCommand { pub(crate) fn run(&self, cli: &Cli) { let mut api = get_chain_api(cli); - api.set_signer(sr25519_core::Pair::from(AccountKeyring::Alice.pair())); + api.set_signer(AccountKeyring::Alice.pair()); let mut nonce = api.get_nonce().unwrap(); for account in &self.accounts { let to = get_accountid_from_str(account); @@ -52,7 +53,7 @@ impl FaucetCommand { ); // send and watch extrinsic until finalized println!("Faucet drips to {} (Alice's nonce={})", to, nonce); - let _blockh = api.send_extrinsic(xt.hex_encode(), XtStatus::Ready).unwrap(); + let _blockh = api.submit_extrinsic(xt.encode()).unwrap(); nonce += 1; } } diff --git a/cli/src/base_cli/commands/listen.rs b/cli/src/base_cli/commands/listen.rs index 6ec657ddfd..39b0c61e5d 100644 --- a/cli/src/base_cli/commands/listen.rs +++ b/cli/src/base_cli/commands/listen.rs @@ -20,8 +20,8 @@ use base58::ToBase58; use codec::{Decode, Encode}; use log::*; use my_node_runtime::{Hash, RuntimeEvent}; -use std::{sync::mpsc::channel, vec::Vec}; -use substrate_api_client::utils::FromHexString; +use std::vec::Vec; +use substrate_api_client::{rpc::HandleSubscription, utils::FromHexString, SubscribeFrameSystem}; #[derive(Parser)] pub struct ListenCommand { @@ -39,10 +39,9 @@ impl ListenCommand { println!("{:?} {:?}", self.events, self.blocks); let api = get_chain_api(cli); info!("Subscribing to events"); - let (events_in, events_out) = channel(); let mut count = 0u32; let mut blocks = 0u32; - api.subscribe_events(events_in).unwrap(); + let mut subscription = api.subscribe_system_events().unwrap(); loop { if let Some(e) = self.events { if count >= e { @@ -54,13 +53,13 @@ impl ListenCommand { return } }; - let event_str = events_out.recv().unwrap(); - let _unhex = Vec::from_hex(event_str).unwrap(); - let mut _er_enc = _unhex.as_slice(); - let _events = - Vec::>::decode(&mut _er_enc); + + let event_bytes = subscription.next().unwrap().unwrap().changes[0].1.clone().unwrap().0; + let events_result = Vec::>::decode( + &mut event_bytes.as_slice(), + ); blocks += 1; - match _events { + match events_result { Ok(evts) => for evr in &evts { println!("decoded: phase {:?} event {:?}", evr.phase, evr.event); diff --git a/cli/src/base_cli/commands/shield_funds.rs b/cli/src/base_cli/commands/shield_funds.rs index 5be2453a92..5773d8108c 100644 --- a/cli/src/base_cli/commands/shield_funds.rs +++ b/cli/src/base_cli/commands/shield_funds.rs @@ -27,7 +27,7 @@ use itp_stf_primitives::types::ShardIdentifier; use log::*; use my_node_runtime::Balance; use sp_core::sr25519 as sr25519_core; -use substrate_api_client::{compose_extrinsic, UncheckedExtrinsicV4, XtStatus}; +use substrate_api_client::{compose_extrinsic, SubmitAndWatch, UncheckedExtrinsicV4, XtStatus}; #[derive(Parser)] pub struct ShieldFundsCommand { @@ -78,7 +78,9 @@ impl ShieldFundsCommand { shard ); - let tx_hash = chain_api.send_extrinsic(xt.hex_encode(), XtStatus::Finalized).unwrap(); + let tx_hash = chain_api + .submit_and_watch_extrinsic_until(xt.encode(), XtStatus::Finalized) + .unwrap(); println!("[+] TrustedOperation got finalized. Hash: {:?}\n", tx_hash); } } diff --git a/cli/src/base_cli/commands/transfer.rs b/cli/src/base_cli/commands/transfer.rs index 288f9185c1..35520a6128 100644 --- a/cli/src/base_cli/commands/transfer.rs +++ b/cli/src/base_cli/commands/transfer.rs @@ -19,10 +19,11 @@ use crate::{ command_utils::{get_accountid_from_str, get_chain_api, *}, Cli, }; +use codec::Encode; use log::*; use my_node_runtime::Balance; use sp_core::{crypto::Ss58Codec, sr25519 as sr25519_core, Pair}; -use substrate_api_client::{GenericAddress, XtStatus}; +use substrate_api_client::{GenericAddress, GetAccountInformation, SubmitAndWatch, XtStatus}; #[derive(Parser)] pub struct TransferCommand { @@ -45,7 +46,7 @@ impl TransferCommand { let mut api = get_chain_api(cli); api.set_signer(sr25519_core::Pair::from(from_account)); let xt = api.balance_transfer(GenericAddress::Id(to_account.clone()), self.amount); - let tx_hash = api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap(); + let tx_hash = api.submit_and_watch_extrinsic_until(xt.encode(), XtStatus::InBlock).unwrap(); println!("[+] TrustedOperation got finalized. Hash: {:?}\n", tx_hash); let result = api.get_account_data(&to_account).unwrap().unwrap(); println!("balance for {} is now {}", to_account, result.free); diff --git a/cli/src/base_cli/mod.rs b/cli/src/base_cli/mod.rs index 65e61bc840..dc969d4bf5 100644 --- a/cli/src/base_cli/mod.rs +++ b/cli/src/base_cli/mod.rs @@ -111,13 +111,13 @@ fn list_accounts() { fn print_metadata(cli: &Cli) { let meta = get_chain_api(cli).metadata(); - println!("Metadata:\n {}", Metadata::pretty_format(&meta).unwrap()); + println!("Metadata:\n {}", Metadata::pretty_format(&meta.runtime_metadata()).unwrap()); } fn print_sgx_metadata(cli: &Cli) { let worker_api_direct = get_worker_api_direct(cli); let metadata = worker_api_direct.get_state_metadata().unwrap(); - println!("Metadata:\n {}", Metadata::pretty_format(&metadata).unwrap()); + println!("Metadata:\n {}", Metadata::pretty_format(metadata.runtime_metadata()).unwrap()); } fn list_workers(cli: &Cli) { diff --git a/cli/src/command_utils.rs b/cli/src/command_utils.rs index 8b8b43c99d..6989542959 100644 --- a/cli/src/command_utils.rs +++ b/cli/src/command_utils.rs @@ -40,7 +40,7 @@ pub(crate) fn get_shielding_key(cli: &Cli) -> Result { pub(crate) fn get_chain_api(cli: &Cli) -> ParentchainApi { let url = format!("{}:{}", cli.node_url, cli.node_port); info!("connecting to {}", url); - ParentchainApi::new(WsRpcClient::new(&url)).unwrap() + ParentchainApi::new(WsRpcClient::new(&url).unwrap()).unwrap() } pub(crate) fn get_accountid_from_str(account: &str) -> AccountId { diff --git a/cli/src/trusted_operation.rs b/cli/src/trusted_operation.rs index b20e49470a..e3c0faa592 100644 --- a/cli/src/trusted_operation.rs +++ b/cli/src/trusted_operation.rs @@ -28,7 +28,7 @@ use itp_node_api::api_client::TEEREX; use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue}; use itp_sgx_crypto::ShieldingCryptoEncrypt; use itp_stf_primitives::types::ShardIdentifier; -use itp_types::{BlockNumber, DirectRequestStatus, Header, TrustedOperationStatus}; +use itp_types::{BlockNumber, DirectRequestStatus, TrustedOperationStatus}; use itp_utils::{FromHexPrefixed, ToHexPrefixed}; use log::*; use my_node_runtime::{AccountId, Hash}; @@ -38,7 +38,10 @@ use std::{ sync::mpsc::{channel, Receiver}, time::Instant, }; -use substrate_api_client::{compose_extrinsic, StaticEvent, XtStatus}; +use substrate_api_client::{ + compose_extrinsic, GetHeader, StaticEvent, SubmitAndWatch, SubscribeEvents, + SubscribeFrameSystem, XtStatus, +}; use teerex_primitives::Request; pub(crate) fn perform_trusted_operation( @@ -121,9 +124,10 @@ fn send_request( let xt = compose_extrinsic!(&chain_api, TEEREX, "call_worker", request); // send and watch extrinsic until block is executed - let block_hash = _chain_api + let block_hash = chain_api .submit_and_watch_extrinsic_until(xt.encode(), XtStatus::InBlock) .unwrap() + .block_hash .unwrap(); info!( @@ -131,16 +135,15 @@ fn send_request( block_hash ); info!("Waiting for execution confirmation from enclave..."); - let (events_in, events_out) = channel(); - chain_api.subscribe_events(events_in).unwrap(); + let mut subscription = chain_api.subscribe_system_events().unwrap(); loop { let ret: ProcessedParentchainBlockArgs = - chain_api.wait_for_event::(&events_out).unwrap(); + chain_api.wait_for_event(&mut subscription).unwrap(); info!("Confirmation of ProcessedParentchainBlock received"); debug!("Expected block Hash: {:?}", block_hash); debug!("Confirmed stf block Hash: {:?}", ret.block_hash); - match chain_api.get_header::
(Some(block_hash)) { + match chain_api.get_header(Some(block_hash)) { Ok(option) => { match option { None => { From d4e3627dd16d985d5d4738a77df4e0c36a110d86 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 09:42:00 +0200 Subject: [PATCH 12/32] and compiled --- cli/src/base_cli/commands/listen.rs | 2 +- cli/src/base_cli/mod.rs | 3 ++- cli/src/trusted_operation.rs | 2 +- core-primitives/node-api/api-client-extensions/src/account.rs | 2 -- core-primitives/types/src/parentchain.rs | 1 + 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/src/base_cli/commands/listen.rs b/cli/src/base_cli/commands/listen.rs index 39b0c61e5d..28ea89e8a9 100644 --- a/cli/src/base_cli/commands/listen.rs +++ b/cli/src/base_cli/commands/listen.rs @@ -21,7 +21,7 @@ use codec::{Decode, Encode}; use log::*; use my_node_runtime::{Hash, RuntimeEvent}; use std::vec::Vec; -use substrate_api_client::{rpc::HandleSubscription, utils::FromHexString, SubscribeFrameSystem}; +use substrate_api_client::{rpc::HandleSubscription, SubscribeFrameSystem}; #[derive(Parser)] pub struct ListenCommand { diff --git a/cli/src/base_cli/mod.rs b/cli/src/base_cli/mod.rs index dc969d4bf5..525ee32eed 100644 --- a/cli/src/base_cli/mod.rs +++ b/cli/src/base_cli/mod.rs @@ -110,7 +110,8 @@ fn list_accounts() { } fn print_metadata(cli: &Cli) { - let meta = get_chain_api(cli).metadata(); + let api = get_chain_api(cli); + let meta = api.metadata(); println!("Metadata:\n {}", Metadata::pretty_format(&meta.runtime_metadata()).unwrap()); } diff --git a/cli/src/trusted_operation.rs b/cli/src/trusted_operation.rs index e3c0faa592..5b4293e39f 100644 --- a/cli/src/trusted_operation.rs +++ b/cli/src/trusted_operation.rs @@ -110,7 +110,7 @@ fn send_request( trusted_args: &TrustedCli, trusted_operation: &TrustedOperation, ) -> Option> { - let chain_api = get_chain_api(cli); + let mut chain_api = get_chain_api(cli); let encryption_key = get_shielding_key(cli).unwrap(); let call_encrypted = encryption_key.encrypt(&trusted_operation.encode()).unwrap(); diff --git a/core-primitives/node-api/api-client-extensions/src/account.rs b/core-primitives/node-api/api-client-extensions/src/account.rs index 7d6947bf40..ee5be86bba 100644 --- a/core-primitives/node-api/api-client-extensions/src/account.rs +++ b/core-primitives/node-api/api-client-extensions/src/account.rs @@ -56,8 +56,6 @@ where }, None => 0, }; - - //maybe_account_info.map_or_else(|| 0, |info| info.data.free.into()) Ok(free_balance) } } diff --git a/core-primitives/types/src/parentchain.rs b/core-primitives/types/src/parentchain.rs index 47772baf19..c8d57df86c 100644 --- a/core-primitives/types/src/parentchain.rs +++ b/core-primitives/types/src/parentchain.rs @@ -18,6 +18,7 @@ //! Parentchain specific params. Be sure to change them if your node uses different types. use sp_runtime::{generic::Header as HeaderG, traits::BlakeTwo256, MultiAddress, MultiSignature}; +use sp_std::vec::Vec; pub type StorageProof = Vec>; From 61b25d40f35246763cb75d22ba157a23c41b5c54 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 09:42:21 +0200 Subject: [PATCH 13/32] readd comment --- service/src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/service/src/main.rs b/service/src/main.rs index c8a45de722..6e32abfd50 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -807,6 +807,8 @@ fn subscribe_to_parentchain_new_headers( parentchain_handler: Arc>, mut last_synced_header: Header, ) -> Result<(), Error> { + // TODO: this should be implemented by parentchain_handler directly, and not via + // exposed parentchain_api let mut subscription = parentchain_handler .parentchain_api() .subscribe_finalized_heads() From 9783efeee6188b6ba3ea763dc18f8576cb04774b Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 09:58:28 +0200 Subject: [PATCH 14/32] add comment --- core-primitives/node-api/api-client-extensions/src/chain.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core-primitives/node-api/api-client-extensions/src/chain.rs b/core-primitives/node-api/api-client-extensions/src/chain.rs index 1987ba0891..a39505426b 100644 --- a/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -121,6 +121,7 @@ where } } +// Necessary because of https://github.com/scs/substrate-api-client/issues/492. fn convert_signed_block( signed_block: substrate_api_client::SignedBlock, ) -> SignedBlock From 4b838667ebe3e96d05950cf13c982597d1389ae6 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 10:09:08 +0200 Subject: [PATCH 15/32] cargo fmt --- service/src/ocall_bridge/worker_on_chain_ocall.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/service/src/ocall_bridge/worker_on_chain_ocall.rs b/service/src/ocall_bridge/worker_on_chain_ocall.rs index 28220d193b..7ea5c949fa 100644 --- a/service/src/ocall_bridge/worker_on_chain_ocall.rs +++ b/service/src/ocall_bridge/worker_on_chain_ocall.rs @@ -23,8 +23,7 @@ use itp_types::{WorkerRequest, WorkerResponse}; use log::*; use sp_runtime::OpaqueExtrinsic; use std::{sync::Arc, vec::Vec}; -use substrate_api_client::{GetStorage, StorageKey}; -use substrate_api_client::SubmitExtrinsic; +use substrate_api_client::{GetStorage, StorageKey, SubmitExtrinsic}; pub struct WorkerOnChainOCall { node_api_factory: Arc, From 0897e00d02480d3181d2333e2e81ab350ffac44c Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 10:39:29 +0200 Subject: [PATCH 16/32] taplo fmt --- core-primitives/node-api/api-client-extensions/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-primitives/node-api/api-client-extensions/Cargo.toml b/core-primitives/node-api/api-client-extensions/Cargo.toml index cba2802052..c5d98cab9a 100644 --- a/core-primitives/node-api/api-client-extensions/Cargo.toml +++ b/core-primitives/node-api/api-client-extensions/Cargo.toml @@ -18,8 +18,8 @@ sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "po substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" } # local deps -itp-types = { path = "../../types" } itp-api-client-types = { path = "../api-client-types" } +itp-types = { path = "../../types" } [features] # used for unit testing only! From 0baf34709f3ad153af5db655ed70090e889ecfd8 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 11:14:39 +0200 Subject: [PATCH 17/32] fix rpc-client mock --- core/rpc-client/src/mock.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/rpc-client/src/mock.rs b/core/rpc-client/src/mock.rs index dde7177f29..12ba0bffeb 100644 --- a/core/rpc-client/src/mock.rs +++ b/core/rpc-client/src/mock.rs @@ -22,9 +22,10 @@ use crate::{ error::Result, }; use codec::Decode; +use frame_metadata::RuntimeMetadataPrefixed; use sgx_crypto_helper::rsa3072::Rsa3072PubKey; use std::{sync::mpsc::Sender as MpscSender, thread::JoinHandle}; -use substrate_api_client::{FromHexString, RuntimeMetadataPrefixed}; +use substrate_api_client::{FromHexString, Metadata}; #[derive(Clone, Default)] pub struct DirectClientMock { @@ -86,13 +87,14 @@ impl DirectApi for DirectClientMock { Ok(self.untrusted_worker_url.clone()) } - fn get_state_metadata(&self) -> Result { - let metadata = match Vec::from_hex(self.metadata.clone()) { + fn get_state_metadata(&self) -> Result { + let metadata_bytes = match Vec::from_hex(self.metadata.clone()) { Ok(m) => m, Err(e) => return Err(Error::Custom(format!("Decode metadata FromHexError: {:?}", e).into())), }; - RuntimeMetadataPrefixed::decode(&mut metadata.as_slice()).map_err(|e| e.into()) + let metadata = RuntimeMetadataPrefixed::decode(&mut metadata_bytes.as_slice())?; + Metadata::try_from(metadata).map_err(|e| e.into()) } fn send(&self, _request: &str) -> Result<()> { From f34d37cfa911e12bdca84e8a0eebf32ce6d20ef7 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 11:32:49 +0200 Subject: [PATCH 18/32] fix tests --- .../test/src/parentchain_block_builder.rs | 21 +++++++++++-------- .../src/tests/mocks/parentchain_api_mock.rs | 14 ++++++------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/parentchain/test/src/parentchain_block_builder.rs b/core/parentchain/test/src/parentchain_block_builder.rs index 9d1c12c49e..bdb0995a92 100644 --- a/core/parentchain/test/src/parentchain_block_builder.rs +++ b/core/parentchain/test/src/parentchain_block_builder.rs @@ -22,15 +22,18 @@ extern crate alloc; use crate::parentchain_header_builder::ParentchainHeaderBuilder; use alloc::vec::Vec; -use itp_types::{Block, Header, SignedBlock}; -use sp_runtime::OpaqueExtrinsic; +use itp_types::parentchain::Header; +use sp_runtime::{ + generic::{Block, SignedBlock}, + traits::MaybeSerialize, +}; -pub struct ParentchainBlockBuilder { +pub struct ParentchainBlockBuilder { header: Header, - extrinsics: Vec, + extrinsics: Vec, } -impl Default for ParentchainBlockBuilder { +impl Default for ParentchainBlockBuilder { fn default() -> Self { ParentchainBlockBuilder { header: ParentchainHeaderBuilder::default().build(), @@ -39,22 +42,22 @@ impl Default for ParentchainBlockBuilder { } } -impl ParentchainBlockBuilder { +impl ParentchainBlockBuilder { pub fn with_header(mut self, header: Header) -> Self { self.header = header; self } - pub fn with_extrinsics(mut self, extrinsics: Vec) -> Self { + pub fn with_extrinsics(mut self, extrinsics: Vec) -> Self { self.extrinsics = extrinsics; self } - pub fn build(self) -> Block { + pub fn build(self) -> Block { Block { header: self.header, extrinsics: self.extrinsics } } - pub fn build_signed(self) -> SignedBlock { + pub fn build_signed(self) -> SignedBlock> { SignedBlock { block: self.build(), justifications: None } } } diff --git a/service/src/tests/mocks/parentchain_api_mock.rs b/service/src/tests/mocks/parentchain_api_mock.rs index 5f02df4f04..8971a95ebe 100644 --- a/service/src/tests/mocks/parentchain_api_mock.rs +++ b/service/src/tests/mocks/parentchain_api_mock.rs @@ -19,8 +19,8 @@ use itc_parentchain_test::{ parentchain_block_builder::ParentchainBlockBuilder, parentchain_header_builder::ParentchainHeaderBuilder, }; -use itp_node_api::api_client::{ApiResult, ChainApi, StorageProof}; -use itp_types::{Header, SignedBlock, H256}; +use itp_node_api::api_client::{ApiResult, ChainApi, SignedBlock}; +use itp_types::parentchain::{Hash, Header, StorageProof}; use sp_finality_grandpa::AuthorityList; pub struct ParentchainApiMock { @@ -49,15 +49,15 @@ impl ChainApi for ParentchainApiMock { Ok(self.parentchain.last().cloned()) } - fn signed_block(&self, _hash: Option) -> ApiResult> { + fn signed_block(&self, _hash: Option) -> ApiResult> { todo!() } - fn get_genesis_hash(&self) -> ApiResult { + fn get_genesis_hash(&self) -> ApiResult { todo!() } - fn get_header(&self, _header_hash: Option) -> ApiResult> { + fn header(&self, _header_hash: Option) -> ApiResult> { todo!() } @@ -77,11 +77,11 @@ impl ChainApi for ParentchainApiMock { todo!() } - fn grandpa_authorities(&self, _hash: Option) -> ApiResult { + fn grandpa_authorities(&self, _hash: Option) -> ApiResult { todo!() } - fn grandpa_authorities_proof(&self, _hash: Option) -> ApiResult { + fn grandpa_authorities_proof(&self, _hash: Option) -> ApiResult { todo!() } } From 924c99e813318ac069a4dd3b7d1ec700c500c1c3 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 11:38:14 +0200 Subject: [PATCH 19/32] fix clippy --- .../node-api/api-client-extensions/src/chain.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core-primitives/node-api/api-client-extensions/src/chain.rs b/core-primitives/node-api/api-client-extensions/src/chain.rs index a39505426b..b8cd43b5b5 100644 --- a/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -57,12 +57,10 @@ where fn signed_block(&self, hash: Option) -> ApiResult> { // Convert the substrate-api-clients `SignedBlock` redefinition into ours. - let maybe_signed_block = self.get_signed_block(hash.map(|h| h.into()))?; - let maybe_converted_block = match maybe_signed_block { - Some(block) => Some(convert_signed_block::(block)), - None => None, - }; - Ok(maybe_converted_block) + let maybe_signed_block = self + .get_signed_block(hash.map(|h| h.into()))? + .map(convert_signed_block::); + Ok(maybe_signed_block) } fn get_genesis_hash(&self) -> ApiResult { From e7bca27f0324a5953fd9fae7c0b8a2e58b1555b5 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 12:07:46 +0200 Subject: [PATCH 20/32] fix clippy --- cli/src/base_cli/commands/faucet.rs | 2 +- service/src/main.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/src/base_cli/commands/faucet.rs b/cli/src/base_cli/commands/faucet.rs index 691b72c851..592bea4a62 100644 --- a/cli/src/base_cli/commands/faucet.rs +++ b/cli/src/base_cli/commands/faucet.rs @@ -44,7 +44,7 @@ impl FaucetCommand { let to = get_accountid_from_str(account); #[allow(clippy::redundant_clone)] let xt: UncheckedExtrinsicV4<_, _> = compose_extrinsic_offline!( - &api.signer().unwrap(), + api.signer().unwrap(), RuntimeCall::Balances(BalancesCall::transfer { dest: MultiAddress::Id(to.clone()), value: PREFUNDING_AMOUNT diff --git a/service/src/main.rs b/service/src/main.rs index 6e32abfd50..3ee68f30a3 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -571,8 +571,11 @@ fn spawn_worker_for_shard_polling( type Events = Vec>; fn parse_events(change_set: StorageChangeSet) -> Result { - let event_bytes = - change_set.changes[0].1.clone().ok_or("Retrieving Events Failed".to_string())?.0; + let event_bytes = change_set.changes[0] + .1 + .clone() + .ok_or_else(|| "Retrieving Events Failed".to_string())? + .0; Events::decode(&mut event_bytes.as_slice()).map_err(|_| "Decoding Events Failed".to_string()) } From d9b068d632e5de9c9101ca53d7c34bb91322ce51 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 13:32:48 +0200 Subject: [PATCH 21/32] fix teeracle --- service/src/teeracle/mod.rs | 60 +++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/service/src/teeracle/mod.rs b/service/src/teeracle/mod.rs index e39a247985..d47019f7c6 100644 --- a/service/src/teeracle/mod.rs +++ b/service/src/teeracle/mod.rs @@ -24,7 +24,7 @@ use itp_utils::hex::hex_encode; use log::*; use sp_runtime::OpaqueExtrinsic; use std::time::Duration; -use substrate_api_client::XtStatus; +use substrate_api_client::{SubmitAndWatch, XtStatus}; use teeracle_metrics::{increment_number_of_request_failures, set_extrinsics_inclusion_success}; use tokio::runtime::Handle; @@ -76,21 +76,22 @@ fn execute_weather_update( extrinsics.into_iter().for_each(|call| { let node_api_clone = node_api.clone(); tokio_handle.spawn(async move { - let hex_encoded_extrinsic = hex_encode(&call.encode()); - debug!("Hex encoded extrinsic to be sent: {}", hex_encoded_extrinsic); + let encoded_extrinsic = call.encode(); + debug!("Hex encoded extrinsic to be sent: {}", hex_encode(&encoded_extrinsic)); println!("[>] Update oracle (send the extrinsic)"); - let extrinsic_hash = - match node_api_clone.send_extrinsic(hex_encoded_extrinsic, XtStatus::InBlock) { - Err(e) => { - error!("Failed to send extrinsic: {:?}", e); - set_extrinsics_inclusion_success(false); - return - }, - Ok(hash) => { - set_extrinsics_inclusion_success(true); - hash - }, - }; + let extrinsic_hash = match node_api_clone + .submit_and_watch_extrinsic_until(encoded_extrinsic, XtStatus::InBlock) + { + Err(e) => { + error!("Failed to send extrinsic: {:?}", e); + set_extrinsics_inclusion_success(false); + return + }, + Ok(report) => { + set_extrinsics_inclusion_success(true); + report.extrinsic_hash + }, + }; println!("[<] Extrinsic got included into a block. Hash: {:?}\n", extrinsic_hash); }); }); @@ -123,22 +124,23 @@ fn execute_update_market( for call in extrinsics.into_iter() { let node_api_clone = node_api.clone(); tokio_handle.spawn(async move { - let hex_encoded_extrinsic = hex_encode(&call.encode()); - debug!("Hex encoded extrinsic to be sent: {}", hex_encoded_extrinsic); + let encoded_extrinsic = call.encode(); + debug!("Hex encoded extrinsic to be sent: {}", hex_encode(&encoded_extrinsic)); println!("[>] Update the exchange rate (send the extrinsic)"); - let extrinsic_hash = - match node_api_clone.send_extrinsic(hex_encoded_extrinsic, XtStatus::InBlock) { - Err(e) => { - error!("Failed to send extrinsic: {:?}", e); - set_extrinsics_inclusion_success(false); - return - }, - Ok(hash) => { - set_extrinsics_inclusion_success(true); - hash - }, - }; + let extrinsic_hash = match node_api_clone + .submit_and_watch_extrinsic_until(encoded_extrinsic, XtStatus::InBlock) + { + Err(e) => { + error!("Failed to send extrinsic: {:?}", e); + set_extrinsics_inclusion_success(false); + return + }, + Ok(report) => { + set_extrinsics_inclusion_success(true); + report.extrinsic_hash + }, + }; println!("[<] Extrinsic got included into a block. Hash: {:?}\n", extrinsic_hash); }); From 8e05322a00680ec2e67d29989ac92ad54f0cb29d Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 13:46:27 +0200 Subject: [PATCH 22/32] fix teeracel --- cli/src/oracle/commands/add_to_whitelist.rs | 11 ++++++++--- cli/src/oracle/commands/listen_to_exchange.rs | 13 +++++-------- cli/src/oracle/commands/listen_to_oracle.rs | 12 +++++------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cli/src/oracle/commands/add_to_whitelist.rs b/cli/src/oracle/commands/add_to_whitelist.rs index 50ba3ce915..fab67ab203 100644 --- a/cli/src/oracle/commands/add_to_whitelist.rs +++ b/cli/src/oracle/commands/add_to_whitelist.rs @@ -19,8 +19,12 @@ use crate::{ command_utils::{get_chain_api, get_pair_from_str, mrenclave_from_base58}, Cli, }; +use codec::Encode; use itp_node_api::api_client::{ADD_TO_WHITELIST, TEERACLE}; -use substrate_api_client::{compose_call, compose_extrinsic, UncheckedExtrinsicV4, XtStatus}; +use substrate_api_client::{ + compose_call, compose_extrinsic, SubmitAndWatch, SubscribeFrameSystem, UncheckedExtrinsicV4, + XtStatus, +}; /// Add a trusted market data source to the on-chain whitelist. #[derive(Debug, Clone, Parser)] @@ -58,7 +62,8 @@ impl AddToWhitelistCmd { // compose the extrinsic let xt: UncheckedExtrinsicV4<_, _> = compose_extrinsic!(api, "Sudo", "sudo", call); - let tx_hash = api.send_extrinsic(xt.hex_encode(), XtStatus::Finalized).unwrap(); - println!("[+] Add to whitelist got finalized. Hash: {:?}\n", tx_hash); + let report = + api.submit_and_watch_extrinsic_until(xt.encode(), XtStatus::Finalized).unwrap(); + println!("[+] Add to whitelist got finalized. Hash: {:?}\n", report.extrinsic_hash); } } diff --git a/cli/src/oracle/commands/listen_to_exchange.rs b/cli/src/oracle/commands/listen_to_exchange.rs index aaeb653e16..e2e803acf4 100644 --- a/cli/src/oracle/commands/listen_to_exchange.rs +++ b/cli/src/oracle/commands/listen_to_exchange.rs @@ -21,8 +21,8 @@ use itp_node_api::api_client::ParentchainApi; use itp_time_utils::{duration_now, remaining_time}; use log::{debug, info, trace}; use my_node_runtime::{Hash, RuntimeEvent}; -use std::{sync::mpsc::channel, time::Duration}; -use substrate_api_client::FromHexString; +use std::time::Duration; +use substrate_api_client::{rpc::HandleSubscription, SubscribeFrameSystem}; /// Listen to exchange rate events. #[derive(Debug, Clone, Parser)] @@ -47,16 +47,13 @@ pub fn count_exchange_rate_update_events(api: &ParentchainApi, duration: Duratio let stop = duration_now() + duration; //subscribe to events - let (events_in, events_out) = channel(); - api.subscribe_events(events_in).unwrap(); + let mut subscription = api.subscribe_system_events().unwrap(); let mut count = 0; while remaining_time(stop).unwrap_or_default() > Duration::ZERO { - let event_str = events_out.recv().unwrap(); - let unhex = Vec::from_hex(event_str).unwrap(); - let mut event_records_encoded = unhex.as_slice(); + let event_bytes = subscription.next().unwrap().unwrap().changes[0].1.clone().unwrap().0; let events_result = Vec::>::decode( - &mut event_records_encoded, + &mut event_bytes.as_slice(), ); if let Ok(events) = events_result { for event_record in &events { diff --git a/cli/src/oracle/commands/listen_to_oracle.rs b/cli/src/oracle/commands/listen_to_oracle.rs index 8a53a80556..f1d19bde67 100644 --- a/cli/src/oracle/commands/listen_to_oracle.rs +++ b/cli/src/oracle/commands/listen_to_oracle.rs @@ -21,8 +21,8 @@ use itp_node_api::api_client::ParentchainApi; use itp_time_utils::{duration_now, remaining_time}; use log::{debug, info}; use my_node_runtime::{Hash, RuntimeEvent}; -use std::{sync::mpsc::channel, time::Duration}; -use substrate_api_client::FromHexString; +use std::time::Duration; +use substrate_api_client::{rpc::HandleSubscription, SubscribeFrameSystem}; /// Listen to exchange rate events. #[derive(Debug, Clone, Parser)] @@ -47,14 +47,12 @@ fn count_oracle_update_events(api: &ParentchainApi, duration: Duration) -> Event let stop = duration_now() + duration; //subscribe to events - let (events_in, events_out) = channel(); - api.subscribe_events(events_in).unwrap(); + let mut subscription = api.subscribe_system_events().unwrap(); let mut count = 0; while remaining_time(stop).unwrap_or_default() > Duration::ZERO { - let events_str = events_out.recv().unwrap(); - let events_vec_bytes = Vec::from_hex(events_str).unwrap(); - count += report_event_count(&events_vec_bytes); + let event_bytes = subscription.next().unwrap().unwrap().changes[0].1.clone().unwrap().0; + count += report_event_count(&event_bytes); } debug!("Received {} ExchangeRateUpdated event(s) in total", count); count From 20d7b6e83d921b67bad3d16d65754786ac821742 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 15:35:32 +0200 Subject: [PATCH 23/32] fix clippy --- cli/src/oracle/commands/add_to_whitelist.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/src/oracle/commands/add_to_whitelist.rs b/cli/src/oracle/commands/add_to_whitelist.rs index fab67ab203..1f43543d6e 100644 --- a/cli/src/oracle/commands/add_to_whitelist.rs +++ b/cli/src/oracle/commands/add_to_whitelist.rs @@ -22,8 +22,7 @@ use crate::{ use codec::Encode; use itp_node_api::api_client::{ADD_TO_WHITELIST, TEERACLE}; use substrate_api_client::{ - compose_call, compose_extrinsic, SubmitAndWatch, SubscribeFrameSystem, UncheckedExtrinsicV4, - XtStatus, + compose_call, compose_extrinsic, SubmitAndWatch, UncheckedExtrinsicV4, XtStatus, }; /// Add a trusted market data source to the on-chain whitelist. From d38eed04f3d83d7820d8f00b7c8c15fc3c7f079c Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 17:37:37 +0200 Subject: [PATCH 24/32] lets try --- service/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/src/main.rs b/service/src/main.rs index 3ee68f30a3..ea8995325d 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -76,7 +76,7 @@ use my_node_runtime::{Hash, Header, RuntimeEvent}; use sgx_types::*; use substrate_api_client::{ primitives::StorageChangeSet, rpc::HandleSubscription, GetHeader, SubmitAndWatchUntilSuccess, - SubscribeChain, SubscribeFrameSystem, + SubscribeChain, SubscribeFrameSystem, XtStatus, }; #[cfg(feature = "dcap")] @@ -797,7 +797,7 @@ fn send_extrinsic( println!("[>] Register the TCB info (send the extrinsic)"); let register_qe_block_hash = api - .submit_and_watch_extrinsic_until_success(extrinsic, true) + .submit_and_watch_extrinsic_until(extrinsic, XtStatus::Finalized) .unwrap() .block_hash; println!("[<] Extrinsic got finalized. Block hash: {:?}\n", register_qe_block_hash); From b28f1aefafa1c861a0b2ab3336f02ff5b505745e Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 30 Mar 2023 17:39:42 +0200 Subject: [PATCH 25/32] lets try that --- service/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/src/main.rs b/service/src/main.rs index ea8995325d..7c2a6dd4e9 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -75,7 +75,7 @@ use log::*; use my_node_runtime::{Hash, Header, RuntimeEvent}; use sgx_types::*; use substrate_api_client::{ - primitives::StorageChangeSet, rpc::HandleSubscription, GetHeader, SubmitAndWatchUntilSuccess, + primitives::StorageChangeSet, rpc::HandleSubscription, GetHeader, SubmitAndWatch, SubscribeChain, SubscribeFrameSystem, XtStatus, }; From 9939687e74162c16881dae143d810568ba7b70df Mon Sep 17 00:00:00 2001 From: haerdib Date: Mon, 3 Apr 2023 08:56:13 +0200 Subject: [PATCH 26/32] simplify account.rs --- .../api-client-extensions/src/account.rs | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/core-primitives/node-api/api-client-extensions/src/account.rs b/core-primitives/node-api/api-client-extensions/src/account.rs index ee5be86bba..244db8df98 100644 --- a/core-primitives/node-api/api-client-extensions/src/account.rs +++ b/core-primitives/node-api/api-client-extensions/src/account.rs @@ -34,28 +34,14 @@ where Signer: Pair, MultiSignature: From, Client: Request, - Runtime: FrameSystemConfig, + Runtime: FrameSystemConfig, Params: ExtrinsicParams, - Runtime::AccountId: From, - Runtime::Index: Into, - Runtime::AccountData: Into, { fn get_nonce_of(&self, who: &AccountId) -> ApiResult { - let account_id = who.clone().into(); - Ok(self.get_account_info(&account_id)?.map_or_else(|| 0, |info| info.nonce.into())) + Ok(self.get_account_info(&who)?.map_or_else(|| 0, |info| info.nonce)) } fn get_free_balance(&self, who: &AccountId) -> ApiResult { - let account_id = who.clone().into(); - let maybe_account_info = self.get_account_info(&account_id)?; - - let free_balance = match maybe_account_info { - Some(account_info) => { - let data: AccountData = account_info.data.into(); - data.free - }, - None => 0, - }; - Ok(free_balance) + Ok(self.get_account_data(&who)?.map_or_else(|| 0, |data| data.free)) } } From e4fab74bdd4d673284c0b7ccc04729758d72fced Mon Sep 17 00:00:00 2001 From: haerdib Date: Mon, 3 Apr 2023 09:08:57 +0200 Subject: [PATCH 27/32] simplfy pallet teerex --- .../api-client-extensions/src/chain.rs | 41 +++++++------------ .../src/pallet_teerex.rs | 13 +++--- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/core-primitives/node-api/api-client-extensions/src/chain.rs b/core-primitives/node-api/api-client-extensions/src/chain.rs index b8cd43b5b5..379e4094d7 100644 --- a/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -15,14 +15,14 @@ */ -use crate::ApiResult; +use crate::{ApiClientError, ApiResult}; use itp_api_client_types::{Block, SignedBlock}; use itp_types::parentchain::{BlockNumber, Hash, Header, StorageProof}; use sp_finality_grandpa::{AuthorityList, VersionedAuthorityList, GRANDPA_AUTHORITIES_KEY}; use sp_runtime::{traits::GetRuntimeBlockType, DeserializeOwned}; use substrate_api_client::{ - api::Error::NoBlockHash, primitives::StorageKey, rpc::Request, Api, ExtrinsicParams, - FrameSystemConfig, GetBlock, GetHeader, GetStorage, + primitives::StorageKey, rpc::Request, Api, ExtrinsicParams, FrameSystemConfig, GetBlock, + GetHeader, GetStorage, }; /// ApiClient extension that simplifies chain data access. @@ -43,43 +43,36 @@ pub trait ChainApi { impl ChainApi for Api where Client: Request, - Runtime: FrameSystemConfig + GetRuntimeBlockType, + Runtime: FrameSystemConfig + + GetRuntimeBlockType, Params: ExtrinsicParams, - Runtime::Header: DeserializeOwned + Into
, - Runtime::Hash: From + Into, + Runtime::Header: DeserializeOwned, Runtime::RuntimeBlock: DeserializeOwned + Into, - Runtime::BlockNumber: Into, { fn last_finalized_block(&self) -> ApiResult> { self.get_finalized_head()? - .map_or_else(|| Ok(None), |hash| self.signed_block(Some(hash.into()))) + .map_or_else(|| Ok(None), |hash| self.signed_block(Some(hash))) } fn signed_block(&self, hash: Option) -> ApiResult> { // Convert the substrate-api-clients `SignedBlock` redefinition into ours. - let maybe_signed_block = self - .get_signed_block(hash.map(|h| h.into()))? - .map(convert_signed_block::); + let maybe_signed_block = self.get_signed_block(hash)?.map(convert_signed_block::); Ok(maybe_signed_block) } fn get_genesis_hash(&self) -> ApiResult { - if let Some(hash) = self.get_block_hash(Some(0u32.into()))? { - Ok(hash.into()) - } else { - Err(NoBlockHash) - } + self.get_block_hash(Some(0u32.into()))?.ok_or(ApiClientError::NoBlockHash) } fn header(&self, header_hash: Option) -> ApiResult> { - Ok(self.get_header(header_hash.map(|h| h.into()))?.map(Into::into)) + Ok(self.get_header(header_hash)?) } fn get_blocks(&self, from: BlockNumber, to: BlockNumber) -> ApiResult> { let mut blocks = Vec::::new(); for n in from..=to { - if let Some(block) = self.get_signed_block_by_num(Some(n.into()))? { + if let Some(block) = self.get_signed_block_by_num(Some(n))? { blocks.push(convert_signed_block::(block)); } } @@ -89,10 +82,7 @@ where fn is_grandpa_available(&self) -> ApiResult { let genesis_hash = Some(self.get_genesis_hash().expect("Failed to get genesis hash")); Ok(self - .get_storage_by_key_hash( - StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec()), - genesis_hash.map(|b| b.into()), - )? + .get_storage_by_key_hash(StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec()), genesis_hash)? .map(|v: VersionedAuthorityList| v.into()) .map(|v: AuthorityList| !v.is_empty()) .unwrap_or(false)) @@ -100,10 +90,7 @@ where fn grandpa_authorities(&self, at_block: Option) -> ApiResult { Ok(self - .get_storage_by_key_hash( - StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec()), - at_block.map(|b| b.into()), - )? + .get_storage_by_key_hash(StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec()), at_block)? .map(|g: VersionedAuthorityList| g.into()) .unwrap_or_default()) } @@ -112,7 +99,7 @@ where Ok(self .get_storage_proof_by_keys( vec![StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec())], - at_block.map(|b| b.into()), + at_block, )? .map(|read_proof| read_proof.proof.into_iter().map(|bytes| bytes.0).collect()) .unwrap_or_default()) diff --git a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs index 0f6e2f8c21..5f75f16fde 100644 --- a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs +++ b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs @@ -42,18 +42,15 @@ pub trait PalletTeerexApi { impl PalletTeerexApi for Api where Client: Request, - Runtime: FrameSystemConfig, + Runtime: FrameSystemConfig, Params: ExtrinsicParams, - Runtime::Hash: From, { fn enclave(&self, index: u64, at_block: Option) -> ApiResult> { - self.get_storage_map(TEEREX, "EnclaveRegistry", index, at_block.map(|b| b.into())) + self.get_storage_map(TEEREX, "EnclaveRegistry", index, at_block) } fn enclave_count(&self, at_block: Option) -> ApiResult { - Ok(self - .get_storage_value(TEEREX, "EnclaveCount", at_block.map(|b| b.into()))? - .unwrap_or(0u64)) + Ok(self.get_storage_value(TEEREX, "EnclaveCount", at_block)?.unwrap_or(0u64)) } fn all_enclaves(&self, at_block: Option) -> ApiResult> { @@ -70,7 +67,7 @@ where shard: &ShardIdentifier, at_block: Option, ) -> ApiResult> { - self.get_storage_map(SIDECHAIN, "WorkerForShard", shard, at_block.map(|b| b.into()))? + self.get_storage_map(SIDECHAIN, "WorkerForShard", shard, at_block)? .map_or_else(|| Ok(None), |w_index| self.enclave(w_index, at_block)) } @@ -79,6 +76,6 @@ where shard: &ShardIdentifier, at_block: Option, ) -> ApiResult> { - self.get_storage_map(TEEREX, "LatestIPFSHash", shard, at_block.map(|b| b.into())) + self.get_storage_map(TEEREX, "LatestIPFSHash", shard, at_block) } } From dc9727c50428301c7f1a0fc5b9494aca299324cf Mon Sep 17 00:00:00 2001 From: haerdib Date: Mon, 3 Apr 2023 09:26:46 +0200 Subject: [PATCH 28/32] simplify signedblock --- Cargo.lock | 1 + core-primitives/enclave-api/Cargo.toml | 1 + core-primitives/enclave-api/src/sidechain.rs | 7 +++-- .../api-client-extensions/src/chain.rs | 28 ++++--------------- .../node-api/api-client-types/src/lib.rs | 4 +-- 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3175a88fc4..a2522e66c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3350,6 +3350,7 @@ dependencies = [ "frame-support", "itc-parentchain", "itp-enclave-api-ffi", + "itp-node-api", "itp-settings", "itp-types", "log 0.4.17", diff --git a/core-primitives/enclave-api/Cargo.toml b/core-primitives/enclave-api/Cargo.toml index dfb221f160..cca657a292 100644 --- a/core-primitives/enclave-api/Cargo.toml +++ b/core-primitives/enclave-api/Cargo.toml @@ -23,3 +23,4 @@ itc-parentchain = { path = "../../core/parentchain/parentchain-crate" } itp-enclave-api-ffi = { path = "ffi" } itp-settings = { path = "../settings" } itp-types = { path = "../types" } +itp-node-api = { path = "../node-api" } diff --git a/core-primitives/enclave-api/src/sidechain.rs b/core-primitives/enclave-api/src/sidechain.rs index 0b045839d3..b79712e2d1 100644 --- a/core-primitives/enclave-api/src/sidechain.rs +++ b/core-primitives/enclave-api/src/sidechain.rs @@ -20,15 +20,16 @@ use crate::{error::Error, Enclave, EnclaveResult}; use codec::Encode; use frame_support::ensure; use itp_enclave_api_ffi as ffi; +use itp_node_api::api_client::GenericSignedBlock; use sgx_types::sgx_status_t; -use sp_runtime::{generic::SignedBlock, traits::Block as ParentchainBlockTrait}; +use sp_runtime::traits::Block as ParentchainBlockTrait; /// trait for handling blocks on the side chain pub trait Sidechain: Send + Sync + 'static { /// Sync parentchain blocks and execute pending tops in the enclave fn sync_parentchain( &self, - blocks: &[SignedBlock], + blocks: &[GenericSignedBlock], nonce: u32, ) -> EnclaveResult<()>; @@ -38,7 +39,7 @@ pub trait Sidechain: Send + Sync + 'static { impl Sidechain for Enclave { fn sync_parentchain( &self, - blocks: &[SignedBlock], + blocks: &[GenericSignedBlock], nonce: u32, ) -> EnclaveResult<()> { let mut retval = sgx_status_t::SGX_SUCCESS; diff --git a/core-primitives/node-api/api-client-extensions/src/chain.rs b/core-primitives/node-api/api-client-extensions/src/chain.rs index 379e4094d7..1574a30cde 100644 --- a/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -19,7 +19,7 @@ use crate::{ApiClientError, ApiResult}; use itp_api_client_types::{Block, SignedBlock}; use itp_types::parentchain::{BlockNumber, Hash, Header, StorageProof}; use sp_finality_grandpa::{AuthorityList, VersionedAuthorityList, GRANDPA_AUTHORITIES_KEY}; -use sp_runtime::{traits::GetRuntimeBlockType, DeserializeOwned}; +use sp_runtime::traits::GetRuntimeBlockType; use substrate_api_client::{ primitives::StorageKey, rpc::Request, Api, ExtrinsicParams, FrameSystemConfig, GetBlock, GetHeader, GetStorage, @@ -44,10 +44,8 @@ impl ChainApi for Api - + GetRuntimeBlockType, + + GetRuntimeBlockType, Params: ExtrinsicParams, - Runtime::Header: DeserializeOwned, - Runtime::RuntimeBlock: DeserializeOwned + Into, { fn last_finalized_block(&self) -> ApiResult> { self.get_finalized_head()? @@ -55,9 +53,7 @@ where } fn signed_block(&self, hash: Option) -> ApiResult> { - // Convert the substrate-api-clients `SignedBlock` redefinition into ours. - let maybe_signed_block = self.get_signed_block(hash)?.map(convert_signed_block::); - Ok(maybe_signed_block) + self.get_signed_block(hash) } fn get_genesis_hash(&self) -> ApiResult { @@ -65,7 +61,7 @@ where } fn header(&self, header_hash: Option) -> ApiResult> { - Ok(self.get_header(header_hash)?) + self.get_header(header_hash) } fn get_blocks(&self, from: BlockNumber, to: BlockNumber) -> ApiResult> { @@ -73,7 +69,7 @@ where for n in from..=to { if let Some(block) = self.get_signed_block_by_num(Some(n))? { - blocks.push(convert_signed_block::(block)); + blocks.push(block); } } Ok(blocks) @@ -105,17 +101,3 @@ where .unwrap_or_default()) } } - -// Necessary because of https://github.com/scs/substrate-api-client/issues/492. -fn convert_signed_block( - signed_block: substrate_api_client::SignedBlock, -) -> SignedBlock -where - Runtime: GetRuntimeBlockType, - Runtime::RuntimeBlock: Into, -{ - SignedBlock { - block: signed_block.block.into(), - justifications: signed_block.justifications.map(|justifactions| justifactions.into()), - } -} diff --git a/core-primitives/node-api/api-client-types/src/lib.rs b/core-primitives/node-api/api-client-types/src/lib.rs index 405dbb4f2e..032dead5da 100644 --- a/core-primitives/node-api/api-client-types/src/lib.rs +++ b/core-primitives/node-api/api-client-types/src/lib.rs @@ -61,13 +61,13 @@ mod api { pub use my_node_runtime::{Block, Runtime, UncheckedExtrinsic}; - pub type SignedBlock = sp_runtime::generic::SignedBlock; - pub use substrate_api_client::{ api::Error as ApiClientError, rpc::{Error as RpcClientError, WsRpcClient}, + SignedBlock as GenericSignedBlock, }; + pub type SignedBlock = GenericSignedBlock; pub type ParentchainApi = Api; } From 62683cd76b859d53e9f6de8c77e6526d0197daed Mon Sep 17 00:00:00 2001 From: haerdib Date: Mon, 3 Apr 2023 09:30:00 +0200 Subject: [PATCH 29/32] remove clone --- service/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/src/main.rs b/service/src/main.rs index 7c2a6dd4e9..70b0104951 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -571,9 +571,9 @@ fn spawn_worker_for_shard_polling( type Events = Vec>; fn parse_events(change_set: StorageChangeSet) -> Result { - let event_bytes = change_set.changes[0] + let event_bytes = &change_set.changes[0] .1 - .clone() + .as_ref() .ok_or_else(|| "Retrieving Events Failed".to_string())? .0; Events::decode(&mut event_bytes.as_slice()).map_err(|_| "Decoding Events Failed".to_string()) From 67c621e9567f7c7ea7939b2b45a837a19ef35044 Mon Sep 17 00:00:00 2001 From: haerdib Date: Mon, 3 Apr 2023 09:46:06 +0200 Subject: [PATCH 30/32] fmt --- core-primitives/enclave-api/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-primitives/enclave-api/Cargo.toml b/core-primitives/enclave-api/Cargo.toml index cca657a292..12410e0c53 100644 --- a/core-primitives/enclave-api/Cargo.toml +++ b/core-primitives/enclave-api/Cargo.toml @@ -21,6 +21,6 @@ sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "po itc-parentchain = { path = "../../core/parentchain/parentchain-crate" } itp-enclave-api-ffi = { path = "ffi" } +itp-node-api = { path = "../node-api" } itp-settings = { path = "../settings" } itp-types = { path = "../types" } -itp-node-api = { path = "../node-api" } From 001f90d32dd07503d0c68d9a613bbe1a6bf562fd Mon Sep 17 00:00:00 2001 From: haerdib Date: Mon, 3 Apr 2023 11:46:36 +0200 Subject: [PATCH 31/32] fix clippy --- core-primitives/node-api/api-client-extensions/src/account.rs | 4 ++-- core-primitives/node-api/api-client-extensions/src/chain.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core-primitives/node-api/api-client-extensions/src/account.rs b/core-primitives/node-api/api-client-extensions/src/account.rs index 244db8df98..7e2a656048 100644 --- a/core-primitives/node-api/api-client-extensions/src/account.rs +++ b/core-primitives/node-api/api-client-extensions/src/account.rs @@ -38,10 +38,10 @@ where Params: ExtrinsicParams, { fn get_nonce_of(&self, who: &AccountId) -> ApiResult { - Ok(self.get_account_info(&who)?.map_or_else(|| 0, |info| info.nonce)) + Ok(self.get_account_info(who)?.map_or_else(|| 0, |info| info.nonce)) } fn get_free_balance(&self, who: &AccountId) -> ApiResult { - Ok(self.get_account_data(&who)?.map_or_else(|| 0, |data| data.free)) + Ok(self.get_account_data(who)?.map_or_else(|| 0, |data| data.free)) } } diff --git a/core-primitives/node-api/api-client-extensions/src/chain.rs b/core-primitives/node-api/api-client-extensions/src/chain.rs index 1574a30cde..a3508a7a4e 100644 --- a/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -57,7 +57,7 @@ where } fn get_genesis_hash(&self) -> ApiResult { - self.get_block_hash(Some(0u32.into()))?.ok_or(ApiClientError::NoBlockHash) + self.get_block_hash(Some(0u32))?.ok_or(ApiClientError::NoBlockHash) } fn header(&self, header_hash: Option) -> ApiResult> { From f47bb1a3e7e3f040fabaffcff996d93f4c158175 Mon Sep 17 00:00:00 2001 From: haerdib Date: Mon, 3 Apr 2023 14:57:04 +0200 Subject: [PATCH 32/32] clean SignedBlock --- Cargo.lock | 1 - core-primitives/enclave-api/Cargo.toml | 1 - core-primitives/enclave-api/src/sidechain.rs | 7 +++---- .../node-api/api-client-extensions/src/chain.rs | 4 ++-- core-primitives/node-api/api-client-types/src/lib.rs | 2 +- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a2522e66c0..3175a88fc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3350,7 +3350,6 @@ dependencies = [ "frame-support", "itc-parentchain", "itp-enclave-api-ffi", - "itp-node-api", "itp-settings", "itp-types", "log 0.4.17", diff --git a/core-primitives/enclave-api/Cargo.toml b/core-primitives/enclave-api/Cargo.toml index 12410e0c53..dfb221f160 100644 --- a/core-primitives/enclave-api/Cargo.toml +++ b/core-primitives/enclave-api/Cargo.toml @@ -21,6 +21,5 @@ sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "po itc-parentchain = { path = "../../core/parentchain/parentchain-crate" } itp-enclave-api-ffi = { path = "ffi" } -itp-node-api = { path = "../node-api" } itp-settings = { path = "../settings" } itp-types = { path = "../types" } diff --git a/core-primitives/enclave-api/src/sidechain.rs b/core-primitives/enclave-api/src/sidechain.rs index b79712e2d1..0b045839d3 100644 --- a/core-primitives/enclave-api/src/sidechain.rs +++ b/core-primitives/enclave-api/src/sidechain.rs @@ -20,16 +20,15 @@ use crate::{error::Error, Enclave, EnclaveResult}; use codec::Encode; use frame_support::ensure; use itp_enclave_api_ffi as ffi; -use itp_node_api::api_client::GenericSignedBlock; use sgx_types::sgx_status_t; -use sp_runtime::traits::Block as ParentchainBlockTrait; +use sp_runtime::{generic::SignedBlock, traits::Block as ParentchainBlockTrait}; /// trait for handling blocks on the side chain pub trait Sidechain: Send + Sync + 'static { /// Sync parentchain blocks and execute pending tops in the enclave fn sync_parentchain( &self, - blocks: &[GenericSignedBlock], + blocks: &[SignedBlock], nonce: u32, ) -> EnclaveResult<()>; @@ -39,7 +38,7 @@ pub trait Sidechain: Send + Sync + 'static { impl Sidechain for Enclave { fn sync_parentchain( &self, - blocks: &[GenericSignedBlock], + blocks: &[SignedBlock], nonce: u32, ) -> EnclaveResult<()> { let mut retval = sgx_status_t::SGX_SUCCESS; diff --git a/core-primitives/node-api/api-client-extensions/src/chain.rs b/core-primitives/node-api/api-client-extensions/src/chain.rs index a3508a7a4e..410f6332a3 100644 --- a/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -53,7 +53,7 @@ where } fn signed_block(&self, hash: Option) -> ApiResult> { - self.get_signed_block(hash) + Ok(self.get_signed_block(hash)?.map(|block| block.into())) } fn get_genesis_hash(&self) -> ApiResult { @@ -69,7 +69,7 @@ where for n in from..=to { if let Some(block) = self.get_signed_block_by_num(Some(n))? { - blocks.push(block); + blocks.push(block.into()); } } Ok(blocks) diff --git a/core-primitives/node-api/api-client-types/src/lib.rs b/core-primitives/node-api/api-client-types/src/lib.rs index 032dead5da..dd35c54ad3 100644 --- a/core-primitives/node-api/api-client-types/src/lib.rs +++ b/core-primitives/node-api/api-client-types/src/lib.rs @@ -57,6 +57,7 @@ pub use api::*; #[cfg(feature = "std")] mod api { use super::ParentchainExtrinsicParams; + use sp_runtime::generic::SignedBlock as GenericSignedBlock; use substrate_api_client::Api; pub use my_node_runtime::{Block, Runtime, UncheckedExtrinsic}; @@ -64,7 +65,6 @@ mod api { pub use substrate_api_client::{ api::Error as ApiClientError, rpc::{Error as RpcClientError, WsRpcClient}, - SignedBlock as GenericSignedBlock, }; pub type SignedBlock = GenericSignedBlock;