Skip to content

Commit cf0094b

Browse files
authored
Merge pull request #125 from tnull/2023-06-remove-redundant-payment-status
Remove unnecessary `PaymentStatus::SendingFailed`
2 parents bbc3ffc + 086491b commit cf0094b

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

bindings/ldk_node.udl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ enum PaymentDirection {
132132

133133
enum PaymentStatus {
134134
"Pending",
135-
"SendingFailed",
136135
"Succeeded",
137136
"Failed",
138137
};

src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,9 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
10101010
let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
10111011

10121012
if let Some(payment) = self.payment_store.get(&payment_hash) {
1013-
if payment.status != PaymentStatus::SendingFailed {
1013+
if payment.status == PaymentStatus::Pending
1014+
|| payment.status == PaymentStatus::Succeeded
1015+
{
10141016
log_error!(self.logger, "Payment error: an invoice must not be paid twice.");
10151017
return Err(Error::DuplicatePayment);
10161018
}
@@ -1057,7 +1059,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
10571059
secret: payment_secret,
10581060
amount_msat: invoice.amount_milli_satoshis(),
10591061
direction: PaymentDirection::Outbound,
1060-
status: PaymentStatus::SendingFailed,
1062+
status: PaymentStatus::Failed,
10611063
};
10621064

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

10941096
let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
10951097
if let Some(payment) = self.payment_store.get(&payment_hash) {
1096-
if payment.status != PaymentStatus::SendingFailed {
1098+
if payment.status == PaymentStatus::Pending
1099+
|| payment.status == PaymentStatus::Succeeded
1100+
{
10971101
log_error!(self.logger, "Payment error: an invoice must not be paid twice.");
10981102
return Err(Error::DuplicatePayment);
10991103
}
@@ -1160,7 +1164,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
11601164
secret: payment_secret,
11611165
amount_msat: Some(amount_msat),
11621166
direction: PaymentDirection::Outbound,
1163-
status: PaymentStatus::SendingFailed,
1167+
status: PaymentStatus::Failed,
11641168
};
11651169
self.payment_store.insert(payment)?;
11661170

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

11861190
if let Some(payment) = self.payment_store.get(&payment_hash) {
1187-
if payment.status != PaymentStatus::SendingFailed {
1191+
if payment.status == PaymentStatus::Pending
1192+
|| payment.status == PaymentStatus::Succeeded
1193+
{
11881194
log_error!(self.logger, "Payment error: must not send duplicate payments.");
11891195
return Err(Error::DuplicatePayment);
11901196
}
@@ -1233,7 +1239,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
12331239
hash: payment_hash,
12341240
preimage: Some(payment_preimage),
12351241
secret: None,
1236-
status: PaymentStatus::SendingFailed,
1242+
status: PaymentStatus::Failed,
12371243
direction: PaymentDirection::Outbound,
12381244
amount_msat: Some(amount_msat),
12391245
};

src/payment_store.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,16 @@ impl_writeable_tlv_based_enum!(PaymentDirection,
5757
pub enum PaymentStatus {
5858
/// The payment is still pending.
5959
Pending,
60-
/// The sending of the payment failed and is safe to be retried.
61-
SendingFailed,
6260
/// The payment suceeded.
6361
Succeeded,
64-
/// The payment failed and is not retryable.
62+
/// The payment failed.
6563
Failed,
6664
}
6765

6866
impl_writeable_tlv_based_enum!(PaymentStatus,
6967
(0, Pending) => {},
70-
(2, SendingFailed) => {},
71-
(4, Succeeded) => {},
72-
(6, Failed) => {};
68+
(2, Succeeded) => {},
69+
(4, Failed) => {};
7370
);
7471

7572
#[derive(Clone, Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)