Skip to content

Commit

Permalink
feat: exit logic for pre-mine spend (#6615)
Browse files Browse the repository at this point in the history
Description
---
Add exit logic for immediate pre-mine spend. In other cases, the wallet
should be started so that the transaction(s) can be broadcast.

Motivation and Context
---
With immediate pre-mne spend, the blockchain does not exist yet and the
transaction will be rejected if the wallet is started.

How Has This Been Tested?
---
System-level testing completed with base nodes and network available.
The wallet did not connect to the network and could not broadcast
partially completed transaction to a base node.

**Step 3**
```
PS H:\node_01> .\minotari_console_wallet.exe --base-path . --network esmeralda --config $pwd"\config\config.toml" --log-config $pwd"\config\log4rs_console_wallet.yml" pre-mine-spend-encumber-aggregate-utxo --session-id 8rJDGzkJv598xVJ3 --input-file-names=step_2_for_leader_from_bob.json --pre-mine-file-path "C:\Users\<user>\Documents\tari_pre_mine\create"
Initializing logging according to "H:\\node_01\\config\\log4rs_console_wallet.yml"
Minotari Console Wallet running... (Command mode started)
==============
Command Runner
==============

1. PreMineSpendEncumberAggregateUtxo(PreMineSpendEncumberAggregateUtxoArgs { session_id: "8rJDGzkJv598xVJ3", input_file_names: ["step_2_for_leader_from_bob.json"], pre_mine_file_path: Some("C:\\Users\\<user>\\Documents\\tari_pre_mine\\create") })


  Processed 1 of 6 transactions
  Processed 2 of 6 transactions
  Processed 3 of 6 transactions
  Processed 4 of 6 transactions
  Processed 5 of 6 transactions
  Processed 6 of 6 transactions

Concluded step 3 'pre-mine-spend-encumber-aggregate-utxo'
Send 'step_3_for_parties.json' to parties for step 4

Minotari Console Wallet running... (Command mode completed)

Shutting down wallet... Done.
```
**Step 5**
```
PS H:\node_01> .\minotari_console_wallet.exe --base-path . --network esmeralda --config $pwd"\config\config.toml" --log-config $pwd"\config\log4rs_console_wallet.yml" pre-mine-spend-aggregate-transaction --session-id 8rJDGzkJv598xVJ3 --input-file-names=step_4_for_leader_from_bob.json
Initializing logging according to "H:\\node_01\\config\\log4rs_console_wallet.yml"
Minotari Console Wallet running... (Command mode started)
==============
Command Runner
==============

1. PreMineSpendAggregateTransaction(PreMineSpendAggregateTransactionArgs { session_id: "8rJDGzkJv598xVJ3", input_file_names: ["step_4_for_leader_from_bob.json"] })


  Processed 1 of 6

  Processed 2 of 6

  Processed 3 of 6

  Processed 4 of 6

  Processed 5 of 6

  Processed 6 of 6

Genesis block immediate pre-mine spend information: 'esmeralda_pre_mine_addition.json' in 'C:\Users\<user>\Documents\tari_pre_mine\spend\8rJDGzkJv598xVJ3'
Concluded step 5 'pre-mine-spend-aggregate-transaction'

Minotari Console Wallet running... (Command mode completed)

Shutting down wallet... Done.
```

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 -->

Co-authored-by: SW van Heerden <swvheerden@gmail.com>
  • Loading branch information
hansieodendaal and SWvheerden authored Oct 8, 2024
1 parent 3608b9a commit b3ea19a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
26 changes: 14 additions & 12 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ pub async fn command_runner(
config: &WalletConfig,
commands: Vec<CliCommands>,
wallet: WalletSqlite,
) -> Result<(), CommandError> {
) -> Result<bool, CommandError> {
let wait_stage = config.command_send_wait_stage;

let mut transaction_service = wallet.transaction_service.clone();
Expand All @@ -747,7 +747,7 @@ pub async fn command_runner(
} else {
(0, vec![])
};
let mut unban_per_manager_peers = false;
let mut unban_peer_manager_peers = false;

#[allow(clippy::enum_glob_use)]
for (idx, parsed) in commands.into_iter().enumerate() {
Expand Down Expand Up @@ -809,15 +809,15 @@ pub async fn command_runner(
Ok(items) => items,
Err(e) => {
eprintln!("\nError: {}\n", e);
return Ok(());
return Ok(false);
},
};

let (session_id, out_dir) = match create_pre_mine_output_dir(Some("pre_mine_status")) {
Ok(values) => values,
Err(e) => {
eprintln!("\nError: {}\n", e);
return Ok(());
return Ok(false);
},
};
let csv_file_name = "pre_mine_items_with_status.csv";
Expand All @@ -828,7 +828,7 @@ pub async fn command_runner(
file_stream.write_all("index,value,maturity,fail_safe_height,beneficiary,spent_status\n".as_bytes())
{
eprintln!("\nError: Could not write pre-mine header ({})\n", e);
return Ok(());
return Ok(false);
}

for (index, item) in pre_mine_items.iter().enumerate() {
Expand All @@ -849,7 +849,7 @@ pub async fn command_runner(
.as_bytes(),
) {
eprintln!("\nError: Could not write pre-mine item ({})\n", e);
return Ok(());
return Ok(false);
}
}

Expand Down Expand Up @@ -920,7 +920,7 @@ pub async fn command_runner(
Ok(values) => values,
Err(e) => {
eprintln!("\nError: {}\n", e);
return Ok(());
return Ok(false);
},
};
let session_info = PreMineSpendStep1SessionInfo {
Expand Down Expand Up @@ -1180,7 +1180,7 @@ pub async fn command_runner(
}

temp_ban_peers(&wallet, &mut peer_list).await;
unban_per_manager_peers = true;
unban_peer_manager_peers = true;

// Read session info
let session_info = read_verify_session_info::<PreMineSpendStep1SessionInfo>(&args.session_id)?;
Expand Down Expand Up @@ -1258,7 +1258,8 @@ pub async fn command_runner(
Ok(items) => items,
Err(e) => {
eprintln!("\nError: {}\n", e);
return Ok(());
lift_temp_ban_peers(&wallet, &mut peer_list).await;
return Ok(true);
},
};
println!();
Expand Down Expand Up @@ -1651,7 +1652,7 @@ pub async fn command_runner(
}

temp_ban_peers(&wallet, &mut peer_list).await;
unban_per_manager_peers = true;
unban_peer_manager_peers = true;

// Read session info
let session_info = read_verify_session_info::<PreMineSpendStep1SessionInfo>(&args.session_id)?;
Expand Down Expand Up @@ -2630,8 +2631,9 @@ pub async fn command_runner(
},
}
}
if unban_per_manager_peers {
if unban_peer_manager_peers {
lift_temp_ban_peers(&wallet, &mut peer_list).await;
return Ok(true);
}

// listen to event stream
Expand Down Expand Up @@ -2669,7 +2671,7 @@ pub async fn command_runner(
}
}

Ok(())
Ok(unban_peer_manager_peers)
}

async fn temp_ban_peers(wallet: &WalletSqlite, peer_list: &mut Vec<Peer>) {
Expand Down
14 changes: 11 additions & 3 deletions applications/minotari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,19 @@ pub(crate) fn command_mode(
println!("{}", CUCUMBER_TEST_MARKER_A);

info!(target: LOG_TARGET, "Starting wallet command mode");
handle.block_on(command_runner(config, vec![command.clone()], wallet.clone()))?;
let exit_override = handle.block_on(command_runner(config, vec![command.clone()], wallet.clone()))?;

// Do not remove this println!
const CUCUMBER_TEST_MARKER_B: &str = "Minotari Console Wallet running... (Command mode completed)";
println!("{}", CUCUMBER_TEST_MARKER_B);

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

let (force_exit, force_interactive) = force_exit_for_pre_mine_commands(&command);
let (force_exit, force_interactive) = if exit_override {
(true, false)
} else {
force_exit_for_pre_mine_commands(&command)
};
wallet_or_exit(
handle,
cli,
Expand Down Expand Up @@ -237,7 +241,11 @@ pub(crate) fn script_mode(
println!("{}", CUCUMBER_TEST_MARKER_A);

println!("Starting the command runner!");
handle.block_on(command_runner(config, commands, wallet.clone()))?;
let exit_override = handle.block_on(command_runner(config, commands, wallet.clone()))?;
if exit_override {
force_exit = true;
force_interactive = false;
}

// Do not remove this println!
const CUCUMBER_TEST_MARKER_B: &str = "Minotari Console Wallet running... (Script mode completed)";
Expand Down

0 comments on commit b3ea19a

Please sign in to comment.