Skip to content

Commit

Permalink
feat(wallet): adds --stealth-one-sided flag to make-it-rain (#4508)
Browse files Browse the repository at this point in the history
Description
---

Adds --stealth-one-sided flag to make-it-rain

Motivation and Context
---
Stress test with stealth addresses

How Has This Been Tested?
---
Manually
  • Loading branch information
sdbondi authored Aug 19, 2022
1 parent 2a3af27 commit 30dd70e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl CommandContext {
if let LivenessEvent::ReceivedPong(pong) = &*event {
if pong.node_id == dest_node_id {
println!(
"🏓️ Pong received, latency in is {:.2?}!",
"🏓️ Pong received, round-trip-time is {:.2?}!",
pong.latency.unwrap_or_default()
);
break;
Expand Down
29 changes: 18 additions & 11 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use std::{
fs,
fs::File,
io,
io::{LineWriter, Write},
path::{Path, PathBuf},
time::{Duration, Instant},
Expand Down Expand Up @@ -68,7 +69,7 @@ use tokio::{

use super::error::CommandError;
use crate::{
cli::CliCommands,
cli::{CliCommands, MakeItRainTransactionType},
utils::db::{CUSTOM_BASE_NODE_ADDRESS_KEY, CUSTOM_BASE_NODE_PUBLIC_KEY_KEY},
};

Expand Down Expand Up @@ -299,7 +300,7 @@ pub async fn make_it_rain(
increase_amount: MicroTari,
start_time: DateTime<Utc>,
destination: PublicKey,
negotiated: bool,
transaction_type: MakeItRainTransactionType,
message: String,
) -> Result<(), CommandError> {
// We are spawning this command in parallel, thus not collecting transaction IDs
Expand Down Expand Up @@ -331,7 +332,6 @@ pub async fn make_it_rain(
delayed_for: Duration,
submit_time: Duration,
}
let transaction_type = if negotiated { "negotiated" } else { "one-sided" };
println!(
"\n`make-it-rain` starting {} {} transactions \"{}\"\n",
num_txs, transaction_type, message
Expand Down Expand Up @@ -367,15 +367,19 @@ pub async fn make_it_rain(
tokio::task::spawn(async move {
let spawn_start = Instant::now();
// Send transaction
let tx_id = if negotiated {
send_tari(tx_service, fee, amount, pk.clone(), msg.clone()).await
} else {
send_one_sided(tx_service, fee, amount, pk.clone(), msg.clone()).await
let tx_id = match transaction_type {
MakeItRainTransactionType::Interactive => {
send_tari(tx_service, fee, amount, pk.clone(), msg.clone()).await
},
MakeItRainTransactionType::OneSided => {
send_one_sided(tx_service, fee, amount, pk.clone(), msg.clone()).await
},
MakeItRainTransactionType::StealthOneSided => {
send_one_sided_to_stealth_address(tx_service, fee, amount, pk.clone(), msg.clone()).await
},
};
let submit_time = Instant::now();
tokio::task::spawn(async move {
print!("{} ", i + 1);
});

if let Err(e) = sender_clone
.send(TransactionSendStats {
i: i + 1,
Expand All @@ -397,6 +401,8 @@ pub async fn make_it_rain(
while let Some(send_stats) = receiver.recv().await {
match send_stats.tx_id {
Ok(tx_id) => {
print!("{} ", send_stats.i);
io::stdout().flush().unwrap();
debug!(
target: LOG_TARGET,
"make-it-rain transaction {} ({}) submitted to queue, tx_id: {}, delayed for ({}ms), submit \
Expand Down Expand Up @@ -606,6 +612,7 @@ pub async fn command_runner(
tx_ids.push(tx_id);
},
MakeItRain(args) => {
let transaction_type = args.transaction_type();
make_it_rain(
transaction_service.clone(),
config.fee_per_gram,
Expand All @@ -615,7 +622,7 @@ pub async fn command_runner(
args.increase_amount,
args.start_time.unwrap_or_else(Utc::now),
args.destination.into(),
!args.one_sided,
transaction_type,
args.message,
)
.await?;
Expand Down
33 changes: 32 additions & 1 deletion applications/tari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{path::PathBuf, time::Duration};
use std::{
fmt::{Display, Formatter},
path::PathBuf,
time::Duration,
};

use chrono::{DateTime, Utc};
use clap::{Args, Parser, Subcommand};
Expand Down Expand Up @@ -144,10 +148,37 @@ pub struct MakeItRainArgs {
pub start_time: Option<DateTime<Utc>>,
#[clap(short, long)]
pub one_sided: bool,
#[clap(short, long, alias = "stealth-one-sided")]
pub stealth: bool,
#[clap(short, long, default_value = "Make it rain")]
pub message: String,
}

impl MakeItRainArgs {
pub fn transaction_type(&self) -> MakeItRainTransactionType {
if self.stealth {
MakeItRainTransactionType::StealthOneSided
} else if self.one_sided {
MakeItRainTransactionType::OneSided
} else {
MakeItRainTransactionType::Interactive
}
}
}

#[derive(Debug, Clone, Copy)]
pub enum MakeItRainTransactionType {
Interactive,
OneSided,
StealthOneSided,
}

impl Display for MakeItRainTransactionType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

fn parse_start_time(arg: &str) -> Result<DateTime<Utc>, chrono::ParseError> {
let mut start_time = Utc::now();
if !arg.is_empty() && arg.to_uppercase() != "NOW" {
Expand Down

0 comments on commit 30dd70e

Please sign in to comment.