diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 6e05f5cf24..15b9be7c05 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -251,7 +251,7 @@ jobs: echo "PROJECT=${{ matrix.flavor_id }}-${{ matrix.demo_name }}" >> $GITHUB_ENV echo "VERSION=dev.$version" >> $GITHUB_ENV echo "WORKER_IMAGE_TAG=integritee-worker:dev.$version" >> $GITHUB_ENV - echo "INTEGRITEE_NODE=integritee-node-dev-ias:1.0.36.$version" >> $GITHUB_ENV + echo "INTEGRITEE_NODE=integritee-node-dev-ias:1.1.0.$version" >> $GITHUB_ENV echo "CLIENT_IMAGE_TAG=integritee-cli:dev.$version" >> $GITHUB_ENV if [[ ${{ matrix.sgx_mode }} == 'HW' ]]; then echo "SGX_PROVISION=/dev/sgx/provision" >> $GITHUB_ENV @@ -296,8 +296,8 @@ jobs: fi docker tag integritee-worker-${{ matrix.flavor_id }}-${{ github.sha }} ${{ env.WORKER_IMAGE_TAG }} docker tag integritee-cli-client-${{ matrix.flavor_id }}-${{ github.sha }} ${{ env.CLIENT_IMAGE_TAG }} - docker pull integritee/integritee-node-dev-ias:1.0.36 - docker tag integritee/integritee-node-dev-ias:1.0.36 ${{ env.INTEGRITEE_NODE }} + docker pull integritee/integritee-node-dev-ias:1.1.0 + docker tag integritee/integritee-node-dev-ias:1.1.0 ${{ env.INTEGRITEE_NODE }} docker images --all ## @@ -463,9 +463,9 @@ jobs: uses: actions/download-artifact@v3 with: name: integritee-worker-teeracle-${{ github.ref_name }}.tar.gz - path: . + path: . - # + # # Temporary comment out until we decide what to release # # - name: Download Integritee Service diff --git a/Cargo.lock b/Cargo.lock index df7c526375..c9c4198956 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -726,7 +726,7 @@ dependencies = [ [[package]] name = "claims-primitives" version = "0.1.0" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ "parity-scale-codec", "rustc-hex", @@ -831,8 +831,13 @@ dependencies = [ [[package]] name = "common-primitives" version = "0.1.0" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ + "derive_more", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", "sp-std", ] @@ -1323,6 +1328,22 @@ dependencies = [ "zeroize", ] +[[package]] +name = "enclave-bridge-primitives" +version = "0.1.0" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" +dependencies = [ + "common-primitives", + "log 0.4.19", + "parity-scale-codec", + "scale-info", + "serde 1.0.164", + "sp-core", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-runtime", + "sp-std", +] + [[package]] name = "encoding_rs" version = "0.8.32" @@ -1718,7 +1739,7 @@ checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-support-procedural", @@ -1771,7 +1792,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", @@ -1810,7 +1831,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "bitflags", "environmental 1.1.4", @@ -1843,7 +1864,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "cfg-expr", @@ -1859,7 +1880,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -1871,7 +1892,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote", @@ -1881,7 +1902,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "log 0.4.19", @@ -1914,7 +1935,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "sp-api", @@ -2732,6 +2753,7 @@ dependencies = [ "blake2-rfc", "chrono 0.4.26", "clap 3.2.25", + "enclave-bridge-primitives", "env_logger 0.9.3", "frame-system", "hdrhistogram", @@ -2748,6 +2770,7 @@ dependencies = [ "itp-utils", "log 0.4.19", "pallet-balances", + "pallet-enclave-bridge", "pallet-evm", "pallet-teerex", "parity-scale-codec", @@ -2765,15 +2788,14 @@ dependencies = [ "sp-runtime", "substrate-api-client", "substrate-client-keystore", - "teerex-primitives", "thiserror 1.0.40", "ws", ] [[package]] name = "integritee-node-runtime" -version = "1.0.33" -source = "git+https://github.com/integritee-network/integritee-node.git?branch=polkadot-v0.9.42#2c13d1fd5708825b7832b6b1bc33448ca3111514" +version = "1.1.34" +source = "git+https://github.com/integritee-network/integritee-node.git?branch=polkadot-v0.9.42#31b72e13596c36c4963ed6caf631377b68d34754" dependencies = [ "frame-executive", "frame-support", @@ -2782,6 +2804,7 @@ dependencies = [ "pallet-aura", "pallet-balances", "pallet-claims", + "pallet-enclave-bridge", "pallet-grandpa", "pallet-insecure-randomness-collective-flip", "pallet-multisig", @@ -2824,6 +2847,7 @@ dependencies = [ "base58", "clap 2.34.0", "dirs", + "enclave-bridge-primitives", "env_logger 0.9.3", "frame-support", "frame-system", @@ -3433,6 +3457,16 @@ dependencies = [ "sgx_types", ] +[[package]] +name = "itp-enclave-bridge-storage" +version = "0.9.0" +dependencies = [ + "itp-storage", + "itp-types", + "parity-scale-codec", + "sp-std", +] + [[package]] name = "itp-enclave-metrics" version = "0.9.0" @@ -3750,6 +3784,7 @@ name = "itp-teerex-storage" version = "0.9.0" dependencies = [ "itp-storage", + "itp-types", "sp-std", ] @@ -3759,13 +3794,13 @@ version = "0.9.0" dependencies = [ "derive_more", "ita-stf", + "itp-enclave-bridge-storage", "itp-ocall-api", "itp-sgx-crypto", "itp-sgx-externalities", "itp-stf-interface", "itp-stf-state-handler", "itp-storage", - "itp-teerex-storage", "itp-time-utils", "itp-types", "jsonrpc-core 18.0.0 (git+https://github.com/scs/jsonrpc?branch=no_std_v18)", @@ -3848,6 +3883,7 @@ name = "itp-types" version = "0.9.0" dependencies = [ "chrono 0.4.26", + "enclave-bridge-primitives", "frame-system", "integritee-node-runtime", "itp-sgx-runtime-primitives", @@ -3859,6 +3895,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-std", + "teerex-primitives", ] [[package]] @@ -4041,6 +4078,7 @@ dependencies = [ name = "its-primitives" version = "0.1.0" dependencies = [ + "itp-types", "parity-scale-codec", "scale-info", "serde 1.0.164", @@ -4142,11 +4180,14 @@ dependencies = [ "derive_more", "frame-support", "itc-parentchain-test", + "itp-enclave-bridge-storage", "itp-ocall-api", "itp-storage", "itp-teerex-storage", "itp-test", "itp-types", + "its-primitives", + "log 0.4.19", "parity-scale-codec", "sp-core", "sp-runtime", @@ -5299,7 +5340,7 @@ dependencies = [ [[package]] name = "pallet-aura" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", @@ -5315,7 +5356,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", @@ -5329,7 +5370,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -5344,7 +5385,7 @@ dependencies = [ [[package]] name = "pallet-claims" version = "0.9.12" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ "claims-primitives", "frame-support", @@ -5411,6 +5452,27 @@ dependencies = [ "syn 2.0.18", ] +[[package]] +name = "pallet-enclave-bridge" +version = "0.10.0" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" +dependencies = [ + "enclave-bridge-primitives", + "frame-support", + "frame-system", + "log 0.4.19", + "pallet-teerex", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "serde 1.0.164", + "sp-core", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-runtime", + "sp-std", + "teerex-primitives", +] + [[package]] name = "pallet-evm" version = "6.0.0-dev" @@ -5438,7 +5500,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -5461,7 +5523,7 @@ dependencies = [ [[package]] name = "pallet-insecure-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", @@ -5475,7 +5537,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -5491,7 +5553,7 @@ dependencies = [ [[package]] name = "pallet-parentchain" version = "0.9.0" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ "frame-support", "frame-system", @@ -5508,7 +5570,7 @@ dependencies = [ [[package]] name = "pallet-preimage" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", @@ -5523,7 +5585,7 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -5538,7 +5600,7 @@ dependencies = [ [[package]] name = "pallet-scheduler" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -5555,7 +5617,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", @@ -5575,12 +5637,14 @@ dependencies = [ [[package]] name = "pallet-sidechain" -version = "0.9.0" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +version = "0.10.0" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ + "enclave-bridge-primitives", "frame-support", "frame-system", "log 0.4.19", + "pallet-enclave-bridge", "pallet-teerex", "pallet-timestamp", "parity-scale-codec", @@ -5619,7 +5683,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", @@ -5633,7 +5697,7 @@ dependencies = [ [[package]] name = "pallet-teeracle" version = "0.1.0" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ "frame-support", "frame-system", @@ -5647,12 +5711,13 @@ dependencies = [ "sp-std", "substrate-fixed", "teeracle-primitives", + "teerex-primitives", ] [[package]] name = "pallet-teerex" -version = "0.9.0" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +version = "0.10.0" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ "frame-support", "frame-system", @@ -5672,7 +5737,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -5690,7 +5755,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", @@ -5706,7 +5771,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -5718,7 +5783,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -5735,7 +5800,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -5751,7 +5816,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -7137,7 +7202,7 @@ dependencies = [ [[package]] name = "sgx-verify" version = "0.1.4" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ "base64 0.13.1", "chrono 0.4.26", @@ -7145,6 +7210,7 @@ dependencies = [ "frame-support", "hex", "hex-literal", + "log 0.4.19", "parity-scale-codec", "ring 0.16.20 (git+https://github.com/Niederb/ring-xous.git?branch=0.16.20-cleanup)", "scale-info", @@ -7423,7 +7489,7 @@ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "sidechain-primitives" version = "0.1.0" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ "parity-scale-codec", "scale-info", @@ -7531,7 +7597,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "hash-db 0.16.0", "log 0.4.19", @@ -7551,7 +7617,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "blake2", @@ -7565,7 +7631,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -7578,7 +7644,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "integer-sqrt", "num-traits 0.2.15", @@ -7592,7 +7658,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "sp-api", @@ -7604,7 +7670,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "async-trait", "futures 0.3.28", @@ -7619,7 +7685,7 @@ dependencies = [ [[package]] name = "sp-consensus-aura" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "async-trait", "parity-scale-codec", @@ -7637,7 +7703,7 @@ dependencies = [ [[package]] name = "sp-consensus-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "finality-grandpa", "log 0.4.19", @@ -7655,7 +7721,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -7667,7 +7733,7 @@ dependencies = [ [[package]] name = "sp-core" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "array-bytes 4.2.0", "bitflags", @@ -7711,7 +7777,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "blake2b_simd", "byteorder 1.4.3", @@ -7725,7 +7791,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote", @@ -7736,7 +7802,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote", @@ -7746,7 +7812,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "environmental 1.1.4", "parity-scale-codec", @@ -7757,7 +7823,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -7795,7 +7861,7 @@ dependencies = [ [[package]] name = "sp-io" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "bytes 1.4.0", "ed25519", @@ -7832,7 +7898,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "futures 0.3.28", "parity-scale-codec", @@ -7846,7 +7912,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "thiserror 1.0.40", "zstd", @@ -7855,7 +7921,7 @@ dependencies = [ [[package]] name = "sp-metadata-ir" version = "0.1.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-metadata 15.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec", @@ -7880,7 +7946,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "sp-api", "sp-core", @@ -7890,7 +7956,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "backtrace", "lazy_static", @@ -7900,7 +7966,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "either", "hash256-std-hasher", @@ -7922,7 +7988,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "bytes 1.4.0", "impl-trait-for-tuples", @@ -7940,7 +8006,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "proc-macro-crate", @@ -7952,7 +8018,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -7966,7 +8032,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -7979,7 +8045,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "hash-db 0.16.0", "log 0.4.19", @@ -7999,12 +8065,12 @@ dependencies = [ [[package]] name = "sp-std" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" [[package]] name = "sp-storage" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8017,7 +8083,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "async-trait", "futures-timer", @@ -8032,7 +8098,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "sp-std", @@ -8044,7 +8110,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "sp-api", "sp-runtime", @@ -8053,7 +8119,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "ahash 0.8.3", "hash-db 0.16.0", @@ -8076,7 +8142,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8093,7 +8159,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -8104,7 +8170,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -8118,7 +8184,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -8289,7 +8355,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "ansi_term", "build-helper", @@ -8358,7 +8424,7 @@ checksum = "fd1ba337640d60c3e96bc6f0638a939b9c9a7f2c316a1598c279828b3d1dc8c5" [[package]] name = "teeracle-primitives" version = "0.1.0" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ "common-primitives", "sp-std", @@ -8368,14 +8434,16 @@ dependencies = [ [[package]] name = "teerex-primitives" version = "0.1.0" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ "common-primitives", + "derive_more", + "log 0.4.19", "parity-scale-codec", "scale-info", "serde 1.0.164", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-runtime", "sp-std", ] @@ -8865,7 +8933,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "digest 0.10.7", "rand 0.8.5", "static_assertions", diff --git a/Cargo.toml b/Cargo.toml index b0c1ac722a..efa7c1c0b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,20 +88,25 @@ sgx_urts = { version = "1.1.6", git = "https://github.com/apache/incubator-teacl #sgx-externalities = { path = "../sgx-runtime/substrate-sgx/externalities"} #[patch."https://github.com/integritee-network/integritee-node"] -#my-node-runtime = { package = "integritee-node-runtime", path = "../integritee-node/runtime"} +#my-node-runtime = { package = "integritee-node-runtime", git = "https://github.com/integritee-network//integritee-node", branch = "ab/integrate-pallet-teerex-refactoring" } #[patch."https://github.com/scs/substrate-api-client"] #substrate-api-client = { path = "../../scs/substrate-api-client" } #substrate-client-keystore = { path = "../../scs/substrate-api-client/client-keystore" } #[patch."https://github.com/integritee-network/pallets.git"] -#pallet-claims = { path = "../pallets/claims" } -#pallet-teerex = { path = "../pallets/teerex" } -#pallet-teeracle = { path = "../pallets/teeracle" } -#teerex-primitives = {path = "../pallets/primitives/teerex"} -#pallet-parentchain = { path = "../pallets/parentchain" } -#itp-types = { path = "../pallets/primitives/types"} -#itp-utils = { path = "../pallets/primitives/utils"} +#pallet-claims = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } +#pallet-enclave-bridge = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } +#pallet-teerex = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } +#pallet-sidechain = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } +#sgx-verify = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } +#pallet-teeracle = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } +#test-utils = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } +#claims-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } +#enclave-bridge-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } +#teerex-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } +#teeracle-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } +#common-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/shard-config-upgradability-2" } #[patch."https://github.com/integritee-network/http_req"] #http_req = {path = '..//http_req' } diff --git a/app-libs/stf/src/trusted_call.rs b/app-libs/stf/src/trusted_call.rs index 1f13721f6b..c81d21eadc 100644 --- a/app-libs/stf/src/trusted_call.rs +++ b/app-libs/stf/src/trusted_call.rs @@ -27,7 +27,7 @@ use frame_support::{ensure, traits::UnfilteredDispatchable}; pub use ita_sgx_runtime::{Balance, Index}; use ita_sgx_runtime::{Runtime, System}; use itp_node_api::metadata::{provider::AccessNodeMetadata, NodeMetadataTrait}; -use itp_node_api_metadata::pallet_teerex::TeerexCallIndexes; +use itp_node_api_metadata::pallet_enclave_bridge::EnclaveBridgeCallIndexes; use itp_stf_interface::ExecuteCall; use itp_stf_primitives::types::{AccountId, KeyPair, ShardIdentifier, Signature}; use itp_types::OpaqueCall; @@ -244,9 +244,9 @@ where unshield_funds(account_incognito, value)?; calls.push(OpaqueCall::from_tuple(&( node_metadata_repo.get_from_metadata(|m| m.unshield_funds_call_indexes())??, + shard, beneficiary, value, - shard, call_hash, ))); Ok(()) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index d9f87ae28d..f49593f1b3 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -26,12 +26,13 @@ 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.42" } +pallet-enclave-bridge = { git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v0.9.42" } pallet-evm = { optional = true, git = "https://github.com/integritee-network/frontier.git", branch = "bar/polkadot-v0.9.42" } pallet-teerex = { git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v0.9.42" } # `default-features = false` to remove the jsonrpsee dependency. +enclave-bridge-primitives = { git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v0.9.42" } substrate-api-client = { default-features = false, features = ["std", "ws-client"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.10.0" } substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.10.0" } -teerex-primitives = { git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v0.9.42" } # substrate dependencies frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } diff --git a/cli/src/base_cli/commands/listen.rs b/cli/src/base_cli/commands/listen.rs index 03d43ecf31..64d9e675e5 100644 --- a/cli/src/base_cli/commands/listen.rs +++ b/cli/src/base_cli/commands/listen.rs @@ -74,10 +74,10 @@ impl ListenCommand { } }, RuntimeEvent::Teerex(ee) => { - println!(">>>>>>>>>> integritee event: {:?}", ee); + println!(">>>>>>>>>> integritee teerex event: {:?}", ee); count += 1; match &ee { - my_node_runtime::pallet_teerex::Event::AddedEnclave{ + my_node_runtime::pallet_teerex::Event::AddedSgxEnclave{ registered_by, worker_url, .. } @@ -85,55 +85,69 @@ impl ListenCommand { println!( "AddedEnclave: {:?} at url {}", registered_by, - String::from_utf8(worker_url.to_vec()) + String::from_utf8(worker_url.clone().unwrap_or("none".into()).to_vec()) .unwrap_or_else(|_| "error".to_string()) ); }, - my_node_runtime::pallet_teerex::Event::RemovedEnclave( + my_node_runtime::pallet_teerex::Event::RemovedSovereignEnclave( accountid, ) => { println!("RemovedEnclave: {:?}", accountid); }, - my_node_runtime::pallet_teerex::Event::Forwarded(shard) => { + my_node_runtime::pallet_teerex::Event::RemovedProxiedEnclave( + eia, + ) => { + println!("RemovedEnclave: {:?}", eia); + }, + _ => debug!("ignoring unsupported teerex event: {:?}", ee), + } + }, + RuntimeEvent::EnclaveBridge(ee) => { + println!(">>>>>>>>>> integritee enclave bridge event: {:?}", ee); + count += 1; + match &ee { + my_node_runtime::pallet_enclave_bridge::Event::IndirectInvocationRegistered(shard) => { println!( "Forwarded request for shard {}", shard.encode().to_base58() ); }, - my_node_runtime::pallet_teerex::Event::ProcessedParentchainBlock( - accountid, + my_node_runtime::pallet_enclave_bridge::Event::ProcessedParentchainBlock { + shard, block_hash, - merkle_root, + trusted_calls_merkle_root, block_number, - ) => { + } => { println!( "ProcessedParentchainBlock from {} with hash {:?}, number {} and merkle root {:?}", - accountid, block_hash, merkle_root, block_number + shard, block_hash, trusted_calls_merkle_root, block_number ); }, - my_node_runtime::pallet_teerex::Event::ShieldFunds( - incognito_account, - ) => { - println!("ShieldFunds for {:?}", incognito_account); + my_node_runtime::pallet_enclave_bridge::Event::ShieldFunds { + shard, encrypted_beneficiary, amount + } => { + println!("ShieldFunds on shard {:?} for {:?}. amount: {:?}", shard, encrypted_beneficiary, amount); }, - my_node_runtime::pallet_teerex::Event::UnshieldedFunds( - public_account, - ) => { - println!("UnshieldFunds for {:?}", public_account); + my_node_runtime::pallet_enclave_bridge::Event::UnshieldedFunds { + shard, beneficiary, amount + } => { + println!("UnshieldFunds on shard {:?} for {:?}. amount: {:?}", shard, beneficiary, amount); }, - _ => debug!("ignoring unsupported teerex event: {:?}", ee), + _ => debug!("ignoring unsupported enclave_bridge event: {:?}", ee), } }, RuntimeEvent::Sidechain(ee) => { + println!(">>>>>>>>>> integritee sidechain event: {:?}", ee); count += 1; match &ee { - my_node_runtime::pallet_sidechain::Event::ProposedSidechainBlock( - accountid, - block_hash, - ) => { + my_node_runtime::pallet_sidechain::Event::FinalizedSidechainBlock { + shard, + block_header_hash, + validateer, + } => { println!( - "ProposedSidechainBlock from {} with hash {:?}", - accountid, block_hash + "ProposedSidechainBlock on shard {} from {} with hash {:?}", + shard, validateer, block_header_hash ); }, _ => debug!("ignoring unsupported sidechain event: {:?}", ee), diff --git a/cli/src/base_cli/commands/shield_funds.rs b/cli/src/base_cli/commands/shield_funds.rs index dbad28d071..0c1c538056 100644 --- a/cli/src/base_cli/commands/shield_funds.rs +++ b/cli/src/base_cli/commands/shield_funds.rs @@ -17,17 +17,17 @@ use crate::{ command_utils::{get_accountid_from_str, get_chain_api, *}, - Cli, CliResult, CliResultOk, + Cli, CliError, CliResult, CliResultOk, }; use base58::FromBase58; use codec::{Decode, Encode}; -use itp_node_api::api_client::{ParentchainExtrinsicSigner, TEEREX}; +use itp_node_api::api_client::{ParentchainExtrinsicSigner, ENCLAVE_BRIDGE}; use itp_sgx_crypto::ShieldingCryptoEncrypt; 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, SubmitAndWatch, XtStatus}; +use substrate_api_client::{compose_extrinsic, SubmitAndWatchUntilSuccess}; #[derive(Parser)] pub struct ShieldFundsCommand { @@ -68,16 +68,25 @@ impl ShieldFundsCommand { // Compose the extrinsic. let xt = compose_extrinsic!( chain_api, - TEEREX, + ENCLAVE_BRIDGE, "shield_funds", + shard, encrypted_recevier, - self.amount, - shard + self.amount ); - let tx_hash = chain_api.submit_and_watch_extrinsic_until(xt, XtStatus::Finalized).unwrap(); - println!("[+] TrustedOperation got finalized. Hash: {:?}\n", tx_hash); - - Ok(CliResultOk::None) + match chain_api.submit_and_watch_extrinsic_until_success(xt, true) { + Ok(xt_report) => { + println!( + "[+] shield funds success. extrinsic hash: {:?} / status: {:?} / block hash: {:?}", + xt_report.extrinsic_hash, xt_report.status, xt_report.block_hash.unwrap() + ); + Ok(CliResultOk::H256 { hash: xt_report.block_hash.unwrap() }) + }, + Err(e) => { + error!("shield_funds extrinsic failed {:?}", e); + Err(CliError::Extrinsic { msg: format!("{:?}", e) }) + }, + } } } diff --git a/cli/src/base_cli/mod.rs b/cli/src/base_cli/mod.rs index 117d1e317f..50dd7d0a33 100644 --- a/cli/src/base_cli/mod.rs +++ b/cli/src/base_cli/mod.rs @@ -24,16 +24,13 @@ use crate::{ Cli, CliResult, CliResultOk, ED25519_KEY_TYPE, SR25519_KEY_TYPE, }; use base58::ToBase58; -use chrono::{DateTime, Utc}; use clap::Subcommand; +use codec::Encode; use itc_rpc_client::direct_client::DirectApi; use itp_node_api::api_client::PalletTeerexApi; use sp_core::crypto::Ss58Codec; use sp_keystore::Keystore; -use std::{ - path::PathBuf, - time::{Duration, UNIX_EPOCH}, -}; +use std::path::PathBuf; use substrate_api_client::Metadata; use substrate_client_keystore::LocalKeystore; @@ -141,29 +138,22 @@ fn print_sgx_metadata(cli: &Cli) -> CliResult { fn list_workers(cli: &Cli) -> CliResult { let api = get_chain_api(cli); - let wcount = api.enclave_count(None).unwrap(); - println!("number of workers registered: {}", wcount); - - let mut mr_enclaves = Vec::with_capacity(wcount as usize); - - for w in 1..=wcount { - let enclave = api.enclave(w, None).unwrap(); - if enclave.is_none() { - println!("error reading enclave data"); - continue - }; - let enclave = enclave.unwrap(); - let timestamp = - DateTime::::from(UNIX_EPOCH + Duration::from_millis(enclave.timestamp)); - let mr_enclave = enclave.mr_enclave.to_base58(); - println!("Enclave {}", w); - println!(" AccountId: {}", enclave.pubkey.to_ss58check()); - println!(" MRENCLAVE: {}", mr_enclave); - println!(" RA timestamp: {}", timestamp); - println!(" URL: {}", enclave.url); - - mr_enclaves.push(mr_enclave); - } - - Ok(CliResultOk::MrEnclaveBase58 { mr_enclaves }) + let enclaves = api.all_enclaves(None).unwrap(); + println!("number of enclaves registered: {}", enclaves.len()); + let fingerprints = enclaves + .iter() + .map(|enclave| { + println!("Enclave"); + println!(" signer: {:?}", enclave.instance_signer()); + println!(" MRENCLAVE: {}", enclave.fingerprint().0.to_base58()); + println!(" RA timestamp: {}", enclave.attestation_timestamp()); + println!( + " URL: {}", + String::from_utf8(enclave.instance_url().unwrap_or_else(|| "none".encode())) + .unwrap() + ); + enclave.fingerprint().0.to_base58() + }) + .collect(); + Ok(CliResultOk::MrEnclaveBase58 { mr_enclaves: fingerprints }) } diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 7f51946c13..3cde133166 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -110,6 +110,8 @@ pub enum CliResultOk { #[derive(Debug, Error)] pub enum CliError { + #[error("extrinsic error: {:?}", msg)] + Extrinsic { msg: String }, #[error("trusted operation error: {:?}", msg)] TrustedOp { msg: String }, #[error("EvmReadCommands error: {:?}", msg)] diff --git a/cli/src/oracle/commands/listen_to_exchange.rs b/cli/src/oracle/commands/listen_to_exchange.rs index 8c27e0e0ca..95bab3ab38 100644 --- a/cli/src/oracle/commands/listen_to_exchange.rs +++ b/cli/src/oracle/commands/listen_to_exchange.rs @@ -56,16 +56,16 @@ pub fn count_exchange_rate_update_events(api: &ParentchainApi, duration: Duratio info!("received event {:?}", event_record.event); if let RuntimeEvent::Teeracle(event) = &event_record.event { match &event { - my_node_runtime::pallet_teeracle::Event::ExchangeRateUpdated( - src, + my_node_runtime::pallet_teeracle::Event::ExchangeRateUpdated { + data_source, trading_pair, exchange_rate, - ) => { + } => { count += 1; debug!("Received ExchangeRateUpdated event"); println!( "ExchangeRateUpdated: TRADING_PAIR : {}, SRC : {}, VALUE :{:?}", - trading_pair, src, exchange_rate + trading_pair, data_source, exchange_rate ); }, _ => trace!("ignoring teeracle event: {:?}", event), diff --git a/cli/src/oracle/commands/listen_to_oracle.rs b/cli/src/oracle/commands/listen_to_oracle.rs index 916e8706ad..d367bc020c 100644 --- a/cli/src/oracle/commands/listen_to_oracle.rs +++ b/cli/src/oracle/commands/listen_to_oracle.rs @@ -71,10 +71,16 @@ fn report_event_count(event_records: Vec) -> EventCount { info!("received event {:?}", event_record.event); if let RuntimeEvent::Teeracle(event) = &event_record.event { match &event { - my_node_runtime::pallet_teeracle::Event::OracleUpdated(oracle_name, src) => { + my_node_runtime::pallet_teeracle::Event::OracleUpdated { + oracle_data_name, + data_source, + } => { count += 1; debug!("Received OracleUpdated event"); - println!("OracleUpdated: ORACLE_NAME : {}, SRC : {}", oracle_name, src); + println!( + "OracleUpdated: ORACLE_NAME : {}, SRC : {}", + oracle_data_name, data_source + ); }, // Can just remove this and ignore handling this case _ => debug!("ignoring teeracle event: {:?}", event), diff --git a/cli/src/trusted_operation.rs b/cli/src/trusted_operation.rs index 24bf9f1035..d8e5dc9a87 100644 --- a/cli/src/trusted_operation.rs +++ b/cli/src/trusted_operation.rs @@ -23,9 +23,10 @@ use crate::{ }; use base58::{FromBase58, ToBase58}; use codec::{Decode, Encode}; +use enclave_bridge_primitives::Request; use ita_stf::{Getter, TrustedOperation}; use itc_rpc_client::direct_client::{DirectApi, DirectClient}; -use itp_node_api::api_client::{ParentchainApi, ParentchainExtrinsicSigner, TEEREX}; +use itp_node_api::api_client::{ParentchainApi, ParentchainExtrinsicSigner, ENCLAVE_BRIDGE}; use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue}; use itp_sgx_crypto::ShieldingCryptoEncrypt; use itp_stf_primitives::types::ShardIdentifier; @@ -33,7 +34,7 @@ use itp_types::{BlockNumber, DirectRequestStatus, TrustedOperationStatus}; use itp_utils::{FromHexPrefixed, ToHexPrefixed}; use log::*; use my_node_runtime::{Hash, RuntimeEvent}; -use pallet_teerex::Event as TeerexEvent; +use pallet_enclave_bridge::Event as EnclaveBridgeEvent; use sp_core::{sr25519 as sr25519_core, H256}; use std::{ result::Result as StdResult, @@ -41,13 +42,14 @@ use std::{ time::Instant, }; use substrate_api_client::{ - compose_extrinsic, GetHeader, SubmitAndWatch, SubscribeEvents, XtStatus, + compose_extrinsic, GetHeader, SubmitAndWatchUntilSuccess, SubscribeEvents, }; -use teerex_primitives::Request; use thiserror::Error; #[derive(Debug, Error)] pub(crate) enum TrustedOperationError { + #[error("extrinsic L1 error: {msg:?}")] + Extrinsic { msg: String }, #[error("default error: {msg:?}")] Default { msg: String }, } @@ -127,7 +129,7 @@ fn send_indirect_request( let shard = read_shard(trusted_args).unwrap(); debug!( - "indirect send_request: trusted operation: {:?}, shard: {}", + "invoke indirect send_request: trusted operation: {:?}, shard: {}", trusted_operation, shard.encode().to_base58() ); @@ -136,14 +138,21 @@ fn send_indirect_request( chain_api.set_signer(ParentchainExtrinsicSigner::new(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, ENCLAVE_BRIDGE, "invoke", request); - // send and watch extrinsic until block is executed - let block_hash = chain_api - .submit_and_watch_extrinsic_until(xt, XtStatus::InBlock) - .unwrap() - .block_hash - .unwrap(); + let block_hash = match chain_api.submit_and_watch_extrinsic_until_success(xt, false) { + Ok(xt_report) => { + println!( + "[+] invoke TrustedOperation extrinsic success. extrinsic hash: {:?} / status: {:?} / block hash: {:?}", + xt_report.extrinsic_hash, xt_report.status, xt_report.block_hash.unwrap() + ); + xt_report.block_hash.unwrap() + }, + Err(e) => { + error!("invoke TrustedOperation extrinsic failed {:?}", e); + return Err(TrustedOperationError::Extrinsic { msg: format!("{:?}", e) }) + }, + }; info!( "Trusted call extrinsic sent for shard {} and successfully included in parentchain block with hash {:?}.", @@ -154,15 +163,17 @@ fn send_indirect_request( loop { let event_records = subscription.next_event::().unwrap().unwrap(); for event_record in event_records { - if let RuntimeEvent::Teerex(TeerexEvent::ProcessedParentchainBlock( - _signer, - confirmed_block_hash, - _merkle_root, - confirmed_block_number, - )) = event_record.event + if let RuntimeEvent::EnclaveBridge(EnclaveBridgeEvent::ProcessedParentchainBlock { + shard, + block_hash: confirmed_block_hash, + trusted_calls_merkle_root, + block_number: confirmed_block_number, + }) = event_record.event { info!("Confirmation of ProcessedParentchainBlock received"); - debug!("Expected block Hash: {:?}", block_hash); + debug!("shard: {:?}", shard); + debug!("confirmed parentchain block Hash: {:?}", block_hash); + debug!("trusted calls merkle root: {:?}", trusted_calls_merkle_root); debug!("Confirmed stf block Hash: {:?}", confirmed_block_hash); if let Err(e) = check_if_received_event_exceeds_expected( &chain_api, diff --git a/core-primitives/enclave-api/src/enclave_base.rs b/core-primitives/enclave-api/src/enclave_base.rs index d6b67480bf..86ffceaeb9 100644 --- a/core-primitives/enclave-api/src/enclave_base.rs +++ b/core-primitives/enclave-api/src/enclave_base.rs @@ -29,6 +29,7 @@ use log::*; use sgx_crypto_helper::rsa3072::Rsa3072PubKey; use sgx_types::*; use sp_core::ed25519; +use teerex_primitives::EnclaveFingerprint; /// Trait for base/common Enclave API functions pub trait EnclaveBase: Send + Sync + 'static { @@ -67,7 +68,7 @@ pub trait EnclaveBase: Send + Sync + 'static { fn get_ecc_signing_pubkey(&self) -> EnclaveResult; - fn get_mrenclave(&self) -> EnclaveResult<[u8; MR_ENCLAVE_SIZE]>; + fn get_fingerprint(&self) -> EnclaveResult; } /// EnclaveApi implementation for Enclave struct @@ -236,7 +237,7 @@ impl EnclaveBase for Enclave { Ok(ed25519::Public::from_raw(pubkey)) } - fn get_mrenclave(&self) -> EnclaveResult<[u8; MR_ENCLAVE_SIZE]> { + fn get_fingerprint(&self) -> EnclaveResult { let mut retval = sgx_status_t::SGX_SUCCESS; let mut mr_enclave = [0u8; MR_ENCLAVE_SIZE]; @@ -252,7 +253,7 @@ impl EnclaveBase for Enclave { ensure!(result == sgx_status_t::SGX_SUCCESS, Error::Sgx(result)); ensure!(retval == sgx_status_t::SGX_SUCCESS, Error::Sgx(retval)); - Ok(mr_enclave) + Ok(mr_enclave.into()) } } diff --git a/core-primitives/enclave-bridge-storage/Cargo.toml b/core-primitives/enclave-bridge-storage/Cargo.toml new file mode 100644 index 0000000000..595fb10189 --- /dev/null +++ b/core-primitives/enclave-bridge-storage/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "itp-enclave-bridge-storage" +version = "0.9.0" +authors = ["Integritee AG "] +edition = "2021" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } + +#local deps +itp-storage = { path = "../storage", default-features = false } +itp-types = { path = "../types", default-features = false } + +[features] +default = ["std"] +std = [ + "sp-std/std", + "itp-storage/std", + "itp-types/std", +] diff --git a/core-primitives/enclave-bridge-storage/src/lib.rs b/core-primitives/enclave-bridge-storage/src/lib.rs new file mode 100644 index 0000000000..9077d756b6 --- /dev/null +++ b/core-primitives/enclave-bridge-storage/src/lib.rs @@ -0,0 +1,31 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +use codec::Encode; +use itp_storage::{storage_map_key, StorageHasher}; +use sp_std::prelude::Vec; + +pub struct EnclaveBridgeStorage; + +// Separate the prefix from the rest because in our case we changed the storage prefix due to +// the rebranding. With the below implementation of the `TeerexStorageKeys`, we could simply +// define another struct `OtherStorage`, implement `StoragePrefix` for it, and get the +// `TeerexStorageKeys` implementation for free. +pub trait StoragePrefix { + fn prefix() -> &'static str; +} + +impl StoragePrefix for EnclaveBridgeStorage { + fn prefix() -> &'static str { + "EnclaveBridge" + } +} + +pub trait EnclaveBridgeStorageKeys { + fn shard_status(shard: T) -> Vec; +} + +impl EnclaveBridgeStorageKeys for S { + fn shard_status(shard: T) -> Vec { + storage_map_key(Self::prefix(), "ShardStatus", &shard, &StorageHasher::Blake2_128Concat) + } +} 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 4265e33393..e123c41908 100644 --- a/core-primitives/node-api/api-client-extensions/src/lib.rs +++ b/core-primitives/node-api/api-client-extensions/src/lib.rs @@ -23,7 +23,6 @@ pub mod account; pub mod chain; pub mod pallet_teeracle; pub mod pallet_teerex; -pub mod pallet_teerex_api_mock; pub use account::*; pub use chain::*; 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 5f75f16fde..5b6556c11e 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,22 +16,30 @@ */ use crate::ApiResult; -use itp_types::{parentchain::Hash, Enclave, IpfsHash, ShardIdentifier}; -use substrate_api_client::{rpc::Request, Api, ExtrinsicParams, FrameSystemConfig, GetStorage}; +use itp_types::{ + parentchain::Hash, AccountId, IpfsHash, MultiEnclave, ShardIdentifier, ShardStatus, +}; +use substrate_api_client::{ + log::error, rpc::Request, Api, ExtrinsicParams, FrameSystemConfig, GetStorage, +}; pub const TEEREX: &str = "Teerex"; -pub const SIDECHAIN: &str = "Sidechain"; +pub const ENCLAVE_BRIDGE: &str = "EnclaveBridge"; /// ApiClient extension that enables communication with the `teerex` pallet. pub trait PalletTeerexApi { - fn enclave(&self, index: u64, at_block: Option) -> ApiResult>; + fn enclave( + &self, + account: &AccountId, + at_block: Option, + ) -> ApiResult>>>; fn enclave_count(&self, at_block: Option) -> ApiResult; - fn all_enclaves(&self, at_block: Option) -> ApiResult>; - fn worker_for_shard( + fn all_enclaves(&self, at_block: Option) -> ApiResult>>>; + fn primary_worker_for_shard( &self, shard: &ShardIdentifier, at_block: Option, - ) -> ApiResult>; + ) -> ApiResult>>>; fn latest_ipfs_hash( &self, shard: &ShardIdentifier, @@ -45,30 +53,50 @@ where Runtime: FrameSystemConfig, Params: ExtrinsicParams, { - fn enclave(&self, index: u64, at_block: Option) -> ApiResult> { - self.get_storage_map(TEEREX, "EnclaveRegistry", index, at_block) + fn enclave( + &self, + account: &AccountId, + at_block: Option, + ) -> ApiResult>>> { + self.get_storage_map(TEEREX, "SovereignEnclaves", account, at_block) } fn enclave_count(&self, at_block: Option) -> ApiResult { - Ok(self.get_storage_value(TEEREX, "EnclaveCount", at_block)?.unwrap_or(0u64)) + Ok(self.all_enclaves(at_block)?.len() as u64) } - fn all_enclaves(&self, at_block: Option) -> ApiResult> { - let count = self.enclave_count(at_block)?; - let mut enclaves = Vec::with_capacity(count as usize); - for n in 1..=count { - enclaves.push(self.enclave(n, at_block)?.expect("None enclave")) + fn all_enclaves(&self, at_block: Option) -> ApiResult>>> { + let key_prefix = self.get_storage_map_key_prefix("Teerex", "SovereignEnclaves")?; + //fixme: solve this properly with infinite elements + let max_keys = 1000; + let storage_keys = + self.get_storage_keys_paged(Some(key_prefix), max_keys, None, at_block)?; + + if storage_keys.len() == max_keys as usize { + error!("results can be wrong because max keys reached for query") } + let enclaves = storage_keys + .iter() + .filter_map(|key| self.get_storage_by_key_hash(key.clone(), at_block).ok()?) + .collect(); Ok(enclaves) } - fn worker_for_shard( + fn primary_worker_for_shard( &self, shard: &ShardIdentifier, at_block: Option, - ) -> ApiResult> { - self.get_storage_map(SIDECHAIN, "WorkerForShard", shard, at_block)? - .map_or_else(|| Ok(None), |w_index| self.enclave(w_index, at_block)) + ) -> ApiResult>>> { + self.get_storage_map(ENCLAVE_BRIDGE, "ShardStatus", shard, at_block)? + .map_or_else( + || Ok(None), + |statuses: ShardStatus| { + statuses.get(0).map_or_else( + || Ok(None), + |signerstatus| self.enclave(&signerstatus.signer, at_block), + ) + }, + ) } fn latest_ipfs_hash( 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 06da958b9d..cb63892da4 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,22 +16,27 @@ */ use crate::{pallet_teerex::PalletTeerexApi, ApiResult}; -use itp_types::{parentchain::Hash, Enclave, IpfsHash, ShardIdentifier}; +use itp_types::{parentchain::Hash, AccountId, IpfsHash, MultiEnclave, ShardIdentifier}; +use std::collections::HashMap; #[derive(Default)] pub struct PalletTeerexApiMock { - registered_enclaves: Vec, + registered_enclaves: HashMap>>, } impl PalletTeerexApiMock { - pub fn with_enclaves(mut self, enclaves: Vec) -> Self { - self.registered_enclaves.extend(enclaves); + pub fn with_enclaves(mut self, enclaves: Vec>>) -> Self { + enclaves.iter().map(|enclave| self.registered_enclaves.insert(enclave)); self } } impl PalletTeerexApi for PalletTeerexApiMock { - fn enclave(&self, index: u64, _at_block: Option) -> ApiResult> { + fn enclave( + &self, + account: AccountId, + _at_block: Option, + ) -> ApiResult>>> { Ok(self.registered_enclaves.get(index as usize).cloned()) } @@ -39,15 +44,15 @@ impl PalletTeerexApi for PalletTeerexApiMock { Ok(self.registered_enclaves.len() as u64) } - fn all_enclaves(&self, _at_block: Option) -> ApiResult> { + fn all_enclaves(&self, _at_block: Option) -> ApiResult>>> { Ok(self.registered_enclaves.clone()) } - fn worker_for_shard( + fn primary_worker_for_shard( &self, _shard: &ShardIdentifier, _at_block: Option, - ) -> ApiResult> { + ) -> ApiResult>>> { todo!() } diff --git a/core-primitives/node-api/metadata/src/lib.rs b/core-primitives/node-api/metadata/src/lib.rs index 43c68a2964..9bb09a21fb 100644 --- a/core-primitives/node-api/metadata/src/lib.rs +++ b/core-primitives/node-api/metadata/src/lib.rs @@ -20,7 +20,8 @@ #![cfg_attr(not(feature = "std"), no_std)] use crate::{ - error::Result, pallet_sidechain::SidechainCallIndexes, pallet_teerex::TeerexCallIndexes, + error::Result, pallet_enclave_bridge::EnclaveBridgeCallIndexes, + pallet_sidechain::SidechainCallIndexes, pallet_teerex::TeerexCallIndexes, }; use codec::{Decode, Encode}; use sp_core::storage::StorageKey; @@ -29,6 +30,7 @@ pub use crate::error::Error; pub use itp_api_client_types::{Metadata, MetadataError}; pub mod error; +pub mod pallet_enclave_bridge; pub mod pallet_sidechain; pub mod pallet_teeracle; pub mod pallet_teerex; @@ -36,8 +38,14 @@ pub mod pallet_teerex; #[cfg(feature = "mocks")] pub mod metadata_mocks; -pub trait NodeMetadataTrait: TeerexCallIndexes + SidechainCallIndexes {} -impl NodeMetadataTrait for T {} +pub trait NodeMetadataTrait: + TeerexCallIndexes + EnclaveBridgeCallIndexes + SidechainCallIndexes +{ +} +impl NodeMetadataTrait + for T +{ +} impl TryFrom for Metadata { type Error = crate::error::Error; diff --git a/core-primitives/node-api/metadata/src/metadata_mocks.rs b/core-primitives/node-api/metadata/src/metadata_mocks.rs index a3e288dad8..57cf0fe327 100644 --- a/core-primitives/node-api/metadata/src/metadata_mocks.rs +++ b/core-primitives/node-api/metadata/src/metadata_mocks.rs @@ -20,6 +20,7 @@ use crate::{ }; use codec::{Decode, Encode}; +use crate::pallet_enclave_bridge::EnclaveBridgeCallIndexes; use itp_api_client_types::Metadata; impl TryFrom for Metadata { @@ -33,16 +34,18 @@ impl TryFrom for Metadata { #[derive(Default, Encode, Decode, Debug, Clone)] pub struct NodeMetadataMock { teerex_module: u8, - register_ias_enclave: u8, - register_dcap_enclave: u8, - unregister_enclave: u8, + register_sgx_enclave: u8, + unregister_sovereign_enclave: u8, + unregister_proxied_enclave: u8, register_quoting_enclave: u8, register_tcb_info: u8, - call_worker: u8, - processed_parentchain_block: u8, + enclave_bridge_module: u8, + invoke: u8, + confirm_processed_parentchain_block: u8, shield_funds: u8, unshield_funds: u8, publish_hash: u8, + update_shard_config: u8, sidechain_module: u8, imported_sidechain_block: u8, runtime_spec_version: u32, @@ -53,16 +56,18 @@ impl NodeMetadataMock { pub fn new() -> Self { NodeMetadataMock { teerex_module: 50u8, - register_ias_enclave: 0u8, - register_dcap_enclave: 6, - unregister_enclave: 1u8, - register_quoting_enclave: 7, - register_tcb_info: 8, - call_worker: 2u8, - processed_parentchain_block: 3u8, - shield_funds: 4u8, - unshield_funds: 5u8, - publish_hash: 9u8, + register_sgx_enclave: 0u8, + unregister_sovereign_enclave: 1u8, + unregister_proxied_enclave: 2u8, + register_quoting_enclave: 3, + register_tcb_info: 4, + enclave_bridge_module: 54u8, + invoke: 0u8, + confirm_processed_parentchain_block: 1u8, + shield_funds: 2u8, + unshield_funds: 3u8, + publish_hash: 4u8, + update_shard_config: 5u8, sidechain_module: 53u8, imported_sidechain_block: 0u8, runtime_spec_version: 25, @@ -72,16 +77,16 @@ impl NodeMetadataMock { } impl TeerexCallIndexes for NodeMetadataMock { - fn register_ias_enclave_call_indexes(&self) -> Result<[u8; 2]> { - Ok([self.teerex_module, self.register_ias_enclave]) + fn register_sgx_enclave_call_indexes(&self) -> Result<[u8; 2]> { + Ok([self.teerex_module, self.register_sgx_enclave]) } - fn register_dcap_enclave_call_indexes(&self) -> Result<[u8; 2]> { - Ok([self.teerex_module, self.register_dcap_enclave]) + fn unregister_sovereign_enclave_call_indexes(&self) -> Result<[u8; 2]> { + Ok([self.teerex_module, self.unregister_sovereign_enclave]) } - fn unregister_enclave_call_indexes(&self) -> Result<[u8; 2]> { - Ok([self.teerex_module, self.unregister_enclave]) + fn unregister_proxied_enclave_call_indexes(&self) -> Result<[u8; 2]> { + Ok([self.teerex_module, self.unregister_proxied_enclave]) } fn register_quoting_enclave_call_indexes(&self) -> Result<[u8; 2]> { @@ -91,25 +96,31 @@ impl TeerexCallIndexes for NodeMetadataMock { fn register_tcb_info_call_indexes(&self) -> Result<[u8; 2]> { Ok([self.teerex_module, self.register_tcb_info]) } +} - fn call_worker_call_indexes(&self) -> Result<[u8; 2]> { - Ok([self.teerex_module, self.call_worker]) +impl EnclaveBridgeCallIndexes for NodeMetadataMock { + fn invoke_call_indexes(&self) -> Result<[u8; 2]> { + Ok([self.enclave_bridge_module, self.invoke]) } fn confirm_processed_parentchain_block_call_indexes(&self) -> Result<[u8; 2]> { - Ok([self.teerex_module, self.processed_parentchain_block]) + Ok([self.enclave_bridge_module, self.confirm_processed_parentchain_block]) } fn shield_funds_call_indexes(&self) -> Result<[u8; 2]> { - Ok([self.teerex_module, self.shield_funds]) + Ok([self.enclave_bridge_module, self.shield_funds]) } fn unshield_funds_call_indexes(&self) -> Result<[u8; 2]> { - Ok([self.teerex_module, self.unshield_funds]) + Ok([self.enclave_bridge_module, self.unshield_funds]) } fn publish_hash_call_indexes(&self) -> Result<[u8; 2]> { - Ok([self.teerex_module, self.unshield_funds]) + Ok([self.enclave_bridge_module, self.publish_hash]) + } + + fn update_shard_config_call_indexes(&self) -> Result<[u8; 2]> { + Ok([self.enclave_bridge_module, self.update_shard_config]) } } diff --git a/core-primitives/node-api/metadata/src/pallet_enclave_bridge.rs b/core-primitives/node-api/metadata/src/pallet_enclave_bridge.rs new file mode 100644 index 0000000000..4813d2ec54 --- /dev/null +++ b/core-primitives/node-api/metadata/src/pallet_enclave_bridge.rs @@ -0,0 +1,75 @@ +/* + 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. + +*/ +use crate::{error::Result, NodeMetadata}; +use sp_core::storage::StorageKey; + +/// Pallet' name: +const ENCLAVE_BRIDGE: &str = "EnclaveBridge"; + +pub trait EnclaveBridgeCallIndexes { + fn invoke_call_indexes(&self) -> Result<[u8; 2]>; + + fn confirm_processed_parentchain_block_call_indexes(&self) -> Result<[u8; 2]>; + + fn shield_funds_call_indexes(&self) -> Result<[u8; 2]>; + + fn unshield_funds_call_indexes(&self) -> Result<[u8; 2]>; + + fn publish_hash_call_indexes(&self) -> Result<[u8; 2]>; + + fn update_shard_config_call_indexes(&self) -> Result<[u8; 2]>; +} + +pub trait EnclaveBridgeStorageKey { + fn shard_status_storage_map_key(&self, index: u64) -> Result; + fn shard_config_registry_storage_map_key(&self, index: u64) -> Result; +} + +impl EnclaveBridgeCallIndexes for NodeMetadata { + fn invoke_call_indexes(&self) -> Result<[u8; 2]> { + self.call_indexes(ENCLAVE_BRIDGE, "invoke") + } + + fn confirm_processed_parentchain_block_call_indexes(&self) -> Result<[u8; 2]> { + self.call_indexes(ENCLAVE_BRIDGE, "confirm_processed_parentchain_block") + } + + fn shield_funds_call_indexes(&self) -> Result<[u8; 2]> { + self.call_indexes(ENCLAVE_BRIDGE, "shield_funds") + } + + fn unshield_funds_call_indexes(&self) -> Result<[u8; 2]> { + self.call_indexes(ENCLAVE_BRIDGE, "unshield_funds") + } + + fn publish_hash_call_indexes(&self) -> Result<[u8; 2]> { + self.call_indexes(ENCLAVE_BRIDGE, "publish_hash") + } + + fn update_shard_config_call_indexes(&self) -> Result<[u8; 2]> { + self.call_indexes(ENCLAVE_BRIDGE, "update_shard_config") + } +} + +impl EnclaveBridgeStorageKey for NodeMetadata { + fn shard_status_storage_map_key(&self, index: u64) -> Result { + self.storage_map_key(ENCLAVE_BRIDGE, "ShardStatus", index) + } + fn shard_config_registry_storage_map_key(&self, index: u64) -> Result { + self.storage_map_key(ENCLAVE_BRIDGE, "ShardConfigRegistry", index) + } +} diff --git a/core-primitives/node-api/metadata/src/pallet_teerex.rs b/core-primitives/node-api/metadata/src/pallet_teerex.rs index c50b991d0a..73f1e2a043 100644 --- a/core-primitives/node-api/metadata/src/pallet_teerex.rs +++ b/core-primitives/node-api/metadata/src/pallet_teerex.rs @@ -21,40 +21,34 @@ use sp_core::storage::StorageKey; const TEEREX: &str = "Teerex"; pub trait TeerexCallIndexes { - fn register_ias_enclave_call_indexes(&self) -> Result<[u8; 2]>; + fn register_sgx_enclave_call_indexes(&self) -> Result<[u8; 2]>; - fn register_dcap_enclave_call_indexes(&self) -> Result<[u8; 2]>; + fn unregister_sovereign_enclave_call_indexes(&self) -> Result<[u8; 2]>; - fn unregister_enclave_call_indexes(&self) -> Result<[u8; 2]>; + fn unregister_proxied_enclave_call_indexes(&self) -> Result<[u8; 2]>; fn register_quoting_enclave_call_indexes(&self) -> Result<[u8; 2]>; fn register_tcb_info_call_indexes(&self) -> Result<[u8; 2]>; - - fn call_worker_call_indexes(&self) -> Result<[u8; 2]>; - - fn confirm_processed_parentchain_block_call_indexes(&self) -> Result<[u8; 2]>; - - fn shield_funds_call_indexes(&self) -> Result<[u8; 2]>; - - fn unshield_funds_call_indexes(&self) -> Result<[u8; 2]>; - - fn publish_hash_call_indexes(&self) -> Result<[u8; 2]>; } pub trait TeerexStorageKey { - fn enclave_count_storage_key(&self) -> Result; + fn sovereign_enclaves_storage_map_key(&self, index: u64) -> Result; - fn enclave_registry_storage_map_key(&self, index: u64) -> Result; + fn proxied_enclaves_storage_map_key(&self, index: u64) -> Result; } impl TeerexCallIndexes for NodeMetadata { - fn register_ias_enclave_call_indexes(&self) -> Result<[u8; 2]> { - self.call_indexes(TEEREX, "register_ias_enclave") + fn register_sgx_enclave_call_indexes(&self) -> Result<[u8; 2]> { + self.call_indexes(TEEREX, "register_sgx_enclave") } - fn register_dcap_enclave_call_indexes(&self) -> Result<[u8; 2]> { - self.call_indexes(TEEREX, "register_dcap_enclave") + fn unregister_sovereign_enclave_call_indexes(&self) -> Result<[u8; 2]> { + self.call_indexes(TEEREX, "unregister_sovereign_enclave") + } + + fn unregister_proxied_enclave_call_indexes(&self) -> Result<[u8; 2]> { + self.call_indexes(TEEREX, "unregister_proxied_enclave") } fn register_quoting_enclave_call_indexes(&self) -> Result<[u8; 2]> { @@ -64,38 +58,13 @@ impl TeerexCallIndexes for NodeMetadata { fn register_tcb_info_call_indexes(&self) -> Result<[u8; 2]> { self.call_indexes(TEEREX, "register_tcb_info") } - - fn unregister_enclave_call_indexes(&self) -> Result<[u8; 2]> { - self.call_indexes(TEEREX, "unregister_enclave") - } - - fn call_worker_call_indexes(&self) -> Result<[u8; 2]> { - self.call_indexes(TEEREX, "call_worker") - } - - fn confirm_processed_parentchain_block_call_indexes(&self) -> Result<[u8; 2]> { - self.call_indexes(TEEREX, "confirm_processed_parentchain_block") - } - - fn shield_funds_call_indexes(&self) -> Result<[u8; 2]> { - self.call_indexes(TEEREX, "shield_funds") - } - - fn unshield_funds_call_indexes(&self) -> Result<[u8; 2]> { - self.call_indexes(TEEREX, "unshield_funds") - } - - fn publish_hash_call_indexes(&self) -> Result<[u8; 2]> { - self.call_indexes(TEEREX, "publish_hash") - } } impl TeerexStorageKey for NodeMetadata { - fn enclave_count_storage_key(&self) -> Result { - self.storage_value_key(TEEREX, "EnclaveCount") + fn sovereign_enclaves_storage_map_key(&self, index: u64) -> Result { + self.storage_map_key(TEEREX, "SovereignEnclaves", index) } - - fn enclave_registry_storage_map_key(&self, index: u64) -> Result { - self.storage_map_key(TEEREX, "EnclaveRegistry", index) + fn proxied_enclaves_storage_map_key(&self, index: u64) -> Result { + self.storage_map_key(TEEREX, "ProxiedEnclaves", index) } } diff --git a/core-primitives/teerex-storage/Cargo.toml b/core-primitives/teerex-storage/Cargo.toml index f2cc061859..15333c49b6 100644 --- a/core-primitives/teerex-storage/Cargo.toml +++ b/core-primitives/teerex-storage/Cargo.toml @@ -9,10 +9,12 @@ sp-std = { default-features = false, git = "https://github.com/paritytech/substr #local deps itp-storage = { path = "../storage", default-features = false } +itp-types = { path = "../types", default-features = false } [features] default = ["std"] std = [ "sp-std/std", "itp-storage/std", + "itp-types/std", ] diff --git a/core-primitives/teerex-storage/src/lib.rs b/core-primitives/teerex-storage/src/lib.rs index 706d92fcb1..61bfe1f37d 100644 --- a/core-primitives/teerex-storage/src/lib.rs +++ b/core-primitives/teerex-storage/src/lib.rs @@ -1,6 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use itp_storage::{storage_map_key, storage_value_key, StorageHasher}; +use itp_storage::{storage_map_key, StorageHasher}; +use itp_types::AccountId; use sp_std::prelude::Vec; pub struct TeeRexStorage; @@ -20,16 +21,16 @@ impl StoragePrefix for TeeRexStorage { } pub trait TeerexStorageKeys { - fn enclave_count() -> Vec; - fn enclave(index: u64) -> Vec; + fn sovereign_enclaves(account: AccountId) -> Vec; } impl TeerexStorageKeys for S { - fn enclave_count() -> Vec { - storage_value_key(Self::prefix(), "EnclaveCount") - } - - fn enclave(index: u64) -> Vec { - storage_map_key(Self::prefix(), "EnclaveRegistry", &index, &StorageHasher::Blake2_128Concat) + fn sovereign_enclaves(account: AccountId) -> Vec { + storage_map_key( + Self::prefix(), + "SovereignEnclaves", + &account, + &StorageHasher::Blake2_128Concat, + ) } } diff --git a/core-primitives/test/Cargo.toml b/core-primitives/test/Cargo.toml index 422b6881ce..366a157577 100644 --- a/core-primitives/test/Cargo.toml +++ b/core-primitives/test/Cargo.toml @@ -20,13 +20,13 @@ sp-std = { default-features = false, git = "https://github.com/paritytech/substr # local deps ita-stf = { path = "../../app-libs/stf", default-features = false } +itp-enclave-bridge-storage = { path = "../enclave-bridge-storage", default-features = false } itp-ocall-api = { path = "../ocall-api", default-features = false } itp-sgx-crypto = { path = "../sgx/crypto", default-features = false } itp-sgx-externalities = { default-features = false, path = "../substrate-sgx/externalities" } itp-stf-interface = { path = "../stf-interface", default-features = false } itp-stf-state-handler = { path = "../stf-state-handler", default-features = false } itp-storage = { path = "../storage", default-features = false } -itp-teerex-storage = { path = "../teerex-storage", default-features = false } itp-time-utils = { path = "../time-utils", default-features = false } itp-types = { path = "../types", default-features = false, features = ["test"] } @@ -40,7 +40,7 @@ std = [ "itp-stf-interface/std", "itp-stf-state-handler/std", "itp-storage/std", - "itp-teerex-storage/std", + "itp-enclave-bridge-storage/std", "itp-time-utils/std", "itp-types/std", "itp-ocall-api/std", diff --git a/core-primitives/test/src/builders/enclave_gen_builder.rs b/core-primitives/test/src/builders/enclave_gen_builder.rs index 1268e5d1b4..85e807c628 100644 --- a/core-primitives/test/src/builders/enclave_gen_builder.rs +++ b/core-primitives/test/src/builders/enclave_gen_builder.rs @@ -17,7 +17,7 @@ */ use itp_time_utils::now_as_millis; -use itp_types::{EnclaveGen, PalletString}; +use itp_types::{Enclave, PalletString}; /// Builder for a generic enclave (`EnclaveGen`) struct. pub struct EnclaveGenBuilder { diff --git a/core-primitives/test/src/lib.rs b/core-primitives/test/src/lib.rs index 7ce2315298..a835b0d3a2 100644 --- a/core-primitives/test/src/lib.rs +++ b/core-primitives/test/src/lib.rs @@ -32,5 +32,4 @@ pub mod sgx_reexport_prelude { pub use jsonrpc_core_sgx as jsonrpc_core; } -pub mod builders; pub mod mock; diff --git a/core-primitives/test/src/mock/onchain_mock.rs b/core-primitives/test/src/mock/onchain_mock.rs index fec1865806..8a96dde164 100644 --- a/core-primitives/test/src/mock/onchain_mock.rs +++ b/core-primitives/test/src/mock/onchain_mock.rs @@ -18,15 +18,15 @@ use codec::{Decode, Encode}; use core::fmt::Debug; +use itp_enclave_bridge_storage::{EnclaveBridgeStorage, EnclaveBridgeStorageKeys}; use itp_ocall_api::{ EnclaveAttestationOCallApi, EnclaveMetricsOCallApi, EnclaveOnChainOCallApi, EnclaveSidechainOCallApi, }; use itp_storage::Error::StorageValueUnavailable; -use itp_teerex_storage::{TeeRexStorage, TeerexStorageKeys}; use itp_types::{ - storage::StorageEntryVerified, BlockHash, Enclave, ShardIdentifier, WorkerRequest, - WorkerResponse, + storage::StorageEntryVerified, AccountId, BlockHash, EnclaveFingerprint, ShardIdentifier, + ShardSignerStatus, WorkerRequest, WorkerResponse, }; use sgx_types::*; use sp_core::H256; @@ -55,11 +55,20 @@ impl OnchainMock { pub fn add_validateer_set>( mut self, header: &Header, - set: Option>, + shard: ShardIdentifier, + set: Option>, ) -> Self { - let set = set.unwrap_or_else(validateer_set); - self.insert_at_header(header, TeeRexStorage::enclave_count(), (set.len() as u64).encode()); - self.with_storage_entries_at_header(header, into_key_value_storage(set)) + let set: Vec = set + .unwrap_or_else(validateer_set) + .iter() + .map(|account| ShardSignerStatus { + signer: account.clone(), + fingerprint: EnclaveFingerprint::default(), + last_activity: 0, + }) + .collect(); + self.insert_at_header(header, EnclaveBridgeStorage::shard_status(shard), set.encode()); + self } pub fn with_mr_enclave(mut self, mr_enclave: [u8; SGX_HASH_SIZE]) -> Self { @@ -208,20 +217,11 @@ impl EnclaveOnChainOCallApi for OnchainMock { } } -pub fn validateer_set() -> Vec { - let default_enclave = Enclave::new( +pub fn validateer_set() -> Vec { + vec![ AccountId32::from([0; 32]), - Default::default(), - Default::default(), - Default::default(), - ); - vec![default_enclave.clone(), default_enclave.clone(), default_enclave.clone(), default_enclave] -} - -fn into_key_value_storage(validateers: Vec) -> Vec<(Vec, Enclave)> { - validateers - .into_iter() - .enumerate() - .map(|(i, e)| (TeeRexStorage::enclave(i as u64 + 1), e)) - .collect() + AccountId32::from([1; 32]), + AccountId32::from([2; 32]), + AccountId32::from([3; 32]), + ] } diff --git a/core-primitives/top-pool-author/src/author.rs b/core-primitives/top-pool-author/src/author.rs index 0a5a12f004..6aec0c4c3e 100644 --- a/core-primitives/top-pool-author/src/author.rs +++ b/core-primitives/top-pool-author/src/author.rs @@ -319,6 +319,10 @@ where self.top_pool.shards() } + fn list_handled_shards(&self) -> Vec { + self.state_facade.list_shards().unwrap_or_default() + } + fn remove_calls_from_pool( &self, shard: ShardIdentifier, diff --git a/core-primitives/top-pool-author/src/mocks.rs b/core-primitives/top-pool-author/src/mocks.rs index 154502245b..693c27f8a4 100644 --- a/core-primitives/top-pool-author/src/mocks.rs +++ b/core-primitives/top-pool-author/src/mocks.rs @@ -168,6 +168,11 @@ impl AuthorApi for AuthorApiMock { self.tops.read().unwrap().keys().cloned().collect() } + fn list_handled_shards(&self) -> Vec { + //dummy + self.tops.read().unwrap().keys().cloned().collect() + } + fn remove_calls_from_pool( &self, shard: ShardIdentifier, diff --git a/core-primitives/top-pool-author/src/traits.rs b/core-primitives/top-pool-author/src/traits.rs index 692431c910..b2e490423f 100644 --- a/core-primitives/top-pool-author/src/traits.rs +++ b/core-primitives/top-pool-author/src/traits.rs @@ -53,8 +53,12 @@ pub trait AuthorApi { account: &AccountId, ) -> Vec; + /// returns all shards which are currently present in the tops in the pool fn get_shards(&self) -> Vec; + /// returns all shards which are handled by our worker + fn list_handled_shards(&self) -> Vec; + /// Remove a collection of trusted operations from the pool. /// Return operations that were not successfully removed. fn remove_calls_from_pool( diff --git a/core-primitives/types/Cargo.toml b/core-primitives/types/Cargo.toml index 701fe14c93..49747cdc99 100644 --- a/core-primitives/types/Cargo.toml +++ b/core-primitives/types/Cargo.toml @@ -3,7 +3,7 @@ name = "itp-types" version = "0.9.0" authors = ["Integritee AG "] homepage = "https://integritee.network/" -repository = "https://github.com/integritee-network/pallets/" +repository = "https://github.com/integritee-network/worker/" license = "Apache-2.0" edition = "2021" @@ -25,7 +25,10 @@ sp-runtime = { default-features = false, git = "https://github.com/paritytech/su sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } # integritee-node +enclave-bridge-primitives = { git = "https://github.com/integritee-network/pallets.git", default-features = false, branch = "polkadot-v0.9.42" } my-node-runtime = { package = "integritee-node-runtime", optional = true, git = "https://github.com/integritee-network/integritee-node.git", branch = "polkadot-v0.9.42" } +teerex-primitives = { git = "https://github.com/integritee-network/pallets.git", default-features = false, branch = "polkadot-v0.9.42" } + [features] default = ["std"] @@ -37,6 +40,8 @@ std = [ "serde_json/std", "primitive-types/std", "itp-sgx-runtime-primitives/std", + "teerex-primitives/std", + "enclave-bridge-primitives/std", # substrate "frame-system/std", "pallet-balances/std", diff --git a/core-primitives/types/src/lib.rs b/core-primitives/types/src/lib.rs index fa1d22f5a7..879d958e84 100644 --- a/core-primitives/types/src/lib.rs +++ b/core-primitives/types/src/lib.rs @@ -44,10 +44,17 @@ pub type IpfsHash = [u8; 46]; pub type MrEnclave = [u8; 32]; pub type ConfirmCallFn = ([u8; 2], ShardIdentifier, H256, Vec); -pub type ShieldFundsFn = ([u8; 2], Vec, Balance, ShardIdentifier); +pub type ShieldFundsFn = ([u8; 2], ShardIdentifier, Vec, Balance); pub type CallWorkerFn = ([u8; 2], Request); -pub type Enclave = EnclaveGen; +use enclave_bridge_primitives::ShardSignerStatus as ShardSignerStatusGen; +pub type ShardSignerStatus = ShardSignerStatusGen; +pub type ShardStatus = Vec; +pub use enclave_bridge_primitives::Request; +pub use teerex_primitives::{ + EnclaveFingerprint, MultiEnclave, SgxBuildMode, SgxEnclave, SgxReportData, SgxStatus, +}; +pub type Enclave = MultiEnclave>; /// Simple blob to hold an encoded call #[derive(Debug, PartialEq, Eq, Clone, Default)] @@ -66,30 +73,6 @@ impl Encode for OpaqueCall { } } -// Note in the pallet teerex this is a struct. But for the codec this does not matter. -#[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)] -pub struct Request { - pub shard: ShardIdentifier, - pub cyphertext: Vec, -} - -// Todo: move this improved enclave definition into a primitives crate in the pallet_teerex repo. -#[derive(Encode, Decode, Clone, PartialEq, sp_core::RuntimeDebug)] -pub struct EnclaveGen { - pub pubkey: AccountId, - // FIXME: this is redundant information - pub mr_enclave: [u8; 32], - pub timestamp: u64, - // unix epoch in milliseconds - pub url: PalletString, // utf8 encoded url -} - -impl EnclaveGen { - pub fn new(pubkey: AccountId, mr_enclave: [u8; 32], timestamp: u64, url: PalletString) -> Self { - Self { pubkey, mr_enclave, timestamp, url } - } -} - #[derive(Debug, Clone, PartialEq, Encode, Decode)] pub enum DirectRequestStatus { /// Direct request was successfully executed diff --git a/core-primitives/utils/Cargo.toml b/core-primitives/utils/Cargo.toml index f2736695af..bc634cfadb 100644 --- a/core-primitives/utils/Cargo.toml +++ b/core-primitives/utils/Cargo.toml @@ -3,7 +3,7 @@ name = "itp-utils" version = "0.9.0" authors = ["Integritee AG "] homepage = "https://integritee.network/" -repository = "https://github.com/integritee-network/pallets/" +repository = "https://github.com/integritee-network/worker/" license = "Apache-2.0" edition = "2021" diff --git a/core/parentchain/indirect-calls-executor/src/executor.rs b/core/parentchain/indirect-calls-executor/src/executor.rs index d426468f00..2730b525fd 100644 --- a/core/parentchain/indirect-calls-executor/src/executor.rs +++ b/core/parentchain/indirect-calls-executor/src/executor.rs @@ -30,7 +30,8 @@ use codec::Encode; use core::marker::PhantomData; use ita_stf::{TrustedCall, TrustedCallSigned}; use itp_node_api::metadata::{ - pallet_teerex::TeerexCallIndexes, provider::AccessNodeMetadata, NodeMetadataTrait, + pallet_enclave_bridge::EnclaveBridgeCallIndexes, provider::AccessNodeMetadata, + NodeMetadataTrait, }; use itp_sgx_crypto::{key_repository::AccessKey, ShieldingCryptoDecrypt, ShieldingCryptoEncrypt}; use itp_stf_executor::traits::StfEnclaveSigning; @@ -127,7 +128,7 @@ impl< let block_number = *block.header().number(); let block_hash = block.hash(); - debug!("Scanning block {:?} for relevant xt", block_number); + trace!("Scanning block {:?} for relevant xt", block_number); let mut executed_calls = Vec::::new(); let events = self @@ -138,7 +139,7 @@ impl< .ok_or_else(|| Error::Other("Could not create events from metadata".into()))?; let xt_statuses = events.get_extrinsic_statuses()?; - debug!("xt_statuses:: {:?}", xt_statuses); + trace!("xt_statuses:: {:?}", xt_statuses); // This would be catastrophic but should never happen if xt_statuses.len() != block.extrinsics().len() { @@ -168,7 +169,7 @@ impl< executed_calls.push(hash_of(&call)); } } - + debug!("successfully processed {} indirect invocations", executed_calls.len()); // Include a processed parentchain block confirmation for each block. self.create_processed_parentchain_block_call::( block_hash, @@ -189,9 +190,14 @@ impl< let call = self.node_meta_data_provider.get_from_metadata(|meta_data| { meta_data.confirm_processed_parentchain_block_call_indexes() })??; - let root: H256 = merkle_root::(extrinsics); - Ok(OpaqueCall::from_tuple(&(call, block_hash, block_number, root))) + + let fallback = ShardIdentifier::default(); + let handled_shards = self.top_pool_author.list_handled_shards(); + trace!("got handled shards: {:?}", handled_shards); + let shard = handled_shards.get(0).unwrap_or(&fallback); + trace!("prepared confirm_processed_parentchain_block() call for block {:?} with index {:?} and merkle root {}", block_number, call, root); + Ok(OpaqueCall::from_tuple(&(call, shard, block_hash, block_number, root))) } } @@ -256,7 +262,7 @@ pub(crate) fn hash_of(xt: &T) -> H256 { mod test { use super::*; use crate::{ - filter_metadata::{ShieldFundsAndCallWorkerFilter, TestEventCreator}, + filter_metadata::{ShieldFundsAndInvokeFilter, TestEventCreator}, parentchain_parser::ParentchainExtrinsicParser, }; use codec::{Decode, Encode}; @@ -290,7 +296,7 @@ mod test { TestStfEnclaveSigner, TestTopPoolAuthor, TestNodeMetadataRepository, - ShieldFundsAndCallWorkerFilter, + ShieldFundsAndInvokeFilter, TestEventCreator, >; @@ -305,8 +311,7 @@ mod test { test_fixtures([0u8; 32], NodeMetadataMock::new()); let opaque_extrinsic = - OpaqueExtrinsic::from_bytes(call_worker_unchecked_extrinsic().encode().as_slice()) - .unwrap(); + OpaqueExtrinsic::from_bytes(invoke_unchecked_extrinsic().encode().as_slice()).unwrap(); let parentchain_block = ParentchainBlockBuilder::default() .with_extrinsics(vec![opaque_extrinsic]) @@ -362,8 +367,14 @@ mod test { let extrinsics = Vec::new(); let confirm_processed_parentchain_block_indexes = dummy_metadata.confirm_processed_parentchain_block_call_indexes().unwrap(); - let expected_call = - (confirm_processed_parentchain_block_indexes, block_hash, 1, H256::default()).encode(); + let expected_call = ( + confirm_processed_parentchain_block_indexes, + ShardIdentifier::default(), + block_hash, + 1, + H256::default(), + ) + .encode(); // when let call = indirect_calls_executor @@ -405,17 +416,17 @@ mod test { let shield_funds_indexes = dummy_metadata.shield_funds_call_indexes().unwrap(); ParentchainUncheckedExtrinsic::::new_signed( - (shield_funds_indexes, target_account, 1000u128, shard_id()), + (shield_funds_indexes, shard_id(), target_account, 1000u128), Address::Address32([1u8; 32]), MultiSignature::Ed25519(default_signature()), default_extrinsic_params().signed_extra(), ) } - fn call_worker_unchecked_extrinsic() -> ParentchainUncheckedExtrinsic { + fn invoke_unchecked_extrinsic() -> ParentchainUncheckedExtrinsic { let request = Request { shard: shard_id(), cyphertext: vec![1u8, 2u8] }; let dummy_metadata = NodeMetadataMock::new(); - let call_worker_indexes = dummy_metadata.call_worker_call_indexes().unwrap(); + let call_worker_indexes = dummy_metadata.invoke_call_indexes().unwrap(); ParentchainUncheckedExtrinsic::::new_signed( (call_worker_indexes, request), diff --git a/core/parentchain/indirect-calls-executor/src/filter_metadata.rs b/core/parentchain/indirect-calls-executor/src/filter_metadata.rs index 23d87bde8f..0a919f5390 100644 --- a/core/parentchain/indirect-calls-executor/src/filter_metadata.rs +++ b/core/parentchain/indirect-calls-executor/src/filter_metadata.rs @@ -18,7 +18,7 @@ use crate::{ error::Result, event_filter::{FilterEvents, MockEvents}, - indirect_calls::{CallWorkerArgs, ShiedFundsArgs}, + indirect_calls::{InvokeArgs, ShieldFundsArgs}, parentchain_parser::ParseExtrinsic, IndirectDispatch, IndirectExecutor, }; @@ -96,12 +96,12 @@ impl FilterIntoDataFrom for DenyAll { } /// Default filter we use for the Integritee-Parachain. -pub struct ShieldFundsAndCallWorkerFilter { +pub struct ShieldFundsAndInvokeFilter { _phantom: PhantomData, } impl FilterIntoDataFrom - for ShieldFundsAndCallWorkerFilter + for ShieldFundsAndInvokeFilter where ExtrinsicParser: ParseExtrinsic, { @@ -123,16 +123,17 @@ where return None }, }; - let index = xt.call_index; let call_args = &mut &xt.call_args[..]; - + log::trace!("attempting to execute indirect call with index {:?}", index); if index == metadata.shield_funds_call_indexes().ok()? { - let args = decode_and_log_error::(call_args)?; + log::trace!("executing shield funds call"); + let args = decode_and_log_error::(call_args)?; Some(IndirectCall::ShieldFunds(args)) - } else if index == metadata.call_worker_call_indexes().ok()? { - let args = decode_and_log_error::(call_args)?; - Some(IndirectCall::CallWorker(args)) + } else if index == metadata.invoke_call_indexes().ok()? { + log::trace!("executing invoke call"); + let args = decode_and_log_error::(call_args)?; + Some(IndirectCall::Invoke(args)) } else { None } @@ -145,15 +146,15 @@ where /// can implemeent their own indirect call there. #[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)] pub enum IndirectCall { - ShieldFunds(ShiedFundsArgs), - CallWorker(CallWorkerArgs), + ShieldFunds(ShieldFundsArgs), + Invoke(InvokeArgs), } impl IndirectDispatch for IndirectCall { fn dispatch(&self, executor: &Executor) -> Result<()> { match self { - IndirectCall::ShieldFunds(shieldfunds) => shieldfunds.dispatch(executor), - IndirectCall::CallWorker(call_worker) => call_worker.dispatch(executor), + IndirectCall::ShieldFunds(shieldfunds_args) => shieldfunds_args.dispatch(executor), + IndirectCall::Invoke(invoke_args) => invoke_args.dispatch(executor), } } } diff --git a/core/parentchain/indirect-calls-executor/src/indirect_calls/call_worker.rs b/core/parentchain/indirect-calls-executor/src/indirect_calls/invoke.rs similarity index 96% rename from core/parentchain/indirect-calls-executor/src/indirect_calls/call_worker.rs rename to core/parentchain/indirect-calls-executor/src/indirect_calls/invoke.rs index 383f8eed4a..076e06e87c 100644 --- a/core/parentchain/indirect-calls-executor/src/indirect_calls/call_worker.rs +++ b/core/parentchain/indirect-calls-executor/src/indirect_calls/invoke.rs @@ -20,11 +20,11 @@ use codec::{Decode, Encode}; use itp_types::Request; #[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)] -pub struct CallWorkerArgs { +pub struct InvokeArgs { request: Request, } -impl IndirectDispatch for CallWorkerArgs { +impl IndirectDispatch for InvokeArgs { fn dispatch(&self, executor: &Executor) -> Result<()> { log::debug!("Found trusted call extrinsic, submitting it to the top pool"); executor.submit_trusted_call(self.request.shard, self.request.cyphertext.clone()); diff --git a/core/parentchain/indirect-calls-executor/src/indirect_calls/mod.rs b/core/parentchain/indirect-calls-executor/src/indirect_calls/mod.rs index 503ed9bbbb..c25aa51717 100644 --- a/core/parentchain/indirect-calls-executor/src/indirect_calls/mod.rs +++ b/core/parentchain/indirect-calls-executor/src/indirect_calls/mod.rs @@ -15,8 +15,8 @@ */ -mod call_worker; +mod invoke; mod shield_funds; -pub use call_worker::CallWorkerArgs; -pub use shield_funds::ShiedFundsArgs; +pub use invoke::InvokeArgs; +pub use shield_funds::ShieldFundsArgs; diff --git a/core/parentchain/indirect-calls-executor/src/indirect_calls/shield_funds.rs b/core/parentchain/indirect-calls-executor/src/indirect_calls/shield_funds.rs index ddf510b696..ed76922705 100644 --- a/core/parentchain/indirect-calls-executor/src/indirect_calls/shield_funds.rs +++ b/core/parentchain/indirect-calls-executor/src/indirect_calls/shield_funds.rs @@ -25,13 +25,13 @@ use std::vec::Vec; /// Arguments of the Integritee-Parachain's shield fund dispatchable. #[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)] -pub struct ShiedFundsArgs { +pub struct ShieldFundsArgs { + shard: ShardIdentifier, account_encrypted: Vec, amount: Balance, - shard: ShardIdentifier, } -impl IndirectDispatch for ShiedFundsArgs { +impl IndirectDispatch for ShieldFundsArgs { fn dispatch(&self, executor: &Executor) -> Result<()> { info!("Found ShieldFunds extrinsic in block: \nAccount Encrypted {:?} \nAmount: {} \nShard: {}", self.account_encrypted, self.amount, bs58::encode(self.shard.encode()).into_string()); diff --git a/core/parentchain/test/Cargo.toml b/core/parentchain/test/Cargo.toml index 54d9b690a0..a54025ea30 100644 --- a/core/parentchain/test/Cargo.toml +++ b/core/parentchain/test/Cargo.toml @@ -3,7 +3,7 @@ name = "itc-parentchain-test" version = "0.9.0" authors = ["Integritee AG "] homepage = "https://integritee.network/" -repository = "https://github.com/integritee-network/pallets/" +repository = "https://github.com/integritee-network/worker/" license = "Apache-2.0" edition = "2021" diff --git a/enclave-runtime/Cargo.lock b/enclave-runtime/Cargo.lock index 0c949dcd05..d4ac83e3c6 100644 --- a/enclave-runtime/Cargo.lock +++ b/enclave-runtime/Cargo.lock @@ -484,6 +484,32 @@ dependencies = [ "generic-array 0.14.7", ] +[[package]] +name = "common-primitives" +version = "0.1.0" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" +dependencies = [ + "derive_more", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "common-primitives" +version = "0.1.0" +source = "git+https://github.com/integritee-network/pallets#5c52182eb3a5156e8d9f69c10ca1441214ee6662" +dependencies = [ + "derive_more", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + [[package]] name = "const-oid" version = "0.9.2" @@ -692,6 +718,22 @@ dependencies = [ "zeroize", ] +[[package]] +name = "enclave-bridge-primitives" +version = "0.1.0" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" +dependencies = [ + "common-primitives 0.1.0 (git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42)", + "log", + "parity-scale-codec", + "scale-info", + "serde 1.0.164", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "enclave-runtime" version = "0.9.0" @@ -770,6 +812,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-std", + "teerex-primitives 0.1.0 (git+https://github.com/integritee-network/pallets)", "webpki", ] @@ -1037,7 +1080,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "bitflags", "environmental 1.1.4", @@ -1067,7 +1110,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "cfg-expr", @@ -1083,7 +1126,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -1095,7 +1138,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote 1.0.28", @@ -1105,7 +1148,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "log", @@ -1911,6 +1954,16 @@ dependencies = [ "thiserror 1.0.9", ] +[[package]] +name = "itp-enclave-bridge-storage" +version = "0.9.0" +dependencies = [ + "itp-storage", + "itp-types", + "parity-scale-codec", + "sp-std", +] + [[package]] name = "itp-enclave-metrics" version = "0.9.0" @@ -2196,6 +2249,7 @@ name = "itp-teerex-storage" version = "0.9.0" dependencies = [ "itp-storage", + "itp-types", "sp-std", ] @@ -2205,13 +2259,13 @@ version = "0.9.0" dependencies = [ "derive_more", "ita-stf", + "itp-enclave-bridge-storage", "itp-ocall-api", "itp-sgx-crypto", "itp-sgx-externalities", "itp-stf-interface", "itp-stf-state-handler", "itp-storage", - "itp-teerex-storage", "itp-time-utils", "itp-types", "jsonrpc-core", @@ -2285,6 +2339,7 @@ name = "itp-types" version = "0.9.0" dependencies = [ "chrono 0.4.26", + "enclave-bridge-primitives", "frame-system", "itp-sgx-runtime-primitives", "pallet-balances", @@ -2295,6 +2350,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-std", + "teerex-primitives 0.1.0 (git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42)", ] [[package]] @@ -2432,6 +2488,7 @@ dependencies = [ name = "its-primitives" version = "0.1.0" dependencies = [ + "itp-types", "parity-scale-codec", "scale-info", "serde 1.0.164", @@ -2498,10 +2555,13 @@ version = "0.9.0" dependencies = [ "derive_more", "frame-support", + "itp-enclave-bridge-storage", "itp-ocall-api", "itp-storage", "itp-teerex-storage", "itp-types", + "its-primitives", + "log", "parity-scale-codec", "sp-core", "sp-runtime", @@ -2952,7 +3012,7 @@ dependencies = [ [[package]] name = "pallet-parentchain" version = "0.9.0" -source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#be26e6b85f14896860ef919488e6bb4cf4b7aa29" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" dependencies = [ "frame-support", "frame-system", @@ -3988,7 +4048,7 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "log", "parity-scale-codec", @@ -4004,7 +4064,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "blake2", @@ -4018,7 +4078,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -4030,7 +4090,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "integer-sqrt", "num-traits 0.2.15", @@ -4098,7 +4158,7 @@ dependencies = [ [[package]] name = "sp-core" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "array-bytes 4.2.0", "bitflags", @@ -4129,7 +4189,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "blake2b_simd 1.0.1", "byteorder 1.4.3", @@ -4143,7 +4203,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote 1.0.28", @@ -4154,7 +4214,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote 1.0.28", @@ -4164,7 +4224,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "environmental 1.1.4", "parity-scale-codec", @@ -4175,7 +4235,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -4208,7 +4268,7 @@ dependencies = [ [[package]] name = "sp-metadata-ir" version = "0.1.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-metadata 15.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec", @@ -4229,7 +4289,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "either", "hash256-std-hasher", @@ -4249,7 +4309,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "bytes 1.4.0", "impl-trait-for-tuples", @@ -4267,7 +4327,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "proc-macro-crate", @@ -4292,7 +4352,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -4304,12 +4364,12 @@ dependencies = [ [[package]] name = "sp-std" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" [[package]] name = "sp-storage" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "ref-cast", @@ -4331,7 +4391,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "sp-std", @@ -4366,7 +4426,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -4379,7 +4439,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -4390,7 +4450,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -4400,7 +4460,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -4469,9 +4529,9 @@ dependencies = [ [[package]] name = "subtle" -version = "2.5.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" @@ -4521,6 +4581,38 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "teerex-primitives" +version = "0.1.0" +source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42#5c52182eb3a5156e8d9f69c10ca1441214ee6662" +dependencies = [ + "common-primitives 0.1.0 (git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.42)", + "derive_more", + "log", + "parity-scale-codec", + "scale-info", + "serde 1.0.164", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "teerex-primitives" +version = "0.1.0" +source = "git+https://github.com/integritee-network/pallets#5c52182eb3a5156e8d9f69c10ca1441214ee6662" +dependencies = [ + "common-primitives 0.1.0 (git+https://github.com/integritee-network/pallets)", + "derive_more", + "log", + "parity-scale-codec", + "scale-info", + "serde 1.0.164", + "sp-core", + "sp-runtime", + "sp-std", +] + [[package]] name = "termcolor" version = "1.0.5" @@ -4685,7 +4777,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "digest 0.10.7", "static_assertions", ] diff --git a/enclave-runtime/Cargo.toml b/enclave-runtime/Cargo.toml index f0d9013793..0447caad54 100644 --- a/enclave-runtime/Cargo.toml +++ b/enclave-runtime/Cargo.toml @@ -89,6 +89,7 @@ base58 = { rev = "sgx_1.1.3", package = "rust-base58", default-features = false, cid = { default-features = false, git = "https://github.com/whalelephant/rust-cid", branch = "nstd" } multibase = { default-features = false, git = "https://github.com/whalelephant/rust-multibase", branch = "nstd" } +teerex-primitives = { git = "https://github.com/integritee-network/pallets", branch = "polkadot-v0.9.42", default-features = false } # local deps ita-oracle = { path = "../app-libs/oracle", default-features = false, optional = true, features = ["sgx"] } diff --git a/enclave-runtime/src/attestation.rs b/enclave-runtime/src/attestation.rs index 4de6316329..7a63b7e0a8 100644 --- a/enclave-runtime/src/attestation.rs +++ b/enclave-runtime/src/attestation.rs @@ -52,6 +52,7 @@ use log::*; use sgx_types::*; use sp_runtime::OpaqueExtrinsic; use std::{prelude::v1::*, slice, vec::Vec}; +use teerex_primitives::SgxAttestationMethod; #[no_mangle] pub unsafe extern "C" fn get_mrenclave(mrenclave: *mut u8, mrenclave_size: usize) -> sgx_status_t { @@ -198,7 +199,11 @@ pub fn generate_dcap_ra_extrinsic_internal( skip_ra, )?; - generate_dcap_ra_extrinsic_from_quote_internal(url, &dcap_quote) + if !skip_ra { + generate_dcap_ra_extrinsic_from_quote_internal(url, &dcap_quote) + } else { + generate_dcap_skip_ra_extrinsic_from_quote_internal(url, &dcap_quote) + } } #[no_mangle] @@ -285,15 +290,42 @@ pub fn generate_dcap_ra_extrinsic_from_quote_internal( info!(" [Enclave] Compose register enclave getting callIDs:"); let call_ids = node_metadata_repo - .get_from_metadata(|m| m.register_dcap_enclave_call_indexes())? + .get_from_metadata(|m| m.register_sgx_enclave_call_indexes())? .map_err(MetadataProviderError::MetadataError)?; info!(" [Enclave] Compose register enclave call DCAP IDs: {:?}", call_ids); - let call = OpaqueCall::from_tuple(&(call_ids, quote, url)); + let call = OpaqueCall::from_tuple(&( + call_ids, + quote, + Some(url), + SgxAttestationMethod::Dcap { proxied: false }, + )); info!(" [Enclave] Compose register enclave got extrinsic, returning"); create_extrinsics(call) } +pub fn generate_dcap_skip_ra_extrinsic_from_quote_internal( + url: String, + quote: &[u8], +) -> EnclaveResult { + let node_metadata_repo = get_node_metadata_repository_from_solo_or_parachain()?; + info!(" [Enclave] Compose register enclave (skip-ra) getting callIDs:"); + + let call_ids = node_metadata_repo + .get_from_metadata(|m| m.register_sgx_enclave_call_indexes())? + .map_err(MetadataProviderError::MetadataError)?; + info!(" [Enclave] Compose register enclave (skip-ra) call DCAP IDs: {:?}", call_ids); + let call = OpaqueCall::from_tuple(&( + call_ids, + quote, + Some(url), + SgxAttestationMethod::Skip { proxied: false }, + )); + + info!(" [Enclave] Compose register enclave (skip-ra) got extrinsic, returning"); + create_extrinsics(call) +} + fn generate_ias_ra_extrinsic_internal( url: String, skip_ra: bool, @@ -301,7 +333,11 @@ fn generate_ias_ra_extrinsic_internal( let attestation_handler = GLOBAL_ATTESTATION_HANDLER_COMPONENT.get()?; let cert_der = attestation_handler.generate_ias_ra_cert(skip_ra)?; - generate_ias_ra_extrinsic_from_der_cert_internal(url, &cert_der) + if !skip_ra { + generate_ias_ra_extrinsic_from_der_cert_internal(url, &cert_der) + } else { + generate_ias_skip_ra_extrinsic_from_der_cert_internal(url, &cert_der) + } } pub fn generate_ias_ra_extrinsic_from_der_cert_internal( @@ -312,10 +348,31 @@ pub fn generate_ias_ra_extrinsic_from_der_cert_internal( info!(" [Enclave] Compose register enclave call"); let call_ids = node_metadata_repo - .get_from_metadata(|m| m.register_ias_enclave_call_indexes())? + .get_from_metadata(|m| m.register_sgx_enclave_call_indexes())? + .map_err(MetadataProviderError::MetadataError)?; + + let call = OpaqueCall::from_tuple(&(call_ids, cert_der, Some(url), SgxAttestationMethod::Ias)); + + create_extrinsics(call) +} + +pub fn generate_ias_skip_ra_extrinsic_from_der_cert_internal( + url: String, + cert_der: &[u8], +) -> EnclaveResult { + let node_metadata_repo = get_node_metadata_repository_from_solo_or_parachain()?; + + info!(" [Enclave] Compose register ias enclave (skip-ra) call"); + let call_ids = node_metadata_repo + .get_from_metadata(|m| m.register_sgx_enclave_call_indexes())? .map_err(MetadataProviderError::MetadataError)?; - let call = OpaqueCall::from_tuple(&(call_ids, cert_der, url)); + let call = OpaqueCall::from_tuple(&( + call_ids, + cert_der, + Some(url), + SgxAttestationMethod::Skip { proxied: false }, + )); create_extrinsics(call) } diff --git a/enclave-runtime/src/initialization/global_components.rs b/enclave-runtime/src/initialization/global_components.rs index 67934d926b..d3fd7789fa 100644 --- a/enclave-runtime/src/initialization/global_components.rs +++ b/enclave-runtime/src/initialization/global_components.rs @@ -41,7 +41,7 @@ use itc_parentchain::{ }, block_importer::ParentchainBlockImporter, indirect_calls_executor::{ - filter_metadata::{EventCreator, ShieldFundsAndCallWorkerFilter}, + filter_metadata::{EventCreator, ShieldFundsAndInvokeFilter}, parentchain_parser::ParentchainExtrinsicParser, IndirectCallsExecutor, }, @@ -140,7 +140,7 @@ pub type EnclaveIndirectCallsExecutor = IndirectCallsExecutor< EnclaveStfEnclaveSigner, EnclaveTopPoolAuthor, EnclaveNodeMetadataRepository, - ShieldFundsAndCallWorkerFilter, + ShieldFundsAndInvokeFilter, EventCreator, >; pub type EnclaveValidatorAccessor = ValidatorAccessor< diff --git a/enclave-runtime/src/test/fixtures/components.rs b/enclave-runtime/src/test/fixtures/components.rs index 10bbabd6ba..d9e617b9f3 100644 --- a/enclave-runtime/src/test/fixtures/components.rs +++ b/enclave-runtime/src/test/fixtures/components.rs @@ -24,7 +24,7 @@ use itp_sgx_crypto::ShieldingCryptoEncrypt; use itp_stf_primitives::types::KeyPair; use itp_top_pool::pool::Options as PoolOptions; use itp_top_pool_author::api::SidechainApi; -use itp_types::{Block as ParentchainBlock, Enclave, ShardIdentifier}; +use itp_types::{Block as ParentchainBlock, ShardIdentifier}; use sp_core::{ed25519, Pair, H256}; use sp_runtime::traits::Header as HeaderTrait; use std::{boxed::Box, sync::Arc, vec::Vec}; @@ -39,13 +39,11 @@ pub(crate) fn create_ocall_api>( header: &Header, signer: &TestSigner, ) -> Arc { - let enclave_validateer = Enclave::new( - signer.public().into(), - Default::default(), - Default::default(), - Default::default(), - ); - Arc::new(TestOCallApi::default().add_validateer_set(header, Some(vec![enclave_validateer]))) + Arc::new(TestOCallApi::default().add_validateer_set( + header, + ShardIdentifier::default(), + Some(vec![signer.public().into()]), + )) } pub(crate) fn encrypt_trusted_operation( diff --git a/enclave-runtime/src/test/top_pool_tests.rs b/enclave-runtime/src/test/top_pool_tests.rs index b4e0ba6447..3a37f23663 100644 --- a/enclave-runtime/src/test/top_pool_tests.rs +++ b/enclave-runtime/src/test/top_pool_tests.rs @@ -34,7 +34,7 @@ use ita_stf::{ TrustedCall, TrustedOperation, }; use itc_parentchain::indirect_calls_executor::{ - filter_metadata::{ShieldFundsAndCallWorkerFilter, TestEventCreator}, + filter_metadata::{ShieldFundsAndInvokeFilter, TestEventCreator}, parentchain_parser::ParentchainExtrinsicParser, ExecuteIndirectCalls, IndirectCallsExecutor, }; @@ -45,7 +45,7 @@ use itp_node_api::{ ParentchainUncheckedExtrinsic, }, metadata::{ - metadata_mocks::NodeMetadataMock, pallet_teerex::TeerexCallIndexes, + metadata_mocks::NodeMetadataMock, pallet_enclave_bridge::EnclaveBridgeCallIndexes, provider::NodeMetadataRepository, }, }; @@ -134,7 +134,7 @@ pub fn submit_shielding_call_to_top_pool() { _, _, _, - ShieldFundsAndCallWorkerFilter, + ShieldFundsAndInvokeFilter, TestEventCreator, >::new( shielding_key_repo, enclave_signer, top_pool_author.clone(), node_meta_data_repository @@ -192,7 +192,7 @@ fn create_shielding_call_extrinsic( let shield_funds_indexes = dummy_node_metadata.shield_funds_call_indexes().unwrap(); let opaque_extrinsic = OpaqueExtrinsic::from_bytes( ParentchainUncheckedExtrinsic::::new_signed( - (shield_funds_indexes, target_account, 1000u128, shard), + (shield_funds_indexes, shard, target_account, 1000u128), Address::Address32([1u8; 32]), MultiSignature::Ed25519(signature), default_extra_for_test.signed_extra(), diff --git a/enclave-runtime/src/top_pool_execution.rs b/enclave-runtime/src/top_pool_execution.rs index cff5971ae7..fbcad96947 100644 --- a/enclave-runtime/src/top_pool_execution.rs +++ b/enclave-runtime/src/top_pool_execution.rs @@ -59,7 +59,7 @@ use its_sidechain::{ }; use log::*; use sgx_types::sgx_status_t; -use sp_core::Pair; +use sp_core::{crypto::UncheckedFrom, Pair}; use sp_runtime::{ generic::SignedBlock as SignedParentchainBlock, traits::Block as BlockTrait, MultiSignature, }; @@ -213,7 +213,7 @@ where HeaderTrait, SignedSidechainBlock::Signature: From, Authority: Pair, - Authority::Public: Encode, + Authority::Public: Encode + UncheckedFrom<[u8; 32]>, OCallApi: ValidateerFetch + EnclaveOnChainOCallApi + Send + 'static, NumberFor: BlockNumberOps, PEnvironment: diff --git a/service/Cargo.toml b/service/Cargo.toml index 6a809ba542..0ecd12edbe 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -63,6 +63,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.42" } sgx-verify = { git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v0.9.42" } # `default-features = false` to remove the jsonrpsee dependency. +enclave-bridge-primitives = { git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v0.9.42" } substrate-api-client = { default-features = false, features = ["std", "ws-client"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.10.0" } teerex-primitives = { git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v0.9.42" } diff --git a/service/src/account_funding.rs b/service/src/account_funding.rs index 15c5038bf0..331a174deb 100644 --- a/service/src/account_funding.rs +++ b/service/src/account_funding.rs @@ -16,7 +16,6 @@ */ use crate::error::{Error, ServiceResult}; -use codec::Encode; use itp_node_api::api_client::{AccountApi, ParentchainApi, ParentchainExtrinsicSigner}; use itp_settings::worker::{ EXISTENTIAL_DEPOSIT_FACTOR_FOR_INIT_FUNDS, REGISTERING_FEE_FACTOR_FOR_INIT_FUNDS, @@ -135,14 +134,12 @@ fn bootstrap_funds_from_alice( funding_amount: u128, ) -> Result<(), Error> { let alice = AccountKeyring::Alice.pair(); - info!("encoding Alice's public = {:?}", alice.public().0.encode()); let alice_acc = AccountId32::from(*alice.public().as_array_ref()); - info!("encoding Alice's AccountId = {:?}", alice_acc.encode()); let alice_free = api.get_free_balance(&alice_acc)?; - info!(" Alice's free balance = {:?}", alice_free); + trace!(" Alice's free balance = {:?}", alice_free); let nonce = api.get_nonce_of(&alice_acc)?; - info!(" Alice's Account Nonce is {}", nonce); + trace!(" Alice's Account Nonce is {}", nonce); if funding_amount > alice_free { println!( @@ -165,7 +162,7 @@ fn bootstrap_funds_from_alice( ); // Verify funds have arrived. let free_balance = alice_signer_api.get_free_balance(accountid); - info!("TEE's NEW free balance = {:?}", free_balance); + trace!("TEE's NEW free balance = {:?}", free_balance); Ok(()) } diff --git a/service/src/main.rs b/service/src/main.rs index bd0ea3b5f0..cab77e7230 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -75,15 +75,16 @@ use substrate_api_client::{ api::XtStatus, rpc::HandleSubscription, GetHeader, SubmitAndWatch, SubscribeChain, SubscribeEvents, }; +use teerex_primitives::AnySigner; #[cfg(feature = "dcap")] use sgx_verify::extract_tcb_info_from_raw_dcap_quote; +use enclave_bridge_primitives::ShardIdentifier; use sp_core::crypto::{AccountId32, Ss58Codec}; use sp_keyring::AccountKeyring; -use sp_runtime::traits::Header as HeaderTrait; +use sp_runtime::MultiSigner; use std::{str, sync::Arc, thread, time::Duration}; -use teerex_primitives::ShardIdentifier; mod account_funding; mod config; @@ -249,7 +250,7 @@ fn main() { enclave.dump_dcap_ra_cert_to_disk().unwrap(); } } else if matches.is_present("mrenclave") { - println!("{}", enclave.get_mrenclave().unwrap().encode().to_base58()); + println!("{}", enclave.get_fingerprint().unwrap().encode().to_base58()); } else if let Some(sub_matches) = matches.subcommand_matches("init-shard") { setup::init_shard( enclave.as_ref(), @@ -325,8 +326,8 @@ fn start_worker( } // ------------------------------------------------------------------------ // initialize the enclave - let mrenclave = enclave.get_mrenclave().unwrap(); - println!("MRENCLAVE={}", mrenclave.to_base58()); + let mrenclave = enclave.get_fingerprint().unwrap(); + println!("MRENCLAVE={}", mrenclave.0.to_base58()); println!("MRENCLAVE in hex {:?}", hex::encode(mrenclave)); // ------------------------------------------------------------------------ @@ -482,9 +483,10 @@ fn start_worker( #[cfg(feature = "dcap")] let register_xt = move || enclave2.generate_dcap_ra_extrinsic(&trusted_url, skip_ra).unwrap(); + let tee_accountid_clone = tee_accountid.clone(); let send_register_xt = move || { println!("[+] Send register enclave extrinsic"); - send_extrinsic(register_xt(), &node_api2, &tee_accountid.clone(), is_development_mode) + send_extrinsic(register_xt(), &node_api2, &tee_accountid_clone, is_development_mode) }; let register_enclave_block_hash = send_register_xt().unwrap(); @@ -493,12 +495,12 @@ fn start_worker( node_api.get_header(Some(register_enclave_block_hash)).unwrap().unwrap(); let we_are_primary_validateer = - we_are_primary_validateer(&node_api, ®ister_enclave_xt_header).unwrap(); + we_are_primary_worker(&node_api, shard, &tee_accountid).unwrap(); if we_are_primary_validateer { - println!("[+] We are the primary validateer"); + println!("[+] We are the primary worker"); } else { - println!("[+] We are NOT the primary validateer"); + println!("[+] We are NOT the primary worker"); } initialization_handler.registered_on_parentchain(); @@ -590,10 +592,15 @@ fn spawn_worker_for_shard_polling( loop { info!("Polling for worker for shard ({} seconds interval)", POLL_INTERVAL_SECS); - if let Ok(Some(enclave)) = node_api.worker_for_shard(&shard_for_initialized, None) { + if let Ok(Some(enclave)) = + node_api.primary_worker_for_shard(&shard_for_initialized, None) + { // Set that the service is initialized. initialization_handler.worker_for_shard_registered(); - println!("[+] Found `WorkerForShard` on parentchain state: {:?}", enclave.pubkey); + println!( + "[+] Found `WorkerForShard` on parentchain state: {:?}", + enclave.instance_signer() + ); break } thread::sleep(Duration::from_secs(POLL_INTERVAL_SECS)); @@ -626,43 +633,68 @@ fn print_events(events: Vec) { RuntimeEvent::Teerex(re) => { debug!("{:?}", re); match &re { - my_node_runtime::pallet_teerex::Event::AddedEnclave { + my_node_runtime::pallet_teerex::Event::AddedSgxEnclave { registered_by, worker_url, .. } => { println!("[+] Received AddedEnclave event"); println!(" Sender (Worker): {:?}", registered_by); - println!(" Registered URL: {:?}", str::from_utf8(worker_url).unwrap()); + println!( + " Registered URL: {:?}", + str::from_utf8(&worker_url.clone().unwrap_or("none".into())).unwrap() + ); + }, + _ => { + trace!("Ignoring unsupported pallet_teerex event"); }, - my_node_runtime::pallet_teerex::Event::Forwarded(shard) => { + } + }, + RuntimeEvent::EnclaveBridge(re) => { + debug!("{:?}", re); + match &re { + my_node_runtime::pallet_enclave_bridge::Event::IndirectInvocationRegistered( + shard, + ) => { println!( "[+] Received trusted call for shard {}", shard.encode().to_base58() ); }, - my_node_runtime::pallet_teerex::Event::ProcessedParentchainBlock( - sender, + my_node_runtime::pallet_enclave_bridge::Event::ProcessedParentchainBlock { + shard, block_hash, - merkle_root, + trusted_calls_merkle_root, block_number, - ) => { + } => { info!("[+] Received ProcessedParentchainBlock event"); - debug!(" From: {:?}", sender); + debug!(" for shard: {:?}", shard); debug!(" Block Hash: {:?}", hex::encode(block_hash)); - debug!(" Merkle Root: {:?}", hex::encode(merkle_root)); + debug!(" Merkle Root: {:?}", hex::encode(trusted_calls_merkle_root)); debug!(" Block Number: {:?}", block_number); }, - my_node_runtime::pallet_teerex::Event::ShieldFunds(incognito_account) => { + my_node_runtime::pallet_enclave_bridge::Event::ShieldFunds { + shard, + encrypted_beneficiary, + amount, + } => { info!("[+] Received ShieldFunds event"); - debug!(" For: {:?}", incognito_account); + debug!(" for shard: {:?}", shard); + debug!(" for enc. beneficiary: {:?}", encrypted_beneficiary); + debug!(" Amount: {:?}", amount); }, - my_node_runtime::pallet_teerex::Event::UnshieldedFunds(incognito_account) => { + my_node_runtime::pallet_enclave_bridge::Event::UnshieldedFunds { + shard, + beneficiary, + amount, + } => { info!("[+] Received UnshieldedFunds event"); - debug!(" For: {:?}", incognito_account); + debug!(" for shard: {:?}", shard); + debug!(" beneficiary: {:?}", beneficiary); + debug!(" Amount: {:?}", amount); }, _ => { - trace!("Ignoring unsupported pallet_teerex event"); + trace!("Ignoring unsupported pallet_enclave_bridge event"); }, } }, @@ -670,39 +702,39 @@ fn print_events(events: Vec) { RuntimeEvent::Teeracle(re) => { debug!("{:?}", re); match &re { - my_node_runtime::pallet_teeracle::Event::ExchangeRateUpdated( - source, - currency, - new_value, - ) => { + my_node_runtime::pallet_teeracle::Event::ExchangeRateUpdated { + data_source, + trading_pair, + exchange_rate, + } => { println!("[+] Received ExchangeRateUpdated event"); - println!(" Data source: {}", source); - println!(" Currency: {}", currency); - println!(" Exchange rate: {:?}", new_value); + println!(" Data source: {}", data_source); + println!(" trading pair: {}", trading_pair); + println!(" Exchange rate: {:?}", exchange_rate); }, - my_node_runtime::pallet_teeracle::Event::ExchangeRateDeleted( - source, - currency, - ) => { + my_node_runtime::pallet_teeracle::Event::ExchangeRateDeleted { + data_source, + trading_pair, + } => { println!("[+] Received ExchangeRateDeleted event"); - println!(" Data source: {}", source); - println!(" Currency: {}", currency); + println!(" Data source: {}", data_source); + println!(" trading pair: {}", trading_pair); }, - my_node_runtime::pallet_teeracle::Event::AddedToWhitelist( - source, - mrenclave, - ) => { + my_node_runtime::pallet_teeracle::Event::AddedToWhitelist { + data_source, + enclave_fingerprint, + } => { println!("[+] Received AddedToWhitelist event"); - println!(" Data source: {}", source); - println!(" Currency: {:?}", mrenclave); + println!(" Data source: {}", data_source); + println!(" fingerprint: {:?}", enclave_fingerprint); }, - my_node_runtime::pallet_teeracle::Event::RemovedFromWhitelist( - source, - mrenclave, - ) => { + my_node_runtime::pallet_teeracle::Event::RemovedFromWhitelist { + data_source, + enclave_fingerprint, + } => { println!("[+] Received RemovedFromWhitelist event"); - println!(" Data source: {}", source); - println!(" Currency: {:?}", mrenclave); + println!(" Data source: {}", data_source); + println!(" fingerprint: {:?}", enclave_fingerprint); }, _ => { trace!("Ignoring unsupported pallet_teeracle event"); @@ -711,13 +743,15 @@ fn print_events(events: Vec) { }, #[cfg(feature = "sidechain")] RuntimeEvent::Sidechain(re) => match &re { - my_node_runtime::pallet_sidechain::Event::ProposedSidechainBlock( - sender, - payload, - ) => { - info!("[+] Received ProposedSidechainBlock event"); - debug!(" From: {:?}", sender); - debug!(" Payload: {:?}", hex::encode(payload)); + my_node_runtime::pallet_sidechain::Event::FinalizedSidechainBlock { + shard, + block_header_hash, + validateer, + } => { + info!("[+] Received FinalizedSidechainBlock event"); + debug!(" for shard: {:?}", shard); + debug!(" From: {:?}", hex::encode(block_header_hash)); + debug!(" validateer: {:?}", validateer); }, _ => { trace!("Ignoring unsupported pallet_sidechain event"); @@ -881,16 +915,35 @@ fn enclave_account(enclave_api: &E) -> AccountId32 { } /// Checks if we are the first validateer to register on the parentchain. -fn we_are_primary_validateer( +fn we_are_primary_worker( node_api: &ParentchainApi, - register_enclave_xt_header: &Header, + shard: &ShardIdentifier, + enclave_account: &AccountId32, ) -> Result { - let enclave_count_of_previous_block = - node_api.enclave_count(Some(*register_enclave_xt_header.parent_hash()))?; - trace!( - "enclave count is {} for previous block 0x{:?}", - enclave_count_of_previous_block, - register_enclave_xt_header.parent_hash() - ); - Ok(enclave_count_of_previous_block == 0) + // are we registered? else fail. + node_api + .enclave(enclave_account, None)? + .expect("our enclave should be registered at this point"); + trace!("our enclave is registered"); + match node_api.primary_worker_for_shard(shard, None).unwrap() { + Some(enclave) => + match enclave.instance_signer() { + AnySigner::Known(MultiSigner::Ed25519(primary)) => + if primary.encode() == enclave_account.encode() { + debug!("We are primary worker on this shard adn we have been previously running."); + Ok(true) + } else { + debug!("The primary worker is {}", primary.to_ss58check()); + Ok(false) + }, + _ => { + warn!("the primary worker is of unknown type"); + Ok(false) + }, + }, + None => { + debug!("We are the primary worker on this shard and the shard is untouched"); + Ok(true) + }, + } } diff --git a/service/src/ocall_bridge/worker_on_chain_ocall.rs b/service/src/ocall_bridge/worker_on_chain_ocall.rs index c5b780010f..1dfea987cf 100644 --- a/service/src/ocall_bridge/worker_on_chain_ocall.rs +++ b/service/src/ocall_bridge/worker_on_chain_ocall.rs @@ -88,7 +88,7 @@ where let api = self.node_api_factory.create_api()?; for call in extrinsics.into_iter() { if let Err(e) = api.submit_opaque_extrinsic(call.encode().into()) { - error!("Could not send extrsinic to node: {:?}", e); + error!("Could not send extrsinic to node: {:?}, error: {:?}", call, e); } } } diff --git a/service/src/setup.rs b/service/src/setup.rs index 9cd6418122..6535091f26 100644 --- a/service/src/setup.rs +++ b/service/src/setup.rs @@ -17,6 +17,7 @@ */ use crate::error::{Error, ServiceResult}; +use base58::ToBase58; use codec::Encode; use itp_enclave_api::{enclave_base::EnclaveBase, Enclave}; use itp_settings::files::{ @@ -54,10 +55,10 @@ pub(crate) fn initialize_shard_and_keys( pub(crate) fn init_shard(enclave: &Enclave, shard_identifier: &ShardIdentifier) { match enclave.init_shard(shard_identifier.encode()) { Err(e) => { - println!("Failed to initialize shard {:?}: {:?}", shard_identifier, e); + println!("Failed to initialize shard {:?}: {:?}", shard_identifier.0.to_base58(), e); }, Ok(_) => { - println!("Successfully initialized shard {:?}", shard_identifier); + println!("Successfully initialized shard {:?}", shard_identifier.0.to_base58()); }, } } diff --git a/service/src/sync_state.rs b/service/src/sync_state.rs index 12ff9bec2a..6c70a5379e 100644 --- a/service/src/sync_state.rs +++ b/service/src/sync_state.rs @@ -75,9 +75,10 @@ async fn get_author_url_of_last_finalized_sidechain_block Result { let enclave = node_api - .worker_for_shard(shard, None)? + .primary_worker_for_shard(shard, None)? .ok_or_else(|| Error::NoWorkerForShardFound(*shard))?; - let worker_api_direct = DirectWorkerApi::new(enclave.url); + let worker_api_direct = + DirectWorkerApi::new(String::from_utf8(enclave.instance_url().unwrap()).unwrap()); Ok(worker_api_direct.get_mu_ra_url()?) } @@ -88,12 +89,13 @@ async fn get_enclave_url_of_first_registered Result { - let self_mr_enclave = enclave_api.get_mrenclave()?; + let self_mr_enclave = enclave_api.get_fingerprint()?; let first_enclave = node_api .all_enclaves(None)? .into_iter() - .find(|e| e.mr_enclave == self_mr_enclave) + .find(|e| e.fingerprint() == self_mr_enclave) .ok_or(Error::NoPeerWorkerFound)?; - let worker_api_direct = DirectWorkerApi::new(first_enclave.url); + let worker_api_direct = + DirectWorkerApi::new(String::from_utf8(first_enclave.instance_url().unwrap()).unwrap()); Ok(worker_api_direct.get_mu_ra_url()?) } diff --git a/service/src/tests/mock.rs b/service/src/tests/mock.rs index 664005eaa1..f6581090c6 100644 --- a/service/src/tests/mock.rs +++ b/service/src/tests/mock.rs @@ -15,38 +15,66 @@ */ +use codec::Encode; use itp_node_api::api_client::{ApiResult, PalletTeerexApi}; -use itp_types::{Enclave, ShardIdentifier, H256 as Hash}; +use itp_types::{ + AccountId, MultiEnclave, SgxBuildMode, SgxEnclave, SgxReportData, SgxStatus, ShardIdentifier, + H256 as Hash, +}; pub struct TestNodeApi; pub const W1_URL: &str = "127.0.0.1:22222"; pub const W2_URL: &str = "127.0.0.1:33333"; -pub fn enclaves() -> Vec { +pub fn enclaves() -> Vec>> { vec![ - Enclave::new([0; 32].into(), [1; 32], 1, format!("wss://{}", W1_URL)), - Enclave::new([2; 32].into(), [3; 32], 2, format!("wss://{}", W2_URL)), + MultiEnclave::from( + SgxEnclave::new( + SgxReportData::default(), + [1; 32], + [1; 32], + 1, + SgxBuildMode::Production, + SgxStatus::Ok, + ) + .with_url(format!("wss://{}", W1_URL).encode()), + ), + MultiEnclave::from( + SgxEnclave::new( + SgxReportData::default(), + [2; 32], + [2; 32], + 2, + SgxBuildMode::Production, + SgxStatus::Ok, + ) + .with_url(format!("wss://{}", W2_URL).encode()), + ), ] } impl PalletTeerexApi for TestNodeApi { - fn enclave(&self, index: u64, _at_block: Option) -> ApiResult> { - Ok(Some(enclaves().remove(index as usize))) + fn enclave( + &self, + _account: &AccountId, + _at_block: Option, + ) -> ApiResult>>> { + Ok(Some(enclaves().remove(0))) } fn enclave_count(&self, _at_block: Option) -> ApiResult { unreachable!() } - fn all_enclaves(&self, _at_block: Option) -> ApiResult> { + fn all_enclaves(&self, _at_block: Option) -> ApiResult>>> { Ok(enclaves()) } - fn worker_for_shard( + fn primary_worker_for_shard( &self, _: &ShardIdentifier, _at_block: Option, - ) -> ApiResult> { + ) -> ApiResult>>> { unreachable!() } fn latest_ipfs_hash( diff --git a/service/src/tests/mocks/enclave_api_mock.rs b/service/src/tests/mocks/enclave_api_mock.rs index f32176332c..21a64323be 100644 --- a/service/src/tests/mocks/enclave_api_mock.rs +++ b/service/src/tests/mocks/enclave_api_mock.rs @@ -17,6 +17,7 @@ use codec::{Decode, Encode}; use core::fmt::Debug; +use enclave_bridge_primitives::EnclaveFingerprint; use frame_support::sp_runtime::traits::Block as ParentchainBlockTrait; use itc_parentchain::primitives::{ ParentchainInitParams, @@ -80,8 +81,8 @@ impl EnclaveBase for EnclaveMock { unreachable!() } - fn get_mrenclave(&self) -> EnclaveResult<[u8; MR_ENCLAVE_SIZE]> { - Ok([1u8; MR_ENCLAVE_SIZE]) + fn get_fingerprint(&self) -> EnclaveResult { + Ok([1u8; MR_ENCLAVE_SIZE].into()) } } diff --git a/service/src/utils.rs b/service/src/utils.rs index c936665350..fd0b60fe82 100644 --- a/service/src/utils.rs +++ b/service/src/utils.rs @@ -33,8 +33,8 @@ pub fn extract_shard( shard.into() }, _ => { - let mrenclave = enclave_api.get_mrenclave().unwrap(); - info!("no shard specified. using mrenclave as id: {}", mrenclave.to_base58()); + let mrenclave = enclave_api.get_fingerprint().unwrap(); + info!("no shard specified. using mrenclave as id: {}", mrenclave.0.to_base58()); ShardIdentifier::from_slice(&mrenclave[..]) }, } diff --git a/service/src/worker.rs b/service/src/worker.rs index 18e67d82eb..a052245a14 100644 --- a/service/src/worker.rs +++ b/service/src/worker.rs @@ -149,8 +149,8 @@ where let mut peer_urls = Vec::::new(); for enclave in enclaves { // FIXME: This is temporary only, as block broadcasting should be moved to trusted ws server. - let enclave_url = enclave.url.clone(); - let worker_api_direct = DirectWorkerApi::new(enclave.url); + let enclave_url = String::from_utf8(enclave.instance_url().unwrap()).unwrap(); + let worker_api_direct = DirectWorkerApi::new(enclave_url.clone()); match worker_api_direct.get_untrusted_worker_url() { Ok(untrusted_worker_url) => { peer_urls.push(untrusted_worker_url); diff --git a/sidechain/block-verification/Cargo.toml b/sidechain/block-verification/Cargo.toml index 20728928d7..376d1267fd 100644 --- a/sidechain/block-verification/Cargo.toml +++ b/sidechain/block-verification/Cargo.toml @@ -4,7 +4,7 @@ description = "Verification logic for sidechain blocks" version = "0.9.0" authors = ["Integritee AG "] homepage = "https://integritee.network/" -repository = "https://github.com/integritee-network/pallets/" +repository = "https://github.com/integritee-network/worker/" license = "Apache-2.0" edition = "2021" diff --git a/sidechain/consensus/aura/src/block_importer.rs b/sidechain/consensus/aura/src/block_importer.rs index 15d7217fb5..d336ba98f7 100644 --- a/sidechain/consensus/aura/src/block_importer.rs +++ b/sidechain/consensus/aura/src/block_importer.rs @@ -37,7 +37,7 @@ use its_primitives::traits::{ }; use its_validateer_fetch::ValidateerFetch; use log::*; -use sp_core::Pair; +use sp_core::{crypto::UncheckedFrom, Pair}; use sp_runtime::{ generic::SignedBlock as SignedParentchainBlock, traits::{Block as ParentchainBlockTrait, Header}, @@ -85,7 +85,7 @@ impl< ParentchainBlockImporter, > where Authority: Pair, - Authority::Public: std::fmt::Debug, + Authority::Public: std::fmt::Debug + UncheckedFrom<[u8; 32]>, ParentchainBlock: ParentchainBlockTrait, SignedSidechainBlock: SignedBlockTrait + 'static, <::Block as SidechainBlockTrait>::HeaderType: @@ -170,7 +170,7 @@ impl< ParentchainBlockImporter, > where Authority: Pair, - Authority::Public: std::fmt::Debug, + Authority::Public: std::fmt::Debug + UncheckedFrom<[u8; 32]>, ParentchainBlock: ParentchainBlockTrait, SignedSidechainBlock: SignedBlockTrait + 'static, <::Block as SidechainBlockTrait>::HeaderType: diff --git a/sidechain/consensus/aura/src/lib.rs b/sidechain/consensus/aura/src/lib.rs index adfe9f22e0..0c52803086 100644 --- a/sidechain/consensus/aura/src/lib.rs +++ b/sidechain/consensus/aura/src/lib.rs @@ -41,7 +41,7 @@ use its_primitives::{ types::block::BlockHash, }; use its_validateer_fetch::ValidateerFetch; -use sp_core::ByteArray; +use sp_core::crypto::UncheckedFrom; use sp_runtime::{ app_crypto::{sp_core::H256, Pair}, generic::SignedBlock as SignedParentchainBlock, @@ -124,6 +124,7 @@ impl where AuthorityPair: Pair, + AuthorityPair::Public: UncheckedFrom<[u8; 32]>, // todo: Relax hash trait bound, but this needs a change to some other parts in the code. ParentchainBlock: ParentchainBlockTrait, E: Environment, @@ -145,9 +146,14 @@ where fn epoch_data( &self, header: &ParentchainBlock::Header, + shard: ShardIdentifierFor, _slot: Slot, ) -> Result { - authorities::<_, AuthorityPair, ParentchainBlock::Header>(&self.ocall_api, header) + authorities::<_, AuthorityPair, SignedSidechainBlock, ParentchainBlock::Header>( + &self.ocall_api, + header, + shard, + ) } fn authorities_len(&self, epoch_data: &Self::EpochData) -> Option { @@ -235,20 +241,23 @@ fn proposing_remaining_duration( std::cmp::min(slot_remaining, proposing_duration) } -fn authorities( +fn authorities( ocall_api: &ValidateerFetcher, header: &ParentchainHeader, + shard: ShardIdentifierFor, ) -> Result>, ConsensusError> where ValidateerFetcher: ValidateerFetch + EnclaveOnChainOCallApi, P: Pair, + P::Public: UncheckedFrom<[u8; 32]>, ParentchainHeader: ParentchainHeaderTrait, + SignedSidechainBlock: its_primitives::traits::SignedBlock, { Ok(ocall_api - .current_validateers(header) + .current_validateers::(header, shard) .map_err(|e| ConsensusError::CouldNotGetAuthorities(e.to_string()))? - .into_iter() - .filter_map(|e| AuthorityId::

