Skip to content

Commit afed8ad

Browse files
committed
Save first confirmed funding txo in ChannelMonitor
Currently, when a ChannelMonitor is persisted, it's funding txo is used as the key. However, when a channel is spliced, there is a new funding txo. Store the first confirmed funding txo in ChannelMonitor such that the persistence does not change. This will be used for v1 channels for backward compatibility while v2 channels will use the channel ID, which for them is not derived from the funding txo. This prevents needing to migrate previously-persisted ChannelMonitors.
1 parent 321abba commit afed8ad

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
879879
holder_revocation_basepoint: RevocationBasepoint,
880880
channel_id: ChannelId,
881881
funding_info: (OutPoint, ScriptBuf),
882+
first_confirmed_funding_txo: OutPoint,
882883
current_counterparty_commitment_txid: Option<Txid>,
883884
prev_counterparty_commitment_txid: Option<Txid>,
884885

@@ -1246,6 +1247,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
12461247
(21, self.balances_empty_height, option),
12471248
(23, self.holder_pays_commitment_tx_fee, option),
12481249
(25, self.payment_preimages, required),
1250+
(27, self.first_confirmed_funding_txo, required),
12491251
});
12501252

12511253
Ok(())
@@ -1398,6 +1400,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
13981400
let mut outputs_to_watch = new_hash_map();
13991401
outputs_to_watch.insert(funding_info.0.txid, vec![(funding_info.0.index as u32, funding_info.1.clone())]);
14001402

1403+
let first_confirmed_funding_txo = funding_info.0;
1404+
14011405
Self::from_impl(ChannelMonitorImpl {
14021406
latest_update_id: 0,
14031407
commitment_transaction_number_obscure_factor,
@@ -1411,6 +1415,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
14111415
holder_revocation_basepoint,
14121416
channel_id,
14131417
funding_info,
1418+
first_confirmed_funding_txo,
14141419
current_counterparty_commitment_txid: None,
14151420
prev_counterparty_commitment_txid: None,
14161421

@@ -5042,6 +5047,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
50425047
let mut channel_id = None;
50435048
let mut holder_pays_commitment_tx_fee = None;
50445049
let mut payment_preimages_with_info: Option<HashMap<_, _>> = None;
5050+
let mut first_confirmed_funding_txo = RequiredWrapper(None);
50455051
read_tlv_fields!(reader, {
50465052
(1, funding_spend_confirmed, option),
50475053
(3, htlcs_resolved_on_chain, optional_vec),
@@ -5056,6 +5062,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
50565062
(21, balances_empty_height, option),
50575063
(23, holder_pays_commitment_tx_fee, option),
50585064
(25, payment_preimages_with_info, option),
5065+
(27, first_confirmed_funding_txo, (default_value, funding_info.0)),
50595066
});
50605067
if let Some(payment_preimages_with_info) = payment_preimages_with_info {
50615068
if payment_preimages_with_info.len() != payment_preimages.len() {
@@ -5108,6 +5115,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
51085115
holder_revocation_basepoint,
51095116
channel_id: channel_id.unwrap_or(ChannelId::v1_from_funding_outpoint(outpoint)),
51105117
funding_info,
5118+
first_confirmed_funding_txo: first_confirmed_funding_txo.0.unwrap(),
51115119
current_counterparty_commitment_txid,
51125120
prev_counterparty_commitment_txid,
51135121

lightning/src/ln/channel.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,8 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
19651965
let shutdown_script = context.shutdown_scriptpubkey.clone().map(|script| script.into_inner());
19661966
let mut monitor_signer = signer_provider.derive_channel_signer(context.channel_value_satoshis, context.channel_keys_id);
19671967
monitor_signer.provide_channel_parameters(&context.channel_transaction_parameters);
1968+
// TODO(RBF): When implementing RBF, the funding_txo passed here must only update
1969+
// ChannelMonitorImp::first_confirmed_funding_txo during channel establishment, not splicing
19681970
let channel_monitor = ChannelMonitor::new(context.secp_ctx.clone(), monitor_signer,
19691971
shutdown_script, context.get_holder_selected_contest_delay(),
19701972
&context.destination_script, (funding_txo, funding_txo_script),

0 commit comments

Comments
 (0)