Skip to content

Commit 543ad4f

Browse files
committed
Add feerate and balances to LatestCounterpartyCommitmentTXInfo
This adds the feerate and local and remote output values to this channel monitor update step so that a monitor can reconstruct the counterparty's commitment transaction from an update. These commitment transactions will be exposed to users in the following commits to support third-party watchtowers in the persistence pipeline. With only the HTLC outputs currently available in the monitor update, we can tell how much of the channel balance is in-flight and towards which side, however it doesn't tell us the amount that resides on either side. Because of dust, we can't reliably derive the remote value from the local value and visa versa. Thus, it seems these are the minimum fields that need to be added.
1 parent 0c25046 commit 543ad4f

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ pub(crate) enum ChannelMonitorUpdateStep {
502502
htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)>,
503503
commitment_number: u64,
504504
their_per_commitment_point: PublicKey,
505+
feerate_per_kw: Option<u32>,
506+
to_broadcaster_value_sat: Option<u64>,
507+
to_countersignatory_value_sat: Option<u64>,
505508
},
506509
PaymentPreimage {
507510
payment_preimage: PaymentPreimage,
@@ -544,8 +547,11 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
544547
},
545548
(1, LatestCounterpartyCommitmentTXInfo) => {
546549
(0, commitment_txid, required),
550+
(1, feerate_per_kw, option),
547551
(2, commitment_number, required),
552+
(3, to_broadcaster_value_sat, option),
548553
(4, their_per_commitment_point, required),
554+
(5, to_countersignatory_value_sat, option),
549555
(6, htlc_outputs, required_vec),
550556
},
551557
(2, PaymentPreimage) => {
@@ -2471,7 +2477,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
24712477
ret = Err(());
24722478
}
24732479
}
2474-
ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo { commitment_txid, htlc_outputs, commitment_number, their_per_commitment_point } => {
2480+
ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo { commitment_txid, htlc_outputs, commitment_number, their_per_commitment_point, .. } => {
24752481
log_trace!(logger, "Updating ChannelMonitor with latest counterparty commitment transaction info");
24762482
self.provide_latest_counterparty_commitment_tx(*commitment_txid, htlc_outputs.clone(), *commitment_number, *their_per_commitment_point, logger)
24772483
},

lightning/src/ln/channel.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5289,7 +5289,9 @@ impl<SP: Deref> Channel<SP> where
52895289
}
52905290
self.context.resend_order = RAACommitmentOrder::RevokeAndACKFirst;
52915291

5292-
let (counterparty_commitment_txid, mut htlcs_ref) = self.build_commitment_no_state_update(logger);
5292+
let (mut htlcs_ref, counterparty_commitment_tx) =
5293+
self.build_commitment_no_state_update(logger);
5294+
let counterparty_commitment_txid = counterparty_commitment_tx.trust().txid();
52935295
let htlcs: Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)> =
52945296
htlcs_ref.drain(..).map(|(htlc, htlc_source)| (htlc, htlc_source.map(|source_ref| Box::new(source_ref.clone())))).collect();
52955297

@@ -5304,17 +5306,23 @@ impl<SP: Deref> Channel<SP> where
53045306
commitment_txid: counterparty_commitment_txid,
53055307
htlc_outputs: htlcs.clone(),
53065308
commitment_number: self.context.cur_counterparty_commitment_transaction_number,
5307-
their_per_commitment_point: self.context.counterparty_cur_commitment_point.unwrap()
5309+
their_per_commitment_point: self.context.counterparty_cur_commitment_point.unwrap(),
5310+
feerate_per_kw: Some(counterparty_commitment_tx.feerate_per_kw()),
5311+
to_broadcaster_value_sat: Some(counterparty_commitment_tx.to_broadcaster_value_sat()),
5312+
to_countersignatory_value_sat: Some(counterparty_commitment_tx.to_countersignatory_value_sat()),
53085313
}]
53095314
};
53105315
self.context.channel_state |= ChannelState::AwaitingRemoteRevoke as u32;
53115316
monitor_update
53125317
}
53135318

5314-
fn build_commitment_no_state_update<L: Deref>(&self, logger: &L) -> (Txid, Vec<(HTLCOutputInCommitment, Option<&HTLCSource>)>) where L::Target: Logger {
5319+
fn build_commitment_no_state_update<L: Deref>(&self, logger: &L)
5320+
-> (Vec<(HTLCOutputInCommitment, Option<&HTLCSource>)>, CommitmentTransaction)
5321+
where L::Target: Logger
5322+
{
53155323
let counterparty_keys = self.context.build_remote_transaction_keys();
53165324
let commitment_stats = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, true, logger);
5317-
let counterparty_commitment_txid = commitment_stats.tx.trust().txid();
5325+
let counterparty_commitment_tx = commitment_stats.tx;
53185326

53195327
#[cfg(any(test, fuzzing))]
53205328
{
@@ -5334,7 +5342,7 @@ impl<SP: Deref> Channel<SP> where
53345342
}
53355343
}
53365344

5337-
(counterparty_commitment_txid, commitment_stats.htlcs_included)
5345+
(commitment_stats.htlcs_included, counterparty_commitment_tx)
53385346
}
53395347

53405348
/// Only fails in case of signer rejection. Used for channel_reestablish commitment_signed

0 commit comments

Comments
 (0)