Skip to content

Commit 0045de2

Browse files
committed
LSPS2: Add support for ongoing proportional fees
1 parent b8673f3 commit 0045de2

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

lightning-liquidity/src/lsps2/client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ where
214214
request_id,
215215
counterparty_node_id: *counterparty_node_id,
216216
opening_fee_params_menu: result.opening_fee_params_menu,
217+
ongoing_proportional: result.ongoing_proportional,
217218
});
218219
},
219220
None => {

lightning-liquidity/src/lsps2/event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub enum LSPS2ClientEvent {
3838
/// The menu of fee parameters the LSP is offering at this time.
3939
/// You must select one of these if you wish to proceed.
4040
opening_fee_params_menu: Vec<LSPS2OpeningFeeParams>,
41+
/// A flag indicating whether the LSP will collect ongoing proportional fees after the initial channel is opened.
42+
ongoing_proportional: bool,
4143
},
4244
/// Provides the necessary information to generate a payable invoice that then may be given to
4345
/// the payer.

lightning-liquidity/src/lsps2/msgs.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ pub struct LSPS2OpeningFeeParams {
115115
pub struct LSPS2GetInfoResponse {
116116
/// A set of opening fee parameters.
117117
pub opening_fee_params_menu: Vec<LSPS2OpeningFeeParams>,
118+
/// A flag for whether ongoing proportional fees will be collected.
119+
pub ongoing_proportional: bool,
118120
}
119121

120122
/// A request to buy a JIT channel.
@@ -348,6 +350,7 @@ mod tests {
348350
let max_client_to_self_delay = 128;
349351
let min_payment_size_msat = 1;
350352
let max_payment_size_msat = 100_000_000;
353+
let ongoing_proportional = true;
351354

352355
let raw = LSPS2RawOpeningFeeParams {
353356
min_fee_msat,
@@ -382,7 +385,7 @@ mod tests {
382385
assert_eq!(buy_request_variable, serde_json::from_str(json_str).unwrap());
383386

384387
// Check we still deserialize correctly if payment_size_msat is 'null'.
385-
let json_str = r#"{"opening_fee_params":{"max_client_to_self_delay":128,"max_payment_size_msat":"100000000","min_fee_msat":"100","min_lifetime":144,"min_payment_size_msat":"1","promise":"1134a5c51e3ba2e8f4259610d5e12c1bf4c50ddcd3f8af563e0a00d1fff41dea","proportional":21,"valid_until":"2023-05-20T08:30:45Z"},"payment_size_msat":null}"#;
388+
let json_str = r#"{"opening_fee_params":{"max_client_to_self_delay":128,"max_payment_size_msat":"100000000","min_fee_msat":"100","min_lifetime":144,"min_payment_size_msat":"1","promise":"1134a5c51e3ba2e8f4259610d5e12c1bf4c50ddcd3f8af563e0a00d1fff41dea","proportional":21,"valid_until":"2023-05-20T08:30:45Z"},"ongoing_proportional":true,"payment_size_msat":null}"#;
386389
assert_eq!(buy_request_variable, serde_json::from_str(json_str).unwrap());
387390
}
388391

@@ -411,7 +414,8 @@ mod tests {
411414
"max_payment_size_msat": "1000000",
412415
"promise": "abcdefghijklmnopqrstuvwxyz"
413416
}
414-
]
417+
],
418+
"ongoing_proportional": true
415419
}"#;
416420
let _get_info_response: LSPS2GetInfoResponse = serde_json::from_str(json_str).unwrap();
417421

@@ -426,6 +430,7 @@ mod tests {
426430
"max_payment_size_msat": "1000000",
427431
"promise": "abcdefghijklmnopqrstuvwxyz"
428432
},
433+
"ongoing_proportional": true,
429434
"payment_size_msat": "42000"
430435
}"#;
431436
let _buy_request: LSPS2BuyRequest = serde_json::from_str(json_str).unwrap();

