Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more log details #474

Merged
merged 5 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions swap/src/asb/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ pub struct ConfigNotInitialized {}
pub fn read_config(config_path: PathBuf) -> Result<Result<Config, ConfigNotInitialized>> {
if config_path.exists() {
info!(
"Using config file at default path: {}",
config_path.display()
path = %config_path.display(),
"Using config file at path",
bonomat marked this conversation as resolved.
Show resolved Hide resolved
);
} else {
return Ok(Err(ConfigNotInitialized {}));
Expand Down Expand Up @@ -148,8 +148,8 @@ where
fs::write(&config_path, toml)?;

info!(
"Initial setup complete, config file created at {} ",
config_path.as_path().display()
path = %config_path.as_path().display(),
"Initial setup complete, config file created",
);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion swap/src/asb/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn init(level: LevelFilter) -> Result<()> {
builder.init();
}

tracing::info!("Initialized tracing with level: {}", level);
tracing::info!(%level, "Initialized tracing");

Ok(())
}
39 changes: 23 additions & 16 deletions swap/src/bin/asb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use swap::protocol::alice::{redeem, run, EventLoop};
use swap::seed::Seed;
use swap::tor::AuthenticatedClient;
use swap::{asb, bitcoin, env, kraken, monero, tor};
use tracing::{info, warn};
use tracing::{debug, info, warn};
use tracing_subscriber::filter::LevelFilter;

#[macro_use]
Expand Down Expand Up @@ -64,8 +64,8 @@ async fn main() -> Result<()> {
};

info!(
"Database and Seed will be stored in directory: {}",
config.data.dir.display()
db_folder = %config.data.dir.display(),
"Database and Seed will be stored in",
);

let db_path = config.data.dir.join("database");
Expand All @@ -81,20 +81,21 @@ async fn main() -> Result<()> {
match opt.cmd {
Command::Start { resume_only } => {
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;

let monero_wallet = init_monero_wallet(&config, env_config).await?;

let bitcoin_balance = bitcoin_wallet.balance().await?;
info!("Bitcoin balance: {}", bitcoin_balance);
info!(%bitcoin_balance, "Initialized Bitcoin wallet");

let monero_balance = monero_wallet.get_balance().await?;
if monero_balance == Amount::ZERO {
let deposit_address = monero_wallet.get_main_address();
let monero_address = monero_wallet.get_main_address();
warn!(
"The Monero balance is 0, make sure to deposit funds at: {}",
deposit_address
%monero_address,
"The Monero balance is 0, make sure to deposit funds",
bonomat marked this conversation as resolved.
Show resolved Hide resolved
)
} else {
info!("Monero balance: {}", monero_balance);
info!(%monero_balance, "Initialized Monero wallet");
}

let kraken_price_updates = kraken::connect()?;
Expand All @@ -104,14 +105,14 @@ async fn main() -> Result<()> {
tor::Client::new(config.tor.socks5_port).with_control_port(config.tor.control_port);
let _ac = match tor_client.assert_tor_running().await {
Ok(_) => {
tracing::info!("Tor found. Setting up hidden service. ");
tracing::info!("Tor found. Setting up hidden service");
let ac =
register_tor_services(config.network.clone().listen, tor_client, &seed)
.await?;
Some(ac)
}
Err(_) => {
tracing::warn!("Tor not found. Running on clear net. ");
tracing::warn!("Tor not found. Running on clear net");
None
}
};
Expand Down Expand Up @@ -153,17 +154,17 @@ async fn main() -> Result<()> {
let swap_id = swap.swap_id;
match run(swap, rate).await {
Ok(state) => {
tracing::debug!(%swap_id, "Swap finished with state {}", state)
tracing::debug!(%swap_id, %state, "Swap finished with state")
}
Err(e) => {
tracing::error!(%swap_id, "Swap failed with {:#}", e)
Err(error) => {
tracing::error!(%swap_id, %error, "Swap failed")
}
}
});
}
});

info!("Our peer id is {}", event_loop.peer_id());
info!(perr_id = %event_loop.peer_id(), "Our peer id");

event_loop.run().await;
}
Expand Down Expand Up @@ -203,7 +204,10 @@ async fn main() -> Result<()> {
let bitcoin_balance = bitcoin_wallet.balance().await?;
let monero_balance = monero_wallet.get_balance().await?;

tracing::info!("Current balance: {}, {}", bitcoin_balance, monero_balance);
tracing::info!(
%bitcoin_balance,
%monero_balance,
"Current balance");
}
Command::ManualRecovery(ManualRecovery::Cancel {
cancel_params: RecoverCommandParams { swap_id, force },
Expand Down Expand Up @@ -274,6 +278,7 @@ async fn init_bitcoin_wallet(
seed: &Seed,
env_config: swap::env::Config,
) -> Result<bitcoin::Wallet> {
debug!("Opening Bitcoin wallet");
let wallet_dir = config.data.dir.join("wallet");

let wallet = bitcoin::Wallet::new(
Expand All @@ -295,6 +300,7 @@ async fn init_monero_wallet(
config: &Config,
env_config: swap::env::Config,
) -> Result<monero::Wallet> {
debug!("Opening Monero wallet");
let wallet = monero::Wallet::open_or_create(
config.monero.wallet_rpc_url.clone(),
DEFAULT_WALLET_NAME.to_string(),
Expand Down Expand Up @@ -341,7 +347,8 @@ async fn register_tor_services(
.get_address_without_dot_onion();

hidden_services_details.iter().for_each(|(port, _)| {
tracing::info!("/onion3/{}:{}", onion_address, port);
let onion_address = format!("/onion3/{}:{}", onion_address, port);
tracing::info!(%onion_address);
});

Ok(ac)
Expand Down
3 changes: 1 addition & 2 deletions swap/src/bin/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ async fn main() -> Result<()> {
debug!("Cancel transaction successfully published with id {}", txid)
}
Err(bob::cancel::Error::CancelTimelockNotExpiredYet) => error!(
"The Cancel Transaction cannot be published yet, \
because the timelock has not expired. Please try again later."
"The Cancel Transaction cannot be published yet, because the timelock has not expired. Please try again later"
),
}
}
Expand Down
26 changes: 15 additions & 11 deletions swap/src/bitcoin/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Wallet {
format!("Failed to broadcast Bitcoin {} transaction {}", kind, txid)
})?;

tracing::info!(%txid, "Published Bitcoin {} transaction", kind);
tracing::info!(%txid, %kind, "Published Bitcoin transaction");

Ok((txid, subscription))
}
Expand Down Expand Up @@ -154,15 +154,16 @@ impl Wallet {

let new_status = match client.lock().await.status_of_script(&tx) {
Ok(new_status) => new_status,
Err(e) => {
tracing::warn!(%txid, "Failed to get status of script: {:#}", e);
Err(error) => {
tracing::warn!(%txid, %error, "Failed to get status of script.");
bonomat marked this conversation as resolved.
Show resolved Hide resolved
return;
}
};

if Some(new_status) != last_status {
tracing::debug!(%txid, "Transaction is {}", new_status);
tracing::debug!(%txid, status = %new_status, "Transaction status.");
}

last_status = Some(new_status);

let all_receivers_gone = sender.send(new_status).is_err();
Expand Down Expand Up @@ -200,7 +201,7 @@ impl Subscription {
let conf_target = self.finality_confirmations;
let txid = self.txid;

tracing::info!(%txid, "Waiting for {} confirmation{} of Bitcoin transaction", conf_target, if conf_target > 1 { "s" } else { "" });
tracing::info!(%txid, required_confirmation=%conf_target, "Waiting for Bitcoin transaction finality.");

let mut seen_confirmations = 0;

Expand All @@ -209,15 +210,18 @@ impl Subscription {
let confirmations = inner.confirmations();

if confirmations > seen_confirmations {
tracing::info!(%txid, "Bitcoin tx has {} out of {} confirmation{}", confirmations, conf_target, if conf_target > 1 { "s" } else { "" });
tracing::info!(%txid,
seen_confirmations = %confirmations,
needed_confirmations = %conf_target,
"Waiting for Bitcoin transaction finality.");
seen_confirmations = confirmations;
}

inner.meets_target(conf_target)
},
_ => false
}
_ => false,
})
.await
.await
}

pub async fn wait_until_seen(&self) -> Result<()> {
Expand Down Expand Up @@ -614,8 +618,8 @@ impl Client {

if let Some(new_block) = latest_block {
tracing::debug!(
"Got notification for new block at height {}",
new_block.height
block_height = new_block.height,
"Got notification for new block."
);
self.latest_block = BlockHeight::try_from(new_block)?;
}
Expand Down
4 changes: 2 additions & 2 deletions swap/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub fn ensure_directory_exists(file: &Path) -> Result<(), std::io::Error> {
if let Some(path) = file.parent() {
if !path.exists() {
tracing::info!(
"Parent directory does not exist, creating recursively: {}",
file.display()
directory = %file.display(),
"Parent directory does not exist, creating recursively",
);
return std::fs::create_dir_all(path);
}
Expand Down
8 changes: 5 additions & 3 deletions swap/src/kraken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ pub fn connect() -> Result<PriceUpdates> {

match result {
Err(e) => {
tracing::warn!("Rate updates incurred an unrecoverable error: {:#}", e);
tracing::warn!(
error = %e,
"Rate updates incurred an unrecoverable error.");

// in case the retries fail permanently, let the subscribers know
price_update.send(Err(Error::PermanentFailure))
Expand Down Expand Up @@ -183,8 +185,8 @@ mod connection {
// if the message is not an event, it is a ticker update or an unknown event
Err(_) => match serde_json::from_str::<wire::PriceUpdate>(&msg) {
Ok(ticker) => ticker,
Err(e) => {
tracing::warn!(%e, "Failed to deserialize message '{}' as ticker update", msg);
Err(error) => {
tracing::warn!(%error, %msg, "Failed to deserialize message as ticker update.");

return Ok(None);
}
Expand Down
48 changes: 32 additions & 16 deletions swap/src/monero/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ impl Wallet {
"Unable to create Monero wallet, please ensure that the monero-wallet-rpc is available",
)?;

tracing::debug!("Created Monero wallet {}", name);
tracing::debug!(monero_wallet_name = %name, "Created Monero wallet");
} else {
tracing::debug!("Opened Monero wallet {}", name);
tracing::debug!(monero_wallet_name = %name, "Opened Monero wallet");
}

Self::connect(client, name, env_config).await
Expand Down Expand Up @@ -148,19 +148,22 @@ impl Wallet {
Ok(_) => match wallet.sweep_all(self.main_address.to_string()).await {
Ok(sweep_all) => {
for tx in sweep_all.tx_hash_list {
tracing::info!(%tx, "Monero transferred back to default wallet {}", self.main_address);
tracing::info!(
%tx,
monero_address = %self.main_address,
"Monero transferred back to default wallet");
}
}
Err(e) => {
Err(error) => {
tracing::warn!(
"Transferring Monero back to default wallet {} failed with {:#}",
self.main_address,
e
address = %self.main_address,
%error,
"Transferring Monero back to default wallet failed",
);
}
},
Err(e) => {
tracing::warn!("Refreshing the generated wallet failed with {:#}", e);
Err(error) => {
tracing::warn!(%error, "Refreshing the generated wallet failed");
}
}

Expand All @@ -187,10 +190,10 @@ impl Wallet {
.await?;

tracing::debug!(
"sent transfer of {} to {} in {}",
amount,
public_spend_key,
res.tx_hash
%amount,
to = %public_spend_key,
tx_id = %res.tx_hash,
"Sent transfer"
);

Ok(TransferProof::new(
Expand All @@ -211,7 +214,11 @@ impl Wallet {

let txid = transfer_proof.tx_hash();

tracing::info!(%txid, "Waiting for {} confirmation{} of Monero transaction", conf_target, if conf_target > 1 { "s" } else { "" });
tracing::info!(
%txid,
target_confirmations = %conf_target,
"Waiting for Monero transaction finality"
);

let address = Address::standard(self.network, public_spend_key, public_view_key.into());

Expand Down Expand Up @@ -311,7 +318,11 @@ where
let tx = match fetch_tx(txid.clone()).await {
Ok(proof) => proof,
Err(error) => {
tracing::debug!(%txid, "Failed to retrieve tx from blockchain: {:#}", error);
tracing::debug!(
%txid,
%error,
"Failed to retrieve tx from blockchain"
);
continue; // treating every error as transient and retrying
// is obviously wrong but the jsonrpc client is
// too primitive to differentiate between all the
Expand All @@ -330,7 +341,12 @@ where

if tx.confirmations > seen_confirmations {
seen_confirmations = tx.confirmations;
tracing::info!(%txid, "Monero lock tx has {} out of {} confirmations", tx.confirmations, conf_target);
tracing::info!(
%txid,
%seen_confirmations,
needed_confirmations = %conf_target,
"Received new confirmation for Monero lock tx"
);
}
}

Expand Down
5 changes: 4 additions & 1 deletion swap/src/monero/wallet_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ impl WalletRpc {
.local_addr()?
.port();

tracing::debug!("Starting monero-wallet-rpc on port {}", port);
tracing::debug!(
monero_wallet_rpc_port = %port,
bonomat marked this conversation as resolved.
Show resolved Hide resolved
"Starting monero-wallet-rpc on port"
bonomat marked this conversation as resolved.
Show resolved Hide resolved
);

let mut child = Command::new(self.exec_path())
.env("LANG", "en_AU.UTF-8")
Expand Down
Loading