Skip to content

Commit 086491b

Browse files
committed
Remove unnecessary PaymentStatus::SendingFailed
Previously, I had a misunderstood in what event retrying payments is safe. It turns out that it's indeed safe to retry a payment as soon as we receive `LdkEvent::PaymentFailed`. Therefore, we can here now only refuse to send duplicate payments if our previous status is `Succeeded` or `Pending`, which renders the additional distinction between `Failed` and `SendingFailed` superfluous. Accordingly, we remove this `PaymentStatus` variant.
1 parent 56fe49c commit 086491b

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
@@ -128,7 +128,6 @@ enum PaymentDirection {
128128

129129
enum PaymentStatus {
130130
"Pending",
131-
"SendingFailed",
132131
"Succeeded",
133132
"Failed",
134133
};

src/lib.rs

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

15201520
if let Some(payment) = self.payment_store.get(&payment_hash) {
1521-
if payment.status != PaymentStatus::SendingFailed {
1521+
if payment.status == PaymentStatus::Pending
1522+
|| payment.status == PaymentStatus::Succeeded
1523+
{
15221524
log_error!(self.logger, "Payment error: an invoice must not be paid twice.");
15231525
return Err(Error::DuplicatePayment);
15241526
}
@@ -1565,7 +1567,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
15651567
secret: payment_secret,
15661568
amount_msat: invoice.amount_milli_satoshis(),
15671569
direction: PaymentDirection::Outbound,
1568-
status: PaymentStatus::SendingFailed,
1570+
status: PaymentStatus::Failed,
15691571
};
15701572

15711573
self.payment_store.insert(payment)?;
@@ -1601,7 +1603,9 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
16011603

16021604
let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
16031605
if let Some(payment) = self.payment_store.get(&payment_hash) {
1604-
if payment.status != PaymentStatus::SendingFailed {
1606+
if payment.status == PaymentStatus::Pending
1607+
|| payment.status == PaymentStatus::Succeeded
1608+
{
16051609
log_error!(self.logger, "Payment error: an invoice must not be paid twice.");
16061610
return Err(Error::DuplicatePayment);
16071611
}
@@ -1668,7 +1672,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
16681672
secret: payment_secret,
16691673
amount_msat: Some(amount_msat),
16701674
direction: PaymentDirection::Outbound,
1671-
status: PaymentStatus::SendingFailed,
1675+
status: PaymentStatus::Failed,
16721676
};
16731677
self.payment_store.insert(payment)?;
16741678

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

16941698
if let Some(payment) = self.payment_store.get(&payment_hash) {
1695-
if payment.status != PaymentStatus::SendingFailed {
1699+
if payment.status == PaymentStatus::Pending
1700+
|| payment.status == PaymentStatus::Succeeded
1701+
{
16961702
log_error!(self.logger, "Payment error: must not send duplicate payments.");
16971703
return Err(Error::DuplicatePayment);
16981704
}
@@ -1741,7 +1747,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
17411747
hash: payment_hash,
17421748
preimage: Some(payment_preimage),
17431749
secret: None,
1744-
status: PaymentStatus::SendingFailed,
1750+
status: PaymentStatus::Failed,
17451751
direction: PaymentDirection::Outbound,
17461752
amount_msat: Some(amount_msat),
17471753
};

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)