Skip to content

Commit

Permalink
Prepare MM backend stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Aug 5, 2024
1 parent 77e5ca9 commit 55a12cd
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 18 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
185 changes: 185 additions & 0 deletions base_layer/core/src/blocks/pre_mine/mainnet_pre_mine.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion base_layer/core/src/blocks/pre_mine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ mod test {
};

// Only run this when you want to create a new utxo file
#[ignore]

#[tokio::test]
async fn print_pre_mine() {
let addresses_for_round = vec![
Expand Down
6 changes: 3 additions & 3 deletions base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,13 @@ impl ConsensusConstants {
valid_blockchain_version_range: 0..=0,
future_time_limit: 540,
difficulty_block_window,
max_block_transaction_weight: 19500,
max_block_transaction_weight: 127_795,
median_timestamp_count: 11,
emission_initial: 10_000_000.into(),
emission_initial: INITIAL_EMISSION,
emission_decay: &EMISSION_DECAY,
inflation_bips: 100,
tail_epoch_length: ANNUAL_BLOCKS,
max_randomx_seed_height: u64::MAX,
max_randomx_seed_height: 3000,
max_extra_field_size: 200,
proof_of_work: algos,
pre_mine_value: MicroMinotari::from(0),
Expand Down
10 changes: 5 additions & 5 deletions base_layer/core/src/mempool/service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ impl MempoolHandle {
pub async fn get_stats(&mut self) -> Result<StatsResponse, MempoolServiceError> {
match self.inner.call(MempoolRequest::GetStats).await?? {
MempoolResponse::Stats(response) => Ok(response),
_ => panic!("Incorrect response"),
_ => Err(MempoolServiceError::InvalidResponse("Incorrect response".to_string())),
}
}

pub async fn get_state(&mut self) -> Result<StateResponse, MempoolServiceError> {
match self.inner.call(MempoolRequest::GetState).await?? {
MempoolResponse::State(response) => Ok(response),
_ => panic!("Incorrect response"),
_ => Err(MempoolServiceError::InvalidResponse("Incorrect response".to_string())),
}
}

Expand All @@ -65,7 +65,7 @@ impl MempoolHandle {
) -> Result<TxStorageResponse, MempoolServiceError> {
match self.inner.call(MempoolRequest::GetTxStateByExcessSig(sig)).await?? {
MempoolResponse::TxStorage(response) => Ok(response),
_ => panic!("Incorrect response"),
_ => Err(MempoolServiceError::InvalidResponse("Incorrect response".to_string())),
}
}

Expand All @@ -79,7 +79,7 @@ impl MempoolHandle {
.await??
{
MempoolResponse::TxStorage(response) => Ok(response),
_ => panic!("Incorrect response"),
_ => Err(MempoolServiceError::InvalidResponse("Incorrect response".to_string())),
}
}

Expand All @@ -94,7 +94,7 @@ impl MempoolHandle {
.await??
{
MempoolResponse::FeePerGramStats { response } => Ok(response),
_ => panic!("Incorrect response"),
_ => Err(MempoolServiceError::InvalidResponse("Incorrect response".to_string())),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,6 @@ async fn manage_multiple_transactions() {

let database_path = temp_dir.path().to_str().unwrap().to_string();

// TODO: When using a memory type db connection this test fails at `assert_eq!(tx_reply, 3, "Need 3 replies");`
let (alice_connection, _tempdir) = make_wallet_database_connection(Some(database_path.clone()));
let (bob_connection, _tempdir) = make_wallet_database_connection(Some(database_path.clone()));
let (carol_connection, _tempdir) = make_wallet_database_connection(Some(database_path.clone()));
Expand Down

0 comments on commit 55a12cd

Please sign in to comment.