diff --git a/node/cli/src/chain_spec/mod.rs b/node/cli/src/chain_spec/mod.rs index a4fbc6bcc..1a6fab785 100644 --- a/node/cli/src/chain_spec/mod.rs +++ b/node/cli/src/chain_spec/mod.rs @@ -33,6 +33,7 @@ pub mod dev; pub mod integration_tests; +pub mod tdx_testnet; pub mod testnet; pub use entropy_runtime::{AccountId, RuntimeGenesisConfig, Signature}; diff --git a/node/cli/src/chain_spec/tdx_testnet.rs b/node/cli/src/chain_spec/tdx_testnet.rs new file mode 100644 index 000000000..9b1c8feeb --- /dev/null +++ b/node/cli/src/chain_spec/tdx_testnet.rs @@ -0,0 +1,88 @@ +// Copyright (C) 2023 Entropy Cryptography Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +use crate::chain_spec::{dev::development_genesis_config, get_account_id_from_seed, ChainSpec}; + +use entropy_runtime::wasm_binary_unwrap; +use entropy_shared::{BoundedVecEncodedVerifyingKey, X25519PublicKey as TssX25519PublicKey}; +use sc_service::ChainType; +use sp_core::sr25519; + +lazy_static::lazy_static! { + pub static ref PCK: BoundedVecEncodedVerifyingKey = vec![ + 2, 166, 103, 136, 58, 157, 155, 124, 186, 75, 81, 133, 87, 255, 233, 182, 192, 125, 235, 230, + 121, 173, 147, 108, 47, 190, 240, 181, 75, 181, 31, 148, 128, + ].try_into().unwrap(); +} + +fn tdx_devnet_four_node_initial_tss_servers( +) -> Vec<(sp_runtime::AccountId32, TssX25519PublicKey, String, BoundedVecEncodedVerifyingKey)> { + let tss_ip = std::env::var("ENTROPY_TESTNET_TSS_IP") + .expect("ENTROPY_TESTNET_TSS_IP environment variable to be set"); + + let alice = ( + crate::chain_spec::tss_account_id::ALICE.clone(), + crate::chain_spec::tss_x25519_public_key::ALICE, + format!("{tss_ip}:3001"), + PCK.clone(), + ); + + let bob = ( + crate::chain_spec::tss_account_id::BOB.clone(), + crate::chain_spec::tss_x25519_public_key::BOB, + format!("{tss_ip}:3002"), + PCK.clone(), + ); + + let charlie = ( + crate::chain_spec::tss_account_id::CHARLIE.clone(), + crate::chain_spec::tss_x25519_public_key::CHARLIE, + format!("{tss_ip}:3003"), + PCK.clone(), + ); + + let dave = ( + crate::chain_spec::tss_account_id::DAVE.clone(), + crate::chain_spec::tss_x25519_public_key::DAVE, + format!("{tss_ip}:3004"), + PCK.clone(), + ); + + vec![alice, bob, charlie, dave] +} + +/// The configuration used for development. +/// +/// Since Entropy requires at two-of-three threshold setup, and requires an additional relayer node, +/// we spin up four validators: Alice, Bob, Charlie and Dave. +pub fn development_config() -> ChainSpec { + ChainSpec::builder(wasm_binary_unwrap(), Default::default()) + .with_name("Development") + .with_id("dev") + .with_chain_type(ChainType::Development) + .with_properties(crate::chain_spec::entropy_properties()) + .with_genesis_config_patch(development_genesis_config( + vec![ + crate::chain_spec::authority_keys_from_seed("Alice"), + crate::chain_spec::authority_keys_from_seed("Bob"), + crate::chain_spec::authority_keys_from_seed("Charlie"), + crate::chain_spec::authority_keys_from_seed("Dave"), + ], + vec![], + get_account_id_from_seed::("Alice"), + tdx_devnet_four_node_initial_tss_servers(), + )) + .build() +} diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index b206b5ee5..49ef5fd28 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -74,6 +74,7 @@ impl SubstrateCli for Cli { // | integration-tests | Two nodes, Four threshold servers, Alice and Bob, Development Configuration | // | testnet-local | Two Nodes, Two threshold servers, Alice and Bob, Testnet Configuration, Docker Compatible | // | testnet | Four nodes, Two threshold servers, Own Seed, Testnet Configuration | + // | tdx-testnet | Four nodes, Four threshold servers, Alice Bob Chalie and Dave, Development Configuration | fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { "" | "dev" => Box::new(chain_spec::dev::development_config()), @@ -88,6 +89,7 @@ impl SubstrateCli for Cli { }, "testnet-local" => Box::new(chain_spec::testnet::testnet_local_config()), "testnet" => Box::new(chain_spec::testnet::testnet_config()), + "tdx-testnet" => Box::new(chain_spec::tdx_testnet::development_config()), path => { Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?) },