Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
backport minor refactoring PR #223
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinfernandez1 committed Jun 12, 2023
1 parent c85ad9f commit fa25d2d
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 61 deletions.
2 changes: 1 addition & 1 deletion node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Extensions {

/// Helper function to generate a crypto pair from seed
pub fn get_public_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
TPublic::Pair::from_string(&format!("//{seed}"), None)
.expect("static values are valid; qed")
.public()
}
Expand Down
6 changes: 3 additions & 3 deletions node/src/chain_spec/stout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ fn testnet_genesis(
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
balances: endowed_accounts.into_iter().map(|k| (k, 1 << 60)).collect(),
},
parachain_info: stout_runtime::ParachainInfoConfig { parachain_id: id },
collator_selection: stout_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
invulnerables: invulnerables.iter().map(|(acc, _)| acc).cloned().collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
..Default::default()
},
Expand Down Expand Up @@ -146,7 +146,7 @@ fn testnet_genesis(
},
assets: AssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] },
council: CouncilConfig {
members: invulnerables.iter().map(|x| x.0.clone()).collect::<Vec<_>>(),
members: invulnerables.into_iter().map(|x| x.0).collect::<Vec<_>>(),
phantom: Default::default(),
},
dex: Default::default(),
Expand Down
29 changes: 11 additions & 18 deletions node/src/chain_spec/trappist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ pub fn testnet_genesis(
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
balances: endowed_accounts.into_iter().map(|k| (k, 1 << 60)).collect(),
},
parachain_info: trappist_runtime::ParachainInfoConfig { parachain_id: id },
collator_selection: trappist_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
invulnerables: invulnerables.iter().map(|(acc, _)| acc).cloned().collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
..Default::default()
},
Expand Down Expand Up @@ -202,7 +202,7 @@ pub fn testnet_genesis(
},
assets: AssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] },
council: CouncilConfig {
members: invulnerables.iter().map(|x| x.0.clone()).collect::<Vec<_>>(),
members: invulnerables.into_iter().map(|x| x.0).collect::<Vec<_>>(),
phantom: Default::default(),
},
treasury: Default::default(),
Expand Down Expand Up @@ -276,32 +276,25 @@ fn trappist_live_genesis(
balances: BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.chain(std::iter::once(root_key.clone()))
.map(|k| {
if k == root_key {
(k, 1_000_000_000_000_000_000)
} else {
(k, 1_500_000_000_000_000_000)
}
})
.map(|x| (x.clone(), 1_500_000_000_000_000_000))
.chain(std::iter::once((root_key.clone(), 1_000_000_000_000_000_000)))
.collect(),
},
parachain_info: trappist_runtime::ParachainInfoConfig { parachain_id: id },
collator_selection: trappist_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
invulnerables: invulnerables.iter().map(|(acc, _)| acc).cloned().collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
..Default::default()
},
democracy: Default::default(),
session: SessionConfig {
keys: invulnerables
.iter()
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc.clone(), // validator id
session_keys(aura.clone()), // session keys
acc.clone(), // account id
acc, // validator id
session_keys(aura), // session keys
)
})
.collect(),
Expand All @@ -319,7 +312,7 @@ fn trappist_live_genesis(
assets: AssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] },
council: CouncilConfig {
// We set the endowed accounts with balance as members of the council.
members: endowed_accounts.iter().map(|x| x.clone()).collect::<Vec<_>>(),
members: endowed_accounts,
phantom: Default::default(),
},
treasury: Default::default(),
Expand Down
2 changes: 2 additions & 0 deletions node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Trappist Node CLI.
#![warn(missing_docs)]
#![warn(unused_extern_crates)]

