From b3ea19ae09bfcac007b3491ce299379df33ddd31 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal <39146854+hansieodendaal@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:55:51 +0200 Subject: [PATCH] feat: exit logic for pre-mine spend (#6615) 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\\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\\\\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\\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. Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify Co-authored-by: SW van Heerden --- .../src/automation/commands.rs | 26 ++++++++++--------- .../src/wallet_modes.rs | 14 +++++++--- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/applications/minotari_console_wallet/src/automation/commands.rs b/applications/minotari_console_wallet/src/automation/commands.rs index f64e13062d..a4a96b418f 100644 --- a/applications/minotari_console_wallet/src/automation/commands.rs +++ b/applications/minotari_console_wallet/src/automation/commands.rs @@ -725,7 +725,7 @@ pub async fn command_runner( config: &WalletConfig, commands: Vec, wallet: WalletSqlite, -) -> Result<(), CommandError> { +) -> Result { let wait_stage = config.command_send_wait_stage; let mut transaction_service = wallet.transaction_service.clone(); @@ -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() { @@ -809,7 +809,7 @@ pub async fn command_runner( Ok(items) => items, Err(e) => { eprintln!("\nError: {}\n", e); - return Ok(()); + return Ok(false); }, }; @@ -817,7 +817,7 @@ pub async fn command_runner( Ok(values) => values, Err(e) => { eprintln!("\nError: {}\n", e); - return Ok(()); + return Ok(false); }, }; let csv_file_name = "pre_mine_items_with_status.csv"; @@ -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() { @@ -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); } } @@ -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 { @@ -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::(&args.session_id)?; @@ -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!(); @@ -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::(&args.session_id)?; @@ -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 @@ -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) { diff --git a/applications/minotari_console_wallet/src/wallet_modes.rs b/applications/minotari_console_wallet/src/wallet_modes.rs index d1370c584d..8f856962db 100644 --- a/applications/minotari_console_wallet/src/wallet_modes.rs +++ b/applications/minotari_console_wallet/src/wallet_modes.rs @@ -140,7 +140,7 @@ 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)"; @@ -148,7 +148,11 @@ 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); + let (force_exit, force_interactive) = if exit_override { + (true, false) + } else { + force_exit_for_pre_mine_commands(&command) + }; wallet_or_exit( handle, cli, @@ -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)";