Skip to content

Commit d34f3b9

Browse files
committed
ln: add accountable signal to OutboundHTLCOutput
1 parent 4a64e98 commit d34f3b9

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

lightning/src/ln/channel.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use crate::ln::interactivetxs::{
6262
InteractiveTxSigningSession, NegotiationError, SharedOwnedInput, SharedOwnedOutput,
6363
TX_COMMON_FIELDS_WEIGHT,
6464
};
65-
use crate::ln::msgs;
65+
use crate::ln::msgs::{self, accountable_from_bool};
6666
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
6767
use crate::ln::onion_utils::{
6868
AttributionData, HTLCFailReason, LocalHTLCFailureReason, HOLD_TIME_UNIT_MILLIS,
@@ -444,6 +444,7 @@ struct OutboundHTLCOutput {
444444
skimmed_fee_msat: Option<u64>,
445445
send_timestamp: Option<Duration>,
446446
hold_htlc: Option<()>,
447+
accountable: bool,
447448
}
448449

449450
/// See AwaitingRemoteRevoke ChannelState for more info
@@ -9721,7 +9722,7 @@ where
97219722
skimmed_fee_msat: htlc.skimmed_fee_msat,
97229723
blinding_point: htlc.blinding_point,
97239724
hold_htlc: htlc.hold_htlc,
9724-
accountable: None,
9725+
accountable: accountable_from_bool(htlc.accountable),
97259726
});
97269727
}
97279728
}
@@ -12703,6 +12704,7 @@ where
1270312704
skimmed_fee_msat,
1270412705
send_timestamp,
1270512706
hold_htlc: hold_htlc.then(|| ()),
12707+
accountable,
1270612708
});
1270712709
self.context.next_holder_htlc_id += 1;
1270812710

@@ -14583,6 +14585,7 @@ where
1458314585
let mut pending_outbound_skimmed_fees: Vec<Option<u64>> = Vec::new();
1458414586
let mut pending_outbound_blinding_points: Vec<Option<PublicKey>> = Vec::new();
1458514587
let mut pending_outbound_held_htlc_flags: Vec<Option<()>> = Vec::new();
14588+
let mut pending_outbound_accountable: Vec<bool> = Vec::new();
1458614589

1458714590
(self.context.pending_outbound_htlcs.len() as u64).write(writer)?;
1458814591
for htlc in self.context.pending_outbound_htlcs.iter() {
@@ -14626,6 +14629,7 @@ where
1462614629
pending_outbound_skimmed_fees.push(htlc.skimmed_fee_msat);
1462714630
pending_outbound_blinding_points.push(htlc.blinding_point);
1462814631
pending_outbound_held_htlc_flags.push(htlc.hold_htlc);
14632+
pending_outbound_accountable.push(htlc.accountable);
1462914633
}
1463014634

1463114635
let holding_cell_htlc_update_count = self.context.holding_cell_htlc_updates.len();
@@ -14927,6 +14931,7 @@ where
1492714931
(71, holder_commitment_point_previous_revoked, option), // Added in 0.3
1492814932
(73, holder_commitment_point_last_revoked, option), // Added in 0.3
1492914933
(75, holding_cell_accountable_flags, optional_vec), // Added in 0.3
14934+
(77, pending_outbound_accountable, optional_vec), // Added in 0.3
1493014935
});
1493114936

1493214937
Ok(())
@@ -15094,6 +15099,7 @@ where
1509415099
blinding_point: None,
1509515100
send_timestamp: None,
1509615101
hold_htlc: None,
15102+
accountable: false,
1509715103
});
1509815104
}
1509915105

@@ -15316,6 +15322,7 @@ where
1531615322
let mut pending_outbound_held_htlc_flags_opt: Option<Vec<Option<()>>> = None;
1531715323
let mut holding_cell_held_htlc_flags_opt: Option<Vec<Option<()>>> = None;
1531815324
let mut holding_cell_accountable: Option<Vec<bool>> = None;
15325+
let mut pending_outbound_accountable: Option<Vec<bool>> = None;
1531915326

1532015327
read_tlv_fields!(reader, {
1532115328
(0, announcement_sigs, option),
@@ -15366,6 +15373,7 @@ where
1536615373
(71, holder_commitment_point_previous_revoked_opt, option), // Added in 0.3
1536715374
(73, holder_commitment_point_last_revoked_opt, option), // Added in 0.3
1536815375
(75, holding_cell_accountable, optional_vec), // Added in 0.3
15376+
(77, pending_outbound_accountable, optional_vec), // Added in 0.3
1536915377
});
1537015378

