@@ -8,7 +8,8 @@ use std::{
88
99pub ( crate ) struct StaticInvoiceStore {
1010 kv_store : Arc < DynStore > ,
11- rate_limiter : Mutex < RateLimiter > ,
11+ request_rate_limiter : Mutex < RateLimiter > ,
12+ persist_rate_limiter : Mutex < RateLimiter > ,
1213}
1314
1415impl StaticInvoiceStore {
@@ -19,11 +20,17 @@ impl StaticInvoiceStore {
1920 const PRIMARY_NAMESPACE : & str = "static_invoices" ;
2021
2122 pub ( crate ) fn new ( kv_store : Arc < DynStore > ) -> Self {
22- Self { kv_store, rate_limiter : Mutex :: new ( RateLimiter :: new ( Duration :: from_millis ( 100 ) ) ) }
23+ Self {
24+ kv_store,
25+ request_rate_limiter : Mutex :: new ( RateLimiter :: new ( Duration :: from_millis ( 100 ) ) ) ,
26+ persist_rate_limiter : Mutex :: new ( RateLimiter :: new ( Duration :: from_millis ( 100 ) ) ) ,
27+ }
2328 }
2429
25- fn check_rate_limit ( & self , recipient_id : & [ u8 ] ) -> Result < ( ) , lightning:: io:: Error > {
26- let mut limiter = self . rate_limiter . lock ( ) . unwrap ( ) ;
30+ fn check_rate_limit (
31+ limiter : & Mutex < RateLimiter > , recipient_id : & [ u8 ] ,
32+ ) -> Result < ( ) , lightning:: io:: Error > {
33+ let mut limiter = limiter. lock ( ) . unwrap ( ) ;
2734 if !limiter. allow ( recipient_id) {
2835 Err ( lightning:: io:: Error :: new ( lightning:: io:: ErrorKind :: Other , "Rate limit exceeded" ) )
2936 } else {
@@ -34,7 +41,7 @@ impl StaticInvoiceStore {
3441 pub ( crate ) async fn handle_static_invoice_requested (
3542 & self , recipient_id : Vec < u8 > , invoice_slot : u16 ,
3643 ) -> Result < Option < StaticInvoice > , lightning:: io:: Error > {
37- self . check_rate_limit ( & recipient_id) ?;
44+ Self :: check_rate_limit ( & self . request_rate_limiter , & recipient_id) ?;
3845
3946 let ( secondary_namespace, key) = Self :: get_storage_location ( invoice_slot, recipient_id) ;
4047
@@ -51,7 +58,7 @@ impl StaticInvoiceStore {
5158 pub ( crate ) async fn handle_persist_static_invoice (
5259 & self , invoice : StaticInvoice , invoice_slot : u16 , recipient_id : Vec < u8 > ,
5360 ) -> Result < ( ) , lightning:: io:: Error > {
54- self . check_rate_limit ( & recipient_id) ?;
61+ Self :: check_rate_limit ( & self . persist_rate_limiter , & recipient_id) ?;
5562
5663 let ( secondary_namespace, key) = Self :: get_storage_location ( invoice_slot, recipient_id) ;
5764
0 commit comments