From 359b3d5702b585a67e4e6d4044c35caf86bd787d Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Mon, 20 Apr 2020 21:19:00 -0400 Subject: [PATCH] Dry-up InputMaterial::Funding As channel_value last usage was for computing feerate but as this one is static per-commitment and will always-be following specification, we remove it. --- lightning/src/ln/channelmonitor.rs | 14 ++++---------- lightning/src/ln/onchaintx.rs | 9 ++------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index c8e6b8260..da8ba03a7 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -442,9 +442,7 @@ pub(crate) enum InputMaterial { preimage: Option, amount: u64, }, - Funding { - channel_value: u64, - } + Funding {} } impl Writeable for InputMaterial { @@ -471,9 +469,8 @@ impl Writeable for InputMaterial { preimage.write(writer)?; writer.write_all(&byte_utils::be64_to_array(*amount))?; }, - &InputMaterial::Funding { ref channel_value } => { + &InputMaterial::Funding {} => { writer.write_all(&[3; 1])?; - channel_value.write(writer)?; } } Ok(()) @@ -520,10 +517,7 @@ impl Readable for InputMaterial { } }, 3 => { - let channel_value = Readable::read(reader)?; - InputMaterial::Funding { - channel_value - } + InputMaterial::Funding {} } _ => return Err(DecodeError::InvalidValue), }; @@ -1864,7 +1858,7 @@ impl ChannelMonitor { } let should_broadcast = self.would_broadcast_at_height(height); if should_broadcast { - claimable_outpoints.push(ClaimRequest { absolute_timelock: height, aggregable: false, outpoint: BitcoinOutPoint { txid: self.funding_info.0.txid.clone(), vout: self.funding_info.0.index as u32 }, witness_data: InputMaterial::Funding { channel_value: self.channel_value_satoshis }}); + claimable_outpoints.push(ClaimRequest { absolute_timelock: height, aggregable: false, outpoint: BitcoinOutPoint { txid: self.funding_info.0.txid.clone(), vout: self.funding_info.0.index as u32 }, witness_data: InputMaterial::Funding {}}); } if should_broadcast { if let Some(commitment_tx) = self.onchain_tx_handler.get_fully_signed_local_tx() { diff --git a/lightning/src/ln/onchaintx.rs b/lightning/src/ln/onchaintx.rs index cb76dcb2a..186793581 100644 --- a/lightning/src/ln/onchaintx.rs +++ b/lightning/src/ln/onchaintx.rs @@ -531,16 +531,11 @@ impl OnchainTxHandler { } return None; }, - &InputMaterial::Funding { ref channel_value } => { + &InputMaterial::Funding {} => { let signed_tx = self.get_fully_signed_local_tx().unwrap(); - let mut amt_outputs = 0; - for outp in signed_tx.output.iter() { - amt_outputs += outp.value; - } - let feerate = (channel_value - amt_outputs) * 1000 / signed_tx.get_weight() as u64; // Timer set to $NEVER given we can't bump tx without anchor outputs log_trace!(self, "Going to broadcast Local Transaction {} claiming funding output {} from {}...", signed_tx.txid(), outp.vout, outp.txid); - return Some((None, feerate, signed_tx)); + return Some((None, self.local_commitment.as_ref().unwrap().feerate_per_kw, signed_tx)); } _ => unreachable!() } -- 2.39.5