Skip to content

Commit

Permalink
feat: add esmeralda pre-mine (#6454)
Browse files Browse the repository at this point in the history
Description
---
Added pre-mine information to the esmeralda genesis block

_**Note:** Temporarily reverted change introduced by release
`v1.1.0-pre.2`, will be fixed in #6452._

Motivation and Context
---
Testing pre-mine

How Has This Been Tested?
---
Unit tests

What process can a PR reviewer use to test or verify this change?
---
Code review

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
hansieodendaal committed Aug 6, 2024
1 parent 260b4ce commit c38a948
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 79 deletions.
113 changes: 66 additions & 47 deletions applications/minotari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,32 @@ pub(crate) fn command_mode(

info!(target: LOG_TARGET, "Completed wallet command mode");

let (force_exit, force_interactive) = force_exit_for_pre_mine_commands(&command);
wallet_or_exit(
handle,
cli,
config,
base_node_config,
wallet,
force_exit_for_pre_mine_commands(&command),
force_exit,
force_interactive,
)
}

fn force_exit_for_pre_mine_commands(command: &CliCommands) -> bool {
matches!(
command,
CliCommands::PreMineCreateScriptInputs(_) |
CliCommands::PreMineCreateGenesisFile(_) |
CliCommands::PreMineCreateVerifyGenesisFile(_) |
CliCommands::PreMineSpendSessionInfo(_) |
CliCommands::PreMineSpendEncumberAggregateUtxo(_) |
CliCommands::PreMineSpendAggregateTransaction(_) |
CliCommands::PreMineSpendPartyDetails(_) |
CliCommands::PreMineSpendInputOutputSigs(_) |
CliCommands::PreMineSpendBackupUtxo(_)
fn force_exit_for_pre_mine_commands(command: &CliCommands) -> (bool, bool) {
(
matches!(
command,
CliCommands::PreMineCreateScriptInputs(_) |
CliCommands::PreMineCreateGenesisFile(_) |
CliCommands::PreMineCreateVerifyGenesisFile(_) |
CliCommands::PreMineSpendSessionInfo(_) |
CliCommands::PreMineSpendEncumberAggregateUtxo(_) |
CliCommands::PreMineSpendPartyDetails(_) |
CliCommands::PreMineSpendInputOutputSigs(_) |
CliCommands::PreMineSpendBackupUtxo(_)
),
matches!(command, CliCommands::PreMineSpendAggregateTransaction(_)),
)
}

Expand Down Expand Up @@ -226,16 +230,17 @@ pub(crate) fn script_mode(

println!("Parsing commands...");
let commands = parse_command_file(script)?;
let mut exit_wallet = false;
let mut force_exit = false;
let mut force_interactive = false;
for command in &commands {
if force_exit_for_pre_mine_commands(command) {
println!("Pre-mine commands may not run in script mode!");
exit_wallet = true;
(force_exit, force_interactive) = force_exit_for_pre_mine_commands(command);
if force_exit || force_interactive {
println!("Pre-mine command '{:?}' may not run in script mode!", command);
break;
}
}

if !exit_wallet {
if !force_exit {
println!("{} commands parsed successfully.", commands.len());

// Do not remove this println!
Expand All @@ -252,7 +257,15 @@ pub(crate) fn script_mode(
info!(target: LOG_TARGET, "Completed wallet script mode");
}

wallet_or_exit(handle, cli, config, base_node_config, wallet, exit_wallet)
wallet_or_exit(
handle,
cli,
config,
base_node_config,
wallet,
force_exit,
force_interactive,
)
}

/// Prompts the user to continue to the wallet, or exit.
Expand All @@ -263,36 +276,42 @@ fn wallet_or_exit(
base_node_config: &PeerConfig,
wallet: WalletSqlite,
force_exit: bool,
force_interactive: bool,
) -> Result<(), ExitError> {
if cli.command_mode_auto_exit {
info!(target: LOG_TARGET, "Auto exit argument supplied - exiting.");
return Ok(());
}
if force_exit {
info!(target: LOG_TARGET, "Forced exit argument supplied by process - exiting.");
return Ok(());
}

if cli.non_interactive_mode {
info!(target: LOG_TARGET, "Starting GRPC server.");
grpc_mode(handle, config, wallet)
if force_interactive {
info!(target: LOG_TARGET, "Starting TUI.");
tui_mode(handle.clone(), config, base_node_config, wallet.clone())
} else {
debug!(target: LOG_TARGET, "Prompting for run or exit key.");
println!("\nPress Enter to continue to the wallet, or type q (or quit) followed by Enter.");
let mut buf = String::new();
std::io::stdin()
.read_line(&mut buf)
.map_err(|e| ExitError::new(ExitCode::IOError, e))?;

match buf.as_str().trim() {
"quit" | "q" | "exit" => {
info!(target: LOG_TARGET, "Exiting.");
Ok(())
},
_ => {
info!(target: LOG_TARGET, "Starting TUI.");
tui_mode(handle, config, base_node_config, wallet)
},
if cli.command_mode_auto_exit {
info!(target: LOG_TARGET, "Auto exit argument supplied - exiting.");
return Ok(());
}
if force_exit {
info!(target: LOG_TARGET, "Forced exit argument supplied by process - exiting.");
return Ok(());
}

if cli.non_interactive_mode {
info!(target: LOG_TARGET, "Starting GRPC server.");
grpc_mode(handle, config, wallet)
} else {
debug!(target: LOG_TARGET, "Prompting for run or exit key.");
println!("\nPress Enter to continue to the wallet, or type q (or quit) followed by Enter.");
let mut buf = String::new();
std::io::stdin()
.read_line(&mut buf)
.map_err(|e| ExitError::new(ExitCode::IOError, e))?;

match buf.as_str().trim() {
"quit" | "q" | "exit" => {
info!(target: LOG_TARGET, "Exiting.");
Ok(())
},
_ => {
info!(target: LOG_TARGET, "Starting TUI.");
tui_mode(handle, config, base_node_config, wallet)
},
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions base_layer/core/src/blocks/genesis_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ pub fn get_esmeralda_genesis_block() -> ChainBlock {

// Hardcode the Merkle roots once they've been computed above
block.header.kernel_mr =
FixedHash::from_hex("b97afb0f165fc41e47d5a6bea4e651a16ffab2ecc6259814b42084aeac8fb959").unwrap();
FixedHash::from_hex("c3b93616d0e6289e8faff111d9d7b009fc45a04f3a5c31a5ad22610bc37f9dd7").unwrap();
block.header.output_mr =
FixedHash::from_hex("a2bbf7770db43bb1ad57c20d7737870f290618376f8b156019414abb494c23a8").unwrap();
FixedHash::from_hex("002a2ca5084105b8f0a165a40b6e707fd6cbae5ae14ca590735e21dd14ddb00a").unwrap();
block.header.validator_node_mr =
FixedHash::from_hex("277da65c40b2cf99db86baedb903a3f0a38540f3a94d40c826eecac7e27d5dfc").unwrap();
}
Expand All @@ -304,7 +304,7 @@ pub fn get_esmeralda_genesis_block() -> ChainBlock {

fn get_esmeralda_genesis_block_raw() -> Block {
// Set genesis timestamp
let genesis_timestamp = DateTime::parse_from_rfc2822("12 Jul 2024 08:00:00 +0200").expect("parse may not fail");
let genesis_timestamp = DateTime::parse_from_rfc2822("06 Aug 2024 08:00:00 +0200").expect("parse may not fail");
// Let us add a "not before" proof to the genesis block
let not_before_proof =
b"as I sip my drink, thoughts of esmeralda consume my mind, like a refreshing nourishing draught \
Expand Down Expand Up @@ -417,11 +417,11 @@ mod test {

#[test]
#[cfg(tari_target_network_testnet)]
fn esme_genesis_sanity_check() {
fn esmeralda_genesis_sanity_check() {
// Note: Generate new data for `pub fn get_esmeralda_genesis_block()` and `fn get_esmeralda_genesis_block_raw()`
// if consensus values change, e.g. new pre_mine or other
let block = get_esmeralda_genesis_block();
check_block(Network::Esmeralda, &block, 20, 1);
check_block(Network::Esmeralda, &block, 164, 1);
}

#[test]
Expand Down
Loading

0 comments on commit c38a948

Please sign in to comment.