Skip to content

Commit

Permalink
feat: prepare MM backend stuff (#6448)
Browse files Browse the repository at this point in the history
Description
---
This removes a few panics, and adds in a fake mainnet block.
Duplicates stagenet consensus values for mainnet. 

Motivation and Context
---
As we are getting closer to mainnet, we need to ensure that we can test
all of the features. This adds in a temporary mainnet block to use in
local testing. This block will not be the final one and will only be a
place holder.

How Has This Been Tested?
---
unit tests

---------

Co-authored-by: Hansie Odendaal <[email protected]>
  • Loading branch information
SWvheerden and hansieodendaal authored Aug 6, 2024
1 parent e726e5d commit 47ddf85
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2351,7 +2351,7 @@ fn create_pre_mine_output_dir() -> Result<(String, PathBuf), CommandError> {
fn get_embedded_pre_mine_outputs(output_indexes: Vec<usize>) -> Result<Vec<TransactionOutput>, CommandError> {
let pre_mine_contents = match Network::get_current_or_user_setting_or_default() {
Network::MainNet => {
unimplemented!("MainNet pre-mine not yet implemented");
include_str!("../../../../base_layer/core/src/blocks/pre_mine/mainnet_pre_mine.json")
},
Network::StageNet => {
include_str!("../../../../base_layer/core/src/blocks/pre_mine/stagenet_pre_mine.json")
Expand Down
18 changes: 12 additions & 6 deletions applications/minotari_miner/src/run_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,24 @@ pub async fn start_miner(cli: Cli) -> Result<(), ExitError> {
if !config.mining_worker_name.is_empty() {
miner_address += &format!("{}{}", ".", config.mining_worker_name);
}
let mut mc = Controller::new(config.num_mining_threads).unwrap_or_else(|e| {
let mut mc = Controller::new(config.num_mining_threads).map_err(|e| {
debug!(target: LOG_TARGET_FILE, "Error loading mining controller: {}", e);
panic!("Error loading mining controller: {}", e);
});
ExitError::new(
ExitCode::UnknownError,
format!("Error loading mining controller: {}", e),
)
})?;
let cc = crate::stratum::controller::Controller::new(&url, Some(miner_address), None, None, mc.tx.clone())
.unwrap_or_else(|e| {
.map_err(|e| {
debug!(
target: LOG_TARGET_FILE,
"Error loading stratum client controller: {:?}", e
);
panic!("Error loading stratum client controller: {:?}", e);
});
ExitError::new(
ExitCode::UnknownError,
format!("Error loading mining controller: {}", e),
)
})?;
mc.set_client_tx(cc.tx.clone());

let _join_handle = thread::Builder::new()
Expand Down
45 changes: 44 additions & 1 deletion base_layer/core/src/blocks/genesis_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,50 @@ fn get_nextnet_genesis_block_raw() -> Block {
}

pub fn get_mainnet_genesis_block() -> ChainBlock {
unimplemented!()
let mut block = get_mainnet_genesis_block_raw();

// Add pre-mine utxos - enable/disable as required
let add_pre_mine_utxos = false;
if add_pre_mine_utxos {
// NB: `stagenet_genesis_sanity_check` must pass
let file_contents = include_str!("pre_mine/mainnet_pre_mine.json");
add_pre_mine_utxos_to_genesis_block(file_contents, &mut block);
// Enable print only if you need to generate new Merkle roots, then disable it again
let print_values = false;
print_mr_values(&mut block, print_values);

// Hardcode the Merkle roots once they've been computed above
block.header.kernel_mr =
FixedHash::from_hex("a08ff15219beea81d4131465290443fb3bd99d28b8af85975dbb2c77cb4cb5a0").unwrap();
block.header.output_mr =
FixedHash::from_hex("435f13e21be06b0d0ae9ad3869ac7c723edd933983fa2e26df843c82594b3245").unwrap();
block.header.validator_node_mr =
FixedHash::from_hex("277da65c40b2cf99db86baedb903a3f0a38540f3a94d40c826eecac7e27d5dfc").unwrap();
}

let accumulated_data = BlockHeaderAccumulatedData {
hash: block.hash(),
total_kernel_offset: block.header.total_kernel_offset.clone(),
achieved_difficulty: Difficulty::min(),
total_accumulated_difficulty: 1.into(),
accumulated_randomx_difficulty: AccumulatedDifficulty::min(),
accumulated_sha3x_difficulty: AccumulatedDifficulty::min(),
target_difficulty: Difficulty::min(),
};
ChainBlock::try_construct(Arc::new(block), accumulated_data).unwrap()
}

fn get_mainnet_genesis_block_raw() -> Block {
// Set genesis timestamp
let genesis_timestamp = DateTime::parse_from_rfc2822("05 Aug 2024 08:00:00 +0200").expect("parse may not fail");
let not_before_proof = b"I am the standin mainnet genesis block, \
\
I am not the real mainnet block \
\
I am only a standin \
\
Do not take me for the real one. I am only a placeholder for the real one";
get_raw_block(&genesis_timestamp, &not_before_proof.to_vec())
}

pub fn get_igor_genesis_block() -> ChainBlock {
Expand Down
Loading

0 comments on commit 47ddf85

Please sign in to comment.