Skip to content

Commit

Permalink
Don't check channel state on force close
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibo-lg committed Jun 20, 2023
1 parent 66b1570 commit 34f7334
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ members = [
]

[patch.crates-io]
lightning = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "dae31e3e" }
lightning-net-tokio = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "dae31e3e" }
lightning-persister = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "dae31e3e" }
lightning = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "74690beb" }
lightning-net-tokio = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "74690beb" }
lightning-persister = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "74690beb" }
2 changes: 1 addition & 1 deletion dlc-manager/src/sub_channel_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ where
.ln_channel_manager
.get_channel_details(channel_id)
.unwrap();
self.ln_channel_manager.with_useable_channel_lock(
self.ln_channel_manager.with_channel_lock_no_check(
channel_id,
&counter_party,
|channel_lock| {
Expand Down
28 changes: 27 additions & 1 deletion dlc-manager/src/subchannel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,25 @@ where
{
/// Returns the details of the channel with given `channel_id` if found.
fn get_channel_details(&self, channel_id: &ChannelId) -> Option<ChannelDetails>;
///
/// Enable executing the provided callback while holding the lock of the channel with provided
/// id, making sure that the channel is in a useable state and that a connection is established
/// with the peer.
fn with_useable_channel_lock<F, T>(
&self,
channel_id: &ChannelId,
counter_party_node_id: &PublicKey,
cb: F,
) -> Result<T, APIError>
where
F: FnOnce(&mut ChannelLock<SP>) -> Result<T, APIError>;
/// Enable executing the provided callback while holding the lock of the channel without
/// checking the channel state or peer connection status.
fn with_channel_lock_no_check<F, T>(
&self,
channel_id: &ChannelId,
counter_party_node_id: &PublicKey,
cb: F,
) -> Result<T, APIError>
where
F: FnOnce(&mut ChannelLock<SP>) -> Result<T, APIError>;
/// Updates the funding output for the channel and returns the [`CommitmentSigned`] message
Expand Down Expand Up @@ -466,6 +478,20 @@ where
{
self.with_useable_channel_lock(channel_id, counter_party_node_id, cb)
}

fn with_channel_lock_no_check<C, RV>(
&self,
channel_id: &ChannelId,
counter_party_node_id: &PublicKey,
cb: C,
) -> Result<RV, APIError>
where
C: FnOnce(
&mut ChannelLock<<<K as Deref>::Target as SignerProvider>::Signer>,
) -> Result<RV, APIError>,
{
self.with_channel_lock_no_check(channel_id, counter_party_node_id, cb)
}
}

/// Generate a temporary channel id for a DLC channel based on the LN channel id, the update index of the
Expand Down
15 changes: 15 additions & 0 deletions dlc-manager/tests/ln_dlc_channel_execution_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ enum TestPath {
CloseRejected,
Reconnect,
ReconnectReOfferAfterClose,
DisconnectedForceClose,
}

impl LnDlcParty {
Expand Down Expand Up @@ -582,6 +583,12 @@ fn ln_dlc_offer_after_offchain_close_disconnect() {
ln_dlc_test(TestPath::ReconnectReOfferAfterClose);
}

#[test]
#[ignore]
fn ln_dlc_disconnected_force_close() {
ln_dlc_test(TestPath::DisconnectedForceClose);
}

// #[derive(Debug)]
// pub struct TestParams {
// pub oracles: Vec<p2pd_oracle_client::P2PDOracleClient>,
Expand Down Expand Up @@ -1102,6 +1109,14 @@ fn ln_dlc_test(test_path: TestPath) {
bob_node.mock_blockchain.discard_id(bob_commit[0].txid());
}

if let TestPath::DisconnectedForceClose = test_path {
alice_node
.peer_manager
.socket_disconnected(&alice_descriptor);

bob_node.peer_manager.socket_disconnected(&bob_descriptor);
}

alice_node
.sub_channel_manager
.force_close_sub_channel(&channel_id)
Expand Down

0 comments on commit 34f7334

Please sign in to comment.