Skip to content

Commit 0710b37

Browse files
brenziclangenb
andauthored
maintenance mode and shard retirement (#1693)
* bump 0.15.13 * mirror L1 state into prefixed L2 state * revert type argument experiment * fetching mirrored values still fails * detecting maintenance mode works * make multifetch opaque * mirroring L1 state works * remove on the fly get_storage_hashes_to_update. only fetch once per parentchain block import * tame logging * cleanup warnings * let all calls fail when in maintenance mode * add trusted call force_unshield_all * batch unshield all native if maintenance mode expired * directly retiring and unshielding all native amounts * ignore technical accounts when force unshielding. and a cli fix * implement force unsheilding all assets too * force unshield assets too * make unshield_all unpermissioned and fix asset feess * add shard-management pallet to sgx-runtime to track ShardConfig and trigger shard retirement after N blocks of maintenance mode * auto retire shard after expired maintenance mode duration * cleanup * fix enclave tests * clippy * fix evm build * some cleanup * Update core-primitives/stf-primitives/src/error.rs Co-authored-by: clangenb <[email protected]> * refactor parentchain mirror stuff into own struct of methods * fmt * add sticky ShardMode and cli getter for ShardInfo * fix shard mode and revert to force_unshield_all. tested. works * fmt * fix enclave tests * fmt * bump 0.16.0 * enclave signer nonce must increase by 1 * fmt * fix nonce * cosmetics and docs * add spam-extrinsics trusted call and some hex cosmetics * filter dangerous calls in production * retire accounts in small batches * tested.works * fmt * taplo * review fixes * cli docstring fix * unregister sessionproxies to reduce consumers before retiring account --------- Co-authored-by: clangenb <[email protected]>
1 parent 00c9a24 commit 0710b37

File tree

74 files changed

+2055
-597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2055
-597
lines changed

Cargo.lock

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,7 +2574,7 @@ dependencies = [
25742574

25752575
[[package]]
25762576
name = "integritee-cli"
2577-
version = "0.15.12"
2577+
version = "0.16.0"
25782578
dependencies = [
25792579
"array-bytes 6.1.0",
25802580
"base58",
@@ -2632,7 +2632,7 @@ dependencies = [
26322632

26332633
[[package]]
26342634
name = "integritee-service"
2635-
version = "0.15.12"
2635+
version = "0.16.0"
26362636
dependencies = [
26372637
"anyhow",
26382638
"async-trait",
@@ -2839,7 +2839,7 @@ dependencies = [
28392839
name = "ita-parentchain-specs"
28402840
version = "0.1.0"
28412841
dependencies = [
2842-
"hex",
2842+
"hex-literal 0.4.1",
28432843
"itp-types",
28442844
"log 0.4.22",
28452845
]
@@ -2861,6 +2861,7 @@ dependencies = [
28612861
"pallet-notes",
28622862
"pallet-parentchain",
28632863
"pallet-session-proxy",
2864+
"pallet-shard-management",
28642865
"pallet-sudo",
28652866
"pallet-timestamp",
28662867
"pallet-transaction-payment",
@@ -2886,6 +2887,7 @@ dependencies = [
28862887
"itp-hashing",
28872888
"itp-node-api",
28882889
"itp-node-api-metadata",
2890+
"itp-pallet-storage",
28892891
"itp-randomness",
28902892
"itp-sgx-externalities",
28912893
"itp-sgx-runtime-primitives",
@@ -2895,6 +2897,7 @@ dependencies = [
28952897
"itp-types",
28962898
"itp-utils",
28972899
"log 0.4.22",
2900+
"pallet-assets",
28982901
"pallet-balances",
28992902
"pallet-notes",
29002903
"pallet-parentchain",
@@ -3370,6 +3373,7 @@ version = "0.9.0"
33703373
dependencies = [
33713374
"derive_more",
33723375
"itp-api-client-types",
3376+
"itp-types",
33733377
"parity-scale-codec",
33743378
"sp-core",
33753379
]
@@ -3411,9 +3415,11 @@ dependencies = [
34113415
name = "itp-pallet-storage"
34123416
version = "0.9.0"
34133417
dependencies = [
3418+
"hex-literal 0.4.1",
34143419
"itp-storage",
34153420
"itp-types",
34163421
"parity-scale-codec",
3422+
"sp-core",
34173423
"sp-std",
34183424
]
34193425

@@ -3519,6 +3525,7 @@ dependencies = [
35193525
"itp-enclave-metrics",
35203526
"itp-node-api",
35213527
"itp-ocall-api",
3528+
"itp-pallet-storage",
35223529
"itp-sgx-crypto",
35233530
"itp-sgx-externalities",
35243531
"itp-stf-interface",
@@ -5329,6 +5336,23 @@ dependencies = [
53295336
"sp-std",
53305337
]
53315338

5339+
[[package]]
5340+
name = "pallet-shard-management"
5341+
version = "0.15.0"
5342+
dependencies = [
5343+
"enclave-bridge-primitives",
5344+
"frame-support",
5345+
"frame-system",
5346+
"log 0.4.22",
5347+
"pallet-balances",
5348+
"parity-scale-codec",
5349+
"scale-info",
5350+
"sp-core",
5351+
"sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)",
5352+
"sp-keyring",
5353+
"sp-runtime",
5354+
]
5355+
53325356
[[package]]
53335357
name = "pallet-sidechain"
53345358
version = "0.11.0"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"app-libs/sgx-runtime/pallets/parentchain",
1111
"app-libs/sgx-runtime/pallets/guess-the-number",
1212
"app-libs/sgx-runtime/pallets/session-proxy",
13+
"app-libs/sgx-runtime/pallets/shard-management",
1314
"app-libs/stf",
1415
"cli",
1516
"core/direct-rpc-server",

app-libs/assets-map/src/lib.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#![cfg_attr(not(feature = "std"), no_std)]
2222
extern crate alloc;
2323

24-
use alloc::sync::Arc;
24+
use alloc::{sync::Arc, vec, vec::Vec};
2525
use codec::{Decode, Encode, MaxEncodedLen};
2626
use hex_literal::hex;
2727
use ita_parentchain_specs::{
@@ -136,30 +136,30 @@ impl AssetId {
136136
}
137137

138138
pub fn is_shieldable(&self, genesis_hash: Hash) -> bool {
139-
let genesis_hash_hex = hex::encode(genesis_hash);
140-
match genesis_hash_hex.as_ref() {
141-
ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX => matches!(
142-
self,
143-
AssetId::USDT | AssetId::USDC | AssetId::USDC_E | AssetId::WETH | AssetId::ETH
144-
),
145-
ASSET_HUB_PASEO_GENESIS_HASH_HEX => matches!(
146-
self,
147-
AssetId::USDT | AssetId::USDC | AssetId::USDC_E | AssetId::WETH | AssetId::ETH
148-
),
149-
ASSET_HUB_POLKADOT_GENESIS_HASH_HEX => matches!(self, AssetId::USDC_E),
150-
_ => false,
139+
Self::all_shieldable(genesis_hash).contains(self)
140+
}
141+
142+
/// returns all AssetId variants which are shieldable for a given shielding target genesis hash.
143+
/// L2 fee payment will be attempted in order provided here.
144+
pub fn all_shieldable(genesis_hash: Hash) -> Vec<Self> {
145+
match genesis_hash.into() {
146+
ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX =>
147+
vec![AssetId::USDT, AssetId::USDC, AssetId::USDC_E, AssetId::WETH, AssetId::ETH],
148+
ASSET_HUB_PASEO_GENESIS_HASH_HEX =>
149+
vec![AssetId::USDT, AssetId::USDC, AssetId::USDC_E, AssetId::WETH, AssetId::ETH],
150+
ASSET_HUB_POLKADOT_GENESIS_HASH_HEX => vec![AssetId::USDC_E],
151+
_ => vec![],
151152
}
152153
}
153154
}
154155

155156
impl AssetTranslation for AssetId {
156157
/// into XCM location. Only applies to foreign assets
157158
fn into_location(self, genesis_hash: Hash) -> Option<Location> {
158-
let genesis_hash_hex = hex::encode(genesis_hash);
159159
match self {
160160
AssetId::USDC_E =>
161161
if matches!(
162-
genesis_hash_hex.as_ref(),
162+
genesis_hash.into(),
163163
ASSET_HUB_POLKADOT_GENESIS_HASH_HEX | ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX
164164
) {
165165
Some(Location {
@@ -174,7 +174,7 @@ impl AssetTranslation for AssetId {
174174
},
175175
AssetId::WETH =>
176176
if matches!(
177-
genesis_hash_hex.as_ref(),
177+
genesis_hash.into(),
178178
ASSET_HUB_PASEO_GENESIS_HASH_HEX | ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX
179179
) {
180180
Some(Location {
@@ -193,11 +193,10 @@ impl AssetTranslation for AssetId {
193193

194194
/// converts our asset into an Asset Hub asset index only if shielding asset is supported on shielding target
195195
fn into_asset_hub_index(self, genesis_hash: Hash) -> Option<ParentchainAssetIdNative> {
196-
let genesis_hash_hex = hex::encode(genesis_hash);
197196
match self {
198197
AssetId::USDT =>
199198
if matches!(
200-
genesis_hash_hex.as_ref(),
199+
genesis_hash.into(),
201200
ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX | ASSET_HUB_PASEO_GENESIS_HASH_HEX
202201
) {
203202
Some(USDT_ASSET_HUB_ID)
@@ -206,7 +205,7 @@ impl AssetTranslation for AssetId {
206205
},
207206
AssetId::USDC =>
208207
if matches!(
209-
genesis_hash_hex.as_ref(),
208+
genesis_hash.into(),
210209
ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX | ASSET_HUB_PASEO_GENESIS_HASH_HEX
211210
) {
212211
Some(USDC_ASSET_HUB_ID)
@@ -222,22 +221,21 @@ impl AssetTranslation for AssetId {
222221
where
223222
Self: Sized,
224223
{
225-
let genesis_hash_hex = hex::encode(genesis_hash);
226224
if location.parents == 2 {
227225
if let X2(junctions) = &location.interior {
228226
match junctions.as_slice() {
229227
[GlobalConsensus(Ethereum { chain_id: ETHEREUM_MAINNET_CHAIN_ID }), AccountKey20 { key: contract, network: None }]
230228
if *contract == USDC_E_MAINNET_CONTRACT_ADDRESS
231229
&& matches!(
232-
genesis_hash_hex.as_ref(),
230+
genesis_hash.into(),
233231
ASSET_HUB_POLKADOT_GENESIS_HASH_HEX
234232
| ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX
235233
) =>
236234
Some(AssetId::USDC_E),
237235
[GlobalConsensus(Ethereum { chain_id: ETHEREUM_SEPOLIA_CHAIN_ID }), AccountKey20 { key: contract, network: None }]
238236
if *contract == WETH_SEPOLIA_CONTRACT_ADDRESS
239237
&& matches!(
240-
genesis_hash_hex.as_ref(),
238+
genesis_hash.into(),
241239
ASSET_HUB_PASEO_GENESIS_HASH_HEX
242240
| ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX
243241
) =>
@@ -254,9 +252,8 @@ impl AssetTranslation for AssetId {
254252

255253
/// converts the index of a native Asset Hub asset to our local type only if supported for shielding target
256254
fn from_asset_hub_index(id: ParentchainAssetIdNative, genesis_hash: Hash) -> Option<Self> {
257-
let genesis_hash_hex = hex::encode(genesis_hash);
258255
if matches!(
259-
genesis_hash_hex.as_ref(),
256+
genesis_hash.into(),
260257
ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX | ASSET_HUB_PASEO_GENESIS_HASH_HEX
261258
) {
262259
match id {

app-libs/parentchain-specs/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ authors = ["Integritee AG <[email protected]>"]
55
edition = "2021"
66

77
[dependencies]
8-
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
8+
hex-literal = "0.4.1"
99
itp-types = { path = "../../core-primitives/types", default-features = false }
1010
log = { version = "0.4", default-features = false }
1111

1212
[features]
1313
default = ["std"]
1414
std = [
15-
"hex/std",
1615
"log/std",
1716
]

app-libs/parentchain-specs/src/lib.rs

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,53 @@
1919

2020
#![cfg_attr(all(not(target_env = "sgx"), not(feature = "std")), no_std)]
2121
#![cfg_attr(target_env = "sgx", feature(rustc_private))]
22-
use itp_types::parentchain::{Balance, Hash};
22+
23+
use hex_literal::hex;
24+
use itp_types::parentchain::{Balance, BlockNumber, Hash};
2325
use log::warn;
2426

25-
pub const PASEO_RELAY_GENESIS_HASH_HEX: &str =
26-
"77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f";
27-
pub const ASSET_HUB_PASEO_GENESIS_HASH_HEX: &str =
28-
"d6eec26135305a8ad257a20d003357284c8aa03d0bdb2b357ab0a22371e11ef2";
29-
pub const INTEGRITEE_PASEO_GENESIS_HASH_HEX: &str =
30-
"1b69c462cd7dfea0e855c2008b66490cc8bbe90bc80b297ec0896a1c0941ce15";
31-
pub const INTEGRITEE_KUSAMA_GENESIS_HASH_HEX: &str =
32-
"cdedc8eadbfa209d3f207bba541e57c3c58a667b05a2e1d1e86353c9000758da";
33-
pub const KUSAMA_RELAY_GENESIS_HASH_HEX: &str =
34-
"b0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe";
35-
pub const ASSET_HUB_KUSAMA_GENESIS_HASH_HEX: &str =
36-
"48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a";
37-
pub const POLKADOT_RELAY_GENESIS_HASH_HEX: &str =
38-
"91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3";
39-
pub const ASSET_HUB_POLKADOT_GENESIS_HASH_HEX: &str =
40-
"68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f";
27+
pub const PASEO_RELAY_GENESIS_HASH_HEX: [u8; 32] =
28+
hex!("77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f");
29+
pub const ASSET_HUB_PASEO_GENESIS_HASH_HEX: [u8; 32] =
30+
hex!("d6eec26135305a8ad257a20d003357284c8aa03d0bdb2b357ab0a22371e11ef2");
31+
pub const INTEGRITEE_PASEO_GENESIS_HASH_HEX: [u8; 32] =
32+
hex!("1b69c462cd7dfea0e855c2008b66490cc8bbe90bc80b297ec0896a1c0941ce15");
33+
pub const INTEGRITEE_KUSAMA_GENESIS_HASH_HEX: [u8; 32] =
34+
hex!("cdedc8eadbfa209d3f207bba541e57c3c58a667b05a2e1d1e86353c9000758da");
35+
pub const INTEGRITEE_POLKADOT_GENESIS_HASH_HEX: [u8; 32] =
36+
hex!("e13e7af377c64e83f95e0d70d5e5c3c01d697a84538776c5b9bbe0e7d7b6034c");
37+
pub const KUSAMA_RELAY_GENESIS_HASH_HEX: [u8; 32] =
38+
hex!("b0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe");
39+
pub const ASSET_HUB_KUSAMA_GENESIS_HASH_HEX: [u8; 32] =
40+
hex!("48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a");
41+
pub const POLKADOT_RELAY_GENESIS_HASH_HEX: [u8; 32] =
42+
hex!("91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3");
43+
pub const ASSET_HUB_POLKADOT_GENESIS_HASH_HEX: [u8; 32] =
44+
hex!("68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f");
4145

4246
/// modify this for testing if necessary (brittle)
43-
pub const LOCAL_TEST_GENESIS_HASH_HEX: &str =
44-
"6ca6d29ad6c4a200c4af356f74f03d6467dbc8a6e9ef225a2e672a990e1c7ead";
45-
47+
pub const LOCAL_TEST_GENESIS_HASH_HEX: [u8; 32] =
48+
hex!("6ca6d29ad6c4a200c4af356f74f03d6467dbc8a6e9ef225a2e672a990e1c7ead");
4649
/// LOCAL ASSET_HUB_ROCOCO (brittle)
47-
pub const ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX: &str =
48-
"af94f065f724b64ec40a7dd7ca3d25b3493d462f1e991b979e7683ae2a5da8d6";
50+
pub const ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX: [u8; 32] =
51+
hex!("af94f065f724b64ec40a7dd7ca3d25b3493d462f1e991b979e7683ae2a5da8d6");
4952

5053
pub struct MinimalChainSpec {}
5154

5255
impl MinimalChainSpec {
5356
pub fn decimals(genesis_hash: Hash) -> u8 {
54-
let genesis_hash_hex = hex::encode(genesis_hash);
55-
match genesis_hash_hex.as_ref() {
57+
match genesis_hash.into() {
5658
PASEO_RELAY_GENESIS_HASH_HEX | ASSET_HUB_PASEO_GENESIS_HASH_HEX => 10,
5759
POLKADOT_RELAY_GENESIS_HASH_HEX | ASSET_HUB_POLKADOT_GENESIS_HASH_HEX => 10,
5860
KUSAMA_RELAY_GENESIS_HASH_HEX | ASSET_HUB_KUSAMA_GENESIS_HASH_HEX => 12,
59-
INTEGRITEE_PASEO_GENESIS_HASH_HEX | INTEGRITEE_KUSAMA_GENESIS_HASH_HEX => 12,
61+
INTEGRITEE_PASEO_GENESIS_HASH_HEX
62+
| INTEGRITEE_KUSAMA_GENESIS_HASH_HEX
63+
| INTEGRITEE_POLKADOT_GENESIS_HASH_HEX => 12,
6064
LOCAL_TEST_GENESIS_HASH_HEX | ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX => 12,
6165
_ => {
6266
warn!(
63-
"parentchain spec for genesis {} unknown. defaulting to 12 decimals",
64-
genesis_hash_hex
67+
"parentchain spec for genesis 0x{:#x} unknown. defaulting to 12 decimals",
68+
genesis_hash
6569
);
6670
12
6771
},
@@ -70,4 +74,31 @@ impl MinimalChainSpec {
7074
pub fn one_unit(genesis_hash: Hash) -> Balance {
7175
10u128.pow(Self::decimals(genesis_hash) as u32)
7276
}
77+
78+
/// maintenance mode should be a temporary measure.
79+
/// If a problem can't be resolved within the time specified here, the shard should be retired to avoid loss of user funds
80+
pub fn maintenance_mode_duration_before_retirement(genesis_hash: Hash) -> BlockNumber {
81+
match genesis_hash.into() {
82+
PASEO_RELAY_GENESIS_HASH_HEX
83+
| ASSET_HUB_PASEO_GENESIS_HASH_HEX
84+
| INTEGRITEE_PASEO_GENESIS_HASH_HEX => 300, // 1h at 12s block time
85+
POLKADOT_RELAY_GENESIS_HASH_HEX | ASSET_HUB_POLKADOT_GENESIS_HASH_HEX => 216_000, // 30d for all production chains
86+
KUSAMA_RELAY_GENESIS_HASH_HEX | ASSET_HUB_KUSAMA_GENESIS_HASH_HEX => 216_000, // 30d for all production chains
87+
INTEGRITEE_KUSAMA_GENESIS_HASH_HEX | INTEGRITEE_POLKADOT_GENESIS_HASH_HEX => 216_000, // 30d for all production chains
88+
LOCAL_TEST_GENESIS_HASH_HEX | ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX => 20, // 10 min at 12s block time
89+
_ => 7200, // if undefined, leave 24h to react
90+
}
91+
}
92+
93+
pub fn is_known_production_chain(genesis_hash: Hash) -> bool {
94+
matches!(
95+
genesis_hash.into(),
96+
POLKADOT_RELAY_GENESIS_HASH_HEX
97+
| ASSET_HUB_POLKADOT_GENESIS_HASH_HEX
98+
| KUSAMA_RELAY_GENESIS_HASH_HEX
99+
| ASSET_HUB_KUSAMA_GENESIS_HASH_HEX
100+
| INTEGRITEE_KUSAMA_GENESIS_HASH_HEX
101+
| INTEGRITEE_POLKADOT_GENESIS_HASH_HEX
102+
)
103+
}
73104
}

app-libs/sgx-runtime/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pallet-guess-the-number = { default-features = false, path = "pallets/guess-the-
1919
pallet-notes = { default-features = false, path = "pallets/notes" }
2020
pallet-parentchain = { default-features = false, path = "pallets/parentchain" }
2121
pallet-session-proxy = { default-features = false, path = "pallets/session-proxy" }
22+
pallet-shard-management = { default-features = false, path = "pallets/shard-management" }
2223

2324
# Substrate dependencies
2425
frame-executive = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
@@ -62,6 +63,7 @@ std = [
6263
"pallet-parentchain/std",
6364
"pallet-notes/std",
6465
"pallet-session-proxy/std",
66+
"pallet-shard-management/std",
6567
"sp-api/std",
6668
"sp-core/std",
6769
"sp-runtime/std",

app-libs/sgx-runtime/pallets/notes/src/mock.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@
1616
*/
1717
pub use crate as dut;
1818

19-
use frame_support::{
20-
ord_parameter_types, parameter_types,
21-
traits::{ConstU8, EitherOfDiverse},
22-
PalletId,
23-
};
19+
use frame_support::{ord_parameter_types, parameter_types};
2420
use frame_system as system;
25-
use frame_system::{EnsureRoot, EnsureSignedBy};
26-
use itp_randomness::MockRandomness;
27-
use sp_core::{crypto::AccountId32, ConstU32, H256};
21+
22+
use sp_core::{crypto::AccountId32, H256};
2823
use sp_keyring::AccountKeyring;
2924
use sp_runtime::{
3025
generic,

0 commit comments

Comments
 (0)