Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stagenet network #5173

Merged
merged 3 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions applications/tari_merge_mining_proxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ mod test {
[config_b.merge_mining_proxy]
submit_to_origin = false
monerod_url = [ "http://network.b.org" ]
monerod_password = "password_esmeralda"
monerod_password = "password_stagenet"
base_node_grpc_address = "/dns4/base_node_b/tcp/8080"
"#;

Expand All @@ -133,7 +133,7 @@ mod test {
assert_eq!(config.monerod_url.as_slice(), &["http://network.b.org".to_string()]);
assert!(!config.submit_to_origin);
assert_eq!(config.monerod_username.as_str(), "cmot");
assert_eq!(config.monerod_password.as_str(), "password_esmeralda");
assert_eq!(config.monerod_password.as_str(), "password_stagenet");
assert_eq!(
config.base_node_grpc_address.to_string().as_str(),
"/dns4/base_node_b/tcp/8080"
Expand Down
105 changes: 104 additions & 1 deletion base_layer/core/src/blocks/genesis_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ use crate::{

/// Returns the genesis block for the selected network.
pub fn get_genesis_block(network: Network) -> ChainBlock {
use Network::{Dibbler, Esmeralda, Igor, LocalNet, MainNet, Ridcully, Stibbons, Weatherwax};
use Network::{Dibbler, Esmeralda, Igor, LocalNet, MainNet, Ridcully, StageNet, Stibbons, Weatherwax};
match network {
MainNet => get_mainnet_genesis_block(),
StageNet => get_stagenet_genesis_block(),
Igor => get_igor_genesis_block(),
Esmeralda => get_esmeralda_genesis_block(),
LocalNet => get_esmeralda_genesis_block(),
Expand All @@ -63,6 +64,100 @@ pub fn get_genesis_block(network: Network) -> ChainBlock {
}
}

pub fn get_stagenet_genesis_block() -> ChainBlock {
brianp marked this conversation as resolved.
Show resolved Hide resolved
let block = get_stagenet_genesis_block_raw();

let accumulated_data = BlockHeaderAccumulatedData {
hash: block.hash(),
total_kernel_offset: block.header.total_kernel_offset.clone(),
achieved_difficulty: 1.into(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the actual difficulty of the block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the difficulty emse has so I left it as is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just check if this is the stagenet difficulty as well.

total_accumulated_difficulty: 1,
accumulated_monero_difficulty: 1.into(),
accumulated_sha_difficulty: 1.into(),
target_difficulty: 1.into(),
};
ChainBlock::try_construct(Arc::new(block), accumulated_data).unwrap()
}

fn get_stagenet_genesis_block_raw() -> Block {
// Note: Use print_new_genesis_block_stagenet in core/tests/helpers/block_builders.rs to generate the required
// fields below
let excess_sig = Signature::new(
PublicKey::from_hex("e487276e01039473094f492f20b707d3805399f799fc9d4ad77c648f2a5c0d18").unwrap(),
PrivateKey::from_hex("544bea13bfa55f26f3cbdf986b0f7fff4a056316b252531896577d201f362704").unwrap(),
);
let coinbase_meta_sig = CommitmentAndPublicKeySignature::new(
Commitment::from_hex("b60caad21427512b85ccc38a455419481ff4f45253b611374c68d8e82533ee66").unwrap(),
PublicKey::from_hex("76dfffcfa2c67c1b140ee04cf04fc271df193bdb4914e0b163b2507504f28b0f").unwrap(),
PrivateKey::from_hex("81631e30518430fd864a010fdba2f08f63c63f974972de179e0c9d7bdfb0d000").unwrap(),
PrivateKey::from_hex("be45ce74a588437453c4dc27ed5cc368c422cd6d86f4f180d66a6fd20a458d07").unwrap(),
PrivateKey::from_hex("43227a2310450b9adcc9d3d0ebdfa8eb6f260e6d7a8e7e5ad9b8230916333104").unwrap(),
);
let extra = "Tokenized and connected";
let coinbase = TransactionOutput::new(
TransactionOutputVersion::get_current_version(),
OutputFeatures::create_coinbase(360, Some(extra.as_bytes().to_vec())),
Commitment::from_hex("002354d7fb5a0e173a7351ebd2ea169998b891542c2995c36621ab30c7e89004").unwrap(),
BulletRangeProof::from_hex("01c24948f13b2dd0ebfb0a3e0697d882d05eef5744f7da5703d6525ffb9e34f556803ea04a2cbe040161ac805a0c3f598f3ad5744e313a175ac6fa2b52a80464499aa29a326ffbee4e3ce54d2f16528be30be1179ae6b8711e2602201d3193bc33ca5fd6812b94c16c50137c42935d856300313facdcc77493783522a7d945546a98f6a76a47c1546260e5b42d5a37be51f5d796568bc725e5aedc190bcbedc8506ed3a1b5e79490d62d10cf79e1440682988acc22d26a81ee5c591831652f967a4026f82b935ffed77e7f53636a9c91df6ccf292e97930da2e149d8c38e5c39301cff35fe5f81a1ee8ccd2f1897726a5530f47b8fc09f7ea63452d546a9fa1130d002041a6a8ac64f4239d8bcda752679df132b4c60a7ed14042ad5a8430eb4075e7d9eefcddb7155d1a8cd077ec567f49679567cdacdda7d6ccd63ca7c3f69232095ad1ff86338cf02a388a5614f563fac0d1cf5916663b2e5a1e1cf5d7bdb70a60231e9582ac23432bfc527daaba93806973fe0cf6261556fa75bc25e2bd653b4cf47727b54b163716be622b8e9e59e931425b154f98360c9d152c50856e34c0a1146ca2ba7f79720e4303b6e4f4f0b87f268b8c9ef36f0c8499fbd58f79129de3b5bb0c3e40fb5e21e1f01c03b3b2c01c973a142fe3385c7bc07c846c2a8002f50e43d544635ce42f031d046a0030b3209d42e4975988a54625eac0ecf6e009064acaeeba32ba641fa8b026891f518e7c5c2c9971e988064033841bbffb200fc6aecb9c24fb6f0ea6f382fa30fb01e55ca552ec38150218e0336ed6ce65407").unwrap(),
// A default script can never be spent, intentionally
script!(Nop),
// The Sender offset public key is not checked for coinbase outputs
PublicKey::from_hex("bc94d6502fa7c1dde829ca5a8d2672784454dc6c42e4f62f5ce83eccbe63b038").unwrap(),
coinbase_meta_sig,
// Covenant
Covenant::default(),
EncryptedValue::default(),
// Genesis blocks don't need to prove a minimum value
MicroTari::zero(),
);
let kernel = TransactionKernel::new(
TransactionKernelVersion::V0,
KernelFeatures::COINBASE_KERNEL,
MicroTari(0),
0,
Commitment::from_hex("02c0544ac33b2baba6da92a13a7b54b454edaacaa5b76eaf561aacf078142471").unwrap(),
excess_sig,
None,
);
let mut body = AggregateBody::new(vec![], vec![coinbase], vec![kernel]);
body.sort();
// set genesis timestamp
let genesis = DateTime::parse_from_rfc2822("8 Feb 2023 13:00:00 -0800").unwrap();
#[allow(clippy::cast_sign_loss)]
let timestamp = genesis.timestamp() as u64;
Block {
header: BlockHeader {
version: 0,
height: 0,
prev_hash: FixedHash::zero(),
timestamp: timestamp.into(),
output_mr: FixedHash::from_hex("a00d1c95378f383cb53f2fda0658b680d15b530ffb251b72d5fdf0af386ae775").unwrap(),
witness_mr: FixedHash::from_hex("945bad8a49c1c74501002ae227a9282a2148c793355c1c2517c07e5c15972d50")
.unwrap(),
output_mmr_size: 1,
kernel_mr: FixedHash::from_hex("ad201fe393372af2313f5c55f491c9d4e864a7a796401453ef52eaf2cd042132").unwrap(),
kernel_mmr_size: 1,
input_mr: FixedHash::zero(),
total_kernel_offset: PrivateKey::from_hex(
"0000000000000000000000000000000000000000000000000000000000000000",
)
.unwrap(),
total_script_offset: PrivateKey::from_hex(
"0000000000000000000000000000000000000000000000000000000000000000",
)
.unwrap(),
nonce: 0,
pow: ProofOfWork {
pow_algo: PowAlgorithm::Sha3,
pow_data: vec![],
},
validator_node_mr: FixedHash::from_hex("e1d55f91ecc7e435080ac2641280516a355a5ecbe231158987da217b5af30047")
.unwrap(),
},
body,
}
}

pub fn get_mainnet_genesis_block() -> ChainBlock {
unimplemented!()
}
Expand Down Expand Up @@ -375,6 +470,14 @@ mod test {
WitnessMmr,
};

#[test]
fn stagenet_genesis_sanity_check() {
// Note: Generate new data for `pub fn get_stagenet_genesis_block()` and `fn get_stagenet_genesis_block_raw()`
// if consensus values change, e.g. new faucet or other
let block = get_stagenet_genesis_block();
check_block(Network::StageNet, &block, 1, 1);
}

#[test]
fn esmeralda_genesis_sanity_check() {
// Note: Generate new data for `pub fn get_esmeralda_genesis_block()` and `fn get_esmeralda_genesis_block_raw()`
Expand Down
54 changes: 53 additions & 1 deletion base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,58 @@ impl ConsensusConstants {
vec![consensus_constants_1]
}

/// *
/// Stagenet has the following characteristics:
/// * 2 min blocks on average (5 min SHA-3, 3 min MM)
/// * 21 billion tXTR with a 3-year half-life
/// * 800 T tail emission (± 1% inflation after initial 21 billion has been mined)
/// * Coinbase lock height - 12 hours = 360 blocks
pub fn stagenet() -> Vec<Self> {
// Note these values are all placeholders for final values
let mut algos = HashMap::new();
algos.insert(PowAlgorithm::Sha3, PowAlgorithmConstants {
max_target_time: 1800,
min_difficulty: 60_000_000.into(),
max_difficulty: u64::MAX.into(),
target_time: 300,
});
algos.insert(PowAlgorithm::Monero, PowAlgorithmConstants {
max_target_time: 1200,
min_difficulty: 60_000.into(),
max_difficulty: u64::MAX.into(),
target_time: 200,
});
let (input_version_range, output_version_range, kernel_version_range) = version_zero();
vec![ConsensusConstants {
effective_from_height: 0,
coinbase_lock_height: 360,
blockchain_version: 0,
valid_blockchain_version_range: 0..=0,
future_time_limit: 540,
difficulty_block_window: 90,
max_block_transaction_weight: 127_795,
median_timestamp_count: 11,
emission_initial: 18_462_816_327 * uT,
emission_decay: &EMISSION_DECAY,
emission_tail: 800 * T,
max_randomx_seed_height: 3000,
proof_of_work: algos,
faucet_value: 0.into(),
transaction_weight: TransactionWeight::v1(),
max_script_byte_size: 2048,
input_version_range,
output_version_range,
kernel_version_range,
permitted_output_types: Self::current_permitted_output_types(),
vn_epoch_length: 60,
vn_validity_period_epochs: VnEpoch(100),
vn_registration_min_deposit_amount: MicroTari(0),
vn_registration_lock_height: 0,
vn_registration_shuffle_interval: VnEpoch(100),
coinbase_output_features_extra_max_length: 64,
}]
}

pub fn mainnet() -> Vec<Self> {
// Note these values are all placeholders for final values
let difficulty_block_window = 90;
Expand Down Expand Up @@ -667,7 +719,7 @@ impl ConsensusConstants {
}
}

static EMISSION_DECAY: [u64; 5] = [22, 23, 24, 26, 27];
static EMISSION_DECAY: [u64; 6] = [21u64, 22, 23, 25, 26, 37];
const DIBBLER_DECAY_PARAMS: [u64; 6] = [21u64, 22, 23, 25, 26, 37]; // less significant values don't matter
const ESMERALDA_DECAY_PARAMS: [u64; 6] = [21u64, 22, 23, 25, 26, 37]; // less significant values don't matter

Expand Down
3 changes: 2 additions & 1 deletion base_layer/core/src/consensus/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ pub struct NetworkConsensus(Network);

impl NetworkConsensus {
pub fn create_consensus_constants(&self) -> Vec<ConsensusConstants> {
use Network::{Dibbler, Esmeralda, Igor, LocalNet, MainNet, Ridcully, Stibbons, Weatherwax};
use Network::{Dibbler, Esmeralda, Igor, LocalNet, MainNet, Ridcully, StageNet, Stibbons, Weatherwax};
match self.as_network() {
MainNet => ConsensusConstants::mainnet(),
StageNet => ConsensusConstants::stagenet(),
LocalNet => ConsensusConstants::localnet(),
Dibbler => ConsensusConstants::dibbler(),
Igor => ConsensusConstants::igor(),
Expand Down
11 changes: 11 additions & 0 deletions base_layer/core/tests/helpers/block_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ fn genesis_template(
(block, output)
}

// #[ignore = "used to generate a new stagenet genesis block"]
/// This is a helper function to generate and print out a block that can be used as the genesis block.
/// 1. Run `cargo test --package tari_core --test mempool -- helpers::block_builders::print_new_genesis_block_stagenet
/// --exact --nocapture`
/// 1. The block and range proof will be printed
/// 1. Profit!
#[test]
fn print_new_genesis_block_stagenet() {
print_new_genesis_block(Network::StageNet, "Tokenized and connected");
}

// #[ignore = "used to generate a new esmeralda genesis block"]
/// This is a helper function to generate and print out a block that can be used as the genesis block.
/// 1. Run `cargo test --package tari_core --test mempool -- helpers::block_builders::print_new_genesis_block_esmeralda
Expand Down
2 changes: 1 addition & 1 deletion base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4650,7 +4650,7 @@ pub unsafe extern "C" fn transport_config_destroy(transport: *mut TariTransportC
/// `database_path` - The database path char array pointer which. This is the folder path where the
/// database files will be created and the application has write access to
/// `discovery_timeout_in_secs`: specify how long the Discovery Timeout for the wallet is.
/// `network`: name of network to connect to. Valid values are: esmeralda, dibbler, igor, localnet, mainnet
/// `network`: name of network to connect to. Valid values are: esmeralda, dibbler, igor, localnet, mainnet, stagenet
/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
/// as an out parameter.
///
Expand Down
2 changes: 1 addition & 1 deletion base_layer/wallet_ffi/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@ void transport_config_destroy(TariTransportConfig *transport);
* `database_path` - The database path char array pointer which. This is the folder path where the
* database files will be created and the application has write access to
* `discovery_timeout_in_secs`: specify how long the Discovery Timeout for the wallet is.
* `network`: name of network to connect to. Valid values are: esmeralda, dibbler, igor, localnet, mainnet
* `network`: name of network to connect to. Valid values are: esmeralda, dibbler, igor, localnet, mainnet, stagenet
* `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
* as an out parameter.
*
Expand Down
6 changes: 3 additions & 3 deletions common/config/presets/a_common.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
########################################################################################################################

[common]
#override_from="esmeralda"
#override_from="stagenet"
#base_path="<HOME>/.tari"

[esmeralda.auto_update]
[stagenet.auto_update]
# Customize the hosts that are used to check for updates. These hosts must contain update information in DNS TXT records.
update_uris = ["updates.esmeralda.taripulse.com"]
update_uris = ["updates.stagenet.taripulse.com"]

[auto_update]
# Name server for auto update (default = "1.1.1.1:53/cloudflare.net")
Expand Down
27 changes: 27 additions & 0 deletions common/config/presets/b_peer_seeds.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@
# All DNS seed records must pass DNSSEC validation
#dns_seeds_use_dnssec = false

[stagenet.p2p.seeds]
# DNS seeds hosts - DNS TXT records are queried from these hosts and the resulting peers added to the comms peer list.
dns_seeds = ["seeds.stagenet.tari.com"]
# Custom specified peer seed nodes
peer_seeds = [
# 1337e9449e63134fd5e0ba3207
"a062ae2345b0db0df9fb1504b99511e23d98f8513f9b5503efcc6dad8eca7e47::/onion3/rhoqxfbzz3uidp23erxu4mkwwexc2gg4q45rcxfpbhb35ycdv4ex2fid:18141",
# 1a1a1a4b79a81467a2c815a371
"b2c5db3a2858451d241d4e88677536f9e82a760111962785fb6a3cddc41f766e::/onion3/q32yxdg7l7os2zzx64e3f5u4mzib3lxlkdyguybkhtkd4pwfkpunjcyd:18141",
# 2b2b2b56e8e1479f1685d5f4ce
"1cdf34d27bee5e1edbc343a17f7d79a8a1974fe3f790e899d8987c1f11697e41::/onion3/fwvmhhcifr7yh7neqsweyjvu4bnlmljg6a6fsjdwify3b4aals2oc3yd:18141",
# 3c3c3c8c3aa72ea4c2a943564a
"a42eea2088e0ef663b8d29a9d039b0e5d51c1ddc1cf5ae28feb05ed52ead5a69::/onion3/k5khqg7fwkq7ujxievps22r42i5ykuieai64ze3kj5snsjkew3v7piid:18141",
# 4d4d4df1add5ac00a8c276f11e
"d49df057e1f1ae399ffabdeb59e7ad542439ab2b0bbd9ed23042175a93e4d03c::/onion3/hjeczose7rjo6o6qhsszkuzhrm6qfs7s4yeqzeuz2m67rkpijrtrwsad:18141",
# 5e5e5eace5fc25c4ce83fbaab6
"e65f18cb4a362b33667e0d39b3c93f06c0e822af09906914bdc65907b7cdc130::/onion3/uuv6j3vwq4dac6z3dblc2mjcoecrnxfka3wg43bcass5avbzix4nmzyd:18141",
# 6f6f6f01facc230ad923de9159
"0a755298f4bee8e6db64e345fe8f937e3882693a48c71b942b88744761b02067::/onion3/ksdogedobmqoud6ampvrjrhoozftgfkolhxqvnt7mo7ajqczku5tyyqd:18141",
# 777777aec8a3e4add50054d457
"0c22d3dc3983c74131d7dfb0c4c8ae9fb90c434826cf8ccc71e793bb72d36213::/onion3/so2be7uyg4kf5l7ys3fbk4eqovsfi63yuaqj7pahkkw2crujq43jdnyd:18141",
# 8888883587be3e94600c246c3b
"2ade610a2e95f1c686873944096f5a1f2c7ffcf47d67112b472c9208cc6e9532::/onion3/rmiknlrf7ngfvgpayf5qzuer2c547rzmyqbkbw45w5uessi3jodasdqd:18141",
# 99999903f5951fa1ca9505c3c2
"369ae9a89c3fc2804d6ec07e20bf10e5d0e72f565a71821fc7c611ae5bee0116::/onion3/crvsrmoyrk5uatvnafsmoykiqgywdqowupn3auq25iz7zxyf7xusjxid:18141",
]

[esmeralda.p2p.seeds]
# DNS seeds hosts - DNS TXT records are queried from these hosts and the resulting peers added to the comms peer list.
dns_seeds = ["seeds.esmeralda.tari.com"]
Expand Down
5 changes: 4 additions & 1 deletion common/config/presets/c_base_node.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ identity_file = "config/base_node_id_igor.json"
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_esmeralda.json"

[stagenet.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_stagenet.json"
# The socket to expose for the gRPC base node server (default = "/ip4/127.0.0.1/tcp/18142")
#grpc_address = "/ip4/127.0.0.1/tcp/18142"

[base_node]
# Selected network (Note: Not implemented properly, please specify on the command line) (default = "emseralda")
#network = "emseralda"
#network = "stagenet"

# Set to false to disable the base node GRPC server (default = true)
#grpc_enabled = true
Expand Down
2 changes: 2 additions & 0 deletions common/src/configuration/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub fn grpc_default_port(app_type: ApplicationType, network: Network) -> u16 {
match app_type {
ApplicationType::BaseNode => match network {
Network::MainNet => 18102u16,
Network::StageNet => 18172u16,
Network::Weatherwax => 18112,
Network::Dibbler => 18122,
Network::Esmeralda => 18142,
Expand All @@ -112,6 +113,7 @@ pub fn grpc_default_port(app_type: ApplicationType, network: Network) -> u16 {
},
ApplicationType::ConsoleWallet => match network {
Network::MainNet => 18103u16,
Network::StageNet => 18173u16,
Network::Weatherwax => 18113,
Network::Dibbler => 18123,
Network::Esmeralda => 18143,
Expand Down
Loading