Skip to content

Commit

Permalink
reintroduce the force close channel check in the tests
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Apr 22, 2022
1 parent a2b0f7b commit 3e41b90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
21 changes: 5 additions & 16 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3679,20 +3679,6 @@ impl<Signer: Sign> Channel<Signer> {
}
}

/// Check if the we are trying to reestablish a connection with a peer with an old commitment
/// transaction that it is not possible recovered.
///
/// If the peer is not out of sync we return an empty result, otherwise just the channel error to sent.
fn try_reestablish_when_peer_is_late(&self, msg: &msgs::ChannelReestablish) -> Result<(), ChannelError> {
let _our_commitment_transaction = INITIAL_COMMITMENT_NUMBER - self.cur_holder_commitment_transaction_number - 1;
if msg.next_remote_commitment_number + 1 < _our_commitment_transaction {
return Err(
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))
);
}
Ok(())
}

/// May panic if some calls other than message-handling calls (which will all Err immediately)
/// have been called between remove_uncommitted_htlcs_and_mark_paused and this call.
pub fn channel_reestablish<L: Deref>(&mut self, msg: &msgs::ChannelReestablish, logger: &L,
Expand Down Expand Up @@ -3732,8 +3718,11 @@ impl<Signer: Sign> Channel<Signer> {

// Before change the state of the channel we check if the peer is sending a very old
// commitment transaction number, if yes we send an error (warning message).
if let Err(err_msg) = self.try_reestablish_when_peer_is_late(msg) {
return Err(err_msg);
let our_commitment_transaction = INITIAL_COMMITMENT_NUMBER - self.cur_holder_commitment_transaction_number - 1;
if msg.next_remote_commitment_number + 1 < our_commitment_transaction {
return Err(
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))
);
}

// Go ahead and unmark PeerDisconnected as various calls we may make check for it (and all
Expand Down
11 changes: 9 additions & 2 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7395,8 +7395,15 @@ fn test_data_loss_protect() {
}
}

// Clear the event received by the node A, the failure need to be handled by the API user.
assert!(!nodes[0].node.get_and_clear_pending_events().is_empty());
// Check A is able to claim to_remote output
let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
// The node B should not broadcast the transaction to force close the channel!
assert!(node_txn.is_empty());
// B should now detect that there is something wrong and should force close the channel.
// FIXME: we sent the warning message when the peer is behind to give the possibility to restore try to fix the problem
// 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.
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";
check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: exp_err.to_string() });
}

#[test]
Expand Down

0 comments on commit 3e41b90

Please sign in to comment.