Skip to content

Commit

Permalink
fix: Set timeout on RenewOffered state
Browse files Browse the repository at this point in the history
Otherwise the channel gets force closed immediately if the periodic check happens to run before the channel has advanced to the next state.
  • Loading branch information
holzeis committed Jan 31, 2024
1 parent da62aa5 commit 0f4c8e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions dlc-manager/src/channel_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,10 +1023,15 @@ 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<T: Deref>(
signed_channel: &mut SignedChannel,
renew_offer: &RenewOffer,
) -> Result<OfferedContract, Error> {
peer_timeout: u64,
time: &T,
) -> Result<OfferedContract, Error>
where
T::Target: Time,
{
if let SignedChannelState::Settled { .. } | SignedChannelState::Established { .. } =
signed_channel.state
{
Expand Down Expand Up @@ -1058,7 +1063,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);
Expand Down
2 changes: 1 addition & 1 deletion dlc-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,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
Expand Down

0 comments on commit 0f4c8e0

Please sign in to comment.