diff --git a/Cargo.toml b/Cargo.toml index a7583c95..266ce56a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,6 @@ members = [ resolver = "2" [patch.crates-io] -lightning = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "6fd61144" } -lightning-net-tokio = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "6fd61144" } -lightning-persister = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "6fd61144" } +lightning = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "78cbe211" } +lightning-net-tokio = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "78cbe211" } +lightning-persister = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "78cbe211" } diff --git a/dlc-manager/src/sub_channel_manager.rs b/dlc-manager/src/sub_channel_manager.rs index 4cfb4f8f..1b58d9ac 100644 --- a/dlc-manager/src/sub_channel_manager.rs +++ b/dlc-manager/src/sub_channel_manager.rs @@ -483,6 +483,7 @@ where let msg = self.ln_channel_manager.with_useable_channel_lock( channel_id, &counter_party, + None, |channel_lock| { let per_split_seed = if let Some(per_split_seed_pk) = offered_sub_channel.per_split_seed { @@ -615,7 +616,7 @@ where .ln_chain_monitor .get_latest_holder_commitment_txn(&funding_txo)?; - let commitment_signed = self + let (commitment_signed, commit_tx_number) = self .ln_channel_manager .get_updated_funding_outpoint_commitment_signed( channel_lock, @@ -668,6 +669,7 @@ where publish_basepoint: offered_sub_channel.own_base_points.publish_basepoint, own_basepoint: offered_sub_channel.own_base_points.own_basepoint, commit_signature: commitment_signed.signature, + commit_tx_number, htlc_signatures: commitment_signed.htlc_signatures, channel_revocation_basepoint: accept_channel.revocation_basepoint, channel_publish_basepoint: accept_channel.publish_basepoint, @@ -1360,63 +1362,68 @@ where .get_channel_details(channel_id) .ok_or_else(|| Error::InvalidParameters(format!("Unknown channel {channel_id:?}")))?; - let (commitment_signed, commitment_transactions) = self - .ln_channel_manager - .with_useable_channel_lock(channel_id, &sub_channel.counter_party, |channel_lock| { - let dlc_channel_id = - sub_channel - .get_dlc_channel_id(0) - .ok_or(Error::InvalidState( - "Could not get dlc channel id.".to_string(), - ))?; - - let dlc_channel = get_channel_in_state!( - self.dlc_channel_manager, - &dlc_channel_id, - Signed, - None:: - )?; - let funding_txo = lightning::chain::transaction::OutPoint { - txid: state.signed_subchannel.split_tx.transaction.input[0] - .previous_output - .txid, - index: state.signed_subchannel.split_tx.transaction.input[0] - .previous_output - .vout as u16, - }; - let commitment_transactions = self - .ln_chain_monitor - .get_latest_holder_commitment_txn(&funding_txo)?; + let ((commitment_signed, commit_tx_number), commitment_transactions) = + self.ln_channel_manager.with_useable_channel_lock( + channel_id, + &sub_channel.counter_party, + None, + |channel_lock| { + let dlc_channel_id = + sub_channel + .get_dlc_channel_id(0) + .ok_or(Error::InvalidState( + "Could not get dlc channel id.".to_string(), + ))?; + + let dlc_channel = get_channel_in_state!( + self.dlc_channel_manager, + &dlc_channel_id, + Signed, + None:: + )?; + let funding_txo = lightning::chain::transaction::OutPoint { + txid: state.signed_subchannel.split_tx.transaction.input[0] + .previous_output + .txid, + index: state.signed_subchannel.split_tx.transaction.input[0] + .previous_output + .vout as u16, + }; + let commitment_transactions = self + .ln_chain_monitor + .get_latest_holder_commitment_txn(&funding_txo)?; - let total_collateral = - dlc_channel.own_params.collateral + dlc_channel.counter_params.collateral; + let total_collateral = + dlc_channel.own_params.collateral + dlc_channel.counter_params.collateral; - debug_assert_eq!(state.accept_balance + state.offer_balance, total_collateral); + debug_assert_eq!(state.accept_balance + state.offer_balance, total_collateral); - let (_, accept_fees) = per_party_fee(sub_channel.fee_rate_per_vb)?; + let (_, accept_fees) = per_party_fee(sub_channel.fee_rate_per_vb)?; - let ln_own_balance_msats = channel_details.outbound_capacity_msat - + channel_details.unspendable_punishment_reserve.unwrap() * 1000 - + accept_fees * 1000 - + state.accept_balance * 1000; + let ln_own_balance_msats = channel_details.outbound_capacity_msat + + channel_details.unspendable_punishment_reserve.unwrap() * 1000 + + accept_fees * 1000 + + state.accept_balance * 1000; - let fund_value = sub_channel.fund_value_satoshis; + let fund_value = sub_channel.fund_value_satoshis; - let commitment_signed = self - .ln_channel_manager - .get_updated_funding_outpoint_commitment_signed( - channel_lock, - &state.signed_subchannel.split_tx.transaction.input[0].previous_output, - fund_value, - ln_own_balance_msats, - )?; + let commitment_signed = self + .ln_channel_manager + .get_updated_funding_outpoint_commitment_signed( + channel_lock, + &state.signed_subchannel.split_tx.transaction.input[0].previous_output, + fund_value, + ln_own_balance_msats, + )?; - Ok((commitment_signed, commitment_transactions)) - })?; + Ok((commitment_signed, commitment_transactions)) + }, + )?; let close_accept = SubChannelCloseAccept { channel_id: *channel_id, commit_signature: commitment_signed.signature, + commit_tx_number, htlc_signatures: commitment_signed.htlc_signatures, }; @@ -1772,12 +1779,13 @@ where let ( split_tx_adaptor_signature, - commitment_signed, + (commitment_signed, commit_tx_number), revoke_and_ack, commitment_transactions, ) = self.ln_channel_manager.with_useable_channel_lock( channel_id, counter_party, + Some(sub_channel_accept.commit_tx_number), |channel_lock| { let split_tx_adaptor_signature = self.get_holder_split_tx_adaptor_signature( *channel_id, @@ -1885,6 +1893,7 @@ where channel_id: sub_channel_accept.channel_id, split_adaptor_signature: split_tx_adaptor_signature, commit_signature: commitment_signed.signature, + commit_tx_number, htlc_signatures: commitment_signed.htlc_signatures, cet_adaptor_signatures: sign_channel.cet_adaptor_signatures, buffer_adaptor_signature: sign_channel.buffer_adaptor_signature, @@ -1954,6 +1963,7 @@ where let msg = self.ln_channel_manager.with_useable_channel_lock( &sub_channel_confirm.channel_id, counter_party, + Some(sub_channel_confirm.commit_tx_number), |channel_lock| { let (mut accepted_sub_channel, state) = get_sub_channel_in_state!( self.dlc_channel_manager, @@ -2122,6 +2132,7 @@ where let msg = self.ln_channel_manager.with_useable_channel_lock( &sub_channel_finalize.channel_id, counter_party, + None, |channel_lock| { let (mut confirmed_sub_channel, state) = get_sub_channel_in_state!( self.dlc_channel_manager, @@ -2230,6 +2241,7 @@ where self.ln_channel_manager.with_useable_channel_lock( &sub_channel_revoke.channel_id, counter_party, + None, |channel_lock| { let (mut confirmed_sub_channel, state) = get_sub_channel_in_state!( self.dlc_channel_manager, @@ -2359,6 +2371,7 @@ where let close_confirm = self.ln_channel_manager.with_useable_channel_lock( &accept.channel_id, counter_party, + Some(accept.commit_tx_number), |channel_lock| { let (mut sub_channel, state) = get_sub_channel_in_state!( self.dlc_channel_manager, @@ -2375,7 +2388,7 @@ where let fund_value = sub_channel.fund_value_satoshis; - let commitment_signed = self + let (commitment_signed, commit_tx_number) = self .ln_channel_manager .get_updated_funding_outpoint_commitment_signed( channel_lock, @@ -2408,6 +2421,7 @@ where let close_confirm = SubChannelCloseConfirm { channel_id: accept.channel_id, commit_signature: commitment_signed.signature, + commit_tx_number, htlc_signatures: commitment_signed.htlc_signatures, split_revocation_secret: per_split_secret, commit_revocation_secret: SecretKey::from_slice(&raa.per_commitment_secret) @@ -2460,6 +2474,7 @@ where let finalize = self.ln_channel_manager.with_useable_channel_lock( &confirm.channel_id, counter_party, + Some(confirm.commit_tx_number), |channel_lock| { let (mut sub_channel, state) = get_sub_channel_in_state!( self.dlc_channel_manager, @@ -2587,6 +2602,7 @@ where self.ln_channel_manager.with_useable_channel_lock( &finalize.channel_id, counter_party, + None, |channel_lock| { let (mut sub_channel, state) = get_sub_channel_in_state!( self.dlc_channel_manager, @@ -3201,115 +3217,132 @@ where } SubChannelState::Accepted(a) => { self.ln_channel_manager - .with_useable_channel_lock(&channel.channel_id, peer_id, |channel_lock| { - let dlc_channel_id = - channel.get_dlc_channel_id(0).ok_or_else(|| { - Error::InvalidState("Could not get dlc channel id".to_string()) - })?; - let dlc_channel = get_channel_in_state!( - self.dlc_channel_manager, - &dlc_channel_id, - Accepted, - None:: - )?; - let contract = get_contract_in_state!( - self.dlc_channel_manager, - &dlc_channel.accepted_contract_id, - Accepted, - None:: - )?; - let offered_channel = OfferedChannel { - offered_contract_id: contract.offered_contract.id, - temporary_channel_id: dlc_channel.temporary_channel_id, - party_points: dlc_channel.offer_base_points, - per_update_point: dlc_channel.offer_per_update_point, - offer_per_update_seed: None, - is_offer_party: false, - counter_party: dlc_channel.counter_party, - cet_nsequence: CET_NSEQUENCE, - }; - self.dlc_channel_manager - .get_store() - .upsert_sub_channel(&channel)?; - self.dlc_channel_manager.get_store().upsert_channel( - Channel::Offered(offered_channel), - Some(Contract::Offered(contract.offered_contract)), - )?; - let party_params = contract.accept_params.clone(); - let funding_inputs_info = contract.funding_inputs; - let accept_points = dlc_channel.accept_base_points.clone(); - let per_update_seed_pk = dlc_channel.accept_per_update_seed; - self.actions.lock().unwrap().push(Action::ReAccept { - channel_id, - party_params, - funding_inputs_info, - accept_points, - per_update_seed_pk, - }); + .with_useable_channel_lock( + &channel.channel_id, + peer_id, + None, + |channel_lock| { + let dlc_channel_id = + channel.get_dlc_channel_id(0).ok_or_else(|| { + Error::InvalidState( + "Could not get dlc channel id".to_string(), + ) + })?; + let dlc_channel = get_channel_in_state!( + self.dlc_channel_manager, + &dlc_channel_id, + Accepted, + None:: + )?; + let contract = get_contract_in_state!( + self.dlc_channel_manager, + &dlc_channel.accepted_contract_id, + Accepted, + None:: + )?; + let offered_channel = OfferedChannel { + offered_contract_id: contract.offered_contract.id, + temporary_channel_id: dlc_channel.temporary_channel_id, + party_points: dlc_channel.offer_base_points, + per_update_point: dlc_channel.offer_per_update_point, + offer_per_update_seed: None, + is_offer_party: false, + counter_party: dlc_channel.counter_party, + cet_nsequence: CET_NSEQUENCE, + }; + self.dlc_channel_manager + .get_store() + .upsert_sub_channel(&channel)?; + self.dlc_channel_manager.get_store().upsert_channel( + Channel::Offered(offered_channel), + Some(Contract::Offered(contract.offered_contract)), + )?; + let party_params = contract.accept_params.clone(); + let funding_inputs_info = contract.funding_inputs; + let accept_points = dlc_channel.accept_base_points.clone(); + let per_update_seed_pk = dlc_channel.accept_per_update_seed; + self.actions.lock().unwrap().push(Action::ReAccept { + channel_id, + party_params, + funding_inputs_info, + accept_points, + per_update_seed_pk, + }); - self.ln_channel_manager.set_funding_outpoint( - channel_lock, - &a.ln_rollback.funding_outpoint, - a.ln_rollback.channel_value_satoshis, - a.ln_rollback.value_to_self_msat, - ); - updated_state = Some(SubChannelState::Offered(OfferedSubChannel { - per_split_point: a.offer_per_split_point, - })); + self.ln_channel_manager.set_funding_outpoint( + channel_lock, + &a.ln_rollback.funding_outpoint, + a.ln_rollback.channel_value_satoshis, + a.ln_rollback.value_to_self_msat, + ); + updated_state = Some(SubChannelState::Offered(OfferedSubChannel { + per_split_point: a.offer_per_split_point, + })); - Ok(()) - }) + Ok(()) + }, + ) .map_err(|e| Error::InvalidState(format!("{:?}", e)))?; } SubChannelState::Confirmed(a) => { self.ln_channel_manager - .with_useable_channel_lock(&channel.channel_id, peer_id, |channel_lock| { - let dlc_channel_id = - channel.get_dlc_channel_id(0).ok_or_else(|| { - Error::InvalidState("Could not get dlc channel id".to_string()) - })?; - let dlc_channel = get_channel_in_state!( - self.dlc_channel_manager, - &dlc_channel_id, - Signed, - None:: - )?; - let contract = get_contract_in_state!( - self.dlc_channel_manager, - &dlc_channel - .get_contract_id() - .expect("Signed contract should have a contract id"), - Signed, - None:: - )?; - let offered_channel = OfferedChannel { - offered_contract_id: contract.accepted_contract.offered_contract.id, - temporary_channel_id: dlc_channel.temporary_channel_id, - party_points: dlc_channel.own_points, - per_update_point: dlc_channel.own_per_update_point, - offer_per_update_seed: channel.per_split_seed, - is_offer_party: true, - counter_party: dlc_channel.counter_party, - // TODO(tibo): use value from original offer - cet_nsequence: CET_NSEQUENCE, - }; - self.ln_channel_manager.set_funding_outpoint( - channel_lock, - &a.ln_rollback.funding_outpoint, - a.ln_rollback.channel_value_satoshis, - a.ln_rollback.value_to_self_msat, - ); - self.dlc_channel_manager.get_store().upsert_channel( - Channel::Offered(offered_channel), - Some(Contract::Offered( - contract.accepted_contract.offered_contract, - )), - )?; - updated_state = Some(SubChannelState::Offered(OfferedSubChannel { - per_split_point: a.own_per_split_point, - })); - Ok(()) - }) + .with_useable_channel_lock( + &channel.channel_id, + peer_id, + None, + |channel_lock| { + let dlc_channel_id = + channel.get_dlc_channel_id(0).ok_or_else(|| { + Error::InvalidState( + "Could not get dlc channel id".to_string(), + ) + })?; + let dlc_channel = get_channel_in_state!( + self.dlc_channel_manager, + &dlc_channel_id, + Signed, + None:: + )?; + let contract = get_contract_in_state!( + self.dlc_channel_manager, + &dlc_channel + .get_contract_id() + .expect("Signed contract should have a contract id"), + Signed, + None:: + )?; + let offered_channel = OfferedChannel { + offered_contract_id: contract + .accepted_contract + .offered_contract + .id, + temporary_channel_id: dlc_channel.temporary_channel_id, + party_points: dlc_channel.own_points, + per_update_point: dlc_channel.own_per_update_point, + offer_per_update_seed: channel.per_split_seed, + is_offer_party: true, + counter_party: dlc_channel.counter_party, + // TODO(tibo): use value from original offer + cet_nsequence: CET_NSEQUENCE, + }; + self.ln_channel_manager.set_funding_outpoint( + channel_lock, + &a.ln_rollback.funding_outpoint, + a.ln_rollback.channel_value_satoshis, + a.ln_rollback.value_to_self_msat, + ); + self.dlc_channel_manager.get_store().upsert_channel( + Channel::Offered(offered_channel), + Some(Contract::Offered( + contract.accepted_contract.offered_contract, + )), + )?; + updated_state = Some(SubChannelState::Offered(OfferedSubChannel { + per_split_point: a.own_per_split_point, + })); + Ok(()) + }, + ) .map_err(|e| Error::InvalidState(format!("{:?}", e)))?; } SubChannelState::Finalized(signed) => { @@ -3324,6 +3357,7 @@ where .with_useable_channel_lock( &channel.channel_id, peer_id, + None, |channel_lock| { let dlc_channel_id = channel.get_dlc_channel_id(0).ok_or_else(|| { @@ -3417,6 +3451,7 @@ where self.ln_channel_manager.with_useable_channel_lock( &channel.channel_id, &channel.counter_party, + None, |channel_lock| { self.ln_channel_manager.set_funding_outpoint( channel_lock, @@ -3450,6 +3485,7 @@ where self.ln_channel_manager.with_useable_channel_lock( &channel.channel_id, &channel.counter_party, + None, |channel_lock| { self.ln_channel_manager.set_funding_outpoint( channel_lock, diff --git a/dlc-manager/src/subchannel/mod.rs b/dlc-manager/src/subchannel/mod.rs index d09e3384..f2ff072a 100644 --- a/dlc-manager/src/subchannel/mod.rs +++ b/dlc-manager/src/subchannel/mod.rs @@ -408,6 +408,7 @@ where &self, channel_id: &ChannelId, counter_party_node_id: &PublicKey, + commit_tx_number: Option, cb: F, ) -> Result where @@ -430,7 +431,7 @@ where funding_outpoint: &OutPoint, channel_value_satoshis: u64, value_to_self_msat: u64, - ) -> Result; + ) -> Result<(CommitmentSigned, u64), APIError>; /// Provides commitment transaction and HTLCs signatures and returns a [`RevokeAndACK`] /// message. fn on_commitment_signed_get_raa( @@ -512,7 +513,7 @@ where funding_outpoint: &OutPoint, channel_value_satoshis: u64, value_to_self_msat: u64, - ) -> Result { + ) -> Result<(CommitmentSigned, u64), APIError> { self.get_updated_funding_outpoint_commitment_signed( channel_lock, &lightning::chain::transaction::OutPoint { @@ -569,6 +570,7 @@ where &self, channel_id: &ChannelId, counter_party_node_id: &PublicKey, + commit_tx_number: Option, cb: C, ) -> Result where @@ -576,7 +578,7 @@ where &mut ChannelLock<<::Target as SignerProvider>::Signer>, ) -> Result, { - self.with_useable_channel_lock(channel_id, counter_party_node_id, cb) + self.with_useable_channel_lock(channel_id, counter_party_node_id, commit_tx_number, cb) } fn with_channel_lock_no_check( diff --git a/dlc-manager/tests/ln_dlc_channel_execution_tests.rs b/dlc-manager/tests/ln_dlc_channel_execution_tests.rs index 3aa33a05..fef86fe0 100644 --- a/dlc-manager/tests/ln_dlc_channel_execution_tests.rs +++ b/dlc-manager/tests/ln_dlc_channel_execution_tests.rs @@ -2443,6 +2443,15 @@ fn offer_sub_channel_internal(test_params: &LnDlcTestParams, do_reconnect: bool) Offered ); + test_params + .alice_node + .sub_channel_manager + .on_sub_channel_message( + &SubChannelMessage::Accept(accept.clone()), + &test_params.bob_node.channel_manager.get_our_node_id(), + ) + .expect_err("Should not accept a stale accept message"); + // Bob should re-send the accept message let mut msgs = test_params.bob_node.sub_channel_manager.periodic_check(); assert_eq!(1, msgs.len()); @@ -2469,6 +2478,7 @@ fn offer_sub_channel_internal(test_params: &LnDlcTestParams, do_reconnect: bool) &test_params.channel_id, Accepted ); + let mut confirm = test_params .alice_node .sub_channel_manager @@ -2546,6 +2556,7 @@ fn offer_sub_channel_internal(test_params: &LnDlcTestParams, do_reconnect: bool) if do_reconnect { reconnect(test_params); + assert_sub_channel_state!( test_params.alice_node.sub_channel_manager, &test_params.channel_id, @@ -2570,7 +2581,7 @@ fn offer_sub_channel_internal(test_params: &LnDlcTestParams, do_reconnect: bool) ); if let (SubChannelMessage::Accept(a), p) = msgs.pop().unwrap() { assert_eq!(p, test_params.alice_node.channel_manager.get_our_node_id()); - let confirm = test_params + let _ = test_params .alice_node .sub_channel_manager .on_sub_channel_message( @@ -2579,15 +2590,50 @@ fn offer_sub_channel_internal(test_params: &LnDlcTestParams, do_reconnect: bool) ) .unwrap() .unwrap(); - finalize = test_params - .bob_node - .sub_channel_manager - .on_sub_channel_message( - &confirm, - &test_params.alice_node.channel_manager.get_our_node_id(), - ) - .unwrap() - .unwrap(); + reconnect(test_params); + assert_sub_channel_state!( + test_params.alice_node.sub_channel_manager, + &test_params.channel_id, + Offered + ); + assert_sub_channel_state!( + test_params.bob_node.sub_channel_manager, + &test_params.channel_id, + Offered + ); + let mut msgs = test_params.bob_node.sub_channel_manager.periodic_check(); + assert_eq!(1, msgs.len()); + assert_eq!( + 0, + test_params + .alice_node + .sub_channel_manager + .periodic_check() + .len() + ); + if let (SubChannelMessage::Accept(a), p) = msgs.pop().unwrap() { + assert_eq!(p, test_params.alice_node.channel_manager.get_our_node_id()); + let confirm = test_params + .alice_node + .sub_channel_manager + .on_sub_channel_message( + &SubChannelMessage::Accept(a), + &test_params.bob_node.channel_manager.get_our_node_id(), + ) + .unwrap() + .unwrap(); + finalize = test_params + .bob_node + .sub_channel_manager + .on_sub_channel_message( + &confirm, + &test_params.alice_node.channel_manager.get_our_node_id(), + ) + .unwrap() + .unwrap(); + } else { + panic!(); + } } else { panic!("Expected an accept message"); } @@ -2898,6 +2944,16 @@ fn off_chain_close_finalize(test_params: &LnDlcTestParams, do_reconnect: bool) { .periodic_check() .len() ); + + test_params + .alice_node + .sub_channel_manager + .on_sub_channel_message( + &SubChannelMessage::CloseAccept(close_accept), + &test_params.bob_node_id, + ) + .expect_err("Should not accept a stale CloseAccept message"); + let mut msgs = test_params.bob_node.sub_channel_manager.periodic_check(); assert_eq!(1, msgs.len()); if let (SubChannelMessage::CloseAccept(c), p) = msgs.pop().unwrap() { diff --git a/dlc-messages/src/message_handler.rs b/dlc-messages/src/message_handler.rs index 1d3f16aa..30def1c4 100644 --- a/dlc-messages/src/message_handler.rs +++ b/dlc-messages/src/message_handler.rs @@ -48,37 +48,6 @@ impl lightning::events::OnionMessageProvider for MessageHandler { } } -impl lightning::ln::msgs::OnionMessageHandler for MessageHandler { - fn handle_onion_message( - &self, - _their_node_id: &PublicKey, - _msg: &lightning::ln::msgs::OnionMessage, - ) { - } - fn peer_connected( - &self, - _their_node_id: &PublicKey, - _init: &lightning::ln::msgs::Init, - _inbound: bool, - ) -> Result<(), ()> { - Ok(()) - } - - fn peer_disconnected(&self, their_node_id: &PublicKey) { - self.clear_pending_messages_sent_by_node(their_node_id); - } - - fn provided_node_features(&self) -> lightning::ln::features::NodeFeatures { - lightning::ln::features::NodeFeatures::empty() - } - fn provided_init_features( - &self, - _their_node_id: &PublicKey, - ) -> lightning::ln::features::InitFeatures { - lightning::ln::features::InitFeatures::empty() - } -} - impl MessageHandler { /// Creates a new instance of a [`MessageHandler`] pub fn new() -> Self { @@ -102,38 +71,6 @@ impl MessageHandler { ret } - /// Drops certain pending messages sent by the remote node. - pub fn clear_pending_messages_sent_by_node(&self, disconnected_node_id: &PublicKey) { - let messages = &mut *self.msg_received.lock().unwrap(); - - messages.retain(|(node_id, message)| { - match message { - Message::SubChannel(SubChannelMessage::Confirm(message)) - if node_id == disconnected_node_id => - { - log::warn!( - "Dropping SubChannelConfirm message for channel {:?} \ - after peer {node_id} disconnected", - message.channel_id - ); - false - } - Message::SubChannel(SubChannelMessage::CloseConfirm(message)) - if node_id == disconnected_node_id => - { - log::warn!( - "Dropping SubChannelCloseConfirm message for channel {:?} \ - after peer {node_id} disconnected", - message.channel_id - ); - false - } - // Keep any other message - _ => true, - } - }); - } - /// Send a message to the peer with given node id. Not that the message is not /// sent right away, but only when the LDK /// [`lightning::ln::peer_handler::PeerManager::process_events`] is next called. diff --git a/dlc-messages/src/sub_channel.rs b/dlc-messages/src/sub_channel.rs index e19387fe..e1ef5c77 100644 --- a/dlc-messages/src/sub_channel.rs +++ b/dlc-messages/src/sub_channel.rs @@ -102,6 +102,8 @@ pub struct SubChannelAccept { pub own_basepoint: PublicKey, /// The signature for the new commit transaction of the Lightning channel. pub commit_signature: Signature, + /// The commit transaction number for which the above signature is intended. + pub commit_tx_number: u64, /// The htlc signatures for the new commit transaction of the Lightning channel. pub htlc_signatures: Vec, /// The first point used to derive public private key pairs used for the split transaction. @@ -139,6 +141,7 @@ impl_dlc_writeable!( (publish_basepoint, writeable), (own_basepoint, writeable), (commit_signature, writeable), + (commit_tx_number, writeable), (htlc_signatures, writeable), (first_per_split_point, writeable), (channel_revocation_basepoint, writeable), @@ -168,6 +171,8 @@ pub struct SubChannelConfirm { pub split_adaptor_signature: EcdsaAdaptorSignature, /// The signature for the new commitment transaction. pub commit_signature: Signature, + /// The commit transaction number for which the above signature is intended. + pub commit_tx_number: u64, /// The htlc signatures for the new commitment transaction. pub htlc_signatures: Vec, /// The adaptor signatures for the DLC channel CETs. @@ -185,6 +190,7 @@ impl_dlc_writeable!(SubChannelConfirm, { (channel_id, writeable), (split_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (commit_signature, writeable), + (commit_tx_number, writeable), (htlc_signatures, writeable), (cet_adaptor_signatures, writeable), (buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), @@ -274,6 +280,8 @@ pub struct SubChannelCloseAccept { /// The signature for the new commitment transaction The signature for the new commitment /// transaction. pub commit_signature: Signature, + /// The commit transaction number for which the above signature is intended. + pub commit_tx_number: u64, /// The htlc signatures for the new commitment transactions. pub htlc_signatures: Vec, } @@ -281,6 +289,7 @@ pub struct SubChannelCloseAccept { impl_dlc_writeable!(SubChannelCloseAccept, { (channel_id, writeable), (commit_signature, writeable), + (commit_tx_number, writeable), (htlc_signatures, writeable) }); @@ -298,6 +307,8 @@ pub struct SubChannelCloseConfirm { /// The signature for the new commitment transaction The signature for the new commitment /// transaction. pub commit_signature: Signature, + /// The commit transaction number for which the above signature is intended. + pub commit_tx_number: u64, /// The htlc signatures for the new commitment transactions. pub htlc_signatures: Vec, /// The pre-image of the split transaction revocation point. @@ -311,6 +322,7 @@ pub struct SubChannelCloseConfirm { impl_dlc_writeable!(SubChannelCloseConfirm, { (channel_id, writeable), (commit_signature, writeable), + (commit_tx_number, writeable), (htlc_signatures, writeable), (split_revocation_secret, writeable), (commit_revocation_secret, writeable),