Skip to content

Commit 996756d

Browse files
committed
Add an inbound_payment_id_secret to ChannelManager
In the next commit we'll start generating `PaymentId`s for inbound payments randomly by HMAC'ing the HTLC set of the payment. Here we start by defining the HMAC secret for these HMACs. This requires one small test adaptation and a full_stack_target fuzz change because it changes the RNG consumption.
1 parent 114c02c commit 996756d

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

fuzz/src/full_stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
664664
// Adding new calls to `EntropySource::get_secure_random_bytes` during startup can change all the
665665
// keys subsequently generated in this test. Rather than regenerating all the messages manually,
666666
// it's easier to just increment the counter here so the keys don't change.
667-
keys_manager.counter.fetch_sub(3, Ordering::AcqRel);
667+
keys_manager.counter.fetch_sub(4, Ordering::AcqRel);
668668
let network_graph = Arc::new(NetworkGraph::new(network, Arc::clone(&logger)));
669669
let gossip_sync =
670670
Arc::new(P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger)));

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,9 @@ where
22052205
/// keeping additional state.
22062206
probing_cookie_secret: [u8; 32],
22072207

2208+
/// When generating [`PaymentId`]s for inbound payments, we HMAC the HTLCs with this secret.
2209+
inbound_payment_id_secret: [u8; 32],
2210+
22082211
/// The highest block timestamp we've seen, which is usually a good guess at the current time.
22092212
/// Assuming most miners are generating blocks with reasonable timestamps, this shouldn't be
22102213
/// very far in the past, and can only ever be up to two hours in the future.
@@ -3086,6 +3089,7 @@ where
30863089
fake_scid_rand_bytes: entropy_source.get_secure_random_bytes(),
30873090

30883091
probing_cookie_secret: entropy_source.get_secure_random_bytes(),
3092+
inbound_payment_id_secret: entropy_source.get_secure_random_bytes(),
30893093

30903094
highest_seen_timestamp: AtomicUsize::new(current_timestamp as usize),
30913095

@@ -12135,6 +12139,7 @@ where
1213512139
let mut events_override = None;
1213612140
let mut in_flight_monitor_updates: Option<HashMap<(PublicKey, OutPoint), Vec<ChannelMonitorUpdate>>> = None;
1213712141
let mut decode_update_add_htlcs: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>> = None;
12142+
let mut inbound_payment_id_secret = None;
1213812143
read_tlv_fields!(reader, {
1213912144
(1, pending_outbound_payments_no_retry, option),
1214012145
(2, pending_intercepted_htlcs, option),
@@ -12149,6 +12154,7 @@ where
1214912154
(11, probing_cookie_secret, option),
1215012155
(13, claimable_htlc_onion_fields, optional_vec),
1215112156
(14, decode_update_add_htlcs, option),
12157+
(15, inbound_payment_id_secret, option),
1215212158
});
1215312159
let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());
1215412160
if fake_scid_rand_bytes.is_none() {
@@ -12159,6 +12165,10 @@ where
1215912165
probing_cookie_secret = Some(args.entropy_source.get_secure_random_bytes());
1216012166
}
1216112167

12168+
if inbound_payment_id_secret.is_none() {
12169+
inbound_payment_id_secret = Some(args.entropy_source.get_secure_random_bytes());
12170+
}
12171+
1216212172
if let Some(events) = events_override {
1216312173
pending_events_read = events;
1216412174
}
@@ -12713,6 +12723,7 @@ where
1271312723
fake_scid_rand_bytes: fake_scid_rand_bytes.unwrap(),
1271412724

1271512725
probing_cookie_secret: probing_cookie_secret.unwrap(),
12726+
inbound_payment_id_secret: inbound_payment_id_secret.unwrap(),
1271612727

1271712728
our_network_pubkey,
1271812729
secp_ctx,

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7668,8 +7668,8 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
76687668
assert_ne!(node_txn[0].input[0].previous_output, node_txn[2].input[0].previous_output);
76697669
assert_ne!(node_txn[1].input[0].previous_output, node_txn[2].input[0].previous_output);
76707670

7671-
assert_eq!(node_txn[1].input[0].previous_output, revoked_htlc_txn[1].input[0].previous_output);
7672-
assert_eq!(node_txn[0].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output);
7671+
assert_eq!(node_txn[0].input[0].previous_output, revoked_htlc_txn[1].input[0].previous_output);
7672+
assert_eq!(node_txn[1].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output);
76737673

76747674
// node_txn[3] spends the revoked outputs from the revoked_htlc_txn (which only have one
76757675
// output, checked above).

0 commit comments

Comments
 (0)