Skip to content

Commit 114340b

Browse files
committed
Track ChannelTransactionParameters in ChannelMonitor FundingScope
The `ChannelTransactionParameters` will change across `FundingScope`s, so we make sure to track it to ensure it is updated accordingly when a new `FundingScope` is applied/considered.
1 parent 646b042 commit 114340b

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ struct FundingScope {
875875
outpoint: OutPoint,
876876
script_pubkey: ScriptBuf,
877877
redeem_script: ScriptBuf,
878-
channel_value_satoshis: u64,
878+
channel_parameters: ChannelTransactionParameters,
879879

880880
current_counterparty_commitment_txid: Option<Txid>,
881881
prev_counterparty_commitment_txid: Option<Txid>,
@@ -1118,7 +1118,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
11181118

11191119
self.counterparty_commitment_params.write(writer)?;
11201120
self.funding.redeem_script.write(writer)?;
1121-
self.funding.channel_value_satoshis.write(writer)?;
1121+
self.funding.channel_parameters.channel_value_satoshis.write(writer)?;
11221122

11231123
match self.their_cur_per_commitment_points {
11241124
Some((idx, pubkey, second_option)) => {
@@ -1378,7 +1378,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
13781378
on_counterparty_tx_csv: u16, destination_script: &Script, funding_outpoint: OutPoint,
13791379
funding_script: ScriptBuf, channel_parameters: &ChannelTransactionParameters,
13801380
holder_pays_commitment_tx_fee: bool, funding_redeemscript: ScriptBuf,
1381-
channel_value_satoshis: u64, commitment_transaction_number_obscure_factor: u64,
1381+
commitment_transaction_number_obscure_factor: u64,
13821382
initial_holder_commitment_tx: HolderCommitmentTransaction, best_block: BestBlock,
13831383
counterparty_node_id: PublicKey, channel_id: ChannelId,
13841384
) -> ChannelMonitor<Signer> {
@@ -1418,8 +1418,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
14181418
};
14191419

14201420
let onchain_tx_handler = OnchainTxHandler::new(
1421-
channel_value_satoshis, channel_keys_id, destination_script.into(), keys,
1422-
channel_parameters.clone(), initial_holder_commitment_tx, secp_ctx
1421+
channel_parameters.channel_value_satoshis, channel_keys_id, destination_script.into(),
1422+
keys, channel_parameters.clone(), initial_holder_commitment_tx, secp_ctx
14231423
);
14241424

14251425
let mut outputs_to_watch = new_hash_map();
@@ -1432,7 +1432,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
14321432
outpoint: funding_outpoint,
14331433
script_pubkey: funding_script,
14341434
redeem_script: funding_redeemscript,
1435-
channel_value_satoshis,
1435+
channel_parameters: channel_parameters.clone(),
14361436

14371437
current_counterparty_commitment_txid: None,
14381438
prev_counterparty_commitment_txid: None,
@@ -3146,7 +3146,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31463146
fn generate_claimable_outpoints_and_watch_outputs(&mut self, reason: ClosureReason) -> (Vec<PackageTemplate>, Vec<TransactionOutputs>) {
31473147
let funding_outp = HolderFundingOutput::build(
31483148
self.funding.redeem_script.clone(),
3149-
self.funding.channel_value_satoshis,
3149+
self.funding.channel_parameters.channel_value_satoshis,
31503150
self.onchain_tx_handler.channel_type_features().clone()
31513151
);
31523152
let commitment_package = PackageTemplate::build_package(
@@ -3403,7 +3403,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34033403
let commitment_txid = commitment_tx.compute_txid();
34043404
debug_assert_eq!(self.funding.current_holder_commitment_tx.txid, commitment_txid);
34053405
let pending_htlcs = self.funding.current_holder_commitment_tx.non_dust_htlcs();
3406-
let commitment_tx_fee_satoshis = self.funding.channel_value_satoshis -
3406+
let channel_value_satoshis = self.funding.channel_parameters.channel_value_satoshis;
3407+
let commitment_tx_fee_satoshis = channel_value_satoshis -
34073408
commitment_tx.output.iter().fold(0u64, |sum, output| sum + output.value.to_sat());
34083409
ret.push(Event::BumpTransaction(BumpTransactionEvent::ChannelClose {
34093410
channel_id,
@@ -3415,7 +3416,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34153416
anchor_descriptor: AnchorDescriptor {
34163417
channel_derivation_parameters: ChannelDerivationParameters {
34173418
keys_id: self.channel_keys_id,
3418-
value_satoshis: self.funding.channel_value_satoshis,
3419+
value_satoshis: channel_value_satoshis,
34193420
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
34203421
},
34213422
outpoint: BitcoinOutPoint {
@@ -3436,7 +3437,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34363437
htlc_descriptors.push(HTLCDescriptor {
34373438
channel_derivation_parameters: ChannelDerivationParameters {
34383439
keys_id: self.channel_keys_id,
3439-
value_satoshis: self.funding.channel_value_satoshis,
3440+
value_satoshis: self.funding.channel_parameters.channel_value_satoshis,
34403441
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
34413442
},
34423443
commitment_txid: htlc.commitment_txid,
@@ -4809,7 +4810,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
48094810
output: outp.clone(),
48104811
revocation_pubkey: broadcasted_holder_revokable_script.2,
48114812
channel_keys_id: self.channel_keys_id,
4812-
channel_value_satoshis: self.funding.channel_value_satoshis,
4813+
channel_value_satoshis: self.funding.channel_parameters.channel_value_satoshis,
48134814
channel_transaction_parameters: Some(self.onchain_tx_handler.channel_transaction_parameters.clone()),
48144815
}));
48154816
}
@@ -4819,7 +4820,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
48194820
outpoint: OutPoint { txid: tx.compute_txid(), index: i as u16 },
48204821
output: outp.clone(),
48214822
channel_keys_id: self.channel_keys_id,
4822-
channel_value_satoshis: self.funding.channel_value_satoshis,
4823+
channel_value_satoshis: self.funding.channel_parameters.channel_value_satoshis,
48234824
channel_transaction_parameters: Some(self.onchain_tx_handler.channel_transaction_parameters.clone()),
48244825
}));
48254826
}
@@ -5183,12 +5184,14 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
51835184
To continue, run a v0.1 release, send/route a payment over the channel or close it.", channel_id);
51845185
}
51855186

5187+
let channel_parameters = onchain_tx_handler.channel_transaction_parameters.clone();
5188+
51865189
Ok((best_block.block_hash, ChannelMonitor::from_impl(ChannelMonitorImpl {
51875190
funding: FundingScope {
51885191
outpoint,
51895192
script_pubkey: funding_script,
51905193
redeem_script: funding_redeemscript,
5191-
channel_value_satoshis,
5194+
channel_parameters,
51925195

51935196
current_counterparty_commitment_txid,
51945197
prev_counterparty_commitment_txid,
@@ -5485,7 +5488,7 @@ mod tests {
54855488
let best_block = BestBlock::from_network(Network::Testnet);
54865489
let monitor = ChannelMonitor::new(
54875490
Secp256k1::new(), keys, Some(shutdown_script.into_inner()), 0, &ScriptBuf::new(),
5488-
funding_txo, ScriptBuf::new(), &channel_parameters, true, ScriptBuf::new(), 46, 0,
5491+
funding_txo, ScriptBuf::new(), &channel_parameters, true, ScriptBuf::new(), 0,
54895492
HolderCommitmentTransaction::dummy(0, &mut Vec::new()), best_block, dummy_key, channel_id,
54905493
);
54915494

@@ -5738,7 +5741,7 @@ mod tests {
57385741
let best_block = BestBlock::from_network(Network::Testnet);
57395742
let monitor = ChannelMonitor::new(
57405743
Secp256k1::new(), keys, Some(shutdown_script.into_inner()), 0, &ScriptBuf::new(),
5741-
funding_txo, ScriptBuf::new(), &channel_parameters, true, ScriptBuf::new(), 46, 0,
5744+
funding_txo, ScriptBuf::new(), &channel_parameters, true, ScriptBuf::new(), 0,
57425745
HolderCommitmentTransaction::dummy(0, &mut Vec::new()), best_block, dummy_key, channel_id,
57435746
);
57445747

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,8 +2137,8 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
21372137
context.secp_ctx.clone(), monitor_signer, shutdown_script,
21382138
funding.get_holder_selected_contest_delay(), &context.destination_script, funding_txo,
21392139
funding_txo_script, &funding.channel_transaction_parameters, funding.is_outbound(),
2140-
funding_redeemscript, funding.get_value_satoshis(), obscure_factor,
2141-
holder_commitment_tx, best_block, context.counterparty_node_id, context.channel_id(),
2140+
funding_redeemscript, obscure_factor, holder_commitment_tx, best_block,
2141+
context.counterparty_node_id, context.channel_id(),
21422142
);
21432143
channel_monitor.provide_initial_counterparty_commitment_tx(
21442144
counterparty_initial_commitment_tx.clone(), logger,

0 commit comments

Comments
 (0)