::from_slice(e.pubkey.as_ref()).ok()) + .iter() + .map(|account| P::Public::unchecked_from(*account.as_ref())) .collect()) } @@ -256,14 +265,14 @@ where mod tests { use super::*; use crate::test::{ - fixtures::{types::TestAura, validateer, SLOT_DURATION}, + fixtures::{types::TestAura, SLOT_DURATION}, mocks::environment_mock::EnvironmentMock, }; use itc_parentchain_block_import_dispatcher::trigger_parentchain_block_import_mock::TriggerParentchainBlockImportMock; use itc_parentchain_test::{ParentchainBlockBuilder, ParentchainHeaderBuilder}; use itp_test::mock::onchain_mock::OnchainMock; use itp_types::{ - Block as ParentchainBlock, Enclave, Header as ParentchainHeader, + AccountId, Block as ParentchainBlock, Header as ParentchainHeader, ShardIdentifier, SignedBlock as SignedParentchainBlock, }; use its_consensus_slots::PerShardSlotWorkerScheduler; @@ -300,8 +309,8 @@ mod tests { vec![Keyring::Alice.public(), Keyring::Bob.public(), Keyring::Charlie.public()] } - fn create_validateer_set_from_publics(authorities: Vec) -> Vec { - authorities.iter().map(|a| validateer(a.clone().into())).collect() + fn create_validateer_set_from_publics(authorities: Vec) -> Vec { + authorities.iter().map(|a| AccountId::from(a.clone())).collect() } fn onchain_mock( @@ -309,7 +318,8 @@ mod tests { authorities: Vec, ) -> OnchainMock { let validateers = create_validateer_set_from_publics(authorities); - OnchainMock::default().add_validateer_set(parentchain_header, Some(validateers)) + let shard = ShardIdentifier::default(); + OnchainMock::default().add_validateer_set(parentchain_header, shard, Some(validateers)) } fn onchain_mock_with_default_authorities_and_header() -> OnchainMock { @@ -478,9 +488,14 @@ mod tests { Keyring::Bob.public(), Keyring::Charlie.public(), ]); + let shard = ShardIdentifier::default(); let onchain_mock = OnchainMock::default() - .add_validateer_set(&already_imported_parentchain_header, Some(validateer_set_one)) - .add_validateer_set(&latest_parentchain_header, Some(validateer_set_two)); + .add_validateer_set( + &already_imported_parentchain_header, + shard, + Some(validateer_set_one), + ) + .add_validateer_set(&latest_parentchain_header, shard, Some(validateer_set_two)); let mut aura = get_aura(onchain_mock, parentchain_block_import_trigger.clone()); @@ -513,9 +528,14 @@ mod tests { Keyring::Bob.public(), Keyring::Charlie.public(), ]); + let shard = ShardIdentifier::default(); let onchain_mock = OnchainMock::default() - .add_validateer_set(&already_imported_parentchain_header, Some(validateer_set_one)) - .add_validateer_set(&latest_parentchain_header, Some(validateer_set_two)); + .add_validateer_set( + &already_imported_parentchain_header, + shard, + Some(validateer_set_one), + ) + .add_validateer_set(&latest_parentchain_header, shard, Some(validateer_set_two)); let mut aura = get_aura(onchain_mock, parentchain_block_import_trigger.clone()); diff --git a/sidechain/consensus/aura/src/test/block_importer_tests.rs b/sidechain/consensus/aura/src/test/block_importer_tests.rs index 9ec2e05bd9..db11810a1d 100644 --- a/sidechain/consensus/aura/src/test/block_importer_tests.rs +++ b/sidechain/consensus/aura/src/test/block_importer_tests.rs @@ -15,7 +15,7 @@ */ -use crate::{block_importer::BlockImporter, test::fixtures::validateer, ShardIdentifierFor}; +use crate::{block_importer::BlockImporter, ShardIdentifierFor}; use codec::Encode; use core::assert_matches::assert_matches; use itc_parentchain_block_import_dispatcher::trigger_parentchain_block_import_mock::TriggerParentchainBlockImportMock; @@ -78,7 +78,8 @@ fn test_fixtures( let top_pool_author = Arc::new(TestTopPoolAuthor::default()); let ocall_api = Arc::new(OnchainMock::default().add_validateer_set( parentchain_header, - Some(vec![validateer(Keyring::Alice.public().into())]), + shard(), + Some(vec![Keyring::Alice.public().into()]), )); let state_key_repository = Arc::new(TestStateKeyRepo::new(state_key())); diff --git a/sidechain/consensus/aura/src/test/fixtures/mod.rs b/sidechain/consensus/aura/src/test/fixtures/mod.rs index 54d47324fa..8a2b0463be 100644 --- a/sidechain/consensus/aura/src/test/fixtures/mod.rs +++ b/sidechain/consensus/aura/src/test/fixtures/mod.rs @@ -17,11 +17,6 @@ pub mod types; -use itp_types::{AccountId, Enclave}; use std::time::Duration; pub const SLOT_DURATION: Duration = Duration::from_millis(300); - -pub fn validateer(account: AccountId) -> Enclave { - Enclave::new(account, Default::default(), Default::default(), Default::default()) -} diff --git a/sidechain/consensus/aura/src/verifier.rs b/sidechain/consensus/aura/src/verifier.rs index 15526f0a74..205549bb17 100644 --- a/sidechain/consensus/aura/src/verifier.rs +++ b/sidechain/consensus/aura/src/verifier.rs @@ -15,7 +15,7 @@ */ -use crate::{authorities, EnclaveOnChainOCallApi}; +use crate::{authorities, EnclaveOnChainOCallApi, ShardIdentifierFor}; use core::marker::PhantomData; use its_block_verification::verify_sidechain_block; use its_consensus_common::{Error as ConsensusError, Verifier}; @@ -24,6 +24,7 @@ use its_primitives::{ types::block::BlockHash, }; use its_validateer_fetch::ValidateerFetch; +use sp_core::crypto::UncheckedFrom; use sp_runtime::{app_crypto::Pair, traits::Block as ParentchainBlockTrait}; use std::{fmt::Debug, time::Duration}; @@ -57,7 +58,7 @@ impl for AuraVerifier where AuthorityPair: Pair, - AuthorityPair::Public: Debug, + AuthorityPair::Public: Debug + UncheckedFrom<[u8; 32]>, // todo: Relax hash trait bound, but this needs a change to some other parts in the code. ParentchainBlock: ParentchainBlockTrait, SignedSidechainBlock: SignedSidechainBlockTrait + 'static, @@ -72,10 +73,15 @@ where &self, signed_block: SignedSidechainBlock, parentchain_header: &ParentchainBlock::Header, + shard: ShardIdentifierFor, ctx: &Self::Context, ) -> Result { - let authorities = - authorities::<_, AuthorityPair, ParentchainBlock::Header>(ctx, parentchain_header)?; + let authorities = authorities::< + _, + AuthorityPair, + SignedSidechainBlock, + ParentchainBlock::Header, + >(ctx, parentchain_header, shard)?; Ok(verify_sidechain_block::( signed_block, diff --git a/sidechain/consensus/common/src/block_import.rs b/sidechain/consensus/common/src/block_import.rs index 24a3a745c3..567728bce2 100644 --- a/sidechain/consensus/common/src/block_import.rs +++ b/sidechain/consensus/common/src/block_import.rs @@ -136,6 +136,7 @@ where verifier.verify( signed_sidechain_block.clone(), &peeked_parentchain_header, + shard, self.get_context(), ) })?; diff --git a/sidechain/consensus/common/src/lib.rs b/sidechain/consensus/common/src/lib.rs index c6a708c9e1..fa2104186f 100644 --- a/sidechain/consensus/common/src/lib.rs +++ b/sidechain/consensus/common/src/lib.rs @@ -68,6 +68,7 @@ where &self, block: SignedSidechainBlock, parentchain_header: &ParentchainBlock::Header, + shard: ShardIdentifierFor, ctx: &Self::Context, ) -> Result; } diff --git a/sidechain/consensus/common/src/test/mocks/verifier_mock.rs b/sidechain/consensus/common/src/test/mocks/verifier_mock.rs index 6e104574ea..e6d8cbeb0e 100644 --- a/sidechain/consensus/common/src/test/mocks/verifier_mock.rs +++ b/sidechain/consensus/common/src/test/mocks/verifier_mock.rs @@ -15,7 +15,7 @@ */ -use crate::{Result, Verifier}; +use crate::{Result, ShardIdentifierFor, Verifier}; use itp_types::H256; use its_primitives::traits::SignedBlock as SignedSidechainBlockTrait; use sp_core::Pair; @@ -54,6 +54,7 @@ where &self, _block: SignedSidechainBlock, _parentchain_header: &ParentchainBlock::Header, + _shard: ShardIdentifierFor, _ctx: &Self::Context, ) -> Result { todo!() diff --git a/sidechain/consensus/slots/src/lib.rs b/sidechain/consensus/slots/src/lib.rs index 1f1b000ebe..cff263fa60 100644 --- a/sidechain/consensus/slots/src/lib.rs +++ b/sidechain/consensus/slots/src/lib.rs @@ -137,6 +137,7 @@ pub trait SimpleSlotWorker { fn epoch_data( &self, header: &ParentchainBlock::Header, + shard: ShardIdentifierFor, slot: Slot, ) -> Result; @@ -214,7 +215,7 @@ pub trait SimpleSlotWorker { }, }; - let epoch_data = match self.epoch_data(&latest_parentchain_header, slot) { + let epoch_data = match self.epoch_data(&latest_parentchain_header, shard, slot) { Ok(epoch_data) => epoch_data, Err(e) => { warn!( @@ -271,7 +272,7 @@ pub trait SimpleSlotWorker { if !timestamp_within_slot(&slot_info, &proposing.block) { warn!( target: logging_target, - "⌛️ Discarding proposal for slot {}, block number {}; block production took too long", + "⌛️ Discarding proposal for slot {}, block number {}; block production took too long", *slot, proposing.block.block().header().block_number(), ); diff --git a/sidechain/consensus/slots/src/mocks.rs b/sidechain/consensus/slots/src/mocks.rs index ea6e4d4d6c..6664351160 100644 --- a/sidechain/consensus/slots/src/mocks.rs +++ b/sidechain/consensus/slots/src/mocks.rs @@ -60,7 +60,12 @@ where "test" } - fn epoch_data(&self, _header: &B::Header, _slot: Slot) -> Result { + fn epoch_data( + &self, + _header: &B::Header, + _shard: ShardIdentifierFor, + _slot: Slot, + ) -> Result { todo!() } diff --git a/sidechain/peer-fetch/src/untrusted_peer_fetch.rs b/sidechain/peer-fetch/src/untrusted_peer_fetch.rs index 7ff9434103..cfdabbfbf4 100644 --- a/sidechain/peer-fetch/src/untrusted_peer_fetch.rs +++ b/sidechain/peer-fetch/src/untrusted_peer_fetch.rs @@ -50,10 +50,15 @@ where let node_api = self.node_api_factory.create_api()?; let validateer = node_api - .worker_for_shard(shard, None)? + .primary_worker_for_shard(shard, None)? .ok_or_else(|| Error::NoPeerFoundForShard(*shard))?; - let trusted_worker_client = DirectWorkerApi::new(validateer.url); + let trusted_worker_client = DirectWorkerApi::new( + validateer + .instance_url() + .map(|url| String::from_utf8(url).unwrap_or_default()) + .ok_or_else(|| Error::NoPeerFoundForShard(*shard))?, + ); Ok(trusted_worker_client.get_untrusted_worker_url()?) } } diff --git a/sidechain/primitives/Cargo.toml b/sidechain/primitives/Cargo.toml index e93e3d9719..45844541a2 100644 --- a/sidechain/primitives/Cargo.toml +++ b/sidechain/primitives/Cargo.toml @@ -3,16 +3,16 @@ name = "its-primitives" version = "0.1.0" authors = ["Integritee AG "] homepage = "https://integritee.network/" -repository = "https://github.com/integritee-network/pallets/" +repository = "https://github.com/integritee-network/worker/" license = "Apache-2.0" edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full"] } +itp-types = { path = "../../core-primitives/types", default-features = false } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } serde = { version = "1.0.13", default-features = false } - # substrate dependencies sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } @@ -29,6 +29,7 @@ std = [ "codec/std", "scale-info/std", "serde/std", + "itp-types/std", # substrate "sp-core/std", "sp-io/std", diff --git a/sidechain/primitives/src/types/header.rs b/sidechain/primitives/src/types/header.rs index a4289193f8..962917f534 100644 --- a/sidechain/primitives/src/types/header.rs +++ b/sidechain/primitives/src/types/header.rs @@ -26,7 +26,7 @@ use sp_std::prelude::*; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; -pub type ShardIdentifier = H256; +pub use itp_types::ShardIdentifier; #[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, Copy, Default, TypeInfo)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] diff --git a/sidechain/test/Cargo.toml b/sidechain/test/Cargo.toml index f6f8fbfc72..002349141f 100644 --- a/sidechain/test/Cargo.toml +++ b/sidechain/test/Cargo.toml @@ -3,7 +3,7 @@ name = "its-test" version = "0.9.0" authors = ["Integritee AG "] homepage = "https://integritee.network/" -repository = "https://github.com/integritee-network/pallets/" +repository = "https://github.com/integritee-network/worker/" license = "Apache-2.0" edition = "2021" diff --git a/sidechain/validateer-fetch/Cargo.toml b/sidechain/validateer-fetch/Cargo.toml index dba26b3189..01988d59ce 100644 --- a/sidechain/validateer-fetch/Cargo.toml +++ b/sidechain/validateer-fetch/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "chain-error"] } derive_more = "0.99.16" +log = "0.4" thiserror = "1.0.26" # substrate deps @@ -16,10 +17,12 @@ sp-runtime = { default-features = false, git = "https://github.com/paritytech/su sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } # local deps +itp-enclave-bridge-storage = { path = "../../core-primitives/enclave-bridge-storage", default-features = false } itp-ocall-api = { path = "../../core-primitives/ocall-api", default-features = false } itp-storage = { path = "../../core-primitives/storage", default-features = false } itp-teerex-storage = { path = "../../core-primitives/teerex-storage", default-features = false } itp-types = { path = "../../core-primitives/types", default-features = false } +its-primitives = { path = "../primitives", default-features = false } [features] default = ["std"] @@ -31,6 +34,8 @@ std = [ "itp-types/std", "itp-storage/std", "itp-ocall-api/std", + "its-primitives/std", + "itp-enclave-bridge-storage/std", ] [dev-dependencies] diff --git a/sidechain/validateer-fetch/src/validateer.rs b/sidechain/validateer-fetch/src/validateer.rs index c35b22c442..3f0c099917 100644 --- a/sidechain/validateer-fetch/src/validateer.rs +++ b/sidechain/validateer-fetch/src/validateer.rs @@ -16,89 +16,108 @@ */ use crate::error::{Error, Result}; -use frame_support::ensure; +use itp_enclave_bridge_storage::{EnclaveBridgeStorage, EnclaveBridgeStorageKeys}; use itp_ocall_api::EnclaveOnChainOCallApi; -use itp_teerex_storage::{TeeRexStorage, TeerexStorageKeys}; -use itp_types::Enclave; +use itp_types::{parentchain::AccountId, ShardSignerStatus}; +use its_primitives::traits::{Block as SidechainBlockTrait, Header as HeaderTrait, SignedBlock}; +use log::trace; use sp_core::H256; use sp_runtime::traits::Header as HeaderT; use sp_std::prelude::Vec; +type ShardIdentifierFor = +<<::Block as SidechainBlockTrait>::HeaderType as HeaderTrait>::ShardIdentifier; + pub trait ValidateerFetch { - fn current_validateers>( + fn current_validateers< + Header: HeaderT, + SignedSidechainBlock: its_primitives::traits::SignedBlock, + >( + &self, + latest_header: &Header, + shard: ShardIdentifierFor, + ) -> Result>; + fn validateer_count< + Header: HeaderT, + SignedSidechainBlock: its_primitives::traits::SignedBlock, + >( &self, latest_header: &Header, - ) -> Result>; - fn validateer_count>(&self, latest_header: &Header) - -> Result; + shard: ShardIdentifierFor, + ) -> Result; } impl ValidateerFetch for OnchainStorage { - fn current_validateers>( + fn current_validateers< + Header: HeaderT, + SignedSidechainBlock: its_primitives::traits::SignedBlock, + >( &self, header: &Header, - ) -> Result> { - let count = self.validateer_count(header)?; - - let mut hashes = Vec::with_capacity(count as usize); - for i in 1..=count { - hashes.push(TeeRexStorage::enclave(i)) - } - - let enclaves: Vec = self - .get_multiple_storages_verified(hashes, header)? - .into_iter() - .filter_map(|e| e.into_tuple().1) - .collect(); - ensure!( - enclaves.len() == count as usize, - Error::Other("Found less validateers onchain than validateer count") - ); - Ok(enclaves) - } - - fn validateer_count>(&self, header: &Header) -> Result { - self.get_storage_verified(TeeRexStorage::enclave_count(), header)? + shard: ShardIdentifierFor, + ) -> Result> { + let shard_status: Vec = self + .get_storage_verified( + EnclaveBridgeStorage::shard_status::>( + shard, + ), + header, + )? .into_tuple() .1 - .ok_or_else(|| Error::Other("Could not get validateer count from chain")) + .ok_or_else(|| Error::Other("Could not get validateer count from chain"))?; + trace!("fetched {} validateers for shard {:?}", shard_status.len(), shard); + Ok(shard_status.iter().map(|sss: &ShardSignerStatus| sss.signer.clone()).collect()) + } + + fn validateer_count< + Header: HeaderT, + SignedSidechainBlock: its_primitives::traits::SignedBlock, + >( + &self, + header: &Header, + shard: ShardIdentifierFor, + ) -> Result { + Ok(self.current_validateers::(header, shard)?.len() as u64) } } #[cfg(test)] mod tests { use super::*; - use codec::Encode; + use itc_parentchain_test::ParentchainHeaderBuilder; use itp_test::mock::onchain_mock::{validateer_set, OnchainMock}; - use std::string::ToString; + use itp_types::ShardIdentifier; #[test] pub fn get_validateer_count_works() { let header = ParentchainHeaderBuilder::default().build(); - let mock = OnchainMock::default().add_validateer_set(&header, None); - assert_eq!(mock.validateer_count(&header).unwrap(), 4u64); + let shard = ShardIdentifier::default(); + let mock = OnchainMock::default().add_validateer_set(&header, shard, None); + assert_eq!( + mock.validateer_count::( + &header, shard + ) + .unwrap(), + 4u64 + ); } #[test] pub fn get_validateer_set_works() { let header = ParentchainHeaderBuilder::default().build(); - let mock = OnchainMock::default().add_validateer_set(&header, None); + let shard = ShardIdentifier::default(); + let mock = OnchainMock::default().add_validateer_set(&header, shard, None); let validateers = validateer_set(); - assert_eq!(mock.current_validateers(&header).unwrap(), validateers); - } - - #[test] - pub fn if_validateer_count_bigger_than_returned_validateers_return_err() { - let header = ParentchainHeaderBuilder::default().build(); - let mut mock = OnchainMock::default().add_validateer_set(&header, None); - mock.insert_at_header(&header, TeeRexStorage::enclave_count(), 5u64.encode()); - assert_eq!( - mock.current_validateers(&header).unwrap_err().to_string(), - "Found less validateers onchain than validateer count".to_string() + mock.current_validateers::( + &header, shard + ) + .unwrap(), + validateers ); } }