Skip to content

Commit b39e910

Browse files
committed
refactor: add IP and TXID identifiers to recovery logs as requested by coderabbit
1 parent 7a95389 commit b39e910

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

src/maker/api.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,18 @@ pub(crate) fn check_for_broadcasted_contracts(maker: Arc<Maker>) -> Result<(), M
606606
if transaction_broadcasted {
607607
// Something is broadcasted. Report, Recover and Abort.
608608
log::warn!(
609-
"Contract txs broadcasted!! txid: {} Recovering from ongoing swaps.",
609+
"[Peer: {}] Contract txs broadcasted!! txid: {} Recovering from ongoing swaps.",
610+
ip,
610611
txid
611612
);
612613
failed_swap_ip.push(ip.clone());
613614

614615
// Spawn a separate thread to wait for contract maturity and broadcasting timelocked/hashlocked.
615616
let maker_clone = maker.clone();
616-
log::info!("Spawning recovery thread after seeing contracts in mempool",);
617+
log::info!(
618+
"[Peer: {}] Spawning recovery thread after seeing contracts in mempool.",
619+
ip
620+
);
617621

618622
let incomings = connection_state.incoming_swapcoins.clone();
619623
let outgoings = connection_state.outgoing_swapcoins.clone();
@@ -688,13 +692,17 @@ pub(crate) fn check_for_idle_states(maker: Arc<Maker>) -> Result<(), MakerError>
688692

689693
if no_response_since > IDLE_CONNECTION_TIMEOUT {
690694
log::error!(
691-
"Potential Dropped Connection from taker. No response since : {} secs. Recovering from swap",
695+
"[Peer: {}] Potential Dropped Connection from taker. No response since : {} secs. Recovering from swap",
696+
ip,
692697
no_response_since.as_secs()
693698
);
694699
bad_ip.push(ip.clone());
695700
// Spawn a separate thread to wait for contract maturity and broadcasting timelocked,hashlocked
696701
let maker_clone = maker.clone();
697-
log::info!("Spawning recovery thread after Taker dropped",);
702+
log::info!(
703+
"[Peer: {}] Spawning recovery thread after Taker dropped",
704+
ip
705+
);
698706

699707
let incomings = state.incoming_swapcoins.clone();
700708
let outgoings = state.outgoing_swapcoins.clone();
@@ -744,8 +752,14 @@ pub(crate) fn recover_from_swap(
744752
.map_err(WalletError::Rpc)? as u32;
745753
let timelock_expiry = start_height.saturating_add(timelock);
746754

755+
let anchor_txid = outgoing_swapcoins
756+
.first()
757+
.map(|o| o.contract_tx.compute_txid().to_string())
758+
.unwrap_or_else(|| "unknown".to_string());
759+
747760
log::info!(
748-
"recover_from_swap started | height={} timelock_expiry={}",
761+
"[Contract: {}] recover_from_swap started | height={} timelock_expiry={}",
762+
anchor_txid,
749763
start_height,
750764
timelock_expiry
751765
);
@@ -805,8 +819,14 @@ fn recover_via_hashlock(
805819
.wallet
806820
.write()?
807821
.spend_from_hashlock_contract(&infos, &maker.watch_service)?;
822+
823+
let anchor_id = incoming
824+
.first()
825+
.map(|c| c.contract_tx.compute_txid().to_string())
826+
.unwrap_or_default();
808827
log::info!(
809-
"Maker hashlock recovery: {}/{} txs broadcasted",
828+
"[Contract: {}] Maker hashlock recovery: {}/{} txs broadcasted",
829+
anchor_id,
810830
broadcasted.len(),
811831
incoming.len()
812832
);
@@ -859,8 +879,14 @@ fn recover_via_timelock(
859879
.wallet
860880
.write()?
861881
.spend_from_timelock_contract(&infos, &maker.watch_service)?;
882+
883+
let anchor_id = outgoing
884+
.first()
885+
.map(|c| c.contract_tx.compute_txid().to_string())
886+
.unwrap_or_default();
862887
log::info!(
863-
"Maker timelock recovery: {}/{} txs broadcasted",
888+
"[Contract: {}] Maker timelock recovery: {}/{} txs broadcasted",
889+
anchor_id,
864890
broadcasted.len(),
865891
outgoing.len()
866892
);

0 commit comments

Comments
 (0)