lightning-liquidity/src/lsps2/service.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ where
634634
/// [`LSPS2ServiceEvent::GetInfo`]: crate::lsps2::event::LSPS2ServiceEvent::GetInfo
635635
pub fn opening_fee_params_generated(
636636
&self, counterparty_node_id: &PublicKey, request_id: LSPSRequestId,
637-
opening_fee_params_menu: Vec<LSPS2RawOpeningFeeParams>,
637+
opening_fee_params_menu: Vec<LSPS2RawOpeningFeeParams>, ongoing_proportional: bool,
638638
) -> Result<(), APIError> {
639639
let (result, response) = {
640640
let outer_state_lock = self.per_peer_state.read().unwrap();
@@ -652,6 +652,7 @@ where
652652
param.into_opening_fee_params(&self.config.promise_secret)
653653
})
654654
.collect(),
655+
ongoing_proportional,
655656
});
656657
(Ok(()), Some(response))
657658
},

lightning-liquidity/tests/lsps2_integration_tests.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,14 @@ fn invoice_generation_flow() {
154154
max_payment_size_msat: 100_000_000,
155155
};
156156

157+
let ongoing_proportional = true;
158+
157159
service_handler
158160
.opening_fee_params_generated(
159161
&client_node_id,
160162
get_info_request_id.clone(),
161163
vec![raw_opening_params],
164+
ongoing_proportional,
162165
)
163166
.unwrap();
164167
let get_info_response = get_lsps_message!(service_node, client_node_id);
@@ -174,9 +177,11 @@ fn invoice_generation_flow() {
174177
request_id,
175178
counterparty_node_id,
176179
opening_fee_params_menu,
180+
ongoing_proportional,
177181
}) => {
178182
assert_eq!(request_id, get_info_request_id);
179183
assert_eq!(counterparty_node_id, service_node_id);
184+
assert_eq!(ongoing_proportional, ongoing_proportional);
180185
let opening_fee_params = opening_fee_params_menu.first().unwrap().clone();
181186
assert!(is_valid_opening_fee_params(&opening_fee_params, &promise_secret));
182187
opening_fee_params
@@ -282,11 +287,15 @@ fn channel_open_failed() {
282287
min_payment_size_msat: 1,
283288
max_payment_size_msat: 100_000_000,
284289
};
290+
291+
let ongoing_proportional = true;
292+
285293
service_handler
286294
.opening_fee_params_generated(
287295
&client_node_id,
288296
get_info_request_id.clone(),
289297
vec![raw_opening_params],
298+
ongoing_proportional,
290299
)
291300
.unwrap();
292301

@@ -430,11 +439,14 @@ fn channel_open_abandoned() {
430439
min_payment_size_msat: 1,
431440
max_payment_size_msat: 100_000_000,
432441
};
442+
let ongoing_proportional = true;
443+
433444
service_handler
434445
.opening_fee_params_generated(
435446
&client_node_id,
436447
get_info_request_id.clone(),
437448
vec![raw_opening_params],
449+
ongoing_proportional,
438450
)
439451
.unwrap();
440452

@@ -584,9 +596,15 @@ fn max_total_requests_buy_rejected() {
584596
min_payment_size_msat: 1,
585597
max_payment_size_msat: 100_000_000,
586598
};
599+
let ongoing_proportional = true;
587600

588601
service_handler
589-
.opening_fee_params_generated(&special_node_id, request_id, vec![raw_opening_params])
602+
.opening_fee_params_generated(
603+
&special_node_id,
604+
request_id,
605+
vec![raw_opening_params],
606+
ongoing_proportional,
607+
)
590608
.unwrap();
591609
} else {
592610
panic!("Unexpected event");
@@ -713,11 +731,13 @@ fn invalid_token_flow() {
713731
min_payment_size_msat: 1,
714732
max_payment_size_msat: 100_000_000,
715733
};
734+
let ongoing_proportional = true;
716735

717736
let result = service_handler.opening_fee_params_generated(
718737
&client_node_id,
719738
request_id.clone(),
720739
vec![raw_opening_params],
740+
ongoing_proportional,
721741
);
722742

723743
assert!(result.is_err(), "Request should have been removed from pending_requests");

0 commit comments

Comments
 (0)