Skip to content

Commit

Permalink
Merge pull request #1827 from get10101/fix/use-correct-dlc-channel
Browse files Browse the repository at this point in the history
fix: Only consider a relevant dlc channels
  • Loading branch information
holzeis authored Jan 17, 2024
2 parents b7d17c5 + 250f3a5 commit 5712583
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 4 additions & 3 deletions coordinator/src/dlc_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use diesel::r2d2::Pool;
use diesel::PgConnection;
use dlc_manager::channel::signed_channel::SignedChannel;
use dlc_manager::channel::signed_channel::SignedChannelState;
use dlc_manager::channel::Channel;
use dlc_messages::Message;
use futures::future::RemoteHandle;
use futures::FutureExt;
Expand Down Expand Up @@ -102,11 +101,13 @@ impl DlcHandler {
}

pub fn on_connect(&self, peer: PublicKey) -> Result<()> {
if let Some(Channel::Signed(SignedChannel {
let signed_dlc_channels = self.node.list_signed_dlc_channels()?;

if let Some(SignedChannel {
channel_id,
state: SignedChannelState::CollaborativeCloseOffered { .. },
..
})) = self.node.list_dlc_channels()?.first()
}) = signed_dlc_channels.iter().find(|c| c.counter_party == peer)
{
tracing::info!("Accepting pending dlc channel close offer.");
// Pending dlc channel close offer with the intend to close the dlc channel
Expand Down
21 changes: 20 additions & 1 deletion mobile/native/src/dlc_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,26 @@ impl DlcHandler {
}

pub fn on_connect(&self, peer: PublicKey) -> Result<()> {
if let Some(channel) = self.node.list_dlc_channels()?.first() {
let dlc_channels: Vec<Channel> = self
.node
.list_dlc_channels()?
.into_iter()
.filter(|c| {
// Filter all dlc channels that have reached a somewhat final state.
!matches!(
c,
Channel::Closed(_)
| Channel::Closing(_)
| Channel::CounterClosed(_)
| Channel::ClosedPunished(_)
| Channel::CollaborativelyClosed(_)
| Channel::FailedAccept(_)
| Channel::FailedSign(_)
)
})
.collect();

if let Some(channel) = dlc_channels.first() {
match channel {
Channel::Offered(OfferedChannel {
temporary_channel_id,
Expand Down

0 comments on commit 5712583

Please sign in to comment.