Skip to content

Commit fe398d5

Browse files
committed
Store the original 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 original 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.
1 parent 56c2089 commit fe398d5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
875875
holder_revocation_basepoint: RevocationBasepoint,
876876
channel_id: ChannelId,
877877
funding_info: (OutPoint, ScriptBuf),
878+
original_funding_txo: OutPoint,
878879
current_counterparty_commitment_txid: Option<Txid>,
879880
prev_counterparty_commitment_txid: Option<Txid>,
880881

@@ -1236,6 +1237,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
12361237
(21, self.balances_empty_height, option),
12371238
(23, self.holder_pays_commitment_tx_fee, option),
12381239
(25, self.payment_preimages, required),
1240+
(27, self.original_funding_txo, required),
12391241
});
12401242

12411243
Ok(())
@@ -1388,6 +1390,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
13881390
let mut outputs_to_watch = new_hash_map();
13891391
outputs_to_watch.insert(funding_info.0.txid, vec![(funding_info.0.index as u32, funding_info.1.clone())]);
13901392

1393+
let original_funding_txo = funding_info.0;
1394+
13911395
Self::from_impl(ChannelMonitorImpl {
13921396
latest_update_id: 0,
13931397
commitment_transaction_number_obscure_factor,
@@ -1401,6 +1405,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
14011405
holder_revocation_basepoint,
14021406
channel_id,
14031407
funding_info,
1408+
original_funding_txo,
14041409
current_counterparty_commitment_txid: None,
14051410
prev_counterparty_commitment_txid: None,
14061411

@@ -4956,6 +4961,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
49564961
let mut channel_id = None;
49574962
let mut holder_pays_commitment_tx_fee = None;
49584963
let mut payment_preimages_with_info: Option<HashMap<_, _>> = None;
4964+
let mut original_funding_txo = RequiredWrapper(None);
49594965
read_tlv_fields!(reader, {
49604966
(1, funding_spend_confirmed, option),
49614967
(3, htlcs_resolved_on_chain, optional_vec),
@@ -4970,6 +4976,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
49704976
(21, balances_empty_height, option),
49714977
(23, holder_pays_commitment_tx_fee, option),
49724978
(25, payment_preimages_with_info, option),
4979+
(27, original_funding_txo, (default_value, funding_info.0)),
49734980
});
49744981
if let Some(payment_preimages_with_info) = payment_preimages_with_info {
49754982
if payment_preimages_with_info.len() != payment_preimages.len() {
@@ -5022,6 +5029,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
50225029
holder_revocation_basepoint,
50235030
channel_id: channel_id.unwrap_or(ChannelId::v1_from_funding_outpoint(outpoint)),
50245031
funding_info,
5032+
original_funding_txo: original_funding_txo.0.unwrap(),
50255033
current_counterparty_commitment_txid,
50265034
prev_counterparty_commitment_txid,
50275035

0 commit comments

Comments
 (0)