Skip to content

Commit 754eb5f

Browse files
committed
f Set channel_id after the fact
1 parent 05b61e0 commit 754eb5f

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6618,7 +6618,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
66186618
return Err(DecodeError::InvalidValue);
66196619
}
66206620
}
6621-
let onchain_tx_handler: OnchainTxHandler<SP::EcdsaSigner> = ReadableArgs::read(
6621+
let mut onchain_tx_handler: OnchainTxHandler<SP::EcdsaSigner> = ReadableArgs::read(
66226622
reader, (entropy_source, signer_provider, channel_value_satoshis, channel_keys_id)
66236623
)?;
66246624

@@ -6714,6 +6714,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
67146714
}
67156715

67166716
let channel_id = channel_id.unwrap_or(ChannelId::v1_from_funding_outpoint(outpoint));
6717+
onchain_tx_handler.set_channel_id(channel_id);
67176718

67186719
let (current_holder_commitment_tx, current_holder_htlc_data) = {
67196720
let holder_commitment_tx = onchain_tx_handler.current_holder_commitment_tx();

lightning/src/chain/onchaintx.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,17 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
348348
entry.write(writer)?;
349349
}
350350

351-
write_tlv_fields!(writer, {
352-
(1, self.channel_id, required),
353-
});
351+
write_tlv_fields!(writer, {});
354352
Ok(())
355353
}
354+
355+
// `ChannelMonitor`s already track the `channel_id`, however, due to the derserialization order
356+
// there we can't make use of `ReadableArgs` to hand it into `OnchainTxHandler`'s
357+
// deserialization logic directly. Instead we opt to initialize it with 0s and override it
358+
// after reading the respective field via this method.
359+
pub(crate) fn set_channel_id(&mut self, channel_id: ChannelId) {
360+
self.channel_id = channel_id;
361+
}
356362
}
357363

358364
impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP, u64, [u8; 32])>
@@ -426,18 +432,13 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
426432
}
427433
}
428434

429-
let mut channel_id = None;
430-
read_tlv_fields!(reader, {
431-
(1, channel_id, option),
432-
});
435+
read_tlv_fields!(reader, {});
433436

434-
// For backwards compatibility with monitors serialized before channel_id was added,
435-
// we derive a channel_id from the funding outpoint if not present.
436-
let channel_id = channel_id.or_else(|| {
437-
channel_parameters.funding_outpoint
438-
.map(|op| ChannelId::v1_from_funding_outpoint(op))
439-
}) // funding_outpoint must be known during intialization.
440-
.ok_or(DecodeError::InvalidValue)?;
437+
// `ChannelMonitor`s already track the `channel_id`, however, due to the derserialization
438+
// order there we can't make use of `ReadableArgs` to hand it in directly. Instead we opt
439+
// to initialize it with 0s and override it after reading the respective field via
440+
// `OnchainTxHandler::set_channel_id`.
441+
let channel_id = ChannelId([0u8; 32]);
441442

442443
let mut secp_ctx = Secp256k1::new();
443444
secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());

0 commit comments

Comments
 (0)