From 8c13abf4283244d0e40b042468f0ffea3c0081b4 Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Wed, 31 Jan 2024 16:29:06 +0100 Subject: [PATCH] fix: Set timeout on `RenewOffered` state Otherwise the channel gets force closed immediately if the periodic check happens to run before the channel has advanced to the next state. --- dlc-manager/src/channel_updater.rs | 10 +++++++--- dlc-manager/src/manager.rs | 12 +++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/dlc-manager/src/channel_updater.rs b/dlc-manager/src/channel_updater.rs index 83fc127c..b17ea46b 100644 --- a/dlc-manager/src/channel_updater.rs +++ b/dlc-manager/src/channel_updater.rs @@ -1483,10 +1483,14 @@ where /// Update the state of the given [`SignedChannel`] from the given [`RenewOffer`]. /// Expects the channel to be in one of [`SignedChannelState::Settled`] or /// [`SignedChannelState::Established`] state. -pub fn on_renew_offer( +pub fn on_renew_offer( signed_channel: &mut SignedChannel, renew_offer: &RenewOffer, -) -> Result { + peer_timeout: u64, + time: &T, +) -> Result where + T::Target: Time, +{ if let SignedChannelState::Settled { .. } | SignedChannelState::Established { .. } = signed_channel.state { @@ -1523,7 +1527,7 @@ pub fn on_renew_offer( counter_payout: renew_offer.counter_payout, offer_next_per_update_point: renew_offer.next_per_update_point, is_offer: false, - timeout: 0, + timeout: time.unix_time_now() + peer_timeout, }; std::mem::swap(&mut signed_channel.state, &mut state); diff --git a/dlc-manager/src/manager.rs b/dlc-manager/src/manager.rs index 1ba5ee5c..093037f7 100644 --- a/dlc-manager/src/manager.rs +++ b/dlc-manager/src/manager.rs @@ -147,6 +147,8 @@ macro_rules! check_for_timed_out_channels { } else { None }; + + log::warn!("Force closing channel that timed out. {} < {}", timeout, $manager.time.unix_time_now()); match $manager.force_close_channel_internal(channel, sub_channel, true) { Err(e) => error!("Error force closing channel {}", e), _ => {} @@ -227,6 +229,8 @@ where msg: &DlcMessage, counter_party: PublicKey, ) -> Result, Error> { + log::info!("===========> Received dlc message IN RUST DLC!!!!"); + match msg { DlcMessage::OnChain(on_chain) => match on_chain { OnChainMessage::Offer(o) => { @@ -1616,7 +1620,7 @@ where } let offered_contract = - crate::channel_updater::on_renew_offer(&mut signed_channel, renew_offer)?; + crate::channel_updater::on_renew_offer(&mut signed_channel, renew_offer,PEER_TIMEOUT, &self.time)?; self.store.create_contract(&offered_contract)?; self.store @@ -2375,6 +2379,8 @@ where buffer_transaction, .. } => { + warn!("Force closing established channel with id: {}", channel.channel_id.to_hex()); + let counter_buffer_adaptor_signature = *counter_buffer_adaptor_signature; let buffer_transaction = buffer_transaction.clone(); self.initiate_unilateral_close_established_channel( @@ -2390,6 +2396,8 @@ where offer_buffer_adaptor_signature, .. } => { + warn!("Force closing renew finalized channel with id: {}", channel.channel_id.to_hex()); + let offer_buffer_adaptor_signature = *offer_buffer_adaptor_signature; let buffer_transaction = buffer_transaction.clone(); self.initiate_unilateral_close_established_channel( @@ -2401,6 +2409,8 @@ where ) } SignedChannelState::Settled { .. } => { + warn!("Force closing settled channel with id: {}", channel.channel_id.to_hex()); + self.close_settled_channel(channel, sub_channel, is_initiator) } SignedChannelState::SettledOffered { .. }