1537115379
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -15502,7 +15510,16 @@ where
1550215510
return Err(DecodeError::InvalidValue);
1550315511
}
1550415512
}
15505-
15513+
if let Some(accountable_htlcs) = pending_outbound_accountable {
15514+
let mut iter = accountable_htlcs.into_iter();
15515+
for htlc in pending_outbound_htlcs.iter_mut() {
15516+
htlc.accountable = iter.next().ok_or(DecodeError::InvalidValue)?;
15517+
}
15518+
// We expect all accountable HTLC signals to be consumed above
15519+
if iter.next().is_some() {
15520+
return Err(DecodeError::InvalidValue);
15521+
}
15522+
}
1550615523
if let Some(attribution_data_list) = removed_htlc_attribution_data {
1550715524
let mut removed_htlcs = pending_inbound_htlcs.iter_mut().filter_map(|status| {
1550815525
if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
@@ -16106,6 +16123,7 @@ mod tests {
1610616123
blinding_point: None,
1610716124
send_timestamp: None,
1610816125
hold_htlc: None,
16126+
accountable: false,
1610916127
});
1611016128

1611116129
// Make sure when Node A calculates their local commitment transaction, none of the HTLCs pass
@@ -16561,6 +16579,7 @@ mod tests {
1656116579
blinding_point: None,
1656216580
send_timestamp: None,
1656316581
hold_htlc: None,
16582+
accountable: false,
1656416583
};
1656516584
let mut pending_outbound_htlcs = vec![dummy_outbound_output.clone(); 10];
1656616585
for (idx, htlc) in pending_outbound_htlcs.iter_mut().enumerate() {
@@ -16959,6 +16978,7 @@ mod tests {
1695916978
blinding_point: None,
1696016979
send_timestamp: None,
1696116980
hold_htlc: None,
16981+
accountable: false,
1696216982
});
1696316983

1696416984
let payment_preimage_3 =
@@ -16974,6 +16994,7 @@ mod tests {
1697416994
blinding_point: None,
1697516995
send_timestamp: None,
1697616996
hold_htlc: None,
16997+
accountable: false,
1697716998
});
1697816999

1697917000
let payment_preimage_4 =
@@ -17389,6 +17410,7 @@ mod tests {
1738917410
blinding_point: None,
1739017411
send_timestamp: None,
1739117412
hold_htlc: None,
17413+
accountable: false,
1739217414
});
1739317415

1739417416
chan.context.pending_outbound_htlcs.push(OutboundHTLCOutput {
@@ -17402,6 +17424,7 @@ mod tests {
1740217424
blinding_point: None,
1740317425
send_timestamp: None,
1740417426
hold_htlc: None,
17427+
accountable: false,
1740517428
});
1740617429

1740717430
test_commitment!("304402207d0870964530f97b62497b11153c551dca0a1e226815ef0a336651158da0f82402200f5378beee0e77759147b8a0a284decd11bfd2bc55c8fafa41c134fe996d43c8",
@@ -17643,6 +17666,7 @@ mod tests {
1764317666
blinding_point: None,
1764417667
send_timestamp: None,
1764517668
hold_htlc: None,
17669+
accountable: false,
1764617670
}),
1764717671
);
1764817672

@@ -17706,6 +17730,7 @@ mod tests {
1770617730
blinding_point: None,
1770717731
send_timestamp: None,
1770817732
hold_htlc: None,
17733+
accountable: false,
1770917734
}),
1771017735
);
1771117736

@@ -17788,6 +17813,7 @@ mod tests {
1778817813
blinding_point: None,
1778917814
send_timestamp: None,
1779017815
hold_htlc: None,
17816+
accountable: false,
1779117817
}
1779217818
}),
1779317819
);
@@ -17844,6 +17870,7 @@ mod tests {
1784417870
blinding_point: None,
1784517871
send_timestamp: None,
1784617872
hold_htlc: None,
17873+
accountable: false,
1784717874
}),
1784817875
);
1784917876

@@ -17880,6 +17907,7 @@ mod tests {
1788017907
blinding_point: None,
1788117908
send_timestamp: None,
1788217909
hold_htlc: None,
17910+
accountable: false,
1788317911
},
1788417912
),
1788517913
);
@@ -17917,6 +17945,7 @@ mod tests {
1791717945
blinding_point: None,
1791817946
send_timestamp: None,
1791917947
hold_htlc: None,
17948+
accountable: false,
1792017949
},
1792117950
),
1792217951
);
@@ -17954,6 +17983,7 @@ mod tests {
1795417983
blinding_point: None,
1795517984
send_timestamp: None,
1795617985
hold_htlc: None,
17986+
accountable: false,
1795717987
},
1795817988
),
1795917989
);
@@ -18014,6 +18044,7 @@ mod tests {
1801418044
blinding_point: None,
1801518045
send_timestamp: None,
1801618046
hold_htlc: None,
18047+
accountable: false,
1801718048
}),
1801818049
);
1801918050

0 commit comments

Comments
 (0)