Skip to content

Commit

Permalink
fix some loggings
Browse files Browse the repository at this point in the history
  • Loading branch information
mojoX911 committed Jan 17, 2025
1 parent ac7ad60 commit 6a0aca5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 65 deletions.
6 changes: 0 additions & 6 deletions src/bin/taker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ fn main() -> Result<(), TakerError> {
}

Commands::FetchOffers => {
println!("Fetching offerdata from the market. use `tail -f <data-dir>/debug.log` to see progress.");
let offerbook = taker.fetch_offers()?;
println!("{:#?}", offerbook)
}
Expand All @@ -230,16 +229,11 @@ fn main() -> Result<(), TakerError> {
tx_count: 1,
required_confirms: REQUIRED_CONFIRMS,
};

println!("Starting coinswap with swap params : {:?}. use `tail -f <data-dir>/debug.log` to see progress.", swap_params);
taker.do_coinswap(swap_params)?;
println!("succesfully completed coinswap!! Check `list-utxo` to see the new coins");
}

Commands::Recover => {
println!("Starting recovery. use `tail -f <data-dir>/debug.log` to see progress.");
taker.recover_from_swap()?;
println!("Recovery completed succesfully.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/maker/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ fn handle_client(maker: Arc<Maker>, stream: &mut TcpStream) -> Result<(), MakerE
}

let taker_msg: TakerToMakerMessage = serde_cbor::from_slice(&taker_msg_bytes)?;
log::info!("[{}] <=== {}", maker.config.network_port, taker_msg);
log::info!("[{}] <=== {}", maker.config.network_port, taker_msg);

let reply = handle_message(&maker, &mut connection_state, taker_msg);

Expand Down
91 changes: 43 additions & 48 deletions src/taker/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ impl Taker {
}

log::info!("Initializing Sync and Save.");
self.wallet.sync()?;
self.save_and_reset_swap_round()?;
log::info!("Completed Sync and Save.");
log::info!("Successfully Completed Coinswap.");
Expand Down Expand Up @@ -1062,7 +1061,7 @@ impl Taker {
.collect()
};

log::info!("===> Sending ProofOfFunding to {}", this_maker.address);
log::info!("===> ProofOfFunding | {}", this_maker.address);

let funding_txids = funding_tx_infos
.iter()
Expand Down Expand Up @@ -1093,7 +1092,7 @@ impl Taker {
self.ongoing_swap_state.id.clone(),
)?;
log::info!(
"<=== Recieved ContractSigsAsRecvrAndSender from {}",
"<=== ReqContractSigsAsRecvrAndSender | {}",
this_maker.address
);

Expand Down Expand Up @@ -1176,10 +1175,6 @@ impl Taker {
// If Next Maker is the Receiver, and Previous Maker is the Sender, request Previous Maker to sign the Reciever's Contract Tx.
let previous_maker = previous_maker.expect("Previous Maker should always exists");
let previous_maker_addr = &previous_maker.peer.address;
log::info!(
"===> Sending SignReceiversContractTx, previous maker is {}",
previous_maker_addr
);
let previous_maker_watchonly_swapcoins =
if self.ongoing_swap_state.taker_position == TakerPosition::LastPeer {
self.ongoing_swap_state
Expand Down Expand Up @@ -1207,7 +1202,7 @@ impl Taker {
}
};
log::info!(
"===> Sending ContractSigsAsReceiverAndSender to {}",
"===> RespContractSigsForRecvrAndSender | {}",
this_maker.address
);
let id = self.ongoing_swap_state.id.clone();
Expand Down Expand Up @@ -1405,10 +1400,6 @@ impl Taker {
.expect("previous maker expected")
.peer
.clone();
log::info!(
"===> Sending ReqContractSigsForRecvr to {}",
last_maker.address
);
let receiver_contract_sig = match self.req_sigs_for_recvr(
&last_maker.address,
&self.ongoing_swap_state.incoming_swapcoins,
Expand Down Expand Up @@ -1487,15 +1478,20 @@ impl Taker {

loop {
ii += 1;
log::info!("Connecting to {} | Req Sigs for Sender", maker_addr_str);
log::info!("===> ReqContractSigsForSender | {}", maker_addr_str);
match req_sigs_for_sender_once(
&mut socket,
outgoing_swapcoins,
maker_multisig_nonces,
maker_hashlock_nonces,
locktime,
) {
Ok(ret) => return Ok(ret),
Ok(ret) => {
return {
log::info!("===> RespContractSigsForSender | {}", maker_addr_str);
Ok(ret)
}
}
Err(e) => {
log::warn!(
"Failed to connect to maker {} to request signatures for receiver, \
Expand Down Expand Up @@ -1571,10 +1567,13 @@ impl Taker {

loop {
ii += 1;
log::info!("Connecting to {} | Req Sigs for Receiver", maker_addr_str);
log::info!("===> ReqContractSigsForRecvr | {}", maker_addr_str);
match req_sigs_for_recvr_once(&mut socket, incoming_swapcoins, receivers_contract_txes)
{
Ok(ret) => return Ok(ret),
Ok(ret) => {
log::info!("<=== RespContractSigsForRecvr | {}", maker_addr_str);
return Ok(ret);
}
Err(e) => {
log::warn!(
"Failed to connect to maker {} to request signatures for receiver, \
Expand Down Expand Up @@ -1661,24 +1660,8 @@ impl Taker {
.collect::<Vec<_>>()
};

let reconnect_time_out = Duration::from_secs(TCP_TIMEOUT_SECONDS);

let mut ii = 0;

let maker_addr_str = maker_address.address.to_string();
let mut socket = match self.config.connection_type {
ConnectionType::CLEARNET => TcpStream::connect(maker_addr_str.clone())?,
#[cfg(feature = "tor")]
ConnectionType::TOR => Socks5Stream::connect(
format!("127.0.0.1:{}", self.config.socks_port).as_str(),
&*maker_addr_str,
)?
.into_inner(),
};

socket.set_read_timeout(Some(reconnect_time_out))?;
socket.set_write_timeout(Some(reconnect_time_out))?;

// Configurable reconnection attempts for testing
let reconnect_attempts = if cfg!(feature = "integration-test") {
10
Expand All @@ -1695,9 +1678,8 @@ impl Taker {

loop {
ii += 1;
log::info!("Connecting to {} || Settle Swap", maker_addr_str);
match self.settle_one_coinswap(
&mut socket,
&maker_address.address,
index,
&mut outgoing_privkeys,
&senders_multisig_redeemscripts,
Expand Down Expand Up @@ -1741,25 +1723,35 @@ impl Taker {
/// [Internal] Setlle one swap. This is recursively called for all the makers.
fn settle_one_coinswap(
&mut self,
socket: &mut TcpStream,
maker_address: &MakerAddress,
index: usize,
outgoing_privkeys: &mut Option<Vec<MultisigPrivkey>>, // TODO: Instead of Option, just take a vector, where empty vector denotes the `None` equivalent.
senders_multisig_redeemscripts: &[ScriptBuf],
receivers_multisig_redeemscripts: &[ScriptBuf],
) -> Result<(), TakerError> {
handshake_maker(socket)?;
let maker_addr_str = maker_address.to_string();
let mut socket = match self.config.connection_type {
ConnectionType::CLEARNET => TcpStream::connect(maker_addr_str.clone())?,
#[cfg(feature = "tor")]
ConnectionType::TOR => Socks5Stream::connect(
format!("127.0.0.1:{}", self.config.socks_port).as_str(),
&*maker_addr_str,
)?
.into_inner(),
};

log::info!("===> Sending HashPreimage to {}", socket.peer_addr()?);
socket.set_read_timeout(Some(Duration::from_secs(TCP_TIMEOUT_SECONDS)))?;
socket.set_write_timeout(Some(Duration::from_secs(TCP_TIMEOUT_SECONDS)))?;
handshake_maker(&mut socket)?;

log::info!("===> HashPreimage | {}", maker_address);
let maker_private_key_handover = send_hash_preimage_and_get_private_keys(
socket,
&mut socket,
senders_multisig_redeemscripts,
receivers_multisig_redeemscripts,
&self.ongoing_swap_state.active_preimage,
)?;
log::info!(
"<=== Received PrivateKeyHandover from {}",
socket.peer_addr()?
);
log::info!("<=== PrivateKeyHandover | {}", maker_address);

let privkeys_reply = if self.ongoing_swap_state.taker_position == TakerPosition::FirstPeer {
self.ongoing_swap_state
Expand Down Expand Up @@ -1795,9 +1787,9 @@ impl Taker {
*outgoing_privkeys = Some(maker_private_key_handover.multisig_privkeys);
ret
})?;
log::info!("===> Sending PrivateKeyHandover to {}", socket.peer_addr()?);
log::info!("===> PrivateKeyHandover | {}", maker_address);
send_message(
socket,
&mut socket,
&TakerToMakerMessage::RespPrivKeyHandover(PrivKeyHandover {
multisig_privkeys: privkeys_reply,
}),
Expand Down Expand Up @@ -1936,16 +1928,19 @@ impl Taker {
.get_raw_transaction_info(&contract_tx.compute_txid(), None)
.is_ok()
{
log::info!("Incoming Contract already broadacsted");
log::info!(
"Incoming Contract already broadacsted. Txid : {}",
contract_tx.compute_txid()
);
} else {
self.wallet.send_tx(contract_tx)?;
log::info!(
"Broadcasted Incoming Contract. Removing from wallet. Contract Txid {}",
"Broadcasting Incoming Contract. Removing from wallet. Txid : {}",
contract_tx.compute_txid()
);
}
log::info!(
"Incoming Swapcoin removed from wallet, Contact Txid: {}",
"Incoming Swapcoin removed from wallet, Txid: {}",
contract_tx.compute_txid()
);
self.wallet.remove_incoming_swapcoin(redeemscript)?;
Expand Down Expand Up @@ -2184,7 +2179,7 @@ impl Taker {
socket.set_write_timeout(Some(reconnect_timeout))?;

send_message(&mut socket, &msg)?;
log::info!("===> Sent {} to {}", msg, maker_addr);
log::info!("===> {} | {}", msg, maker_addr);

Ok(())
}
Expand Down
10 changes: 0 additions & 10 deletions src/taker/routines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ pub(crate) fn req_sigs_for_sender_once<S: SwapCoin>(
locktime: u16,
) -> Result<ContractSigsForSender, TakerError> {
handshake_maker(socket)?;
log::info!(
"===> Sending ReqContractSigsForSender to {}",
socket.peer_addr()?
);

let txs_info = maker_multisig_nonces
.iter()
.zip(maker_hashlock_nonces.iter())
Expand Down Expand Up @@ -229,11 +224,6 @@ pub(crate) fn req_sigs_for_recvr_once<S: SwapCoin>(
{
swapcoin.verify_contract_tx_receiver_sig(sig)?;
}

log::info!(
"<=== Received ContractSigsForRecvr from {}",
socket.peer_addr()?
);
Ok(contract_sigs_for_recvr)
}

Expand Down

0 comments on commit 6a0aca5

Please sign in to comment.