-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache LSP information #919
base: main
Are you sure you want to change the base?
Conversation
@dangeross One of the requests to this is from invoice creation. We need that to match the invoice expiry. It seems that now we can get into a state where the expensive fee param will be chosen for the default one hour invoice? |
No, if any of the fee param values are expired, it is deemed invalid and it requests an updated version from the server. It uses the same validate function as when validating the initial response from the server: |
Ah, I see I think, for the expiry of the invoice is needs to be valid |
I've added a |
let persisted_lsp_info = | ||
persister.get_lsp_information()?.and_then(|lsp_info| { | ||
match !skip_cache && lsp_info.opening_fee_params_list.is_valid() { | ||
true => Some(lsp_info), | ||
false => { | ||
debug!("Ignoring LSP information: {:?} {:?}", skip_cache, lsp_info); | ||
None | ||
} | ||
} | ||
}); | ||
match persisted_lsp_info { | ||
Some(lsp_info) => { | ||
debug!("Using persisted LSP information"); | ||
Ok(lsp_info) | ||
} | ||
None => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let persisted_lsp_info = | |
persister.get_lsp_information()?.and_then(|lsp_info| { | |
match !skip_cache && lsp_info.opening_fee_params_list.is_valid() { | |
true => Some(lsp_info), | |
false => { | |
debug!("Ignoring LSP information: {:?} {:?}", skip_cache, lsp_info); | |
None | |
} | |
} | |
}); | |
match persisted_lsp_info { | |
Some(lsp_info) => { | |
debug!("Using persisted LSP information"); | |
Ok(lsp_info) | |
} | |
None => { | |
let persisted_lsp_info = persister.get_lsp_information()?; | |
let cached_lsp_info = persisted_lsp_info | |
.filter(|_| !skip_cache) | |
.filter(|lsp_info| lsp_info.opening_fee_params_list.is_valid()); | |
match cached_lsp_info { | |
Some(lsp_info) => { | |
debug!("Using cached LSP info"); | |
Ok(lsp_info) | |
} | |
None => { | |
debug!("Ignoring cached LSP info: skip_cache={skip_cache} lsp_info={lsp_info:?}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a suggestion on how the first part of the method could be rewritten for clarity.
IMO this looks good. |
This PR caches the LspInformation and only refreshes it when a record of the opening fee params expires (hourly) or on reconnect. The aim is to help reduce the requests sent to the Breez server when we already have valid fee param promises.