Expand Down
38 changes: 21 additions & 17 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,37 +712,41 @@ where
<<AuraId as AppKey>::Pair as Pair>::Signature:
TryFrom<Vec<u8>> + std::hash::Hash + sp_runtime::traits::Member + Codec,
{
let client2 = client.clone();
let aura_verifier = {
let client = client.clone();

let aura_verifier = move || {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client2).unwrap();
move || {
let slot_duration =
cumulus_client_consensus_aura::slot_duration(client.as_ref()).unwrap();

Box::new(
cumulus_client_consensus_aura::build_verifier::<<AuraId as AppKey>::Pair, _, _, _>(
cumulus_client_consensus_aura::BuildVerifierParams {
client: client2.clone(),
create_inherent_data_providers: move |_, _| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
Box::new(cumulus_client_consensus_aura::build_verifier::<
<AuraId as AppKey>::Pair,
_,
_,
_,
>(cumulus_client_consensus_aura::BuildVerifierParams {
client,
create_inherent_data_providers: move |_, _| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

let slot =
let slot =
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);

Ok((slot, timestamp))
},
telemetry: telemetry_handle,
Ok((slot, timestamp))
},
),
) as Box<_>
telemetry: telemetry_handle,
})) as Box<_>
}
};

let relay_chain_verifier =
Box::new(RelayChainVerifier::new(client.clone(), |_, _| async { Ok(()) })) as Box<_>;
Box::new(RelayChainVerifier::new(client.clone(), |_, _| async { Ok(()) }));

let verifier = Verifier {
client: client.clone(),
client,
relay_chain_verifier,
aura_verifier: BuildOnAccess::Uninitialized(Some(Box::new(aura_verifier))),
_phantom: PhantomData,
Expand Down
8 changes: 2 additions & 6 deletions pallets/lockdown-mode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {
LockdownModeStatus::<T>::put(&self.initial_status);
LockdownModeStatus::<T>::put(self.initial_status);
}
}

Expand Down Expand Up @@ -148,11 +148,7 @@ pub mod pallet {

impl<T: Config> Contains<T::RuntimeCall> for Pallet<T> {
fn contains(call: &T::RuntimeCall) -> bool {
if LockdownModeStatus::<T>::get() {
T::BlackListedCalls::contains(call)
} else {
return true
}
!LockdownModeStatus::<T>::get() || T::BlackListedCalls::contains(call)
}
}

Expand Down
7 changes: 4 additions & 3 deletions runtime/trappist/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ pub mod currency {

/// Fee-related.
pub mod fee {
use super::currency::CENTS;
use frame_support::weights::{
constants::{ExtrinsicBaseWeight, WEIGHT_REF_TIME_PER_SECOND},
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
constants::{ExtrinsicBaseWeight, WEIGHT_REF_TIME_PER_SECOND}, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
};
use polkadot_core_primitives::Balance;
use smallvec::smallvec;
pub use sp_runtime::Perbill;

use super::currency::CENTS;

/// The block saturation level. Fees will be updates based on this value.
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);

Expand Down
23 changes: 11 additions & 12 deletions runtime/trappist/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,17 @@ where
pub struct RuntimeBlackListedCalls;
impl Contains<RuntimeCall> for RuntimeBlackListedCalls {
fn contains(call: &RuntimeCall) -> bool {
match call {
RuntimeCall::Balances(_) => false,
RuntimeCall::Assets(_) => false,
RuntimeCall::Dex(_) => false,
RuntimeCall::PolkadotXcm(_) => false,
RuntimeCall::Treasury(_) => false,
RuntimeCall::Chess(_) => false,
RuntimeCall::Contracts(_) => false,
RuntimeCall::Uniques(_) => false,
RuntimeCall::AssetRegistry(_) => false,
_ => true,
}
!matches!(
call,
RuntimeCall::Balances(_) |
RuntimeCall::Assets(_) |
RuntimeCall::Dex(_) |
RuntimeCall::PolkadotXcm(_) |
RuntimeCall::Treasury(_) |
RuntimeCall::Contracts(_) |
RuntimeCall::Uniques(_) |
RuntimeCall::AssetRegistry(_)
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion templates/file_header.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
// 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.
// limitations under the License.

0 comments on commit fa25d2d

Please sign in to comment.