Tidy up log messages across the codebase

1. Clearly separate the log messages from any fields that are
captured. The log message itself should be meaningful because it
depends on the underlying formatter, how/if the fields are displayed.
2. Some log messages had very little context, expand that.
3. Wording of errors was inconsistent, hopefully all errors should
now start with `Failed to ...`.
4. Some log messages were duplicated across multiple layers (like opening
the database).
5. Some log messages were split into two where one part is now an `error!`
and the 2nd part is an `info!` on what is happening next.
6. Where appropriate, punctuation has been removed to not interrupt
the reader's flow.
This commit is contained in:
Thomas Eizinger 2021-07-06 16:42:05 +10:00 committed by Daniel Karzel
parent 78480547d5
commit 9119ce5cc4
No known key found for this signature in database
GPG key ID: 30C3FC2E438ADB6E
13 changed files with 79 additions and 74 deletions

View file

@ -11,6 +11,7 @@ use miniscript::{Descriptor, DescriptorTrait};
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::collections::HashMap;
use std::fmt;
use std::ops::Add;
/// Represent a timelock, expressed in relative block height as defined in
@ -47,6 +48,12 @@ impl PartialEq<CancelTimelock> for u32 {
}
}
impl fmt::Display for CancelTimelock {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} blocks", self.0)
}
}
/// Represent a timelock, expressed in relative block height as defined in
/// [BIP68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki).
/// E.g. The timelock expires 10 blocks after the reference transaction is

View file

@ -151,14 +151,14 @@ impl TxLock {
witness: Vec::new(),
};
let spending_fee = spending_fee.as_sat();
tracing::debug!(%spending_fee, "Redeem tx fee");
let fee = spending_fee.as_sat();
let tx_out = TxOut {
value: self.inner.clone().extract_tx().output[self.lock_output_vout()].value
- spending_fee,
value: self.inner.clone().extract_tx().output[self.lock_output_vout()].value - fee,
script_pubkey: spend_address.script_pubkey(),
};
tracing::debug!(%fee, "Constructed Bitcoin spending transaction");
Transaction {
version: 2,
lock_time: 0,

View file

@ -144,13 +144,18 @@ impl Wallet {
let new_status = match client.lock().await.status_of_script(&tx) {
Ok(new_status) => new_status,
Err(error) => {
tracing::warn!(%txid, "Failed to get status of script. Error {:#}", error);
tracing::warn!(%txid, "Failed to get status of script: {:#}", error);
return;
}
};
if Some(new_status) != last_status {
tracing::debug!(%txid, status = %new_status, "Transaction");
match (last_status, new_status) {
(None, new_status) => {
tracing::debug!(%txid, status = %new_status, "Found relevant Bitcoin transaction");
},
(Some(old_status), new_status) => {
tracing::debug!(%txid, %new_status, %old_status, "Bitcoin transaction status changed");
}
}
last_status = Some(new_status);
@ -409,9 +414,7 @@ where
) -> Result<bitcoin::Amount> {
let client = self.client.lock().await;
let fee_rate = client.estimate_feerate(self.target_block)?;
let min_relay_fee = client.min_relay_fee()?;
tracing::debug!("Min relay fee: {}", min_relay_fee);
estimate_fee(weight, transfer_amount, fee_rate, min_relay_fee)
}
@ -443,20 +446,21 @@ fn estimate_fee(
let weight = Decimal::from(weight);
let weight_factor = dec!(4.0);
let fee_rate = Decimal::from_f32(fee_rate_svb).context("Could not parse fee_rate.")?;
let fee_rate = Decimal::from_f32(fee_rate_svb).context("Failed to parse fee rate")?;
let sats_per_vbyte = weight / weight_factor * fee_rate;
tracing::debug!(
"Estimated fee for weight: {} for fee_rate: {:?} is in total: {}",
weight,
fee_rate,
sats_per_vbyte
%weight,
%fee_rate,
%sats_per_vbyte,
"Estimated fee for transaction",
);
let transfer_amount = Decimal::from(transfer_amount.as_sat());
let max_allowed_fee = transfer_amount * MAX_RELATIVE_TX_FEE;
let min_relay_fee = Decimal::from(min_relay_fee.as_sat());
let recommended_fee = if sats_per_vbyte < min_relay_fee {
tracing::warn!(
"Estimated fee of {} is smaller than the min relay fee, defaulting to min relay fee {}",
@ -482,6 +486,7 @@ fn estimate_fee(
let amount = recommended_fee
.map(bitcoin::Amount::from_sat)
.context("Could not estimate tranasction fee.")?;
Ok(amount)
}