Skip to content

Commit 91f9b13

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 02ebbb5 commit 91f9b13

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

@@ -5033,6 +5038,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
50335038
let mut channel_id = None;
50345039
let mut holder_pays_commitment_tx_fee = None;
50355040
let mut payment_preimages_with_info: Option<HashMap<_, _>> = None;
5041+
let mut first_confirmed_funding_txo = RequiredWrapper(None);
50365042
read_tlv_fields!(reader, {
50375043
(1, funding_spend_confirmed, option),
50385044
(3, htlcs_resolved_on_chain, optional_vec),
@@ -5047,6 +5053,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
50475053
(21, balances_empty_height, option),
50485054
(23, holder_pays_commitment_tx_fee, option),
50495055
(25, payment_preimages_with_info, option),
5056+
(27, first_confirmed_funding_txo, (default_value, funding_info.0)),
50505057
});
50515058
if let Some(payment_preimages_with_info) = payment_preimages_with_info {
50525059
if payment_preimages_with_info.len() != payment_preimages.len() {
@@ -5099,6 +5106,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
50995106
holder_revocation_basepoint,
51005107
channel_id: channel_id.unwrap_or(ChannelId::v1_from_funding_outpoint(outpoint)),
51015108
funding_info,
5109+
first_confirmed_funding_txo: first_confirmed_funding_txo.0.unwrap(),
51025110
current_counterparty_commitment_txid,
51035111
prev_counterparty_commitment_txid,
51045112

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)