Skip to content

Commit

Permalink
Merge branch 'development' into hashing-move-to-common-crate
Browse files Browse the repository at this point in the history
* development:
  feat: make the make_it_rain submission rate a float (tari-project#6180)
  feat: wallet ffi use dns (tari-project#6152)
  chore: add localnet gen block (tari-project#6176)
  fix: hide unmined coinbase (tari-project#6159)
  chore: removes panics from wallet burn task (tari-project#6163)
  test: fix cucumber network environment (tari-project#6175)
  feat: lazily evaluate for new random_x template (tari-project#6170)
  • Loading branch information
sdbondi committed Mar 5, 2024
2 parents af925a6 + 75d773b commit 12ab21d
Show file tree
Hide file tree
Showing 65 changed files with 920 additions and 521 deletions.
1 change: 0 additions & 1 deletion applications/minotari_app_utilities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ license = "BSD-3-Clause"
tari_common = { path = "../../common" }
tari_common_types = { path = "../../base_layer/common_types" }
tari_comms = { path = "../../comms/core" }
tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.9" }
tari_utilities = { version = "0.7" }
minotari_app_grpc = { path = "../minotari_app_grpc", optional = true }

Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_app_utilities/src/common_cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl CommonCliArgs {
}

impl ConfigOverrideProvider for CommonCliArgs {
fn get_config_property_overrides(&self, _default_network: Network) -> Vec<(String, String)> {
fn get_config_property_overrides(&self, _network: &mut Network) -> Vec<(String, String)> {
let mut overrides = self.config_property_overrides.clone();
overrides.push((
"common.base_path".to_string(),
Expand Down
1 change: 0 additions & 1 deletion applications/minotari_app_utilities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

pub mod common_cli_args;
pub mod identity_management;
pub mod network_check;
#[cfg(feature = "miner_input")]
pub mod parse_miner_input;
pub mod utilities;
Expand Down
17 changes: 13 additions & 4 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ async fn set_base_node_peer(
) -> Result<(CommsPublicKey, Multiaddr), CommandError> {
println!("Setting base node peer...");
println!("{}::{}", public_key, address);
wallet.set_base_node_peer(public_key.clone(), address.clone()).await?;
wallet
.set_base_node_peer(public_key.clone(), Some(address.clone()))
.await?;
Ok((public_key, address))
}

Expand Down Expand Up @@ -349,7 +351,7 @@ pub async fn discover_peer(
pub async fn make_it_rain(
wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: u64,
transactions_per_second: u32,
transactions_per_second: f64,
duration: Duration,
start_amount: MicroMinotari,
increase_amount: MicroMinotari,
Expand All @@ -358,6 +360,13 @@ pub async fn make_it_rain(
transaction_type: MakeItRainTransactionType,
message: String,
) -> Result<(), CommandError> {
// Limit the transactions per second to a reasonable range
// Notes:
// - The 'transactions_per_second' is best effort and not guaranteed.
// - If a slower rate is requested as what is achievable, transactions will be delayed to match the rate.
// - If a faster rate is requested as what is achievable, the maximum rate will be that of the integrated system.
// - The default value of 25/s may not be achievable.
let transactions_per_second = transactions_per_second.abs().max(0.01).min(250.0);
// We are spawning this command in parallel, thus not collecting transaction IDs
tokio::task::spawn(async move {
// Wait until specified test start time
Expand All @@ -378,7 +387,7 @@ pub async fn make_it_rain(
);
sleep(Duration::from_millis(delay_ms)).await;

let num_txs = (f64::from(transactions_per_second) * duration.as_secs() as f64) as usize;
let num_txs = (transactions_per_second * duration.as_secs() as f64) as usize;
let started_at = Utc::now();

struct TransactionSendStats {
Expand Down Expand Up @@ -409,7 +418,7 @@ pub async fn make_it_rain(

// Manage transaction submission rate
let actual_ms = (Utc::now() - started_at).num_milliseconds();
let target_ms = (i as f64 * (1000.0 / f64::from(transactions_per_second))) as i64;
let target_ms = (i as f64 * (1000.0 / transactions_per_second)) as i64;
trace!(
target: LOG_TARGET,
"make-it-rain {}: target {:?} ms vs. actual {:?} ms", i, target_ms, actual_ms
Expand Down
10 changes: 5 additions & 5 deletions applications/minotari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ pub struct Cli {
}

impl ConfigOverrideProvider for Cli {
fn get_config_property_overrides(&self, default_network: Network) -> Vec<(String, String)> {
let mut overrides = self.common.get_config_property_overrides(default_network);
let network = self.common.network.unwrap_or(default_network);
fn get_config_property_overrides(&self, network: &mut Network) -> Vec<(String, String)> {
let mut overrides = self.common.get_config_property_overrides(network);
*network = self.common.network.unwrap_or(*network);
overrides.push(("wallet.network".to_string(), network.to_string()));
overrides.push(("wallet.override_from".to_string(), network.to_string()));
overrides.push(("p2p.seeds.override_from".to_string(), network.to_string()));
Expand Down Expand Up @@ -163,8 +163,8 @@ pub struct MakeItRainArgs {
pub destination: TariAddress,
#[clap(short, long, alias="amount", default_value_t = tari_amount::T)]
pub start_amount: MicroMinotari,
#[clap(short, long, alias = "tps", default_value_t = 25)]
pub transactions_per_second: u32,
#[clap(short, long, alias = "tps", default_value_t = 25.0)]
pub transactions_per_second: f64,
#[clap(short, long, parse(try_from_str = parse_duration), default_value="60")]
pub duration: Duration,
#[clap(long, default_value_t=tari_amount::T)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
println!("{}::{}", public_key, net_address);
let mut wallet = self.wallet.clone();
wallet
.set_base_node_peer(public_key.clone(), net_address.clone())
.set_base_node_peer(public_key.clone(), Some(net_address.clone()))
.await
.map_err(|e| Status::internal(format!("{:?}", e)))?;

Expand Down Expand Up @@ -736,26 +736,31 @@ impl wallet_server::Wallet for WalletGrpcServer {
) -> Result<Response<Self::GetCompletedTransactionsStream>, Status> {
debug!(
target: LOG_TARGET,
"Incoming GRPC request for GetAllCompletedTransactions"
"GetAllCompletedTransactions: Incoming GRPC request"
);
let mut transaction_service = self.get_transaction_service();
let transactions = transaction_service
.get_completed_transactions()
.await
.map_err(|err| Status::not_found(format!("No completed transactions found: {:?}", err)))?;
debug!(
target: LOG_TARGET,
"GetAllCompletedTransactions: Found {} completed transactions",
transactions.len()
);

let (mut sender, receiver) = mpsc::channel(transactions.len());
task::spawn(async move {
for (_, txn) in transactions {
for (i, (_, txn)) in transactions.iter().enumerate() {
let response = GetCompletedTransactionsResponse {
transaction: Some(TransactionInfo {
tx_id: txn.tx_id.into(),
source_address: txn.source_address.to_bytes().to_vec(),
dest_address: txn.destination_address.to_bytes().to_vec(),
status: TransactionStatus::from(txn.status) as i32,
status: TransactionStatus::from(txn.status.clone()) as i32,
amount: txn.amount.into(),
is_cancelled: txn.cancelled.is_some(),
direction: TransactionDirection::from(txn.direction) as i32,
direction: TransactionDirection::from(txn.direction.clone()) as i32,
fee: txn.fee.into(),
timestamp: txn.timestamp.timestamp() as u64,
excess_sig: txn
Expand All @@ -764,11 +769,19 @@ impl wallet_server::Wallet for WalletGrpcServer {
.unwrap_or(&Signature::default())
.get_signature()
.to_vec(),
message: txn.message,
message: txn.message.clone(),
}),
};
match sender.send(Ok(response)).await {
Ok(_) => (),
Ok(_) => {
debug!(
target: LOG_TARGET,
"GetAllCompletedTransactions: Sent transaction TxId: {} ({} of {})",
txn.tx_id,
i + 1,
transactions.len()
);
},
Err(err) => {
warn!(target: LOG_TARGET, "Error sending transaction via GRPC: {}", err);
match sender.send(Err(Status::unknown("Error sending data"))).await {
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ pub async fn start_wallet(
.ok_or_else(|| ExitError::new(ExitCode::ConfigError, "Configured base node has no address!"))?;

wallet
.set_base_node_peer(base_node.public_key.clone(), net_address.address().clone())
.set_base_node_peer(base_node.public_key.clone(), Some(net_address.address().clone()))
.await
.map_err(|e| {
ExitError::new(
Expand Down
4 changes: 1 addition & 3 deletions applications/minotari_console_wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub use cli::{
};
use init::{change_password, get_base_node_peer_config, init_wallet, start_wallet, tari_splash_screen, WalletBoot};
use log::*;
use minotari_app_utilities::{common_cli_args::CommonCliArgs, consts, network_check::set_network_if_choice_valid};
use minotari_app_utilities::{common_cli_args::CommonCliArgs, consts};
use minotari_wallet::transaction_service::config::TransactionRoutingMechanism;
use recovery::{get_seed_from_seed_words, prompt_private_key_from_seed_words};
use tari_common::{
Expand Down Expand Up @@ -117,8 +117,6 @@ pub fn run_wallet_with_cli(
consts::APP_VERSION
);

set_network_if_choice_valid(config.wallet.network)?;

let password = get_password(config, &cli);

if password.is_none() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ impl<B: Backend> Component<B> for TransactionsTab {
error!(target: LOG_TARGET, "Error rebroadcasting transactions: {}", e);
}
},
'a' => app_state.toggle_abandoned_coinbase_filter(),
'\n' => match self.selected_tx_list {
SelectedTransactionList::None => {},
SelectedTransactionList::PendingTxs => {
Expand Down
31 changes: 27 additions & 4 deletions applications/minotari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub struct AppState {
inner: Arc<RwLock<AppStateInner>>,
cached_data: AppStateData,
cache_update_cooldown: Option<Instant>,
completed_tx_filter: TransactionFilter,
config: AppStateConfig,
wallet_config: WalletConfig,
wallet_connectivity: WalletConnectivityHandle,
Expand All @@ -121,6 +122,7 @@ impl AppState {
cached_data,
cache_update_cooldown: None,
config: AppStateConfig::default(),
completed_tx_filter: TransactionFilter::AbandonedCoinbases,
wallet_connectivity,
balance_enquiry_debouncer: BalanceEnquiryDebouncer::new(
inner,
Expand Down Expand Up @@ -185,6 +187,13 @@ impl AppState {
Ok(())
}

pub fn toggle_abandoned_coinbase_filter(&mut self) {
self.completed_tx_filter = match self.completed_tx_filter {
TransactionFilter::AbandonedCoinbases => TransactionFilter::None,
TransactionFilter::None => TransactionFilter::AbandonedCoinbases,
};
}

pub async fn update_cache(&mut self) {
let update = match self.cache_update_cooldown {
Some(last_update) => last_update.elapsed() > self.config.cache_update_cooldown,
Expand Down Expand Up @@ -556,7 +565,15 @@ impl AppState {
}

pub fn get_completed_txs(&self) -> Vec<&CompletedTransactionInfo> {
self.cached_data.completed_txs.iter().collect()
if self.completed_tx_filter == TransactionFilter::AbandonedCoinbases {
self.cached_data
.completed_txs
.iter()
.filter(|tx| !matches!(tx.status, TransactionStatus::CoinbaseNotInBlockChain))
.collect()
} else {
self.cached_data.completed_txs.iter().collect()
}
}

pub fn get_confirmations(&self, tx_id: TxId) -> Option<&u64> {
Expand Down Expand Up @@ -1033,7 +1050,7 @@ impl AppStateInner {
self.wallet
.set_base_node_peer(
peer.public_key.clone(),
peer.addresses.best().ok_or(UiError::NoAddress)?.address().clone(),
Some(peer.addresses.best().ok_or(UiError::NoAddress)?.address().clone()),
)
.await?;

Expand All @@ -1058,7 +1075,7 @@ impl AppStateInner {
self.wallet
.set_base_node_peer(
peer.public_key.clone(),
peer.addresses.best().ok_or(UiError::NoAddress)?.address().clone(),
Some(peer.addresses.best().ok_or(UiError::NoAddress)?.address().clone()),
)
.await?;

Expand Down Expand Up @@ -1096,7 +1113,7 @@ impl AppStateInner {
self.wallet
.set_base_node_peer(
previous.public_key.clone(),
previous.addresses.best().ok_or(UiError::NoAddress)?.address().clone(),
Some(previous.addresses.best().ok_or(UiError::NoAddress)?.address().clone()),
)
.await?;

Expand Down Expand Up @@ -1370,3 +1387,9 @@ impl Default for AppStateConfig {
}
}
}

#[derive(Clone, PartialEq)]
pub enum TransactionFilter {
None,
AbandonedCoinbases,
}
47 changes: 36 additions & 11 deletions applications/minotari_console_wallet/src/ui/state/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,19 @@ pub async fn send_burn_transaction_task(
// burning minotari
// ----------------------------------------------------------------------------

let (burn_tx_id, original_proof) = transaction_service_handle
let (burn_tx_id, original_proof) = match transaction_service_handle
.burn_tari(amount, selection_criteria, fee_per_gram, message, claim_public_key)
.await
.map_err(|err| {
log::error!("failed to burn minotari: {:?}", err);

{
Ok((burn_tx_id, original_proof)) => (burn_tx_id, original_proof),
Err(e) => {
error!(target: LOG_TARGET, "failed to burn minotari: {:?}", e);
result_tx
.send(UiTransactionBurnStatus::Error(UiError::from(err).to_string()))
.send(UiTransactionBurnStatus::Error(format!("burn error: {}", e)))
.unwrap();
})
.unwrap();

return;
},
};
// ----------------------------------------------------------------------------
// starting a feedback loop to wait for the answer from the transaction service
// ----------------------------------------------------------------------------
Expand All @@ -292,14 +293,38 @@ pub async fn send_burn_transaction_task(
range_proof: original_proof.range_proof.0,
};

let serialized_proof =
serde_json::to_string_pretty(&wrapped_proof).expect("failed to serialize burn proof");
let serialized_proof = match serde_json::to_string_pretty(&wrapped_proof) {
Ok(proof) => proof,
Err(e) => {
error!(target: LOG_TARGET, "failed to serialize burn proof: {:?}", e);
result_tx
.send(UiTransactionBurnStatus::Error(format!(
"failure to create proof {:?}",
e
)))
.unwrap();
return;
},
};

let proof_id = random::<u32>();

let filepath =
burn_proof_filepath.unwrap_or_else(|| PathBuf::from(format!("{}.json", proof_id)));

std::fs::write(filepath, serialized_proof.as_bytes()).expect("failed to save burn proof");
match std::fs::write(filepath, serialized_proof.as_bytes()) {
Ok(()) => {},
Err(e) => {
error!(target: LOG_TARGET, "failed to write burn proof: {:?}", e);
result_tx
.send(UiTransactionBurnStatus::Error(format!(
"failure to write proof {:?}",
e
)))
.unwrap();
return;
},
};

let result = db.create_burnt_proof(
proof_id,
Expand Down
18 changes: 9 additions & 9 deletions applications/minotari_merge_mining_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ edition = "2018"
default = []

[dependencies]
minotari_app_grpc = { path = "../minotari_app_grpc" }
minotari_app_utilities = { path = "../minotari_app_utilities", features = ["miner_input"] }
minotari_node_grpc_client = { path = "../../clients/rust/base_node_grpc_client" }
minotari_wallet_grpc_client = { path = "../../clients/rust/wallet_grpc_client" }
tari_common = { path = "../../common" }
tari_common_types = { path = "../../base_layer/common_types" }
tari_comms = { path = "../../comms/core" }
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] }
minotari_app_utilities = { path = "../minotari_app_utilities", features = ["miner_input"] }
tari_utilities = { version = "0.7" }
minotari_node_grpc_client = { path = "../../clients/rust/base_node_grpc_client" }
minotari_wallet_grpc_client = { path = "../../clients/rust/wallet_grpc_client" }
minotari_app_grpc = { path = "../minotari_app_grpc" }
tari_key_manager = { path = "../../base_layer/key_manager", features = ["key_manager_service"] }
tari_utilities = { version = "0.7" }

anyhow = "1.0.53"
crossterm = { version = "0.25.0" }
bincode = "1.3.1"
borsh = "1.2"
bytes = "1.1"
chrono = { version = "0.4.6", default-features = false }
chrono = { version = "0.4.19", default-features = false }
clap = { version = "3.2", features = ["derive", "env"] }
config = { version = "0.13.0" }
futures = "0.3.5"
crossterm = { version = "0.25.0" }
futures = { version = "^0.3.16", features = ["async-await"] }
hex = "0.4.2"
hyper = "0.14.12"
jsonrpc = "0.12.0"
log = { version = "0.4.8", features = ["std"] }
monero = { version = "0.20.0" }
reqwest = { version = "0.11.4", features = ["json"] }
serde = { version = "1.0.106", features = ["derive"] }
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.57"
thiserror = "1.0.26"
tokio = { version = "1.23", features = ["macros"] }
Expand Down
Loading

0 comments on commit 12ab21d

Please sign in to comment.