Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Merge pull request #601 from LOL-LLC/txs-timeout
Browse files Browse the repository at this point in the history
TXS timeout and error handling
  • Loading branch information
soaresa authored Jul 18, 2021
2 parents a52aa6b + 86f1077 commit 02fd9ae
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 31 deletions.
13 changes: 11 additions & 2 deletions ol/txs/src/commands/autopay_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![allow(clippy::never_loop)]

use std::process::exit;

use abscissa_core::{Command, Options, Runnable};

use crate::{entrypoint, submit_tx::{ maybe_submit, tx_params_wrapper}};
Expand Down Expand Up @@ -30,12 +32,19 @@ impl Runnable for AutopayCmd {
} else {
panic!("must choose --enable or --disable");
};
maybe_submit(

match maybe_submit(
script,
&tx_params,
entry_args.no_send,
entry_args.save_path,
).unwrap();
) {
Err(e) => {
println!("ERROR: could not submit autopay transaction, message: \n{:?}", &e);
exit(1);
},
_ => {}
}



Expand Down
22 changes: 10 additions & 12 deletions ol/txs/src/commands/create_account_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use abscissa_core::{Command, Options, Runnable};
use ol_types::config::TxType;
use crate::{entrypoint, submit_tx::{tx_params_wrapper, maybe_submit}};
use libra_types::{transaction::{Script}};
use std::{fs, path::PathBuf};
use std::{fs, path::PathBuf, process::exit};

/// `CreateAccount` subcommand
#[derive(Command, Debug, Default, Options)]
Expand Down Expand Up @@ -44,20 +44,18 @@ impl Runnable for CreateAccountCmd {
let entry_args = entrypoint::get_args();
let account_json = self.account_json_path.to_str().unwrap();
let tx_params = tx_params_wrapper(TxType::Mgmt).unwrap();
maybe_submit(

match maybe_submit(
create_user_account_script(account_json),
&tx_params,
entry_args.no_send,
entry_args.save_path,
).unwrap();
// match submit_tx(
// &tx_params,
// create_user_account_script(account_json)
// ) {
// Err(err) => { println!("{:?}", err) }
// Ok(res) => {
// eval_tx_status(res);
// }
// }
) {
Err(e) => {
println!("ERROR: could not submit account creation transaction, message: \n{:?}", &e);
exit(1);
},
_ => {}
}
}
}
15 changes: 13 additions & 2 deletions ol/txs/src/commands/demo_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![allow(clippy::never_loop)]

use std::process::exit;

use abscissa_core::{Command, Options, Runnable};
use ol_types::config::TxType;
use crate::{entrypoint, submit_tx::{tx_params_wrapper, maybe_submit}};
Expand All @@ -16,11 +18,20 @@ impl Runnable for DemoCmd {
let entry_args = entrypoint::get_args();

let tx_params = tx_params_wrapper(TxType::Cheap).unwrap();
maybe_submit(

match maybe_submit(
transaction_builder::encode_demo_e2e_script(42),
&tx_params,
entry_args.no_send,
entry_args.save_path
).unwrap();
) {
Ok(r) => {
println!("{:?}", &r);
},
Err(e) => {
println!("ERROR: could not submit demo transaction, message: \n{:?}", &e);
exit(1);
},
}
}
}
12 changes: 9 additions & 3 deletions ol/txs/src/commands/oracle_upgrade_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use abscissa_core::{Command, Options, Runnable};
use ol_types::config::TxType;
use crate::{entrypoint, prelude::app_config, submit_tx::{tx_params_wrapper, maybe_submit}};
use libra_types::{transaction::{Script}};
use std::{fs, io::prelude::*, path::PathBuf};
use std::{fs, io::prelude::*, path::PathBuf, process::exit};

/// `OracleUpgrade` subcommand
#[derive(Command, Debug, Default, Options)]
Expand Down Expand Up @@ -35,11 +35,17 @@ impl Runnable for OracleUpgradeCmd {
cfg.workspace.stdlib_bin_path.clone().unwrap()
});

maybe_submit(
match maybe_submit(
oracle_tx_script(&path),
&tx_params,
entry_args.no_send,
entry_args.save_path
).unwrap();
) {
Err(e) => {
println!("ERROR: could not submit upgrade transaction, message: \n{:?}", &e);
exit(1);
},
_ => {}
}
}
}
10 changes: 8 additions & 2 deletions ol/txs/src/commands/relay_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(clippy::never_loop)]

use std::path::PathBuf;
use std::{path::PathBuf, process::exit};

use abscissa_core::{Command, Options, Runnable};
use crate::relay::relay_from_file;
Expand All @@ -18,6 +18,12 @@ pub struct RelayCmd {

impl Runnable for RelayCmd {
fn run(&self) {
relay_from_file(self.relay_file.clone()).unwrap();
match relay_from_file(self.relay_file.clone()) {
Err(e) => {
println!("ERROR: could not relay transaction, message: \n{:?}", &e);
exit(1);
},
_ => {}
}
}
}
13 changes: 10 additions & 3 deletions ol/txs/src/commands/valset_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![allow(clippy::never_loop)]

use std::process::exit;

use crate::{
entrypoint,
submit_tx::{maybe_submit, tx_params_wrapper},
Expand Down Expand Up @@ -37,13 +39,18 @@ impl Runnable for ValSetCmd {
panic!("need to set --join or --leave flags")
};

maybe_submit(
match maybe_submit(
script,
// transaction_builder::encode_demo_e2e_script(42),
&tx_params,
entry_args.no_send,
entry_args.save_path,
)
.unwrap();
) {
Err(e) => {
println!("ERROR: could not submit validator-set transaction, message: \n{:?}", &e);
exit(1);
},
_ => {}
}
}
}
10 changes: 8 additions & 2 deletions ol/txs/src/commands/wallet_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ impl Runnable for WalletCmd {
};

let tx_params = tx_params_wrapper(TxType::Cheap).unwrap();
maybe_submit(
match maybe_submit(
transaction_builder::encode_set_wallet_type_script(type_int),
&tx_params,
entry_args.no_send,
entry_args.save_path
).unwrap();
) {
Err(e) => {
println!("ERROR: could not submit wallet type transaction, message: \n{:?}", &e);
exit(1);
},
_ => {}
}
}
}
12 changes: 7 additions & 5 deletions ol/txs/src/submit_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,16 @@ pub fn wait_for_tx(
client: &mut LibraClient,
) -> Option<TransactionView> {
println!(
"\nAwaiting tx status \n\
Submitted from account: {} with sequence number: {}",
signer_address, sequence_number
"\nAwaiting tx status \nSubmitted from account: {} with sequence number: {}",
signer_address,
sequence_number
);

const MAX_ITERATIONS: u8 = 30;

let mut iter = 0;
const MAX_ITERATIONS: u8 = 10; // 5000 * 2/1000
loop {
thread::sleep(time::Duration::from_millis(1000));
thread::sleep(time::Duration::from_millis(1_000));
// prevent all the logging the client does while
// it loops through the query.
stdout().flush().unwrap();
Expand All @@ -411,6 +412,7 @@ pub fn wait_for_tx(
iter += 1;

if iter==MAX_ITERATIONS {
println!("Timeout waiting for response");
return None;
}
}
Expand Down

0 comments on commit 02fd9ae

Please sign in to comment.