Skip to content

Commit

Permalink
Merge pull request #250 from sander2/feat/start-shutdown
Browse files Browse the repository at this point in the history
feat: option to start in SHUTDOWN
  • Loading branch information
gregdhill authored Aug 30, 2021
2 parents 1671fca + 5996a00 commit 184e190
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/security/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -22,6 +23,7 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0
[features]
default = ["std"]
std = [
"serde",
"codec/std",
"sha2/std",

Expand Down
17 changes: 14 additions & 3 deletions crates/security/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {
Pallet::<T>::set_status(self.initial_status);

Pallet::<T>::insert_error(ErrorCode::OracleOffline);
Pallet::<T>::set_status(StatusCode::Error);
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/security/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -843,7 +844,7 @@ construct_runtime! {
Relay: relay::{Pallet, Call, Storage, Event<T>},

// Operational
Security: security::{Pallet, Call, Storage, Event<T>},
Security: security::{Pallet, Call, Config, Storage, Event<T>},
VaultRegistry: vault_registry::{Pallet, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
Oracle: oracle::{Pallet, Call, Config<T>, Storage, Event<T>},
Issue: issue::{Pallet, Call, Config<T>, Storage, Event<T>},
Expand Down
20 changes: 18 additions & 2 deletions parachain/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -109,6 +110,7 @@ pub fn local_config(id: ParaId) -> ChainSpec {
)],
id,
DEFAULT_BITCOIN_CONFIRMATIONS,
false,
)
},
vec![],
Expand Down Expand Up @@ -161,6 +163,7 @@ pub fn development_config(id: ParaId) -> ChainSpec {
],
id,
DEFAULT_BITCOIN_CONFIRMATIONS,
false,
)
},
Vec::new(),
Expand Down Expand Up @@ -203,6 +206,7 @@ pub fn rococo_testnet_config(id: ParaId) -> ChainSpec {
],
id,
DEFAULT_BITCOIN_CONFIRMATIONS,
false,
)
},
Vec::new(),
Expand Down Expand Up @@ -263,6 +267,7 @@ pub fn westend_testnet_config(id: ParaId) -> ChainSpec {
],
id,
DEFAULT_BITCOIN_CONFIRMATIONS,
false,
)
},
Vec::new(),
Expand All @@ -283,6 +288,7 @@ fn testnet_genesis(
authorized_oracles: Vec<(AccountId, Vec<u8>)>,
id: ParaId,
bitcoin_confirmations: u32,
start_shutdown: bool,
) -> GenesisConfig {
GenesisConfig {
system: SystemConfig {
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion standalone/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -411,7 +412,7 @@ construct_runtime! {
BTCRelay: btc_relay::{Pallet, Call, Config<T>, Storage, Event<T>},

// Operational
Security: security::{Pallet, Call, Storage, Event<T>},
Security: security::{Pallet, Call, Config, Storage, Event<T>},
Relay: relay::{Pallet, Call, Storage, Event<T>},
VaultRegistry: vault_registry::{Pallet, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
Oracle: oracle::{Pallet, Call, Config<T>, Storage, Event<T>},
Expand Down
15 changes: 13 additions & 2 deletions standalone/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,6 +88,7 @@ pub fn local_config() -> ChainSpec {
"Bob".as_bytes().to_vec(),
)],
0,
false,
)
},
vec![],
Expand Down Expand Up @@ -151,6 +152,7 @@ pub fn beta_testnet_config() -> ChainSpec {
),
],
1,
false,
)
},
Vec::new(),
Expand Down Expand Up @@ -199,6 +201,7 @@ pub fn development_config() -> ChainSpec {
),
],
1,
false,
)
},
Vec::new(),
Expand All @@ -215,6 +218,7 @@ fn testnet_genesis(
endowed_accounts: Vec<AccountId>,
authorized_oracles: Vec<(AccountId, Vec<u8>)>,
bitcoin_confirmations: u32,
start_shutdown: bool,
) -> GenesisConfig {
GenesisConfig {
system: SystemConfig {
Expand All @@ -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(),
Expand Down

0 comments on commit 184e190

Please sign in to comment.