diff --git a/cli/src/chain_spec.rs b/cli/src/chain_spec.rs index be00aab20ca96..f8854685bf087 100644 --- a/cli/src/chain_spec.rs +++ b/cli/src/chain_spec.rs @@ -144,7 +144,7 @@ pub fn development_config() -> Result { ("Alice//stash", endowed_balance), ("Bob//stash", endowed_balance), ], - crate::res::load_mainnet_btc_genesis_header_info, + crate::res::load_testnet_btc_genesis_header_info, crate::genesis::trustees::local_testnet_trustees(), ) }; @@ -225,7 +225,7 @@ pub fn local_testnet_config() -> Result { ("Eve//stash", endowed_balance), ("Ferdie//stash", endowed_balance), ], - crate::res::load_mainnet_btc_genesis_header_info, + crate::res::load_testnet_btc_genesis_header_info, crate::genesis::trustees::local_testnet_trustees(), ) }; @@ -659,6 +659,21 @@ where .into_iter() .map(|((val, referral_id), _, _, _, _, _)| (val, referral_id, STAKING_LOCKED)) .collect::>(); + let btc_genesis_trustees = trustees + .iter() + .find_map(|(chain, _, trustee_params)| { + if *chain == Chain::Bitcoin { + Some( + trustee_params + .iter() + .map(|i| (i.0).clone()) + .collect::>(), + ) + } else { + None + } + }) + .expect("must success for bitcoin trustee info"); GenesisConfig { frame_system: Some(SystemConfig { @@ -729,6 +744,7 @@ where confirmed_count, } = bitcoin_info(); // crate::res::load_mainnet_btc_genesis_header_info(); Some(XGatewayBitcoinConfig { + genesis_trustees: btc_genesis_trustees, genesis_info, genesis_hash, network_id: network, diff --git a/cli/src/genesis/trustees.rs b/cli/src/genesis/trustees.rs index 470aea677c743..dd14b0edda971 100644 --- a/cli/src/genesis/trustees.rs +++ b/cli/src/genesis/trustees.rs @@ -33,18 +33,18 @@ pub fn local_testnet_trustees() -> Vec<(Chain, TrusteeInfoConfig, Vec}, XGatewayCommon: xpallet_gateway_common::{Module, Call, Storage, Event, Config}, - XGatewayBitcoin: xpallet_gateway_bitcoin::{Module, Call, Storage, Event, Config}, + XGatewayBitcoin: xpallet_gateway_bitcoin::{Module, Call, Storage, Event, Config}, // DEX XSpot: xpallet_dex_spot::{Module, Call, Storage, Event, Config}, diff --git a/xpallets/gateway/bitcoin/src/lib.rs b/xpallets/gateway/bitcoin/src/lib.rs index 1fdf93b6d8566..7e3db2e333d18 100644 --- a/xpallets/gateway/bitcoin/src/lib.rs +++ b/xpallets/gateway/bitcoin/src/lib.rs @@ -233,6 +233,7 @@ decl_storage! { } add_extra_genesis { config(genesis_hash): H256; + config(genesis_trustees): Vec; build(|config| { let genesis_header = config.genesis_info.0; let genesis_hash = genesis_header.hash(); @@ -262,11 +263,11 @@ decl_storage! { MainChain::insert(&genesis_hash, ()); BestIndex::put(genesis_index); - // ConfirmedIndex::put(genesis_index); - Module::::deposit_event(RawEvent::InsertHeader( - genesis_hash, - )); + // init trustee (not this action should ha) + if !config.genesis_trustees.is_empty() { + T::TrusteeSessionProvider::genesis_trustee(Module::::chain(), &config.genesis_trustees); + } }) } } diff --git a/xpallets/gateway/bitcoin/src/tests/mock.rs b/xpallets/gateway/bitcoin/src/tests/mock.rs index 6842dd05022fd..0142d43788288 100644 --- a/xpallets/gateway/bitcoin/src/tests/mock.rs +++ b/xpallets/gateway/bitcoin/src/tests/mock.rs @@ -221,7 +221,8 @@ impl ExtBuilder { // let (genesis_info, genesis_hash, network_id) = load_mock_btc_genesis_header_info(); let genesis_hash = btc_genesis.0.hash(); let network_id = btc_network; - let _ = GenesisConfig { + let _ = GenesisConfig:: { + genesis_trustees: vec![], genesis_info: btc_genesis, genesis_hash, network_id, @@ -238,7 +239,7 @@ impl ExtBuilder { btc_withdrawal_fee: 500000, max_withdrawal_count: 100, } - .assimilate_storage::(&mut storage); + .assimilate_storage(&mut storage); let ext = sp_io::TestExternalities::new(storage); ext @@ -274,14 +275,30 @@ impl ExtBuilder { } .assimilate_storage(&mut storage); - let _ = xpallet_gateway_common::GenesisConfig:: { - trustees: trustees_info(), - } - .assimilate_storage(&mut storage); + let info = trustees_info(); + let genesis_trustees = info + .iter() + .find_map(|(chain, _, trustee_params)| { + if *chain == Chain::Bitcoin { + Some( + trustee_params + .iter() + .map(|i| (i.0).clone()) + .collect::>(), + ) + } else { + None + } + }) + .unwrap(); + + let _ = xpallet_gateway_common::GenesisConfig:: { trustees: info } + .assimilate_storage(&mut storage); let (genesis_info, genesis_hash, network_id) = load_mainnet_btc_genesis_header_info(); - let _ = GenesisConfig { + let _ = GenesisConfig:: { + genesis_trustees, genesis_info, genesis_hash, network_id, @@ -298,7 +315,7 @@ impl ExtBuilder { btc_withdrawal_fee: 500000, max_withdrawal_count: 100, } - .assimilate_storage::(&mut storage); + .assimilate_storage(&mut storage); let ext = sp_io::TestExternalities::new(storage); ext diff --git a/xpallets/gateway/common/rpc/src/lib.rs b/xpallets/gateway/common/rpc/src/lib.rs index 1423868b09b32..1fe2fa9cbf630 100644 --- a/xpallets/gateway/common/rpc/src/lib.rs +++ b/xpallets/gateway/common/rpc/src/lib.rs @@ -83,9 +83,7 @@ pub trait XGatewayCommonApi { /// A struct that implements the [`XStakingApi`]. pub struct XGatewayCommon { client: Arc, - _marker: std::marker::PhantomData, - _marker2: std::marker::PhantomData, - _marker3: std::marker::PhantomData, + _marker: std::marker::PhantomData<(B, AccountId, Balance)>, } impl XGatewayCommon { @@ -94,8 +92,6 @@ impl XGatewayCommon { Self { client, _marker: Default::default(), - _marker2: Default::default(), - _marker3: Default::default(), } } } diff --git a/xpallets/gateway/common/src/lib.rs b/xpallets/gateway/common/src/lib.rs index d00ae126a6947..feb2fa67be019 100644 --- a/xpallets/gateway/common/src/lib.rs +++ b/xpallets/gateway/common/src/lib.rs @@ -248,10 +248,9 @@ decl_storage! { .expect("setup trustee can not fail; qed"); trustees.push(who.clone()); } - // config set should before transitino + // config set should before transition TrusteeInfoConfigOf::insert(chain, info_config.clone()); - Module::::transition_trustee_session_impl(*chain, trustees) - .expect("trustee session transition can not fail; qed"); + // trustee init should happen in chain module like gateway_bitcoin/gateway_ethereum. } }) } diff --git a/xpallets/gateway/common/src/traits.rs b/xpallets/gateway/common/src/traits.rs index e42e493fa2a4c..624e767078803 100644 --- a/xpallets/gateway/common/src/traits.rs +++ b/xpallets/gateway/common/src/traits.rs @@ -47,6 +47,9 @@ pub trait TrusteeSession { fn last_trustee_session( ) -> result::Result, DispatchError>; + + #[cfg(feature = "std")] + fn genesis_trustee(chain: Chain, init: &[AccountId]); } impl TrusteeSession for () { @@ -65,6 +68,9 @@ impl TrusteeSession result::Result, DispatchError> { Err("NoTrustee".into()) } + + #[cfg(feature = "std")] + fn genesis_trustee(_: Chain, _: &[AccountId]) {} } pub trait ChannelBinding { diff --git a/xpallets/gateway/common/src/trustees/mod.rs b/xpallets/gateway/common/src/trustees/mod.rs index 6c6ac0ba14e0b..6e0cc0969fc3a 100644 --- a/xpallets/gateway/common/src/trustees/mod.rs +++ b/xpallets/gateway/common/src/trustees/mod.rs @@ -67,6 +67,12 @@ impl e }) } + + #[cfg(feature = "std")] + fn genesis_trustee(chain: Chain, trustees: &[T::AccountId]) { + Module::::transition_trustee_session_impl(chain, trustees.to_vec()) + .expect("trustee session transition can not fail; qed"); + } } pub struct TrusteeMultisigProvider(PhantomData, PhantomData); diff --git a/xpallets/gateway/common/tests/mock.rs b/xpallets/gateway/common/tests/mock.rs index 114f32ce4caa5..d6891c7a72cb8 100644 --- a/xpallets/gateway/common/tests/mock.rs +++ b/xpallets/gateway/common/tests/mock.rs @@ -237,7 +237,8 @@ impl ExtBuilder { let (genesis_info, genesis_hash, network_id) = load_mainnet_btc_genesis_header_info(); - let _ = xpallet_gateway_bitcoin::GenesisConfig { + let _ = xpallet_gateway_bitcoin::GenesisConfig:: { + genesis_trustees: vec![], genesis_info, genesis_hash, network_id, @@ -254,7 +255,7 @@ impl ExtBuilder { btc_withdrawal_fee: 500000, max_withdrawal_count: 100, } - .assimilate_storage::(&mut storage); + .assimilate_storage(&mut storage); let _ = xpallet_gateway_common::GenesisConfig:: { trustees: trustees(),