diff --git a/Cargo.lock b/Cargo.lock index 6f0c5c8b80..44df768280 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9628,6 +9628,7 @@ dependencies = [ "frame-system", "mocktopus", "parity-scale-codec", + "serde", "sha2 0.8.2", "sp-core", "sp-io", diff --git a/crates/security/Cargo.toml b/crates/security/Cargo.toml index 6cdb341c18..893e897114 100644 --- a/crates/security/Cargo.toml +++ b/crates/security/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [dependencies] codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } sha2 = { version = "0.8.2", default-features = false } +serde = { version = "1.0.119", default-features = false, features = ["derive"], optional = true } # Substrate dependencies sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } @@ -22,6 +23,7 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0 [features] default = ["std"] std = [ + "serde", "codec/std", "sha2/std", diff --git a/crates/security/src/lib.rs b/crates/security/src/lib.rs index dddb2713df..63bbc93ee0 100644 --- a/crates/security/src/lib.rs +++ b/crates/security/src/lib.rs @@ -90,14 +90,25 @@ pub mod pallet { } #[pallet::genesis_config] - #[derive(Default)] - pub struct GenesisConfig; + pub struct GenesisConfig { + pub initial_status: StatusCode, + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + Self { + initial_status: StatusCode::Error, + } + } + } #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { + Pallet::::set_status(self.initial_status); + Pallet::::insert_error(ErrorCode::OracleOffline); - Pallet::::set_status(StatusCode::Error); } } diff --git a/crates/security/src/types.rs b/crates/security/src/types.rs index b224035ef3..7ec854e5ec 100644 --- a/crates/security/src/types.rs +++ b/crates/security/src/types.rs @@ -2,7 +2,8 @@ use codec::{Decode, Encode}; use sp_std::{cmp::Ord, fmt::Debug}; /// Enum indicating the status of the BTC Parachain. -#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)] +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, Debug)] pub enum StatusCode { /// BTC Parachain is fully operational. Running = 0, diff --git a/parachain/runtime/src/lib.rs b/parachain/runtime/src/lib.rs index a02fc31097..b1035e9c7d 100644 --- a/parachain/runtime/src/lib.rs +++ b/parachain/runtime/src/lib.rs @@ -51,6 +51,7 @@ pub use sp_runtime::{Perbill, Permill}; // interBTC exports pub use btc_relay::{bitcoin, Call as RelayCall, TARGET_SPACING}; pub use module_oracle_rpc_runtime_api::BalanceWrapper; +pub use security::StatusCode; pub use primitives::{ self, AccountId, Balance, BlockNumber, CurrencyId, Hash, Moment, Nonce, Signature, SignedFixedPoint, SignedInner, @@ -843,7 +844,7 @@ construct_runtime! { Relay: relay::{Pallet, Call, Storage, Event}, // Operational - Security: security::{Pallet, Call, Storage, Event}, + Security: security::{Pallet, Call, Config, Storage, Event}, VaultRegistry: vault_registry::{Pallet, Call, Config, Storage, Event, ValidateUnsigned}, Oracle: oracle::{Pallet, Call, Config, Storage, Event}, Issue: issue::{Pallet, Call, Config, Storage, Event}, diff --git a/parachain/src/chain_spec.rs b/parachain/src/chain_spec.rs index 6dcfbf51b2..fd5b7b4be8 100644 --- a/parachain/src/chain_spec.rs +++ b/parachain/src/chain_spec.rs @@ -3,8 +3,9 @@ use cumulus_primitives_core::ParaId; use hex_literal::hex; use interbtc_runtime::{ AccountId, AuraConfig, BTCRelayConfig, Balance, CurrencyId, FeeConfig, GenesisConfig, IssueConfig, - NominationConfig, OracleConfig, ParachainInfoConfig, RedeemConfig, RefundConfig, ReplaceConfig, Signature, - SudoConfig, SystemConfig, TokensConfig, VaultRegistryConfig, BITCOIN_BLOCK_SPACING, DAYS, KSM, WASM_BINARY, + NominationConfig, OracleConfig, ParachainInfoConfig, RedeemConfig, RefundConfig, ReplaceConfig, SecurityConfig, + Signature, StatusCode, SudoConfig, SystemConfig, TokensConfig, VaultRegistryConfig, BITCOIN_BLOCK_SPACING, DAYS, + KSM, WASM_BINARY, }; use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use serde::{Deserialize, Serialize}; @@ -109,6 +110,7 @@ pub fn local_config(id: ParaId) -> ChainSpec { )], id, DEFAULT_BITCOIN_CONFIRMATIONS, + false, ) }, vec![], @@ -161,6 +163,7 @@ pub fn development_config(id: ParaId) -> ChainSpec { ], id, DEFAULT_BITCOIN_CONFIRMATIONS, + false, ) }, Vec::new(), @@ -203,6 +206,7 @@ pub fn rococo_testnet_config(id: ParaId) -> ChainSpec { ], id, DEFAULT_BITCOIN_CONFIRMATIONS, + false, ) }, Vec::new(), @@ -263,6 +267,7 @@ pub fn westend_testnet_config(id: ParaId) -> ChainSpec { ], id, DEFAULT_BITCOIN_CONFIRMATIONS, + false, ) }, Vec::new(), @@ -283,6 +288,7 @@ fn testnet_genesis( authorized_oracles: Vec<(AccountId, Vec)>, id: ParaId, bitcoin_confirmations: u32, + start_shutdown: bool, ) -> GenesisConfig { GenesisConfig { system: SystemConfig { @@ -297,6 +303,13 @@ fn testnet_genesis( aura_ext: Default::default(), parachain_system: Default::default(), parachain_info: ParachainInfoConfig { parachain_id: id }, + security: SecurityConfig { + initial_status: if start_shutdown { + StatusCode::Shutdown + } else { + StatusCode::Error + }, + }, sudo: SudoConfig { // Assign network admin rights. key: root_key.clone(), @@ -490,6 +503,9 @@ fn mainnet_genesis( aura_ext: Default::default(), parachain_system: Default::default(), parachain_info: ParachainInfoConfig { parachain_id: id }, + security: SecurityConfig { + initial_status: StatusCode::Shutdown, + }, sudo: SudoConfig { // Assign network admin rights. key: root_key.clone(), diff --git a/standalone/runtime/src/lib.rs b/standalone/runtime/src/lib.rs index 2d6d9fd851..53cac6f063 100644 --- a/standalone/runtime/src/lib.rs +++ b/standalone/runtime/src/lib.rs @@ -46,6 +46,7 @@ pub use sp_runtime::{Perbill, Permill}; // interBTC exports pub use btc_relay::{bitcoin, Call as RelayCall, TARGET_SPACING}; pub use module_oracle_rpc_runtime_api::BalanceWrapper; +pub use security::StatusCode; use currency::Amount; pub use primitives::{ @@ -411,7 +412,7 @@ construct_runtime! { BTCRelay: btc_relay::{Pallet, Call, Config, Storage, Event}, // Operational - Security: security::{Pallet, Call, Storage, Event}, + Security: security::{Pallet, Call, Config, Storage, Event}, Relay: relay::{Pallet, Call, Storage, Event}, VaultRegistry: vault_registry::{Pallet, Call, Config, Storage, Event, ValidateUnsigned}, Oracle: oracle::{Pallet, Call, Config, Storage, Event}, diff --git a/standalone/src/chain_spec.rs b/standalone/src/chain_spec.rs index 21d500fd61..a001880219 100644 --- a/standalone/src/chain_spec.rs +++ b/standalone/src/chain_spec.rs @@ -2,8 +2,8 @@ use bitcoin::utils::{virtual_transaction_size, InputType, TransactionInputMetada use hex_literal::hex; use interbtc_runtime::{ AccountId, AuraConfig, BTCRelayConfig, CurrencyId, FeeConfig, GenesisConfig, GrandpaConfig, IssueConfig, - NominationConfig, OracleConfig, RedeemConfig, RefundConfig, ReplaceConfig, Signature, SudoConfig, SystemConfig, - TokensConfig, VaultRegistryConfig, BITCOIN_BLOCK_SPACING, DAYS, DOT, WASM_BINARY, + NominationConfig, OracleConfig, RedeemConfig, RefundConfig, ReplaceConfig, SecurityConfig, Signature, StatusCode, + SudoConfig, SystemConfig, TokensConfig, VaultRegistryConfig, BITCOIN_BLOCK_SPACING, DAYS, DOT, WASM_BINARY, }; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::crypto::UncheckedInto; @@ -88,6 +88,7 @@ pub fn local_config() -> ChainSpec { "Bob".as_bytes().to_vec(), )], 0, + false, ) }, vec![], @@ -151,6 +152,7 @@ pub fn beta_testnet_config() -> ChainSpec { ), ], 1, + false, ) }, Vec::new(), @@ -199,6 +201,7 @@ pub fn development_config() -> ChainSpec { ), ], 1, + false, ) }, Vec::new(), @@ -215,6 +218,7 @@ fn testnet_genesis( endowed_accounts: Vec, authorized_oracles: Vec<(AccountId, Vec)>, bitcoin_confirmations: u32, + start_shutdown: bool, ) -> GenesisConfig { GenesisConfig { system: SystemConfig { @@ -229,6 +233,13 @@ fn testnet_genesis( grandpa: GrandpaConfig { authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(), }, + security: SecurityConfig { + initial_status: if start_shutdown { + StatusCode::Shutdown + } else { + StatusCode::Error + }, + }, sudo: SudoConfig { // Assign network admin rights. key: root_key.clone(),