Skip to content

Commit

Permalink
Change account names to something meaningful (paritytech#1497)
Browse files Browse the repository at this point in the history
* change testnets account "names" to something meaningful

* fixes

* fix doc

* fmt

* account names as consts

* fmt

* spelling
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent cabd207 commit 34f4700
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 151 deletions.
127 changes: 58 additions & 69 deletions bridges/bin/millau/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.

use beefy_primitives::crypto::AuthorityId as BeefyId;
use bp_millau::derive_account_from_rialto_id;
use millau_runtime::{
AccountId, AuraConfig, BalancesConfig, BeefyConfig, BridgeRialtoMessagesConfig,
BridgeRialtoParachainMessagesConfig, BridgeWestendGrandpaConfig, GenesisConfig, GrandpaConfig,
Expand All @@ -26,6 +25,21 @@ use sp_core::{sr25519, Pair, Public};
use sp_finality_grandpa::AuthorityId as GrandpaId;
use sp_runtime::traits::{IdentifyAccount, Verify};

/// "Names" of the authorities accounts at local testnet.
const LOCAL_AUTHORITIES_ACCOUNTS: [&str; 5] = ["Alice", "Bob", "Charlie", "Dave", "Eve"];
/// "Names" of the authorities accounts at development testnet.
const DEV_AUTHORITIES_ACCOUNTS: [&str; 1] = [LOCAL_AUTHORITIES_ACCOUNTS[0]];
/// "Names" of all possible authorities accounts.
const ALL_AUTHORITIES_ACCOUNTS: [&str; 5] = LOCAL_AUTHORITIES_ACCOUNTS;
/// "Name" of the `sudo` account.
const SUDO_ACCOUNT: &str = "Sudo";
/// "Name" of the account, which owns the with-Westend GRANDPA pallet.
const WESTEND_GRANDPA_PALLET_OWNER: &str = "Westend.GrandpaOwner";
/// "Name" of the account, which owns the with-Rialto messages pallet.
const RIALTO_MESSAGES_PALLET_OWNER: &str = "Rialto.MessagesOwner";
/// "Name" of the account, which owns the with-RialtoParachain messages pallet.
const RIALTO_PARACHAIN_MESSAGES_PALLET_OWNER: &str = "RialtoParachain.MessagesOwner";

/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;

Expand Down Expand Up @@ -86,8 +100,11 @@ impl Alternative {
sc_service::ChainType::Development,
|| {
testnet_genesis(
vec![get_authority_keys_from_seed("Alice")],
get_account_id_from_seed::<sr25519::Public>("Alice"),
DEV_AUTHORITIES_ACCOUNTS
.into_iter()
.map(get_authority_keys_from_seed)
.collect(),
get_account_id_from_seed::<sr25519::Public>(SUDO_ACCOUNT),
endowed_accounts(),
true,
)
Expand All @@ -105,14 +122,11 @@ impl Alternative {
sc_service::ChainType::Local,
|| {
testnet_genesis(
vec![
get_authority_keys_from_seed("Alice"),
get_authority_keys_from_seed("Bob"),
get_authority_keys_from_seed("Charlie"),
get_authority_keys_from_seed("Dave"),
get_authority_keys_from_seed("Eve"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
LOCAL_AUTHORITIES_ACCOUNTS
.into_iter()
.map(get_authority_keys_from_seed)
.collect(),
get_account_id_from_seed::<sr25519::Public>(SUDO_ACCOUNT),
endowed_accounts(),
true,
)
Expand All @@ -133,56 +147,39 @@ impl Alternative {
/// accounts used by relayers in our test deployments, accounts used for demonstration
/// purposes), are all available on these chains.
fn endowed_accounts() -> Vec<AccountId> {
let all_authorities = ALL_AUTHORITIES_ACCOUNTS.iter().flat_map(|x| {
[
get_account_id_from_seed::<sr25519::Public>(x),
get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", x)),
]
});
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
// Sudo account
get_account_id_from_seed::<sr25519::Public>(SUDO_ACCOUNT),
// Regular (unused) accounts
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("George"),
get_account_id_from_seed::<sr25519::Public>("Harry"),
get_account_id_from_seed::<sr25519::Public>("Iden"),
get_account_id_from_seed::<sr25519::Public>("Ken"),
get_account_id_from_seed::<sr25519::Public>("Leon"),
get_account_id_from_seed::<sr25519::Public>("Mary"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
get_account_id_from_seed::<sr25519::Public>("George//stash"),
get_account_id_from_seed::<sr25519::Public>("Harry//stash"),
get_account_id_from_seed::<sr25519::Public>("Iden//stash"),
get_account_id_from_seed::<sr25519::Public>("Ken//stash"),
get_account_id_from_seed::<sr25519::Public>("Leon//stash"),
get_account_id_from_seed::<sr25519::Public>("Mary//stash"),
get_account_id_from_seed::<sr25519::Public>("RialtoMessagesOwner"),
get_account_id_from_seed::<sr25519::Public>("RialtoParachainMessagesOwner"),
pallet_bridge_messages::relayer_fund_account_id::<
bp_millau::AccountId,
bp_millau::AccountIdConverter,
>(),
derive_account_from_rialto_id(bp_runtime::SourceAccount::Account(
get_account_id_from_seed::<sr25519::Public>("Alice"),
)),
derive_account_from_rialto_id(bp_runtime::SourceAccount::Account(
get_account_id_from_seed::<sr25519::Public>("Bob"),
)),
derive_account_from_rialto_id(bp_runtime::SourceAccount::Account(
get_account_id_from_seed::<sr25519::Public>("Charlie"),
)),
derive_account_from_rialto_id(bp_runtime::SourceAccount::Account(
get_account_id_from_seed::<sr25519::Public>("Dave"),
)),
derive_account_from_rialto_id(bp_runtime::SourceAccount::Account(
get_account_id_from_seed::<sr25519::Public>("Eve"),
)),
derive_account_from_rialto_id(bp_runtime::SourceAccount::Account(
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
)),
// Accounts, used by Westend<>Millau bridge
get_account_id_from_seed::<sr25519::Public>(WESTEND_GRANDPA_PALLET_OWNER),
get_account_id_from_seed::<sr25519::Public>("Westend.HeadersRelay1"),
get_account_id_from_seed::<sr25519::Public>("Westend.HeadersRelay2"),
get_account_id_from_seed::<sr25519::Public>("Westend.WestmintHeaders1"),
get_account_id_from_seed::<sr25519::Public>("Westend.WestmintHeaders2"),
// Accounts, used by Rialto<>Millau bridge
get_account_id_from_seed::<sr25519::Public>(RIALTO_MESSAGES_PALLET_OWNER),
get_account_id_from_seed::<sr25519::Public>("Rialto.HeadersAndMessagesRelay"),
get_account_id_from_seed::<sr25519::Public>("Rialto.OutboundMessagesRelay.Lane00000001"),
get_account_id_from_seed::<sr25519::Public>("Rialto.InboundMessagesRelay.Lane00000001"),
get_account_id_from_seed::<sr25519::Public>("Rialto.MessagesSender"),
// Accounts, used by RialtoParachain<>Millau bridge
get_account_id_from_seed::<sr25519::Public>(RIALTO_PARACHAIN_MESSAGES_PALLET_OWNER),
get_account_id_from_seed::<sr25519::Public>("RialtoParachain.HeadersAndMessagesRelay"),
get_account_id_from_seed::<sr25519::Public>("RialtoParachain.RialtoHeadersRelay"),
get_account_id_from_seed::<sr25519::Public>("RialtoParachain.MessagesSender"),
]
.into_iter()
.chain(all_authorities)
.collect()
}

fn session_keys(aura: AuraId, beefy: BeefyId, grandpa: GrandpaId) -> SessionKeys {
Expand Down Expand Up @@ -217,28 +214,20 @@ fn testnet_genesis(
bridge_westend_grandpa: BridgeWestendGrandpaConfig {
// for our deployments to avoid multiple same-nonces transactions:
// //Alice is already used to initialize Rialto<->Millau bridge
// => let's use //George to initialize Westend->Millau bridge
owner: Some(get_account_id_from_seed::<sr25519::Public>("George")),
// => let's use //Westend.GrandpaOwner to initialize Westend->Millau bridge
owner: Some(get_account_id_from_seed::<sr25519::Public>(WESTEND_GRANDPA_PALLET_OWNER)),
..Default::default()
},
bridge_rialto_messages: BridgeRialtoMessagesConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>("RialtoMessagesOwner")),
owner: Some(get_account_id_from_seed::<sr25519::Public>(RIALTO_MESSAGES_PALLET_OWNER)),
..Default::default()
},
bridge_rialto_parachain_messages: BridgeRialtoParachainMessagesConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>(
"RialtoParachainMessagesOwner",
RIALTO_PARACHAIN_MESSAGES_PALLET_OWNER,
)),
..Default::default()
},
xcm_pallet: Default::default(),
}
}

#[test]
fn derived_dave_account_is_as_expected() {
let dave = get_account_id_from_seed::<sr25519::Public>("Dave");
let derived: AccountId =
derive_account_from_rialto_id(bp_runtime::SourceAccount::Account(dave));
assert_eq!(derived.to_string(), "5DNW6UVnb7TN6wX5KwXtDYR3Eccecbdzuw89HqjyNfkzce6J".to_string());
}
54 changes: 38 additions & 16 deletions bridges/bin/rialto-parachain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

/// "Names" of the authorities accounts at local testnet.
const LOCAL_AUTHORITIES_ACCOUNTS: [&str; 2] = ["Alice", "Bob"];
/// "Names" of the authorities accounts at development testnet.
const DEV_AUTHORITIES_ACCOUNTS: [&str; 2] = LOCAL_AUTHORITIES_ACCOUNTS;
/// "Names" of all possible authorities accounts.
const ALL_AUTHORITIES_ACCOUNTS: [&str; 2] = LOCAL_AUTHORITIES_ACCOUNTS;
/// "Name" of the `sudo` account.
const SUDO_ACCOUNT: &str = "Sudo";
/// "Name" of the account, which owns the with-Millau messages pallet.
const MILLAU_MESSAGES_PALLET_OWNER: &str = "Millau.MessagesOwner";

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec =
sc_service::GenericChainSpec<rialto_parachain_runtime::GenesisConfig, Extensions>;
Expand Down Expand Up @@ -67,27 +78,32 @@ where
/// accounts used by relayers in our test deployments, accounts used for demonstration
/// purposes), are all available on these chains.
fn endowed_accounts() -> Vec<AccountId> {
let all_authorities = ALL_AUTHORITIES_ACCOUNTS.iter().flat_map(|x| {
[
get_account_id_from_seed::<sr25519::Public>(x),
get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", x)),
]
});
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
// Sudo account
get_account_id_from_seed::<sr25519::Public>(SUDO_ACCOUNT),
// Regular (unused) accounts
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("George"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
get_account_id_from_seed::<sr25519::Public>("George//stash"),
get_account_id_from_seed::<sr25519::Public>("MillauMessagesOwner"),
pallet_bridge_messages::relayer_fund_account_id::<
bp_rialto_parachain::AccountId,
bp_rialto_parachain::AccountIdConverter,
>(),
// Accounts, used by RialtoParachain<>Millau bridge
get_account_id_from_seed::<sr25519::Public>(MILLAU_MESSAGES_PALLET_OWNER),
get_account_id_from_seed::<sr25519::Public>("Millau.HeadersAndMessagesRelay"),
get_account_id_from_seed::<sr25519::Public>("Millau.MessagesSender"),
]
.into_iter()
.chain(all_authorities)
.collect()
}

pub fn development_config(id: ParaId) -> ChainSpec {
Expand All @@ -104,8 +120,11 @@ pub fn development_config(id: ParaId) -> ChainSpec {
ChainType::Local,
move || {
testnet_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![get_from_seed::<AuraId>("Alice"), get_from_seed::<AuraId>("Bob")],
get_account_id_from_seed::<sr25519::Public>(SUDO_ACCOUNT),
DEV_AUTHORITIES_ACCOUNTS
.into_iter()
.map(|x| get_from_seed::<AuraId>(x))
.collect(),
endowed_accounts(),
id,
)
Expand Down Expand Up @@ -136,8 +155,11 @@ pub fn local_testnet_config(id: ParaId) -> ChainSpec {
ChainType::Local,
move || {
testnet_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![get_from_seed::<AuraId>("Alice"), get_from_seed::<AuraId>("Bob")],
get_account_id_from_seed::<sr25519::Public>(SUDO_ACCOUNT),
LOCAL_AUTHORITIES_ACCOUNTS
.into_iter()
.map(|x| get_from_seed::<AuraId>(x))
.collect(),
endowed_accounts(),
id,
)
Expand Down Expand Up @@ -174,7 +196,7 @@ fn testnet_genesis(
aura: rialto_parachain_runtime::AuraConfig { authorities: initial_authorities },
aura_ext: Default::default(),
bridge_millau_messages: BridgeMillauMessagesConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>("MillauMessagesOwner")),
owner: Some(get_account_id_from_seed::<sr25519::Public>(MILLAU_MESSAGES_PALLET_OWNER)),
..Default::default()
},
}
Expand Down
Loading

0 comments on commit 34f4700

Please sign in to comment.