Skip to content

Commit

Permalink
feat: add dibbler testnet and genesis block
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron Hambly committed Sep 10, 2021
1 parent a2917b3 commit 6f355f7
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 30 deletions.
113 changes: 106 additions & 7 deletions base_layer/core/src/blocks/genesis_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ pub fn get_weatherwax_genesis_block() -> ChainBlock {
ChainBlock::try_construct(Arc::new(block), accumulated_data).unwrap()
}

#[allow(deprecated)]
pub fn get_weatherwax_genesis_block_raw() -> Block {
fn get_weatherwax_genesis_block_raw() -> Block {
let sig = Signature::new(
PublicKey::from_hex("f2139d1cdbcfa670bbb60d4d03d9d50b0a522e674b11280e8064f6dc30e84133").unwrap(),
PrivateKey::from_hex("3ff7522d9a744ebf99c7b6664c0e2c8c64d2a7b902a98b78964766f9f7f2b107").unwrap(),
Expand Down Expand Up @@ -153,7 +152,6 @@ pub fn get_weatherwax_genesis_block_raw() -> Block {
}
}

/// This will get the ridcully gen block
pub fn get_ridcully_genesis_block() -> ChainBlock {
// lets get the block
let mut block = get_ridcully_genesis_block_raw();
Expand Down Expand Up @@ -193,8 +191,7 @@ pub fn get_ridcully_genesis_block() -> ChainBlock {
ChainBlock::try_construct(Arc::new(block), accumulated_data).unwrap()
}

#[allow(deprecated)]
pub fn get_ridcully_genesis_block_raw() -> Block {
fn get_ridcully_genesis_block_raw() -> Block {
let sig = Signature::new(
PublicKey::from_hex("f2139d1cdbcfa670bbb60d4d03d9d50b0a522e674b11280e8064f6dc30e84133").unwrap(),
PrivateKey::from_hex("3ff7522d9a744ebf99c7b6664c0e2c8c64d2a7b902a98b78964766f9f7f2b107").unwrap(),
Expand Down Expand Up @@ -275,8 +272,7 @@ pub fn get_igor_genesis_block() -> ChainBlock {
ChainBlock::try_construct(Arc::new(block), accumulated_data).unwrap()
}

#[allow(deprecated)]
pub fn get_igor_genesis_block_raw() -> Block {
fn get_igor_genesis_block_raw() -> Block {
let sig = Signature::new(
PublicKey::from_hex("f2139d1cdbcfa670bbb60d4d03d9d50b0a522e674b11280e8064f6dc30e84133").unwrap(),
PrivateKey::from_hex("3ff7522d9a744ebf99c7b6664c0e2c8c64d2a7b902a98b78964766f9f7f2b107").unwrap(),
Expand Down Expand Up @@ -348,6 +344,91 @@ pub fn get_igor_genesis_block_raw() -> Block {
}
}

pub fn get_dibbler_genesis_block() -> ChainBlock {
// lets get the block
let block = get_dibbler_genesis_block_raw();

let accumulated_data = BlockHeaderAccumulatedData {
hash: block.hash(),
total_kernel_offset: block.header.total_kernel_offset.clone(),
achieved_difficulty: 1.into(),
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_dibbler_genesis_block_raw() -> Block {
let sig = Signature::new(
PublicKey::from_hex("6e6b47d8f6c654367858204b4277d854f78e0267baaf26cd513813ee23c16969").unwrap(),
PrivateKey::from_hex("92a310f7bbb351850e599ac6719d530625643fad74cb2902ab4adaf9207ff60d").unwrap(),
);
let mut body = AggregateBody::new(
vec![],
vec![TransactionOutput {
features: OutputFeatures {
flags: OutputFlags::COINBASE_OUTPUT,
maturity: 60,
..Default::default()
},
commitment: Commitment::from_hex(
"c44428c3c707009befb074fb6db679049fd1a6c9b0466b281945c12670e8d706",
)
.unwrap(),
proof: BulletRangeProof::from_hex("72101d8e581bb12bf153bed6eb321dd151e94e5d966e7545504b2f73a2cfda43bce0d87a9c0b4008762d30edaa4574b787824614b2f150e6456b609a7c2640603cc06570b44c60eeec2b88dc43a2aea484f357ef14ecb078a1f80f40b57d3812beab3a6fe23cacb3644b16967fdfd390daa6443fc03f711b001e9fe551f9f979db76189f4e17ed648bcfa419abd455bb5ec40e1801302d8cb870a3fbe4ad760a7dece961bff85989a75216f24c342c266f8819df33805e1df3dab7e6b8451007c58192a9bc3e660324309e0c34a3a67bab78156cc2443c7718a351136905a80af0268b08fb015b2b32cd6a9f6d839716cf549303c6c34a9db0f92e015a32414bfa5c680cf51439c9810a0783a51cc6176e52bddfd98bad7897742e9c107732791a5047022ec1f4e3c7569214e79cb1903131e43c2a2bd537c0ef04904e667a46961a5961340e17b38ac511176adfb0f94dd3b112589ef35b42c2745dd1d9ed5acadfd3226c51fed42f71c0cacbfefd05abe5d7dc7f799d7f2147c7803762cb1bc0da30fa9eca2e9748f9a55e19fb5ffad19865d370850a98bb165649c7a2814d147718ae8e58d126b7acb3500ce871d709083917873a8618ef04d364376ac142721c6d86c8b4a8d45cbf62310c18656ff950302a6fffc56ca1160e6496be756f40769bfc259043904d9d2c94bb9d69d842dc0bea5dcd708c1d96e47dba856d5cb46f0c69f67a02ec8da5ed5cc96d5f4a375059c2f38607da525e51453040d6647870a4ab6a7656cb5e2161412d1cb5284ba2abe7a21966f6ef3c615a9e4507711880fdb192277d1255318a4a5a9ff3b55a861bcadbee41e9fa653515a24bef2d6adf2db066c59c89bcc8b131dacb20f3f7390922a8a69c7105bb53e204f5e009eed3f5838b8d95e6cd1f00721c21f48419597ece1611b83c6b53abc2dd1b1804").unwrap(),
// For genesis block: A default script can never be spent, intentionally
script: TariScript::default(),
// Script offset never checked for coinbase, thus can use default
sender_offset_public_key: Default::default(),
// For genesis block: Metadata signature will never be checked
metadata_signature: Default::default(),
unique_id: None,
parent_public_key: None,
}],
vec![TransactionKernel {
features: KernelFeatures::COINBASE_KERNEL,
fee: MicroTari(0),
lock_height: 0,
excess: Commitment::from_hex("d0d8c0f6ba4913fd6f30595e0d7268e108cfbc8ae4a602dc6a33daf67fca434e").unwrap(),
excess_sig: sig,
}],
);
body.sort();
// set genesis timestamp
let genesis = DateTime::parse_from_rfc2822("09 Sep 2021 00:00:00 +0200").unwrap();
let timestamp = genesis.timestamp() as u64;
Block {
header: BlockHeader {
version: 0,
height: 0,
prev_hash: vec![0; BLOCK_HASH_LENGTH],
timestamp: timestamp.into(),
output_mr: from_hex("aba0712711944acb920b549c196973c7cccdb38725eb595dbc5da5b33ce0220a").unwrap(),
witness_mr: from_hex("a84f23daa5f85af99f97fb2b13262d61f09e1059a625fb479c1926d2c63948bc").unwrap(),
output_mmr_size: 1,
kernel_mr: from_hex("12624ca9347f092db4fb832f122221d2a2514978ecf44def0438f53001253367").unwrap(),
kernel_mmr_size: 1,
input_mr: vec![0; BLOCK_HASH_LENGTH],
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![],
},
},
body,
}
}

#[cfg(test)]
mod test {
use super::*;
Expand All @@ -370,4 +451,22 @@ mod test {
let coinbase_kernel = block.block().body.kernels().first().unwrap();
assert!(coinbase_kernel.features.contains(KernelFeatures::COINBASE_KERNEL));
}

#[test]
fn dibbler_genesis_sanity_check() {
let block = get_dibbler_genesis_block();
assert_eq!(block.block().body.outputs().len(), 1);

let factories = CryptoFactories::default();
let coinbase = block.block().body.outputs().first().unwrap();
assert!(coinbase.is_coinbase());
coinbase.verify_range_proof(&factories.range_proof).unwrap();
assert_eq!(block.block().body.kernels().len(), 1);
for kernel in block.block().body.kernels() {
kernel.verify_signature().unwrap();
}

let coinbase_kernel = block.block().body.kernels().first().unwrap();
assert!(coinbase_kernel.features.contains(KernelFeatures::COINBASE_KERNEL));
}
}
32 changes: 32 additions & 0 deletions base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,38 @@ impl ConsensusConstants {
}]
}

pub fn dibbler() -> Vec<Self> {
let mut algos = HashMap::new();
// seting sha3/monero to 40/60 split
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,
});
vec![ConsensusConstants {
effective_from_height: 0,
coinbase_lock_height: 6,
blockchain_version: 1,
future_time_limit: 540,
difficulty_block_window: 90,
max_block_transaction_weight: 19500,
median_timestamp_count: 11,
emission_initial: 5_538_846_115 * uT,
emission_decay: &EMISSION_DECAY,
emission_tail: 100.into(),
max_randomx_seed_height: std::u64::MAX,
proof_of_work: algos,
faucet_value: (5000 * 4000) * T,
}]
}

pub fn mainnet() -> Vec<Self> {
// Note these values are all placeholders for final values
let difficulty_block_window = 90;
Expand Down
11 changes: 2 additions & 9 deletions base_layer/core/src/consensus/consensus_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use crate::{
blocks::{
genesis_block::{
get_igor_genesis_block,
get_mainnet_genesis_block,
get_ridcully_genesis_block,
get_weatherwax_genesis_block,
},
Block,
},
blocks::{genesis_block::*, Block},
chain_storage::{ChainBlock, ChainStorageError},
consensus::{
chain_strength_comparer::{strongest_chain, ChainStrengthComparer},
Expand Down Expand Up @@ -83,6 +75,7 @@ impl ConsensusManager {
.clone()
.unwrap_or_else(get_weatherwax_genesis_block),
Network::Igor => get_igor_genesis_block(),
Network::Dibbler => get_dibbler_genesis_block(),
}
}

Expand Down
1 change: 1 addition & 0 deletions base_layer/core/src/consensus/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl NetworkConsensus {
Weatherwax => ConsensusConstants::weatherwax(),
LocalNet => ConsensusConstants::localnet(),
Igor => ConsensusConstants::igor(),
Dibbler => ConsensusConstants::dibbler(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/transactions/crypto_factories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use tari_common_types::types::{CommitmentFactory, RangeProofService, MAX_RANGE_PROOF_RANGE};

/// A convenience struct wrapping cryptographic factories that are used through-out the rest of the code base
/// A convenience struct wrapping cryptographic factories that are used throughout the rest of the code base
/// Uses Arcs internally so calling clone on this is cheap, no need to wrap this in an Arc
pub struct CryptoFactories {
pub commitment: Arc<CommitmentFactory>,
Expand Down
30 changes: 17 additions & 13 deletions base_layer/core/tests/helpers/block_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,17 @@ fn genesis_template(
(block, output)
}

// This is a helper function to generate and print out a block that can be used as the genesis block.
// #[test]
pub fn _create_act_gen_block() {
let network = Network::Weatherwax;
#[test]
#[ignore = "used to generate a new genesis block"]
/// This is a helper function to generate and print out a block that can be used as the genesis block.
/// 1. Pick a network
/// 1. Run `cargo test --package tari_core --test mempool -- helpers::block_builders::print_new_genesis_block --exact
/// --nocapture --ignored`
/// 1. The block and range proof will be printed
/// 1. Profit!
fn print_new_genesis_block() {
let network = Network::Dibbler;

let consensus_manager: ConsensusManager = ConsensusManagerBuilder::new(network).build();
let factories = CryptoFactories::default();
let mut header = BlockHeader::new(consensus_manager.consensus_constants(0).blockchain_version());
Expand All @@ -126,17 +133,14 @@ pub fn _create_act_gen_block() {
.build()
.unwrap();

let utxo_hash = utxo.hash();
let witness_hash = utxo.witness_hash();
let kern = kernel.hash();
header.kernel_mr = kern;
header.output_mr = utxo_hash;
header.witness_mr = witness_hash;
header.kernel_mr = kernel.hash();
header.output_mr = utxo.hash();
header.witness_mr = utxo.witness_hash();

let block = header.into_builder().with_coinbase_utxo(utxo, kernel).build();
println!("{}", &block);
dbg!(&key.to_hex());
dbg!(&block.body.outputs()[0].proof.to_hex());
panic!(); // this is so that the output is printed
println!("spending key: {}", &key.to_hex());
println!("range proof: {}", &block.body.outputs()[0].proof.to_hex());
}

/// Create a genesis block returning it with the spending key for the coinbase utxo
Expand Down
3 changes: 3 additions & 0 deletions common/src/configuration/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub enum Network {
Stibbons = 0x22,
Weatherwax = 0xa3,
Igor = 0x24,
Dibbler = 0x25,
}

impl Network {
Expand All @@ -53,6 +54,7 @@ impl Network {
Stibbons => "stibbons",
Weatherwax => "weatherwax",
Igor => "igor",
Dibbler => "dibbler",
LocalNet => "localnet",
}
}
Expand All @@ -76,6 +78,7 @@ impl FromStr for Network {
"mainnet" => Ok(MainNet),
"localnet" => Ok(LocalNet),
"igor" => Ok(Igor),
"dibbler" => Ok(Dibbler),
invalid => Err(ConfigurationError::new(
"network",
&format!("Invalid network option: {}", invalid),
Expand Down
59 changes: 59 additions & 0 deletions common/src/configuration/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,33 @@ pub fn default_config(bootstrap: &ConfigBootstrap) -> Config {
cfg.set_default("base_node.igor.dns_seeds_use_dnssec", true).unwrap();
cfg.set_default("base_node.igor.auto_ping_interval", 30).unwrap();

//---------------------------------- Dibbler Defaults --------------------------------------------//

cfg.set_default("base_node.dibbler.db_type", "lmdb").unwrap();
cfg.set_default("base_node.dibbler.orphan_storage_capacity", 720)
.unwrap();
cfg.set_default("base_node.dibbler.orphan_db_clean_out_threshold", 0)
.unwrap();
cfg.set_default("base_node.dibbler.pruning_horizon", 0).unwrap();
cfg.set_default("base_node.dibbler.pruned_mode_cleanup_interval", 50)
.unwrap();
cfg.set_default("base_node.dibbler.flood_ban_max_msg_count", 1000)
.unwrap();
cfg.set_default(
"base_node.dibbler.public_address",
format!("{}/tcp/18141", local_ip_addr),
)
.unwrap();
cfg.set_default("base_node.dibbler.grpc_enabled", false).unwrap();
cfg.set_default("base_node.dibbler.grpc_base_node_address", "127.0.0.1:18142")
.unwrap();
cfg.set_default("base_node.dibbler.grpc_console_wallet_address", "127.0.0.1:18143")
.unwrap();
cfg.set_default("base_node.dibbler.dns_seeds_name_server", "1.1.1.1:53")
.unwrap();
cfg.set_default("base_node.dibbler.dns_seeds_use_dnssec", true).unwrap();
cfg.set_default("base_node.dibbler.auto_ping_interval", 30).unwrap();

set_transport_defaults(&mut cfg).unwrap();
set_merge_mining_defaults(&mut cfg);
set_mining_node_defaults(&mut cfg);
Expand All @@ -277,6 +304,8 @@ fn set_stratum_transcoder_defaults(cfg: &mut Config) {
.unwrap();
cfg.set_default("stratum_transcoder.igor.transcoder_host_address", "127.0.0.1:7879")
.unwrap();
cfg.set_default("stratum_transcoder.dibbler.transcoder_host_address", "127.0.0.1:7879")
.unwrap();
}

fn set_merge_mining_defaults(cfg: &mut Config) {
Expand Down Expand Up @@ -322,6 +351,18 @@ fn set_merge_mining_defaults(cfg: &mut Config) {
cfg.set_default("merge_mining_proxy.igor.monerod_password", "").unwrap();
cfg.set_default("merge_mining_proxy.igor.wait_for_initial_sync_at_startup", true)
.unwrap();
cfg.set_default("merge_mining_proxy.dibbler.proxy_host_address", "127.0.0.1:7878")
.unwrap();
cfg.set_default("merge_mining_proxy.dibbler.proxy_submit_to_origin", true)
.unwrap();
cfg.set_default("merge_mining_proxy.dibbler.monerod_use_auth", "false")
.unwrap();
cfg.set_default("merge_mining_proxy.dibbler.monerod_username", "")
.unwrap();
cfg.set_default("merge_mining_proxy.dibbler.monerod_password", "")
.unwrap();
cfg.set_default("merge_mining_proxy.dibbler.wait_for_initial_sync_at_startup", true)
.unwrap();
}

fn set_mining_node_defaults(cfg: &mut Config) {
Expand Down Expand Up @@ -417,6 +458,24 @@ fn set_transport_defaults(cfg: &mut Config) -> Result<(), config::ConfigError> {
cfg.set_default(&format!("{}.igor.socks5_proxy_address", app), "/ip4/0.0.0.0/tcp/9150")?;

cfg.set_default(&format!("{}.igor.socks5_auth", app), "none")?;

// dibbler
cfg.set_default(&format!("{}.dibbler.transport", app), "tor")?;

cfg.set_default(
&format!("{}.dibbler.tor_control_address", app),
"/ip4/127.0.0.1/tcp/9051",
)?;
cfg.set_default(&format!("{}.dibbler.tor_control_auth", app), "none")?;
cfg.set_default(&format!("{}.dibbler.tor_forward_address", app), "/ip4/127.0.0.1/tcp/0")?;
cfg.set_default(&format!("{}.dibbler.tor_onion_port", app), "18141")?;

cfg.set_default(
&format!("{}.dibbler.socks5_proxy_address", app),
"/ip4/0.0.0.0/tcp/9150",
)?;

cfg.set_default(&format!("{}.dibbler.socks5_auth", app), "none")?;
}
Ok(())
}
Expand Down

0 comments on commit 6f355f7

Please sign in to comment.