Skip to content

Commit

Permalink
Rename Refund::payer_id
Browse files Browse the repository at this point in the history
For consistency with Offer::issuer_signing_pubkey, rename
Refund::payer_id to use "signing_pubkey" instead of "id".
  • Loading branch information
jkczyz committed Sep 16, 2024
1 parent 76a1e6b commit b670d90
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 41 deletions.
10 changes: 5 additions & 5 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9115,7 +9115,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
.and_then(|paths| paths.into_iter().next().ok_or(()))
.map_err(|_| Bolt12SemanticError::MissingPaths)?;

let builder = RefundBuilder::deriving_payer_id(
let builder = RefundBuilder::deriving_signing_pubkey(
node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
)?
.chain_hash($self.chain_hash)
Expand Down Expand Up @@ -9315,9 +9315,9 @@ where
/// # Limitations
///
/// Requires a direct connection to an introduction node in [`Refund::paths`] or to
/// [`Refund::payer_id`], if empty. This request is best effort; an invoice will be sent to each
/// node meeting the aforementioned criteria, but there's no guarantee that they will be
/// received and no retries will be made.
/// [`Refund::payer_signing_pubkey`], if empty. This request is best effort; an invoice will be
/// sent to each node meeting the aforementioned criteria, but there's no guarantee that they
/// will be received and no retries will be made.
///
/// # Errors
///
Expand Down Expand Up @@ -9378,7 +9378,7 @@ where
if refund.paths().is_empty() {
for reply_path in reply_paths {
let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
destination: Destination::Node(refund.payer_id()),
destination: Destination::Node(refund.payer_signing_pubkey()),
reply_path,
};
let message = OffersMessage::Invoice(invoice.clone());
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/ln/offers_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
assert_ne!(refund.payer_id(), david_id);
assert_ne!(refund.payer_signing_pubkey(), david_id);
assert!(!refund.paths().is_empty());
for path in refund.paths() {
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(charlie_id));
Expand Down Expand Up @@ -779,7 +779,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
assert_ne!(refund.payer_id(), bob_id);
assert_ne!(refund.payer_signing_pubkey(), bob_id);
assert!(!refund.paths().is_empty());
for path in refund.paths() {
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
Expand Down Expand Up @@ -886,7 +886,7 @@ fn pays_for_refund_without_blinded_paths() {
.unwrap()
.clear_paths()
.build().unwrap();
assert_eq!(refund.payer_id(), bob_id);
assert_eq!(refund.payer_signing_pubkey(), bob_id);
assert!(refund.paths().is_empty());
expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);

Expand Down Expand Up @@ -1040,7 +1040,7 @@ fn send_invoice_for_refund_with_distinct_reply_path() {
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_ne!(refund.payer_id(), alice_id);
assert_ne!(refund.payer_signing_pubkey(), alice_id);
for path in refund.paths() {
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
}
Expand Down Expand Up @@ -1315,7 +1315,7 @@ fn creates_refund_with_blinded_path_using_unannounced_introduction_node() {
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_ne!(refund.payer_id(), bob_id);
assert_ne!(refund.payer_signing_pubkey(), bob_id);
assert!(!refund.paths().is_empty());
for path in refund.paths() {
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id));
Expand Down Expand Up @@ -1598,7 +1598,7 @@ fn fails_authentication_when_handling_invoice_for_refund() {
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_ne!(refund.payer_id(), david_id);
assert_ne!(refund.payer_signing_pubkey(), david_id);
assert!(!refund.paths().is_empty());
for path in refund.paths() {
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(charlie_id));
Expand Down Expand Up @@ -1632,7 +1632,7 @@ fn fails_authentication_when_handling_invoice_for_refund() {
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_ne!(refund.payer_id(), david_id);
assert_ne!(refund.payer_signing_pubkey(), david_id);
assert!(!refund.paths().is_empty());
for path in refund.paths() {
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(charlie_id));
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,8 @@ impl InvoiceContents {

fn payer_signing_pubkey(&self) -> PublicKey {
match self {
InvoiceContents::ForRefund { refund, .. } => refund.payer_id(),
InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.payer_signing_pubkey(),
InvoiceContents::ForRefund { refund, .. } => refund.payer_signing_pubkey(),
}
}

Expand Down
5 changes: 3 additions & 2 deletions lightning/src/offers/invoice_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,10 @@ impl Readable for InvoiceRequest {
/// Valid type range for invoice_request TLV records.
pub(super) const INVOICE_REQUEST_TYPES: core::ops::Range<u64> = 80..160;

/// TLV record type for [`InvoiceRequest::payer_signing_pubkey`] and [`Refund::payer_id`].
/// TLV record type for [`InvoiceRequest::payer_signing_pubkey`] and
/// [`Refund::payer_signing_pubkey`].
///
/// [`Refund::payer_id`]: crate::offers::refund::Refund::payer_id
/// [`Refund::payer_signing_pubkey`]: crate::offers::refund::Refund::payer_signing_pubkey
pub(super) const INVOICE_REQUEST_PAYER_ID_TYPE: u64 = 88;

// This TLV stream is used for both InvoiceRequest and Refund, but not all TLV records are valid for
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/offers/payer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use crate::util::ser::WithoutLength;
use crate::prelude::*;

/// An unpredictable sequence of bytes typically containing information needed to derive
/// [`InvoiceRequest::payer_signing_pubkey`].
/// [`InvoiceRequest::payer_signing_pubkey`] and [`Refund::payer_signing_pubkey`].
///
/// [`InvoiceRequest::payer_signing_pubkey`]: crate::offers::invoice_request::InvoiceRequest::payer_signing_pubkey
/// [`Refund::payer_signing_pubkey`]: crate::offers::refund::Refund::payer_signing_pubkey
#[derive(Clone, Debug)]
#[cfg_attr(test, derive(PartialEq))]
pub(super) struct PayerContents(pub Metadata);
Expand Down
50 changes: 25 additions & 25 deletions lightning/src/offers/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ pub struct RefundMaybeWithDerivedMetadataBuilder<'a> {
}

macro_rules! refund_explicit_metadata_builder_methods { () => {
/// Creates a new builder for a refund using the [`Refund::payer_id`] for the public node id to
/// send to if no [`Refund::paths`] are set. Otherwise, it may be a transient pubkey.
/// Creates a new builder for a refund using the `signing_pubkey` for the public node id to send
/// to if no [`Refund::paths`] are set. Otherwise, `signing_pubkey` may be a transient pubkey.
///
/// Additionally, sets the required (empty) [`Refund::description`], [`Refund::payer_metadata`],
/// and [`Refund::amount_msats`].
Expand All @@ -164,7 +164,7 @@ macro_rules! refund_explicit_metadata_builder_methods { () => {
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
/// [`ChannelManager::create_refund_builder`]: crate::ln::channelmanager::ChannelManager::create_refund_builder
pub fn new(
metadata: Vec<u8>, payer_id: PublicKey, amount_msats: u64
metadata: Vec<u8>, signing_pubkey: PublicKey, amount_msats: u64
) -> Result<Self, Bolt12SemanticError> {
if amount_msats > MAX_VALUE_MSAT {
return Err(Bolt12SemanticError::InvalidAmount);
Expand All @@ -175,7 +175,7 @@ macro_rules! refund_explicit_metadata_builder_methods { () => {
refund: RefundContents {
payer: PayerContents(metadata), description: String::new(), absolute_expiry: None,
issuer: None, chain: None, amount_msats, features: InvoiceRequestFeatures::empty(),
quantity: None, payer_id, payer_note: None, paths: None,
quantity: None, payer_signing_pubkey: signing_pubkey, payer_note: None, paths: None,
},
secp_ctx: None,
})
Expand All @@ -202,7 +202,7 @@ macro_rules! refund_builder_methods { (
/// [`Bolt12Invoice::verify_using_metadata`]: crate::offers::invoice::Bolt12Invoice::verify_using_metadata
/// [`Bolt12Invoice::verify_using_payer_data`]: crate::offers::invoice::Bolt12Invoice::verify_using_payer_data
/// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
pub fn deriving_payer_id(
pub fn deriving_signing_pubkey(
node_id: PublicKey, expanded_key: &ExpandedKey, nonce: Nonce,
secp_ctx: &'a Secp256k1<$secp_context>, amount_msats: u64, payment_id: PaymentId
) -> Result<Self, Bolt12SemanticError> {
Expand All @@ -217,7 +217,7 @@ macro_rules! refund_builder_methods { (
refund: RefundContents {
payer: PayerContents(metadata), description: String::new(), absolute_expiry: None,
issuer: None, chain: None, amount_msats, features: InvoiceRequestFeatures::empty(),
quantity: None, payer_id: node_id, payer_note: None, paths: None,
quantity: None, payer_signing_pubkey: node_id, payer_note: None, paths: None,
},
secp_ctx: Some(secp_ctx),
})
Expand Down Expand Up @@ -249,7 +249,7 @@ macro_rules! refund_builder_methods { (
}

/// Adds a blinded path to [`Refund::paths`]. Must include at least one path if only connected
/// by private channels or if [`Refund::payer_id`] is not a public node id.
/// by private channels or if [`Refund::payer_signing_pubkey`] is not a public node id.
///
/// Successive calls to this method will add another blinded path. Caller is responsible for not
/// adding duplicate paths.
Expand Down Expand Up @@ -324,7 +324,7 @@ macro_rules! refund_builder_methods { (
metadata.derive_from(iv_bytes, tlv_stream, $self.secp_ctx);
metadata = derived_metadata;
if let Some(keys) = keys {
$self.refund.payer_id = keys.public_key();
$self.refund.payer_signing_pubkey = keys.public_key();
}

$self.refund.payer.0 = metadata;
Expand Down Expand Up @@ -434,7 +434,7 @@ pub(super) struct RefundContents {
amount_msats: u64,
features: InvoiceRequestFeatures,
quantity: Option<u64>,
payer_id: PublicKey,
payer_signing_pubkey: PublicKey,
payer_note: Option<String>,
paths: Option<Vec<BlindedMessagePath>>,
}
Expand Down Expand Up @@ -477,9 +477,9 @@ impl Refund {
}

/// An unpredictable series of bytes, typically containing information about the derivation of
/// [`payer_id`].
/// [`payer_signing_pubkey`].
///
/// [`payer_id`]: Self::payer_id
/// [`payer_signing_pubkey`]: Self::payer_signing_pubkey
pub fn payer_metadata(&self) -> &[u8] {
self.contents.metadata()
}
Expand Down Expand Up @@ -510,8 +510,8 @@ impl Refund {
/// transient pubkey.
///
/// [`paths`]: Self::paths
pub fn payer_id(&self) -> PublicKey {
self.contents.payer_id()
pub fn payer_signing_pubkey(&self) -> PublicKey {
self.contents.payer_signing_pubkey()
}

/// Payer provided note to include in the invoice.
Expand Down Expand Up @@ -727,8 +727,8 @@ impl RefundContents {
/// transient pubkey.
///
/// [`paths`]: Self::paths
pub fn payer_id(&self) -> PublicKey {
self.payer_id
pub fn payer_signing_pubkey(&self) -> PublicKey {
self.payer_signing_pubkey
}

/// Payer provided note to include in the invoice.
Expand Down Expand Up @@ -765,7 +765,7 @@ impl RefundContents {
amount: Some(self.amount_msats),
features,
quantity: self.quantity,
payer_id: Some(&self.payer_id),
payer_id: Some(&self.payer_signing_pubkey),
payer_note: self.payer_note.as_ref(),
paths: self.paths.as_ref(),
};
Expand Down Expand Up @@ -901,14 +901,14 @@ impl TryFrom<RefundTlvStream> for RefundContents {

let features = features.unwrap_or_else(InvoiceRequestFeatures::empty);

let payer_id = match payer_id {
let payer_signing_pubkey = match payer_id {
None => return Err(Bolt12SemanticError::MissingPayerSigningPubkey),
Some(payer_id) => payer_id,
};

Ok(RefundContents {
payer, description, absolute_expiry, issuer, chain, amount_msats, features, quantity,
payer_id, payer_note, paths,
payer_signing_pubkey, payer_note, paths,
})
}
}
Expand Down Expand Up @@ -985,7 +985,7 @@ mod tests {
assert_eq!(refund.chain(), ChainHash::using_genesis_block(Network::Bitcoin));
assert_eq!(refund.amount_msats(), 1000);
assert_eq!(refund.features(), &InvoiceRequestFeatures::empty());
assert_eq!(refund.payer_id(), payer_pubkey());
assert_eq!(refund.payer_signing_pubkey(), payer_pubkey());
assert_eq!(refund.payer_note(), None);

assert_eq!(
Expand Down Expand Up @@ -1040,10 +1040,10 @@ mod tests {
let payment_id = PaymentId([1; 32]);

let refund = RefundBuilder
::deriving_payer_id(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id)
::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id)
.unwrap()
.build().unwrap();
assert_eq!(refund.payer_id(), node_id);
assert_eq!(refund.payer_signing_pubkey(), node_id);

// Fails verification with altered fields
let invoice = refund
Expand Down Expand Up @@ -1089,7 +1089,7 @@ mod tests {
}

#[test]
fn builds_refund_with_derived_payer_id() {
fn builds_refund_with_derived_signing_pubkey() {
let node_id = payer_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
Expand All @@ -1106,11 +1106,11 @@ mod tests {
);

let refund = RefundBuilder
::deriving_payer_id(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id)
::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id)
.unwrap()
.path(blinded_path)
.build().unwrap();
assert_ne!(refund.payer_id(), node_id);
assert_ne!(refund.payer_signing_pubkey(), node_id);

let invoice = refund
.respond_with_no_std(payment_paths(), payment_hash(), recipient_pubkey(), now())
Expand Down Expand Up @@ -1211,7 +1211,7 @@ mod tests {
.build()
.unwrap();
let (_, _, invoice_request_tlv_stream) = refund.as_tlv_stream();
assert_eq!(refund.payer_id(), pubkey(42));
assert_eq!(refund.payer_signing_pubkey(), pubkey(42));
assert_eq!(refund.paths(), paths.as_slice());
assert_ne!(pubkey(42), pubkey(44));
assert_eq!(invoice_request_tlv_stream.payer_id, Some(&pubkey(42)));
Expand Down

0 comments on commit b670d90

Please sign in to comment.