Skip to content

Commit e11670d

Browse files
committed
Prefactor: Simplify state transitions, drop lock around PaymentQueue
The previous transition pattern of `OutboundJITChannelState` was never great: we'd take `&mut self`, only to also return `Self` and required updating the state externally to the state transtion methods. In addition, we previously wrapped `PaymentQueue` in an `Arc<Mutex<..>>` to avoid cloning them during state transtions. Here, we clean up all of this, having the state transtion methods updating the state in-place and merely returning an `action` in the method's `Result`s. We also use `core::mem::take` to move the `payment_queue` to the new states without reallocation.
1 parent 9167a29 commit e11670d

File tree

2 files changed

+147
-173
lines changed

2 files changed

+147
-173
lines changed

lightning-liquidity/src/lsps2/payment_queue.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@ use lightning_types::payment::PaymentHash;
66
/// Holds payments with the corresponding HTLCs until it is possible to pay the fee.
77
/// When the fee is successfully paid with a forwarded payment, the queue should be consumed and the
88
/// remaining payments forwarded.
9-
#[derive(Clone, PartialEq, Eq, Debug)]
9+
#[derive(Clone, Default, PartialEq, Eq, Debug)]
1010
pub(crate) struct PaymentQueue {
1111
payments: Vec<(PaymentHash, Vec<InterceptedHTLC>)>,
1212
}
1313

14-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
15-
pub(crate) struct InterceptedHTLC {
16-
pub(crate) intercept_id: InterceptId,
17-
pub(crate) expected_outbound_amount_msat: u64,
18-
pub(crate) payment_hash: PaymentHash,
19-
}
20-
2114
impl PaymentQueue {
2215
pub(crate) fn new() -> PaymentQueue {
2316
PaymentQueue { payments: Vec::new() }
@@ -55,6 +48,13 @@ impl PaymentQueue {
5548
}
5649
}
5750

51+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
52+
pub(crate) struct InterceptedHTLC {
53+
pub(crate) intercept_id: InterceptId,
54+
pub(crate) expected_outbound_amount_msat: u64,
55+
pub(crate) payment_hash: PaymentHash,
56+
}
57+
5858
#[cfg(test)]
5959
mod tests {
6060
use super::*;

0 commit comments

Comments
 (0)