Skip to content

Commit 3e41b90

Browse files
reintroduce the force close channel check in the tests
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent a2b0f7b commit 3e41b90

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

lightning/src/ln/channel.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,20 +3679,6 @@ impl<Signer: Sign> Channel<Signer> {
36793679
}
36803680
}
36813681

3682-
/// Check if the we are trying to reestablish a connection with a peer with an old commitment
3683-
/// transaction that it is not possible recovered.
3684-
///
3685-
/// If the peer is not out of sync we return an empty result, otherwise just the channel error to sent.
3686-
fn try_reestablish_when_peer_is_late(&self, msg: &msgs::ChannelReestablish) -> Result<(), ChannelError> {
3687-
let _our_commitment_transaction = INITIAL_COMMITMENT_NUMBER - self.cur_holder_commitment_transaction_number - 1;
3688-
if msg.next_remote_commitment_number + 1 < _our_commitment_transaction {
3689-
return Err(
3690-
ChannelError::Warn(format!("Peer attempted to reestablish channel with a very old local commitment transaction: {} (received) vs {} (expected)", msg.next_remote_commitment_number, _our_commitment_transaction))
3691-
);
3692-
}
3693-
Ok(())
3694-
}
3695-
36963682
/// May panic if some calls other than message-handling calls (which will all Err immediately)
36973683
/// have been called between remove_uncommitted_htlcs_and_mark_paused and this call.
36983684
pub fn channel_reestablish<L: Deref>(&mut self, msg: &msgs::ChannelReestablish, logger: &L,
@@ -3732,8 +3718,11 @@ impl<Signer: Sign> Channel<Signer> {
37323718

37333719
// Before change the state of the channel we check if the peer is sending a very old
37343720
// commitment transaction number, if yes we send an error (warning message).
3735-
if let Err(err_msg) = self.try_reestablish_when_peer_is_late(msg) {
3736-
return Err(err_msg);
3721+
let our_commitment_transaction = INITIAL_COMMITMENT_NUMBER - self.cur_holder_commitment_transaction_number - 1;
3722+
if msg.next_remote_commitment_number + 1 < our_commitment_transaction {
3723+
return Err(
3724+
ChannelError::Warn(format!("Peer attempted to reestablish channel with a very old local commitment transaction: {} (received) vs {} (expected)", msg.next_remote_commitment_number, our_commitment_transaction))
3725+
);
37373726
}
37383727

37393728
// Go ahead and unmark PeerDisconnected as various calls we may make check for it (and all

lightning/src/ln/functional_tests.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7395,8 +7395,15 @@ fn test_data_loss_protect() {
73957395
}
73967396
}
73977397

7398-
// Clear the event received by the node A, the failure need to be handled by the API user.
7399-
assert!(!nodes[0].node.get_and_clear_pending_events().is_empty());
7398+
// Check A is able to claim to_remote output
7399+
let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
7400+
// The node B should not broadcast the transaction to force close the channel!
7401+
assert!(node_txn.is_empty());
7402+
// B should now detect that there is something wrong and should force close the channel.
7403+
// FIXME: we sent the warning message when the peer is behind to give the possibility to restore try to fix the problem
7404+
// but the spec is unclear on what we should do in the case of a warning message. For now we force close the channel anyway.
7405+
let exp_err = "We have fallen behind - we have received proof that if we broadcast remote is going to claim our funds - we can\'t do any automated broadcasting";
7406+
check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: exp_err.to_string() });
74007407
}
74017408

74027409
#[test]

0 commit comments

Comments
 (0)