Skip to content

Commit

Permalink
chore: create testnet and mainnet runtime (#324)
Browse files Browse the repository at this point in the history
* chore: remove standalone folder

* split to two runtimes

* everything compiles

* everything compiles

* split to chainspects

* remove legacy pallets

* cleanup pallets

* merge fixes
  • Loading branch information
1xstj authored Nov 30, 2023
1 parent c5d21b7 commit 41a2e90
Show file tree
Hide file tree
Showing 39 changed files with 6,056 additions and 1,585 deletions.
3,678 changes: 2,318 additions & 1,360 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ members = [
"client/rpc-core/*",
"client/voter",
"node",
"runtime",
"runtime/evm_tracer",
"runtime/testnet",
"runtime/testnet/evm_tracer",
"runtime/mainnet",
"pallets/*",
"pallets/roles",
"pallets/jobs/rpc",
Expand Down Expand Up @@ -80,7 +81,8 @@ dkg-primitives = { git = "https://github.com/webb-tools/dkg-substrate.git", tag
webb-relayer-gadget = { git = "https://github.com/webb-tools/dkg-substrate.git", tag = "v0.4.7" }
webb-relayer-gadget-cli = { git = "https://github.com/webb-tools/dkg-substrate.git", tag = "v0.4.7" }

tangle-runtime = { package = "tangle-standalone-runtime", path = "runtime" }
tangle-testnet-runtime = { package = "tangle-testnet-runtime", path = "runtime/testnet" }
tangle-mainnet-runtime = { package = "tangle-mainnet-runtime", path = "runtime/mainnet" }

# Tangle Dependencies
pallet-ecdsa-claims = { path = "pallets/claims", default-features = false }
Expand Down Expand Up @@ -307,7 +309,7 @@ rpc-core-types = { path = "client/rpc-core/types" }
rpc-debug = { path = "client/rpc/debug" }
rpc-trace = { path = "client/rpc/trace" }
rpc-txpool = { path = "client/rpc/txpool" }
evm-tracer = { path = "runtime/evm_tracer", default-features = false }
evm-tracer = { path = "runtime/testnet/evm_tracer", default-features = false }

[profile.release]
panic = "unwind"
12 changes: 7 additions & 5 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,16 @@ rpc-primitives-txpool = { workspace = true }
rpc-trace = { workspace = true }
rpc-txpool = { workspace = true }

tangle-runtime = { workspace = true }
tangle-primitives = { workspace = true }
tangle-testnet-runtime = { workspace = true }
tangle-mainnet-runtime = { workspace = true }

[features]
default = ["with-rocksdb-weights", "rocksdb", "sql"]
runtime-benchmarks = ["tangle-runtime/runtime-benchmarks"]
integration-tests = ["tangle-runtime/integration-tests"]
with-rocksdb-weights = ["tangle-runtime/with-rocksdb-weights"]
with-paritydb-weights = ["tangle-runtime/with-paritydb-weights"]
runtime-benchmarks = ["tangle-testnet-runtime/runtime-benchmarks"]
integration-tests = ["tangle-testnet-runtime/integration-tests"]
with-rocksdb-weights = ["tangle-testnet-runtime/with-rocksdb-weights"]
with-paritydb-weights = ["tangle-testnet-runtime/with-paritydb-weights"]
rocksdb = [
"sc-cli/rocksdb",
"sc-service/rocksdb",
Expand Down
2 changes: 1 addition & 1 deletion node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sp_inherents::{InherentData, InherentDataProvider};
use sp_keyring::Sr25519Keyring;
use sp_runtime::OpaqueExtrinsic;
use std::{sync::Arc, time::Duration};
use tangle_runtime::{AccountId, Balance, BalancesCall, SystemCall};
use tangle_testnet_runtime::{AccountId, Balance, BalancesCall, SystemCall};

/// Generates `System::Remark` extrinsics for the benchmarks.
///
Expand Down
168 changes: 4 additions & 164 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
// 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.

use std::{collections::BTreeMap, marker::PhantomData};

use crate::{
distributions::{combine_distributions, develop, mainnet, testnet},
distributions::{combine_distributions, develop, testnet},
testnet_fixtures::{
get_standalone_bootnodes, get_standalone_initial_authorities, get_testnet_root_key,
},
Expand All @@ -28,7 +27,7 @@ use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{sr25519, Pair, Public, H160};
use sp_runtime::traits::{IdentifyAccount, Verify};
use tangle_runtime::{
use tangle_testnet_runtime::{
AccountId, Balance, BalancesConfig, DKGConfig, DKGId, DKGProposalsConfig, EVMChainIdConfig,
EVMConfig, ElectionsConfig, Eth2ClientConfig, ImOnlineConfig, MaxNominations, Perbill,
RuntimeGenesisConfig, SessionConfig, Signature, StakerStatus, StakingConfig, SudoConfig,
Expand Down Expand Up @@ -103,8 +102,8 @@ fn dkg_session_keys(
aura: AuraId,
im_online: ImOnlineId,
dkg: DKGId,
) -> tangle_runtime::opaque::SessionKeys {
tangle_runtime::opaque::SessionKeys { grandpa, aura, dkg, im_online }
) -> tangle_testnet_runtime::opaque::SessionKeys {
tangle_testnet_runtime::opaque::SessionKeys { grandpa, aura, dkg, im_online }
}

pub fn local_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
Expand Down Expand Up @@ -263,71 +262,6 @@ pub fn tangle_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
))
}

pub fn tangle_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "tangle wasm not available".to_string())?;
let boot_nodes = get_standalone_bootnodes();
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());

Ok(ChainSpec::from_genesis(
"Tangle Mainnet",
"tangle-mainnet",
ChainType::Live,
move || {
mainnet_genesis(
wasm_binary,
// Initial PoA authorities
vec![
authority_keys_from_seed("Alice", "Alice//stash"),
authority_keys_from_seed("Bob", "Bob//stash"),
authority_keys_from_seed("Charlie", "Charlie//stash"),
authority_keys_from_seed("Dave", "Dave//stash"),
authority_keys_from_seed("Eve", "Eve//stash"),
],
// Sudo account
get_testnet_root_key(),
// Pre-funded accounts
vec![
get_testnet_root_key(),
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"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
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"),
],
chain_id,
combine_distributions(vec![
mainnet::get_edgeware_genesis_balance_distribution(),
mainnet::get_leaderboard_balance_distribution(),
]),
mainnet::get_substrate_balance_distribution(),
true,
)
},
// Bootnodes
boot_nodes,
// Telemetry
None,
// Protocol ID
None,
// Fork id
None,
// Properties
Some(properties),
// Extensions
None,
))
}

/// Configure initial storage state for FRAME modules.
#[allow(clippy::too_many_arguments)]
fn testnet_genesis(
Expand Down Expand Up @@ -455,97 +389,3 @@ fn testnet_genesis(
base_fee: Default::default(),
}
}

/// Configure initial storage state for FRAME modules.
#[allow(clippy::too_many_arguments)]
fn mainnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AccountId, AccountId, AuraId, GrandpaId, ImOnlineId, DKGId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
chain_id: u64,
_genesis_evm_distribution: Vec<(H160, fp_evm::GenesisAccount)>,
genesis_substrate_distribution: Vec<(AccountId, Balance)>,
_enable_println: bool,
) -> RuntimeGenesisConfig {
const ENDOWMENT: Balance = 100 * UNIT;
const STASH: Balance = ENDOWMENT / 100;

// stakers: all validators and nominators.
let _rng = rand::thread_rng();
let stakers = initial_authorities
.iter()
.map(|x| (x.0.clone(), x.0.clone(), STASH, StakerStatus::Validator))
.collect();

RuntimeGenesisConfig {
system: SystemConfig {
// Add Wasm runtime to storage.
code: wasm_binary.to_vec(),
..Default::default()
},
sudo: SudoConfig { key: Some(root_key) },
balances: BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, ENDOWMENT))
.chain(genesis_substrate_distribution.iter().cloned().map(|(k, v)| (k, v)))
.collect(),
},
vesting: Default::default(),
indices: Default::default(),
session: SessionConfig {
keys: initial_authorities
.iter()
.map(|x| {
(
x.1.clone(),
x.0.clone(),
dkg_session_keys(x.3.clone(), x.2.clone(), x.4.clone(), x.5.clone()),
)
})
.collect::<Vec<_>>(),
},
staking: StakingConfig {
validator_count: initial_authorities.len() as u32,
minimum_validator_count: initial_authorities.len() as u32 - 1,
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
slash_reward_fraction: Perbill::from_percent(10),
stakers,
..Default::default()
},
democracy: Default::default(),
council: Default::default(),
elections: Default::default(),
treasury: Default::default(),
aura: Default::default(),
grandpa: Default::default(),
im_online: ImOnlineConfig { keys: vec![] },
nomination_pools: Default::default(),
transaction_payment: Default::default(),
// EVM compatibility
evm_chain_id: EVMChainIdConfig { chain_id, ..Default::default() },
evm: Default::default(),
ethereum: Default::default(),
dynamic_fee: Default::default(),
base_fee: Default::default(),
// ETH2 light client
eth_2_client: Eth2ClientConfig {
networks: vec![(
webb_proposals::TypedChainId::Evm(1),
NetworkConfig::new(&Network::Mainnet),
)],
phantom: PhantomData,
},
// TODO: Remove these pallets and re-architect for mainnet
dkg: DKGConfig {
authorities: initial_authorities.iter().map(|(.., x)| x.clone()).collect::<_>(),
keygen_threshold: 2,
signature_threshold: 1,
authority_ids: initial_authorities.iter().map(|(x, ..)| x.clone()).collect::<_>(),
},
dkg_proposals: Default::default(),
bridge_registry: Default::default(),
}
}
Loading

0 comments on commit 41a2e90

Please sign in to comment.