Skip to content

Commit

Permalink
feat: set address prefixes (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
1xstj authored Jan 4, 2024
1 parent a89445d commit a2acee0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tangle"
build = "build.rs"
description = "Tangle Standalone chain node"
description = "Tangle chain node"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
Expand Down
7 changes: 5 additions & 2 deletions node/src/chainspec/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn local_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "TNT".into());
properties.insert("tokenDecimals".into(), 18u32.into());
properties.insert("ss58Format".into(), 4006.into());
properties.insert("ss58Format".into(), tangle_primitives::MAINNET_SS58_PREFIX.into());

Ok(ChainSpec::from_genesis(
"Local Tangle Mainnet",
Expand All @@ -112,6 +112,9 @@ pub fn local_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
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>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
Expand Down Expand Up @@ -151,7 +154,7 @@ pub fn tangle_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "TNT".into());
properties.insert("tokenDecimals".into(), 18u32.into());
properties.insert("ss58Format".into(), 4006.into());
properties.insert("ss58Format".into(), tangle_primitives::MAINNET_SS58_PREFIX.into());

Ok(ChainSpec::from_genesis(
"Tangle Mainnet",
Expand Down
41 changes: 14 additions & 27 deletions node/src/chainspec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ use tangle_crypto_primitives::crypto::AuthorityId as RoleKeyId;
use tangle_primitives::types::BlockNumber;
use tangle_testnet_runtime::{
AccountId, BabeConfig, Balance, BalancesConfig, ClaimsConfig, EVMChainIdConfig, EVMConfig,
ElectionsConfig, Eth2ClientConfig, ImOnlineConfig, MaxNominations, MaxVestingSchedules,
Perbill, RuntimeGenesisConfig, SessionConfig, Signature, StakerStatus, StakingConfig,
SudoConfig, SystemConfig, TreasuryPalletId, UNIT, WASM_BINARY,
ElectionsConfig, Eth2ClientConfig, ImOnlineConfig, MaxVestingSchedules, Perbill,
RuntimeGenesisConfig, SessionConfig, Signature, StakerStatus, StakingConfig, SudoConfig,
SystemConfig, TreasuryPalletId, UNIT, WASM_BINARY,
};
use webb_consensus_types::network_config::{Network, NetworkConfig};

Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn local_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "tTNT".into());
properties.insert("tokenDecimals".into(), 18u32.into());
properties.insert("ss58Format".into(), 42.into());
properties.insert("ss58Format".into(), tangle_primitives::TESTNET_SS58_PREFIX.into());

Ok(ChainSpec::from_genesis(
// Name
Expand Down Expand Up @@ -124,11 +124,8 @@ pub fn local_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
get_account_id_from_seed::<sr25519::Public>("Eve"),
],
chain_id,
combine_distributions(vec![
develop::get_evm_balance_distribution(),
testnet::get_evm_balance_distribution(),
]),
testnet::get_substrate_balance_distribution(),
vec![],
vec![],
true,
)
},
Expand All @@ -153,12 +150,12 @@ pub fn tangle_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "tTNT".into());
properties.insert("tokenDecimals".into(), 18u32.into());
properties.insert("ss58Format".into(), 42.into());
properties.insert("ss58Format".into(), tangle_primitives::TESTNET_SS58_PREFIX.into());

Ok(ChainSpec::from_genesis(
"Tangle Standalone Testnet",
"Tangle Testnet",
"tangle-testnet",
ChainType::Development,
ChainType::Live,
move || {
testnet_genesis(
wasm_binary,
Expand Down Expand Up @@ -225,7 +222,7 @@ pub fn tangle_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
fn testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AccountId, BabeId, GrandpaId, ImOnlineId, RoleKeyId)>,
initial_nominators: Vec<AccountId>,
_initial_nominators: Vec<AccountId>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
chain_id: u64,
Expand All @@ -237,22 +234,12 @@ fn testnet_genesis(
const STASH: Balance = ENDOWMENT / 100;

// stakers: all validators and nominators.
let mut rng = rand::thread_rng();
let _rng = rand::thread_rng();
// stakers: all validators and nominators.
let stakers = initial_authorities
.iter()
.map(|x| (x.0.clone(), x.0.clone(), STASH, StakerStatus::Validator))
.chain(initial_nominators.iter().map(|x| {
use rand::{seq::SliceRandom, Rng};
let limit = (MaxNominations::get() as usize).min(initial_authorities.len());
let count = rng.gen::<usize>() % limit;
let nominations = initial_authorities
.as_slice()
.choose_multiple(&mut rng, count)
.map(|choice| choice.0.clone())
.collect::<Vec<_>>();
(x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations))
}))
.collect::<Vec<_>>();
.map(|x| (x.0.clone(), x.0.clone(), UNIT, StakerStatus::Validator))
.collect();

let num_endowed_accounts = endowed_accounts.len();
let claims: Vec<(MultiAddress, Balance, Option<StatementKind>)> = endowed_accounts
Expand Down
8 changes: 8 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,11 @@ pub const MAXIMUM_BLOCK_WEIGHT: Weight =
Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, MAX_POV_SIZE as u64);

pub use sp_consensus_babe::AuthorityId as BabeId;

// 5845 this would give us addresses with tg prefix for mainnet like
// tgGmBRR5yM53bvq8tTzgsUirpPtfCXngYYU7uiihmWFJhmYGM
pub const MAINNET_SS58_PREFIX: u16 = 5845;

// 3799 this would give us addresses with tt prefix for testnet like
// ttFELSU4MTyzpfsgZ9tFinrmox7pV7nF1BLbfYjsu4rfDYM74
pub const TESTNET_SS58_PREFIX: u16 = 3799;
2 changes: 1 addition & 1 deletion runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ parameter_types! {
::with_sensible_defaults(MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(MAXIMUM_BLOCK_LENGTH, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u8 = 42;
pub const SS58Prefix: u16 = tangle_primitives::MAINNET_SS58_PREFIX;
}

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
Expand Down
2 changes: 1 addition & 1 deletion runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ parameter_types! {
::with_sensible_defaults(MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(MAXIMUM_BLOCK_LENGTH, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u8 = 42;
pub const SS58Prefix: u16 = tangle_primitives::TESTNET_SS58_PREFIX;
}

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
Expand Down

0 comments on commit a2acee0

Please sign in to comment.