Skip to content

Commit 7014391

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 65530ad commit 7014391

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
@@ -2239,6 +2239,9 @@ where
22392239
/// keeping additional state.
22402240
probing_cookie_secret: [u8; 32],
22412241

2242+
/// When generating [`PaymentId`]s for inbound payments, we HMAC the HTLCs with this secret.
2243+
inbound_payment_id_secret: [u8; 32],
2244+
22422245
/// The highest block timestamp we've seen, which is usually a good guess at the current time.
22432246
/// Assuming most miners are generating blocks with reasonable timestamps, this shouldn't be
22442247
/// very far in the past, and can only ever be up to two hours in the future.
@@ -3120,6 +3123,7 @@ where
31203123
fake_scid_rand_bytes: entropy_source.get_secure_random_bytes(),
31213124

31223125
probing_cookie_secret: entropy_source.get_secure_random_bytes(),
3126+
inbound_payment_id_secret: entropy_source.get_secure_random_bytes(),
31233127

31243128
highest_seen_timestamp: AtomicUsize::new(current_timestamp as usize),
31253129

@@ -12232,6 +12236,7 @@ where
1223212236
let mut events_override = None;
1223312237
let mut in_flight_monitor_updates: Option<HashMap<(PublicKey, OutPoint), Vec<ChannelMonitorUpdate>>> = None;
1223412238
let mut decode_update_add_htlcs: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>> = None;
12239+
let mut inbound_payment_id_secret = None;
1223512240
read_tlv_fields!(reader, {
1223612241
(1, pending_outbound_payments_no_retry, option),
1223712242
(2, pending_intercepted_htlcs, option),
@@ -12246,6 +12251,7 @@ where
1224612251
(11, probing_cookie_secret, option),
1224712252
(13, claimable_htlc_onion_fields, optional_vec),
1224812253
(14, decode_update_add_htlcs, option),
12254+
(15, inbound_payment_id_secret, option),
1224912255
});
1225012256
let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());
1225112257
if fake_scid_rand_bytes.is_none() {
@@ -12256,6 +12262,10 @@ where
1225612262
probing_cookie_secret = Some(args.entropy_source.get_secure_random_bytes());
1225712263
}
1225812264

12265+
if inbound_payment_id_secret.is_none() {
12266+
inbound_payment_id_secret = Some(args.entropy_source.get_secure_random_bytes());
12267+
}
12268+
1225912269
if let Some(events) = events_override {
1226012270
pending_events_read = events;
1226112271
}
@@ -12807,6 +12817,7 @@ where
1280712817
fake_scid_rand_bytes: fake_scid_rand_bytes.unwrap(),
1280812818

1280912819
probing_cookie_secret: probing_cookie_secret.unwrap(),
12820+
inbound_payment_id_secret: inbound_payment_id_secret.unwrap(),
1281012821

1281112822
our_network_pubkey,
1281212823
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)