@@ -2989,15 +2989,6 @@ struct PendingFunding {
29892989 contributions: Vec<FundingContribution>,
29902990}
29912991
2992- impl_ser_tlv_based!(PendingFunding, {
2993- (1, funding_negotiation, upgradable_option),
2994- (3, negotiated_candidates, required_vec),
2995- (5, sent_funding_txid, option),
2996- (7, received_funding_txid, option),
2997- (8, last_funding_feerate_sat_per_1000_weight, option),
2998- (10, contributions, optional_vec),
2999- });
3000-
30012992#[derive(Debug)]
30022993enum FundingNegotiation {
30032994 AwaitingAck {
@@ -3037,6 +3028,57 @@ impl_writeable_tlv_based_enum_upgradable!(FundingNegotiation,
30373028 unread_variants: AwaitingAck, ConstructingTransaction
30383029);
30393030
3031+ struct PendingFundingWriteable<'a> {
3032+ pending_funding: &'a PendingFunding,
3033+ reset_funding_negotiation: bool,
3034+ }
3035+
3036+ impl Writeable for PendingFundingWriteable<'_> {
3037+ fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
3038+ let funding_negotiation = if self.reset_funding_negotiation {
3039+ None
3040+ } else {
3041+ self.pending_funding.funding_negotiation.as_ref()
3042+ };
3043+ debug_assert!(
3044+ funding_negotiation.is_none()
3045+ || matches!(
3046+ funding_negotiation,
3047+ Some(FundingNegotiation::AwaitingSignatures { .. })
3048+ )
3049+ );
3050+ let contributions_len = if self.reset_funding_negotiation
3051+ && self.pending_funding.funding_negotiation.is_some()
3052+ {
3053+ self.pending_funding.contributions.len().saturating_sub(1)
3054+ } else {
3055+ self.pending_funding.contributions.len()
3056+ };
3057+ write_tlv_fields!(writer, {
3058+ (1, funding_negotiation, upgradable_option),
3059+ (3, self.pending_funding.negotiated_candidates, required_vec),
3060+ (5, self.pending_funding.sent_funding_txid, option),
3061+ (7, self.pending_funding.received_funding_txid, option),
3062+ (8, self.pending_funding.last_funding_feerate_sat_per_1000_weight, option),
3063+ (10, self.pending_funding.contributions[..contributions_len], optional_vec),
3064+ });
3065+ Ok(())
3066+ }
3067+ }
3068+
3069+ impl Readable for PendingFunding {
3070+ fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
3071+ Ok(_decode_and_build!(reader, Self, {
3072+ (1, funding_negotiation, upgradable_option),
3073+ (3, negotiated_candidates, required_vec),
3074+ (5, sent_funding_txid, option),
3075+ (7, received_funding_txid, option),
3076+ (8, last_funding_feerate_sat_per_1000_weight, option),
3077+ (10, contributions, optional_vec),
3078+ }))
3079+ }
3080+ }
3081+
30403082impl FundingNegotiation {
30413083 fn as_funding(&self) -> Option<&FundingScope> {
30423084 match self {
@@ -16305,10 +16347,18 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> {
1630516347 let holder_commitment_point_next = self.holder_commitment_point.next_point();
1630616348 let holder_commitment_point_pending_next = self.holder_commitment_point.pending_next_point;
1630716349
16308- // We don't have to worry about resetting the pending `FundingNegotiation` because we
16309- // can only read `FundingNegotiation::AwaitingSignatures` variants anyway.
16310- let pending_splice =
16311- self.pending_splice.as_ref().filter(|_| !self.should_reset_pending_splice_state(true));
16350+ // Avoid writing any negotiations that are not at the signing stage yet, as they cannot be
16351+ // resumed on reestablishment, but keep any already-negotiated candidates.
16352+ let reset_funding_negotiation = self.should_reset_pending_splice_state(true);
16353+ let should_persist_pending_splice =
16354+ !reset_funding_negotiation || !self.pending_funding().is_empty();
16355+ let pending_splice = should_persist_pending_splice
16356+ .then(|| ())
16357+ .and_then(|_| self.pending_splice.as_ref())
16358+ .map(|pending_funding| PendingFundingWriteable {
16359+ pending_funding,
16360+ reset_funding_negotiation,
16361+ });
1631216362
1631316363 let monitor_pending_tx_signatures =
1631416364 self.context.monitor_pending_tx_signatures.then_some(());
0 commit comments