Skip to content

Commit 961f225

Browse files
committed
Rename payment_basepoint/key to simply payment_point/key.
We no longer derive any keys from the payment point, so they aren't a "base" but simply a point/key.
1 parent ab3d2fd commit 961f225

7 files changed

+57
-56
lines changed

lightning/src/chain/keysinterface.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@ pub trait ChannelKeys : Send+Clone {
195195
fn funding_key<'a>(&'a self) -> &'a SecretKey;
196196
/// Gets the local secret key for blinded revocation pubkey
197197
fn revocation_base_key<'a>(&'a self) -> &'a SecretKey;
198-
/// Gets the local secret key used in to_remote output of remote commitment tx
199-
/// (and also as part of obscured commitment number)
200-
fn payment_base_key<'a>(&'a self) -> &'a SecretKey;
198+
/// Gets the local secret key used in the to_remote output of remote commitment tx (ie the
199+
/// output to us in transactions our counterparty broadcasts).
200+
/// Also as part of obscured commitment number.
201+
fn payment_key<'a>(&'a self) -> &'a SecretKey;
201202
/// Gets the local secret key used in HTLC-Success/HTLC-Timeout txn and to_local output
202203
fn delayed_payment_base_key<'a>(&'a self) -> &'a SecretKey;
203204
/// Gets the local htlc secret key used in commitment tx htlc outputs
@@ -244,8 +245,8 @@ pub struct InMemoryChannelKeys {
244245
funding_key: SecretKey,
245246
/// Local secret key for blinded revocation pubkey
246247
revocation_base_key: SecretKey,
247-
/// Local secret key used in commitment tx htlc outputs
248-
payment_base_key: SecretKey,
248+
/// Local secret key used in commitment txn generated by us (for broadcast by our counterparty)
249+
payment_key: SecretKey,
249250
/// Local secret key used in HTLC tx
250251
delayed_payment_base_key: SecretKey,
251252
/// Local htlc secret key used in commitment tx htlc outputs
@@ -266,19 +267,19 @@ impl InMemoryChannelKeys {
266267
secp_ctx: &Secp256k1<C>,
267268
funding_key: SecretKey,
268269
revocation_base_key: SecretKey,
269-
payment_base_key: SecretKey,
270+
payment_key: SecretKey,
270271
delayed_payment_base_key: SecretKey,
271272
htlc_base_key: SecretKey,
272273
commitment_seed: [u8; 32],
273274
channel_value_satoshis: u64) -> InMemoryChannelKeys {
274275
let local_channel_pubkeys =
275276
InMemoryChannelKeys::make_local_keys(secp_ctx, &funding_key, &revocation_base_key,
276-
&payment_base_key, &delayed_payment_base_key,
277+
&payment_key, &delayed_payment_base_key,
277278
&htlc_base_key);
278279
InMemoryChannelKeys {
279280
funding_key,
280281
revocation_base_key,
281-
payment_base_key,
282+
payment_key,
282283
delayed_payment_base_key,
283284
htlc_base_key,
284285
commitment_seed,
@@ -291,14 +292,14 @@ impl InMemoryChannelKeys {
291292
fn make_local_keys<C: Signing>(secp_ctx: &Secp256k1<C>,
292293
funding_key: &SecretKey,
293294
revocation_base_key: &SecretKey,
294-
payment_base_key: &SecretKey,
295+
payment_key: &SecretKey,
295296
delayed_payment_base_key: &SecretKey,
296297
htlc_base_key: &SecretKey) -> ChannelPublicKeys {
297298
let from_secret = |s: &SecretKey| PublicKey::from_secret_key(secp_ctx, s);
298299
ChannelPublicKeys {
299300
funding_pubkey: from_secret(&funding_key),
300301
revocation_basepoint: from_secret(&revocation_base_key),
301-
payment_basepoint: from_secret(&payment_base_key),
302+
payment_point: from_secret(&payment_key),
302303
delayed_payment_basepoint: from_secret(&delayed_payment_base_key),
303304
htlc_basepoint: from_secret(&htlc_base_key),
304305
}
@@ -308,7 +309,7 @@ impl InMemoryChannelKeys {
308309
impl ChannelKeys for InMemoryChannelKeys {
309310
fn funding_key(&self) -> &SecretKey { &self.funding_key }
310311
fn revocation_base_key(&self) -> &SecretKey { &self.revocation_base_key }
311-
fn payment_base_key(&self) -> &SecretKey { &self.payment_base_key }
312+
fn payment_key(&self) -> &SecretKey { &self.payment_key }
312313
fn delayed_payment_base_key(&self) -> &SecretKey { &self.delayed_payment_base_key }
313314
fn htlc_base_key(&self) -> &SecretKey { &self.htlc_base_key }
314315
fn commitment_seed(&self) -> &[u8; 32] { &self.commitment_seed }
@@ -372,7 +373,7 @@ impl Writeable for InMemoryChannelKeys {
372373
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
373374
self.funding_key.write(writer)?;
374375
self.revocation_base_key.write(writer)?;
375-
self.payment_base_key.write(writer)?;
376+
self.payment_key.write(writer)?;
376377
self.delayed_payment_base_key.write(writer)?;
377378
self.htlc_base_key.write(writer)?;
378379
self.commitment_seed.write(writer)?;
@@ -387,7 +388,7 @@ impl Readable for InMemoryChannelKeys {
387388
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
388389
let funding_key = Readable::read(reader)?;
389390
let revocation_base_key = Readable::read(reader)?;
390-
let payment_base_key = Readable::read(reader)?;
391+
let payment_key = Readable::read(reader)?;
391392
let delayed_payment_base_key = Readable::read(reader)?;
392393
let htlc_base_key = Readable::read(reader)?;
393394
let commitment_seed = Readable::read(reader)?;
@@ -396,13 +397,13 @@ impl Readable for InMemoryChannelKeys {
396397
let secp_ctx = Secp256k1::signing_only();
397398
let local_channel_pubkeys =
398399
InMemoryChannelKeys::make_local_keys(&secp_ctx, &funding_key, &revocation_base_key,
399-
&payment_base_key, &delayed_payment_base_key,
400+
&payment_key, &delayed_payment_base_key,
400401
&htlc_base_key);
401402

402403
Ok(InMemoryChannelKeys {
403404
funding_key,
404405
revocation_base_key,
405-
payment_base_key,
406+
payment_key,
406407
delayed_payment_base_key,
407408
htlc_base_key,
408409
commitment_seed,
@@ -548,15 +549,15 @@ impl KeysInterface for KeysManager {
548549
}
549550
let funding_key = key_step!(b"funding key", commitment_seed);
550551
let revocation_base_key = key_step!(b"revocation base key", funding_key);
551-
let payment_base_key = key_step!(b"payment base key", revocation_base_key);
552-
let delayed_payment_base_key = key_step!(b"delayed payment base key", payment_base_key);
552+
let payment_key = key_step!(b"payment base key", revocation_base_key);
553+
let delayed_payment_base_key = key_step!(b"delayed payment base key", payment_key);
553554
let htlc_base_key = key_step!(b"HTLC base key", delayed_payment_base_key);
554555

555556
InMemoryChannelKeys::new(
556557
&self.secp_ctx,
557558
funding_key,
558559
revocation_base_key,
559-
payment_base_key,
560+
payment_key,
560561
delayed_payment_base_key,
561562
htlc_base_key,
562563
commitment_seed,

lightning/src/ln/chan_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub struct ChannelPublicKeys {
276276
pub revocation_basepoint: PublicKey,
277277
/// The base point which is used (with derive_public_key) to derive a per-commitment payment
278278
/// public key which receives immediately-spendable non-HTLC-encumbered funds.
279-
pub payment_basepoint: PublicKey,
279+
pub payment_point: PublicKey,
280280
/// The base point which is used (with derive_public_key) to derive a per-commitment payment
281281
/// public key which receives non-HTLC-encumbered funds which are only available for spending
282282
/// after some delay (or can be claimed via the revocation path).
@@ -289,7 +289,7 @@ pub struct ChannelPublicKeys {
289289
impl_writeable!(ChannelPublicKeys, 33*5, {
290290
funding_pubkey,
291291
revocation_basepoint,
292-
payment_basepoint,
292+
payment_point,
293293
delayed_payment_basepoint,
294294
htlc_basepoint
295295
});

lightning/src/ln/channel.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
561561
let their_pubkeys = ChannelPublicKeys {
562562
funding_pubkey: msg.funding_pubkey,
563563
revocation_basepoint: msg.revocation_basepoint,
564-
payment_basepoint: msg.payment_basepoint,
564+
payment_point: msg.payment_point,
565565
delayed_payment_basepoint: msg.delayed_payment_basepoint,
566566
htlc_basepoint: msg.htlc_basepoint
567567
};
@@ -777,15 +777,15 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
777777

778778
fn get_commitment_transaction_number_obscure_factor(&self) -> u64 {
779779
let mut sha = Sha256::engine();
780-
let our_payment_basepoint = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_base_key());
780+
let our_payment_point = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key());
781781

782-
let their_payment_basepoint = &self.their_pubkeys.as_ref().unwrap().payment_basepoint.serialize();
782+
let their_payment_point = &self.their_pubkeys.as_ref().unwrap().payment_point.serialize();
783783
if self.channel_outbound {
784-
sha.input(&our_payment_basepoint.serialize());
785-
sha.input(their_payment_basepoint);
784+
sha.input(&our_payment_point.serialize());
785+
sha.input(their_payment_point);
786786
} else {
787-
sha.input(their_payment_basepoint);
788-
sha.input(&our_payment_basepoint.serialize());
787+
sha.input(their_payment_point);
788+
sha.input(&our_payment_point.serialize());
789789
}
790790
let res = Sha256::from_engine(sha).into_inner();
791791

@@ -985,8 +985,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
985985
txouts.push((TxOut {
986986
script_pubkey: Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
987987
.push_slice(&Hash160::hash(&if local {
988-
self.their_pubkeys.as_ref().unwrap().payment_basepoint
989-
} else { self.local_keys.pubkeys().payment_basepoint }.serialize())[..])
988+
self.their_pubkeys.as_ref().unwrap().payment_point
989+
} else { self.local_keys.pubkeys().payment_point }.serialize())[..])
990990
.into_script(),
991991
value: value_to_b as u64
992992
}, None));
@@ -1422,7 +1422,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
14221422
let their_pubkeys = ChannelPublicKeys {
14231423
funding_pubkey: msg.funding_pubkey,
14241424
revocation_basepoint: msg.revocation_basepoint,
1425-
payment_basepoint: msg.payment_basepoint,
1425+
payment_point: msg.payment_point,
14261426
delayed_payment_basepoint: msg.delayed_payment_basepoint,
14271427
htlc_basepoint: msg.htlc_basepoint
14281428
};
@@ -3278,7 +3278,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
32783278
max_accepted_htlcs: OUR_MAX_HTLCS,
32793279
funding_pubkey: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()),
32803280
revocation_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.revocation_base_key()),
3281-
payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_base_key()),
3281+
payment_point: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key()),
32823282
delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.delayed_payment_base_key()),
32833283
htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.htlc_base_key()),
32843284
first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret),
@@ -3311,7 +3311,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
33113311
max_accepted_htlcs: OUR_MAX_HTLCS,
33123312
funding_pubkey: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()),
33133313
revocation_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.revocation_base_key()),
3314-
payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_base_key()),
3314+
payment_point: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key()),
33153315
delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.delayed_payment_base_key()),
33163316
htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.htlc_base_key()),
33173317
first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret),
@@ -4362,12 +4362,12 @@ mod tests {
43624362
let their_pubkeys = ChannelPublicKeys {
43634363
funding_pubkey: public_from_secret_hex(&secp_ctx, "1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13"),
43644364
revocation_basepoint: PublicKey::from_slice(&hex::decode("02466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f27").unwrap()[..]).unwrap(),
4365-
payment_basepoint: public_from_secret_hex(&secp_ctx, "4444444444444444444444444444444444444444444444444444444444444444"),
4365+
payment_point: public_from_secret_hex(&secp_ctx, "4444444444444444444444444444444444444444444444444444444444444444"),
43664366
delayed_payment_basepoint: public_from_secret_hex(&secp_ctx, "1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13"),
43674367
htlc_basepoint: public_from_secret_hex(&secp_ctx, "4444444444444444444444444444444444444444444444444444444444444444")
43684368
};
43694369

4370-
assert_eq!(their_pubkeys.payment_basepoint.serialize()[..],
4370+
assert_eq!(their_pubkeys.payment_point.serialize()[..],
43714371
hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]);
43724372

43734373
assert_eq!(their_pubkeys.funding_pubkey.serialize()[..],

lightning/src/ln/channelmonitor.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ enum Storage<ChanSigner: ChannelKeys> {
396396
revocation_base_key: SecretKey,
397397
htlc_base_key: SecretKey,
398398
delayed_payment_base_key: SecretKey,
399-
payment_base_key: SecretKey,
399+
payment_key: SecretKey,
400400
shutdown_pubkey: PublicKey,
401401
funding_info: Option<(OutPoint, Script)>,
402402
current_remote_commitment_txid: Option<Sha256dHash>,
@@ -836,14 +836,14 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
836836
U48(self.commitment_transaction_number_obscure_factor).write(writer)?;
837837

838838
match self.key_storage {
839-
Storage::Local { ref keys, ref funding_key, ref revocation_base_key, ref htlc_base_key, ref delayed_payment_base_key, ref payment_base_key, ref shutdown_pubkey, ref funding_info, ref current_remote_commitment_txid, ref prev_remote_commitment_txid } => {
839+
Storage::Local { ref keys, ref funding_key, ref revocation_base_key, ref htlc_base_key, ref delayed_payment_base_key, ref payment_key, ref shutdown_pubkey, ref funding_info, ref current_remote_commitment_txid, ref prev_remote_commitment_txid } => {
840840
writer.write_all(&[0; 1])?;
841841
keys.write(writer)?;
842842
writer.write_all(&funding_key[..])?;
843843
writer.write_all(&revocation_base_key[..])?;
844844
writer.write_all(&htlc_base_key[..])?;
845845
writer.write_all(&delayed_payment_base_key[..])?;
846-
writer.write_all(&payment_base_key[..])?;
846+
writer.write_all(&payment_key[..])?;
847847
writer.write_all(&shutdown_pubkey.serialize())?;
848848
match funding_info {
849849
&Some((ref outpoint, ref script)) => {
@@ -1054,7 +1054,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
10541054
let revocation_base_key = keys.revocation_base_key().clone();
10551055
let htlc_base_key = keys.htlc_base_key().clone();
10561056
let delayed_payment_base_key = keys.delayed_payment_base_key().clone();
1057-
let payment_base_key = keys.payment_base_key().clone();
1057+
let payment_key = keys.payment_key().clone();
10581058
ChannelMonitor {
10591059
latest_update_id: 0,
10601060
commitment_transaction_number_obscure_factor,
@@ -1065,7 +1065,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
10651065
revocation_base_key,
10661066
htlc_base_key,
10671067
delayed_payment_base_key,
1068-
payment_base_key,
1068+
payment_key,
10691069
shutdown_pubkey: shutdown_pubkey.clone(),
10701070
funding_info: Some(funding_info),
10711071
current_remote_commitment_txid: None,
@@ -1382,12 +1382,12 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13821382
let secret = self.get_secret(commitment_number).unwrap();
13831383
let per_commitment_key = ignore_error!(SecretKey::from_slice(&secret));
13841384
let (revocation_pubkey, revocation_key, b_htlc_key, local_payment_key) = match self.key_storage {
1385-
Storage::Local { ref keys, ref revocation_base_key, ref payment_base_key, .. } => {
1385+
Storage::Local { ref keys, ref revocation_base_key, ref payment_key, .. } => {
13861386
let per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key);
13871387
(ignore_error!(chan_utils::derive_public_revocation_key(&self.secp_ctx, &per_commitment_point, &keys.pubkeys().revocation_basepoint)),
13881388
ignore_error!(chan_utils::derive_private_revocation_key(&self.secp_ctx, &per_commitment_key, &revocation_base_key)),
13891389
ignore_error!(chan_utils::derive_public_key(&self.secp_ctx, &per_commitment_point, &keys.pubkeys().htlc_basepoint)),
1390-
Some(payment_base_key))
1390+
Some(payment_key))
13911391
},
13921392
Storage::Watchtower { .. } => {
13931393
unimplemented!()
@@ -1570,10 +1570,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
15701570
for (idx, outp) in tx.output.iter().enumerate() {
15711571
if outp.script_pubkey.is_v0_p2wpkh() {
15721572
match self.key_storage {
1573-
Storage::Local { ref payment_base_key, .. } => {
1573+
Storage::Local { ref payment_key, .. } => {
15741574
spendable_outputs.push(SpendableOutputDescriptor::DynamicOutputP2WPKH {
15751575
outpoint: BitcoinOutPoint { txid: commitment_txid, vout: idx as u32 },
1576-
key: payment_base_key.clone(),
1576+
key: payment_key.clone(),
15771577
output: outp.clone(),
15781578
});
15791579
},
@@ -1604,16 +1604,16 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
16041604
}
16051605
} else {
16061606
match self.key_storage {
1607-
Storage::Local { ref payment_base_key, .. } => {
1608-
let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &payment_base_key).serialize());
1607+
Storage::Local { ref payment_key, .. } => {
1608+
let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &payment_key).serialize());
16091609
let our_payment_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
16101610
.push_slice(&payment_hash160)
16111611
.into_script();
16121612
for (idx, outp) in tx.output.iter().enumerate() {
16131613
if our_payment_script == outp.script_pubkey {
16141614
spendable_outputs.push(SpendableOutputDescriptor::DynamicOutputP2WPKH {
16151615
outpoint: BitcoinOutPoint { txid: commitment_txid, vout: idx as u32 },
1616-
key: payment_base_key.clone(),
1616+
key: payment_key.clone(),
16171617
output: outp.clone(),
16181618
});
16191619
}
@@ -2300,7 +2300,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
23002300
let revocation_base_key = Readable::read(reader)?;
23012301
let htlc_base_key = Readable::read(reader)?;
23022302
let delayed_payment_base_key = Readable::read(reader)?;
2303-
let payment_base_key = Readable::read(reader)?;
2303+
let payment_key = Readable::read(reader)?;
23042304
let shutdown_pubkey = Readable::read(reader)?;
23052305
// Technically this can fail and serialize fail a round-trip, but only for serialization of
23062306
// barely-init'd ChannelMonitors that we can't do anything with.
@@ -2317,7 +2317,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
23172317
revocation_base_key,
23182318
htlc_base_key,
23192319
delayed_payment_base_key,
2320-
payment_base_key,
2320+
payment_key,
23212321
shutdown_pubkey,
23222322
funding_info,
23232323
current_remote_commitment_txid,

lightning/src/ln/functional_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5519,7 +5519,7 @@ fn bolt2_open_channel_sending_node_checks_part2() {
55195519
assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.funding_pubkey.serialize()).is_ok());
55205520
assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.revocation_basepoint.serialize()).is_ok());
55215521
assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.htlc_basepoint.serialize()).is_ok());
5522-
assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.payment_basepoint.serialize()).is_ok());
5522+
assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.payment_point.serialize()).is_ok());
55235523
assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.delayed_payment_basepoint.serialize()).is_ok());
55245524
}
55255525

0 commit comments

Comments
 (0)