From 2611a5423f22e17f5e990c5ea229c588b6a056cf Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Mon, 29 Jul 2024 17:01:42 +0200 Subject: [PATCH 1/3] WIP on development initial sync --- .../src/automation/commands.rs | 71 ++++++++++++++++++- .../minotari_console_wallet/src/cli.rs | 7 ++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/applications/minotari_console_wallet/src/automation/commands.rs b/applications/minotari_console_wallet/src/automation/commands.rs index 1795b0d4e1..9d30ff898f 100644 --- a/applications/minotari_console_wallet/src/automation/commands.rs +++ b/applications/minotari_console_wallet/src/automation/commands.rs @@ -91,7 +91,7 @@ use tokio::{ sync::{broadcast, mpsc}, time::{sleep, timeout}, }; - +use minotari_wallet::utxo_scanner_service::handle::UtxoScannerEvent; use super::error::CommandError; use crate::{ automation::{ @@ -1500,6 +1500,75 @@ pub async fn command_runner( }, Err(err) => eprintln!("Error generating certificates: {}", err), }, + Sync(args) =>{ + let mut utxo_scanner = wallet.utxo_scanner_service.clone(); + let receiver = utxo_scanner.get_event_receiver(); + + if !online { + match wait_for_comms(&connectivity_requester).await { + Ok(..) => { + online = true; + }, + Err(e) => { + eprintln!("Sync error! {}", e); + continue; + }, + } + } + + loop{ + match receiver.recv().await { + Ok(event) => { + match event { + UtxoScannerEvent::ConnectingToBaseNode(Node) => { + println!("Connecting to base node..."); + }, + UtxoScannerEvent::ConnectedToBaseNode(_,_) => { + println!("Connected to base node"); + }, + UtxoScannerEvent::ConnectionFailedToBaseNode{..} => { + println!("Failed to connect to base node"); + }, + UtxoScannerEvent::ScanningRoundFailed { + num_retries, + retry_limit, + error, + }=> { + println!("Scanning round failed. Retries: {}/{}. Error: {}", num_retries, retry_limit, error); + }, + UtxoScannerEvent::Progress { + current_height, + tip_height, + }=> { + println!("Progress: {}/{}", current_height, tip_height); + if current_height => args.sync_to_height{ + break; + } + } + UtxoScannerEvent::Completed { + final_height, + num_recovered, + value_recovered, + time_taken, + }=> { + println!("Completed! Height: {}, UTXOs recovered: {}, Value recovered: {}, Time taken: {}", final_height, num_recovered, value_recovered, time_taken); + + break; + }, + UtxoScannerEvent::ScanningFailed=> { + println!("Scanning failed"); + break; + }, + } + }, + Err(e) => { + eprintln!("Sync error! {}", e); + break; + }, + } + } + + } } } diff --git a/applications/minotari_console_wallet/src/cli.rs b/applications/minotari_console_wallet/src/cli.rs index 51d28584ad..e10e1bd91d 100644 --- a/applications/minotari_console_wallet/src/cli.rs +++ b/applications/minotari_console_wallet/src/cli.rs @@ -141,6 +141,7 @@ pub enum CliCommands { RevalidateWalletDb, RegisterValidatorNode(RegisterValidatorNodeArgs), CreateTlsCerts, + Sync(SyncArgs) } #[derive(Debug, Args, Clone)] @@ -362,3 +363,9 @@ pub struct RegisterValidatorNodeArgs { #[clap(short, long, default_value = "Registering VN")] pub message: String, } + +#[derive(Debug, Args, Clone)] +pub struct SyncArgs { + #[clap(short, long, default_value = "0")] + pub sync_to_height: u64, +} From a4551e6c1215ca211678de3ba2749bee2baa484c Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Tue, 30 Jul 2024 08:12:34 +0200 Subject: [PATCH 2/3] sync --- .../src/automation/commands.rs | 132 ++++++++++++------ .../minotari_console_wallet/src/cli.rs | 2 +- 2 files changed, 88 insertions(+), 46 deletions(-) diff --git a/applications/minotari_console_wallet/src/automation/commands.rs b/applications/minotari_console_wallet/src/automation/commands.rs index 9d30ff898f..44c6c43d2e 100644 --- a/applications/minotari_console_wallet/src/automation/commands.rs +++ b/applications/minotari_console_wallet/src/automation/commands.rs @@ -38,11 +38,15 @@ use log::*; use minotari_app_grpc::tls::certs::{generate_self_signed_certs, print_warning, write_cert_to_disk}; use minotari_wallet::{ connectivity_service::WalletConnectivityInterface, - output_manager_service::{handle::OutputManagerHandle, UtxoSelectionCriteria}, + output_manager_service::{ + handle::{OutputManagerEvent, OutputManagerHandle}, + UtxoSelectionCriteria, + }, transaction_service::{ handle::{TransactionEvent, TransactionServiceHandle}, storage::models::WalletTransaction, }, + utxo_scanner_service::handle::UtxoScannerEvent, TransactionStage, WalletConfig, WalletSqlite, @@ -91,7 +95,7 @@ use tokio::{ sync::{broadcast, mpsc}, time::{sleep, timeout}, }; -use minotari_wallet::utxo_scanner_service::handle::UtxoScannerEvent; + use super::error::CommandError; use crate::{ automation::{ @@ -1500,9 +1504,9 @@ pub async fn command_runner( }, Err(err) => eprintln!("Error generating certificates: {}", err), }, - Sync(args) =>{ + Sync(args) => { let mut utxo_scanner = wallet.utxo_scanner_service.clone(); - let receiver = utxo_scanner.get_event_receiver(); + let mut receiver = utxo_scanner.get_event_receiver(); if !online { match wait_for_comms(&connectivity_requester).await { @@ -1516,50 +1520,57 @@ pub async fn command_runner( } } - loop{ + loop { match receiver.recv().await { - Ok(event) => { - match event { - UtxoScannerEvent::ConnectingToBaseNode(Node) => { - println!("Connecting to base node..."); - }, - UtxoScannerEvent::ConnectedToBaseNode(_,_) => { - println!("Connected to base node"); - }, - UtxoScannerEvent::ConnectionFailedToBaseNode{..} => { - println!("Failed to connect to base node"); - }, - UtxoScannerEvent::ScanningRoundFailed { - num_retries, - retry_limit, - error, - }=> { - println!("Scanning round failed. Retries: {}/{}. Error: {}", num_retries, retry_limit, error); - }, - UtxoScannerEvent::Progress { - current_height, - tip_height, - }=> { - println!("Progress: {}/{}", current_height, tip_height); - if current_height => args.sync_to_height{ - break; - } + Ok(event) => match event { + UtxoScannerEvent::ConnectingToBaseNode(_) => { + println!("Connecting to base node..."); + }, + UtxoScannerEvent::ConnectedToBaseNode(_, _) => { + println!("Connected to base node"); + }, + UtxoScannerEvent::ConnectionFailedToBaseNode { .. } => { + println!("Failed to connect to base node"); + }, + UtxoScannerEvent::ScanningRoundFailed { + num_retries, + retry_limit, + error, + } => { + println!( + "Scanning round failed. Retries: {}/{}. Error: {}", + num_retries, retry_limit, error + ); + }, + UtxoScannerEvent::Progress { + current_height, + tip_height, + } => { + println!("Progress: {}/{}", current_height, tip_height); + if current_height >= args.sync_to_height && args.sync_to_height > 0 { + break; } - UtxoScannerEvent::Completed { + }, + UtxoScannerEvent::Completed { + final_height, + num_recovered, + value_recovered, + time_taken, + } => { + println!( + "Completed! Height: {}, UTXOs recovered: {}, Value recovered: {}, Time taken: {}", final_height, num_recovered, value_recovered, - time_taken, - }=> { - println!("Completed! Height: {}, UTXOs recovered: {}, Value recovered: {}, Time taken: {}", final_height, num_recovered, value_recovered, time_taken); - - break; - }, - UtxoScannerEvent::ScanningFailed=> { - println!("Scanning failed"); - break; - }, - } + time_taken.as_secs() + ); + + break; + }, + UtxoScannerEvent::ScanningFailed => { + println!("Scanning failed"); + break; + }, }, Err(e) => { eprintln!("Sync error! {}", e); @@ -1567,8 +1578,39 @@ pub async fn command_runner( }, } } - - } + println!("Starting validation process"); + let mut oms = wallet.output_manager_service.clone(); + oms.validate_txos().await?; + let mut event = oms.get_event_stream(); + loop { + match event.recv().await { + Ok(event) => match *event { + OutputManagerEvent::TxoValidationSuccess(_) => { + println!("Validation succeeded"); + break; + }, + OutputManagerEvent::TxoValidationAlreadyBusy(_) => { + println!("Validation already busy"); + }, + _ => { + println!("Validation failed"); + break; + }, + }, + Err(e) => { + eprintln!("Sync error! {}", e); + break; + }, + } + } + println!("balance as of scanning height"); + match output_service.clone().get_balance().await { + Ok(balance) => { + println!("{}", balance); + }, + Err(e) => eprintln!("GetBalance error! {}", e), + } + }, } } diff --git a/applications/minotari_console_wallet/src/cli.rs b/applications/minotari_console_wallet/src/cli.rs index e10e1bd91d..401ebaeaf2 100644 --- a/applications/minotari_console_wallet/src/cli.rs +++ b/applications/minotari_console_wallet/src/cli.rs @@ -141,7 +141,7 @@ pub enum CliCommands { RevalidateWalletDb, RegisterValidatorNode(RegisterValidatorNodeArgs), CreateTlsCerts, - Sync(SyncArgs) + Sync(SyncArgs), } #[derive(Debug, Args, Clone)] From ce41b0b0f5807627a139e3013fa156d7ae05a260 Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Tue, 30 Jul 2024 10:51:40 +0200 Subject: [PATCH 3/3] fix test --- applications/minotari_console_wallet/src/wallet_modes.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/minotari_console_wallet/src/wallet_modes.rs b/applications/minotari_console_wallet/src/wallet_modes.rs index a3e3b6d688..31666865ce 100644 --- a/applications/minotari_console_wallet/src/wallet_modes.rs +++ b/applications/minotari_console_wallet/src/wallet_modes.rs @@ -614,6 +614,7 @@ mod test { CliCommands::RegisterValidatorNode(_) => {}, CliCommands::CreateTlsCerts => {}, CliCommands::PreMineSpendBackupUtxo(_) => {}, + CliCommands::Sync(_) => {}, } } assert!(