Skip to content

Commit

Permalink
Merge pull request #125 from tnull/2023-06-remove-redundant-payment-s…
Browse files Browse the repository at this point in the history
…tatus

Remove unnecessary `PaymentStatus::SendingFailed`
  • Loading branch information
tnull authored Jun 20, 2023
2 parents bbc3ffc + 086491b commit cf0094b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
1 change: 0 additions & 1 deletion bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ enum PaymentDirection {

enum PaymentStatus {
"Pending",
"SendingFailed",
"Succeeded",
"Failed",
};
Expand Down
18 changes: 12 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,9 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());

if let Some(payment) = self.payment_store.get(&payment_hash) {
if payment.status != PaymentStatus::SendingFailed {
if payment.status == PaymentStatus::Pending
|| payment.status == PaymentStatus::Succeeded
{
log_error!(self.logger, "Payment error: an invoice must not be paid twice.");
return Err(Error::DuplicatePayment);
}
Expand Down Expand Up @@ -1057,7 +1059,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
secret: payment_secret,
amount_msat: invoice.amount_milli_satoshis(),
direction: PaymentDirection::Outbound,
status: PaymentStatus::SendingFailed,
status: PaymentStatus::Failed,
};

self.payment_store.insert(payment)?;
Expand Down Expand Up @@ -1093,7 +1095,9 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {

let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
if let Some(payment) = self.payment_store.get(&payment_hash) {
if payment.status != PaymentStatus::SendingFailed {
if payment.status == PaymentStatus::Pending
|| payment.status == PaymentStatus::Succeeded
{
log_error!(self.logger, "Payment error: an invoice must not be paid twice.");
return Err(Error::DuplicatePayment);
}
Expand Down Expand Up @@ -1160,7 +1164,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
secret: payment_secret,
amount_msat: Some(amount_msat),
direction: PaymentDirection::Outbound,
status: PaymentStatus::SendingFailed,
status: PaymentStatus::Failed,
};
self.payment_store.insert(payment)?;

Expand All @@ -1184,7 +1188,9 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());

if let Some(payment) = self.payment_store.get(&payment_hash) {
if payment.status != PaymentStatus::SendingFailed {
if payment.status == PaymentStatus::Pending
|| payment.status == PaymentStatus::Succeeded
{
log_error!(self.logger, "Payment error: must not send duplicate payments.");
return Err(Error::DuplicatePayment);
}
Expand Down Expand Up @@ -1233,7 +1239,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
hash: payment_hash,
preimage: Some(payment_preimage),
secret: None,
status: PaymentStatus::SendingFailed,
status: PaymentStatus::Failed,
direction: PaymentDirection::Outbound,
amount_msat: Some(amount_msat),
};
Expand Down
9 changes: 3 additions & 6 deletions src/payment_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,16 @@ impl_writeable_tlv_based_enum!(PaymentDirection,
pub enum PaymentStatus {
/// The payment is still pending.
Pending,
/// The sending of the payment failed and is safe to be retried.
SendingFailed,
/// The payment suceeded.
Succeeded,
/// The payment failed and is not retryable.
/// The payment failed.
Failed,
}

impl_writeable_tlv_based_enum!(PaymentStatus,
(0, Pending) => {},
(2, SendingFailed) => {},
(4, Succeeded) => {},
(6, Failed) => {};
(2, Succeeded) => {},
(4, Failed) => {};
);

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down

0 comments on commit cf0094b

Please sign in to comment.