Skip to content

Commit aa09c33

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 803366a commit aa09c33

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

fuzz/src/full_stack.rs

+1-1
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

+11
Original file line numberDiff line numberDiff line change
@@ -2261,6 +2261,9 @@ where
22612261
/// keeping additional state.
22622262
probing_cookie_secret: [u8; 32],
22632263

2264+
/// When generating [`PaymentId`]s for inbound payments, we HMAC the HTLCs with this secret.
2265+
inbound_payment_id_secret: [u8; 32],
2266+
22642267
/// The highest block timestamp we've seen, which is usually a good guess at the current time.
22652268
/// Assuming most miners are generating blocks with reasonable timestamps, this shouldn't be
22662269
/// very far in the past, and can only ever be up to two hours in the future.
@@ -3152,6 +3155,7 @@ where
31523155
fake_scid_rand_bytes: entropy_source.get_secure_random_bytes(),
31533156

31543157
probing_cookie_secret: entropy_source.get_secure_random_bytes(),
3158+
inbound_payment_id_secret: entropy_source.get_secure_random_bytes(),
31553159

31563160
highest_seen_timestamp: AtomicUsize::new(current_timestamp as usize),
31573161

@@ -12381,6 +12385,7 @@ where
1238112385
let mut events_override = None;
1238212386
let mut in_flight_monitor_updates: Option<HashMap<(PublicKey, OutPoint), Vec<ChannelMonitorUpdate>>> = None;
1238312387
let mut decode_update_add_htlcs: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>> = None;
12388+
let mut inbound_payment_id_secret = None;
1238412389
read_tlv_fields!(reader, {
1238512390
(1, pending_outbound_payments_no_retry, option),
1238612391
(2, pending_intercepted_htlcs, option),
@@ -12395,6 +12400,7 @@ where
1239512400
(11, probing_cookie_secret, option),
1239612401
(13, claimable_htlc_onion_fields, optional_vec),
1239712402
(14, decode_update_add_htlcs, option),
12403+
(15, inbound_payment_id_secret, option),
1239812404
});
1239912405
let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());
1240012406
if fake_scid_rand_bytes.is_none() {
@@ -12405,6 +12411,10 @@ where
1240512411
probing_cookie_secret = Some(args.entropy_source.get_secure_random_bytes());
1240612412
}
1240712413

12414+
if inbound_payment_id_secret.is_none() {
12415+
inbound_payment_id_secret = Some(args.entropy_source.get_secure_random_bytes());
12416+
}
12417+
1240812418
if let Some(events) = events_override {
1240912419
pending_events_read = events;
1241012420
}
@@ -12930,6 +12940,7 @@ where
1293012940
fake_scid_rand_bytes: fake_scid_rand_bytes.unwrap(),
1293112941

1293212942
probing_cookie_secret: probing_cookie_secret.unwrap(),
12943+
inbound_payment_id_secret: inbound_payment_id_secret.unwrap(),
1293312944

1293412945
our_network_pubkey,
1293512946
secp_ctx,

lightning/src/ln/functional_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7670,8 +7670,8 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
76707670
assert_ne!(node_txn[0].input[0].previous_output, node_txn[2].input[0].previous_output);
76717671
assert_ne!(node_txn[1].input[0].previous_output, node_txn[2].input[0].previous_output);
76727672

7673-
assert_eq!(node_txn[1].input[0].previous_output, revoked_htlc_txn[1].input[0].previous_output);
7674-
assert_eq!(node_txn[0].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output);
7673+
assert_eq!(node_txn[0].input[0].previous_output, revoked_htlc_txn[1].input[0].previous_output);
7674+
assert_eq!(node_txn[1].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output);
76757675

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

0 commit comments

Comments
 (0)