From bd0029601eddc38f1805d8936c009cfdf5a7a87b Mon Sep 17 00:00:00 2001 From: Leo Nash Date: Fri, 10 Jan 2025 02:27:33 +0000 Subject: [PATCH] Removed unused field in `HolderFundingOutput` --- lightning/src/chain/channelmonitor.rs | 10 +++++----- lightning/src/chain/package.rs | 13 +++++-------- lightning/src/ln/channel.rs | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 3c587ddc2da..d291edcd750 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -878,6 +878,7 @@ pub(crate) struct ChannelMonitorImpl { prev_counterparty_commitment_txid: Option, counterparty_commitment_params: CounterpartyCommitmentParameters, + // this field is not used, but kept for backwards compatibility funding_redeemscript: ScriptBuf, channel_value_satoshis: u64, // first is the idx of the first of the two per-commitment points @@ -1340,7 +1341,7 @@ impl ChannelMonitor { pub(crate) fn new(secp_ctx: Secp256k1, mut keys: Signer, shutdown_script: Option, on_counterparty_tx_csv: u16, destination_script: &Script, funding_info: (OutPoint, ScriptBuf), channel_parameters: &ChannelTransactionParameters, holder_pays_commitment_tx_fee: bool, - funding_redeemscript: ScriptBuf, channel_value_satoshis: u64, + channel_value_satoshis: u64, commitment_transaction_number_obscure_factor: u64, initial_holder_commitment_tx: HolderCommitmentTransaction, best_block: BestBlock, counterparty_node_id: PublicKey, channel_id: ChannelId, @@ -1404,7 +1405,7 @@ impl ChannelMonitor { prev_counterparty_commitment_txid: None, counterparty_commitment_params, - funding_redeemscript, + funding_redeemscript: ScriptBuf::new(), channel_value_satoshis, their_cur_per_commitment_points: None, @@ -3069,7 +3070,6 @@ impl ChannelMonitorImpl { fn generate_claimable_outpoints_and_watch_outputs(&mut self, reason: ClosureReason) -> (Vec, Vec) { let funding_outp = HolderFundingOutput::build( - self.funding_redeemscript.clone(), self.channel_value_satoshis, self.onchain_tx_handler.channel_type_features().clone() ); @@ -5277,7 +5277,7 @@ mod tests { let monitor = ChannelMonitor::new(Secp256k1::new(), keys, Some(ShutdownScript::new_p2wpkh_from_pubkey(shutdown_pubkey).into_inner()), 0, &ScriptBuf::new(), (OutPoint { txid: Txid::from_slice(&[43; 32]).unwrap(), index: 0 }, ScriptBuf::new()), - &channel_parameters, true, ScriptBuf::new(), 46, 0, HolderCommitmentTransaction::dummy(&mut Vec::new()), + &channel_parameters, true, 46, 0, HolderCommitmentTransaction::dummy(&mut Vec::new()), best_block, dummy_key, channel_id); let mut htlcs = preimages_slice_to_htlcs!(preimages[0..10]); @@ -5527,7 +5527,7 @@ mod tests { let monitor = ChannelMonitor::new(Secp256k1::new(), keys, Some(ShutdownScript::new_p2wpkh_from_pubkey(shutdown_pubkey).into_inner()), 0, &ScriptBuf::new(), (OutPoint { txid: Txid::from_slice(&[43; 32]).unwrap(), index: 0 }, ScriptBuf::new()), - &channel_parameters, true, ScriptBuf::new(), 46, 0, HolderCommitmentTransaction::dummy(&mut Vec::new()), + &channel_parameters, true, 46, 0, HolderCommitmentTransaction::dummy(&mut Vec::new()), best_block, dummy_key, channel_id); let chan_id = monitor.inner.lock().unwrap().channel_id(); diff --git a/lightning/src/chain/package.rs b/lightning/src/chain/package.rs index 1d714d90ec7..96f2bf5b07f 100644 --- a/lightning/src/chain/package.rs +++ b/lightning/src/chain/package.rs @@ -455,16 +455,14 @@ impl Readable for HolderHTLCOutput { /// Note that on upgrades, some features of existing outputs may be missed. #[derive(Clone, PartialEq, Eq)] pub(crate) struct HolderFundingOutput { - funding_redeemscript: ScriptBuf, pub(crate) funding_amount: Option, channel_type_features: ChannelTypeFeatures, } impl HolderFundingOutput { - pub(crate) fn build(funding_redeemscript: ScriptBuf, funding_amount: u64, channel_type_features: ChannelTypeFeatures) -> Self { + pub(crate) fn build(funding_amount: u64, channel_type_features: ChannelTypeFeatures) -> Self { HolderFundingOutput { - funding_redeemscript, funding_amount: Some(funding_amount), channel_type_features, } @@ -475,7 +473,7 @@ impl Writeable for HolderFundingOutput { fn write(&self, writer: &mut W) -> Result<(), io::Error> { let legacy_deserialization_prevention_marker = chan_utils::legacy_deserialization_prevention_marker_for_channel_type_features(&self.channel_type_features); write_tlv_fields!(writer, { - (0, self.funding_redeemscript, required), + (0, None::, option), (1, self.channel_type_features, required), (2, legacy_deserialization_prevention_marker, option), (3, self.funding_amount, option), @@ -486,13 +484,13 @@ impl Writeable for HolderFundingOutput { impl Readable for HolderFundingOutput { fn read(reader: &mut R) -> Result { - let mut funding_redeemscript = RequiredWrapper(None); + let mut _funding_redeemscript: Option = None; let mut _legacy_deserialization_prevention_marker: Option<()> = None; let mut channel_type_features = None; let mut funding_amount = None; read_tlv_fields!(reader, { - (0, funding_redeemscript, required), + (0, _funding_redeemscript, option), (1, channel_type_features, option), (2, _legacy_deserialization_prevention_marker, option), (3, funding_amount, option), @@ -501,7 +499,6 @@ impl Readable for HolderFundingOutput { verify_channel_type_features(&channel_type_features, None)?; Ok(Self { - funding_redeemscript: funding_redeemscript.0.unwrap(), channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key()), funding_amount }) @@ -1420,7 +1417,7 @@ mod tests { macro_rules! dumb_funding_output { () => { - PackageSolvingData::HolderFundingOutput(HolderFundingOutput::build(ScriptBuf::new(), 0, ChannelTypeFeatures::only_static_remote_key())) + PackageSolvingData::HolderFundingOutput(HolderFundingOutput::build(0, ChannelTypeFeatures::only_static_remote_key())) } } diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index b16e845466c..ac2eea6a314 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -1623,7 +1623,7 @@ trait InitialRemoteCommitmentReceiver where SP::Target: SignerProvide shutdown_script, context.get_holder_selected_contest_delay(), &context.destination_script, (funding_txo, funding_txo_script), &context.channel_transaction_parameters, context.is_outbound(), - funding_redeemscript.clone(), context.channel_value_satoshis, + context.channel_value_satoshis, obscure_factor, holder_commitment_tx, best_block, context.counterparty_node_id, context.channel_id()); channel_monitor.provide_initial_counterparty_commitment_tx(