-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support liquidated vaults in metrics #559
Merged
gianfra-t
merged 7 commits into
main
from
548-make-vault-clients-export-metrics-with-default-values-if-no-data-is-available
Oct 18, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
39e752f
support liquidated vaults for metrics
gianfra-t 9f641d2
add method to fetch only active vaults ids from manager, only accept …
gianfra-t 0fb7848
add metric for liquidated
gianfra-t dc06c66
clippy fixes
gianfra-t a1a7c9b
simplify liquidation status metric updater
gianfra-t 49bfc01
remove comment
gianfra-t 8a0f731
remove unused method
gianfra-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ pub struct VaultData { | |
pub vault_id: VaultId, | ||
pub stellar_wallet: ArcRwLock<StellarWallet>, | ||
pub metrics: PerCurrencyMetrics, | ||
pub liquidated: bool, | ||
} | ||
|
||
#[derive(Clone)] | ||
|
@@ -88,19 +89,21 @@ impl VaultIdManager { | |
vault_id: key.clone(), | ||
stellar_wallet: stellar_wallet.clone(), | ||
metrics: PerCurrencyMetrics::dummy(), | ||
liquidated: false, | ||
}, | ||
) | ||
}) | ||
.collect(); | ||
Self { vault_data: Arc::new(RwLock::new(vault_data)), spacewalk_parachain, stellar_wallet } | ||
} | ||
|
||
async fn add_vault_id(&self, vault_id: VaultId) -> Result<(), Error> { | ||
async fn add_vault_id(&self, vault_id: VaultId, is_liquidated: bool) -> Result<(), Error> { | ||
let metrics = PerCurrencyMetrics::new(&vault_id); | ||
let data = VaultData { | ||
vault_id: vault_id.clone(), | ||
stellar_wallet: self.stellar_wallet.clone(), | ||
metrics, | ||
liquidated: is_liquidated, | ||
}; | ||
PerCurrencyMetrics::initialize_values(self.spacewalk_parachain.clone(), &data).await; | ||
|
||
|
@@ -119,11 +122,14 @@ impl VaultIdManager { | |
{ | ||
// check if vault is registered | ||
match self.spacewalk_parachain.get_vault(&vault_id).await { | ||
Ok(_) => self.add_vault_id(vault_id.clone()).await?, | ||
Err(RuntimeError::VaultLiquidated) => tracing::error!( | ||
"[{}] Vault is liquidated -- not going to process events for this vault.", | ||
vault_id.pretty_print() | ||
), | ||
Ok(_) => self.add_vault_id(vault_id.clone(), false).await?, | ||
Err(RuntimeError::VaultLiquidated) => { | ||
self.add_vault_id(vault_id.clone(), true).await?; | ||
tracing::error!( | ||
"[{}] Vault is liquidated -- not going to process events for this vault.", | ||
vault_id.pretty_print() | ||
); | ||
}, | ||
Err(e) => return Err(e.into()), | ||
} | ||
} | ||
|
@@ -138,7 +144,7 @@ impl VaultIdManager { | |
let vault_id = event.vault_id; | ||
if self.spacewalk_parachain.is_this_vault(&vault_id) { | ||
tracing::info!("New vault registered: {}", vault_id.pretty_print()); | ||
let _ = self.add_vault_id(vault_id).await; | ||
let _ = self.add_vault_id(vault_id, false).await; | ||
} | ||
}, | ||
|err| tracing::error!("Error (RegisterVaultEvent): {}", err.to_string()), | ||
|
@@ -150,11 +156,32 @@ impl VaultIdManager { | |
self.vault_data.read().await.get(vault_id).map(|x| x.stellar_wallet.clone()) | ||
} | ||
|
||
pub async fn get_active_vault(&self, vault_id: &VaultId) -> Option<VaultData> { | ||
let vault = self.vault_data.read().await.get(vault_id)?.clone(); | ||
// Filter liquidated | ||
if vault.liquidated { | ||
return None; | ||
} | ||
return Some(vault); | ||
} | ||
|
||
pub async fn get_vault(&self, vault_id: &VaultId) -> Option<VaultData> { | ||
self.vault_data.read().await.get(vault_id).cloned() | ||
} | ||
|
||
// Get all ACTIVE vaults | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't want to change the name of this method to |
||
pub async fn get_entries(&self) -> Vec<VaultData> { | ||
self.vault_data | ||
.read() | ||
.await | ||
.iter() | ||
.filter(|(_, value)| !value.liquidated) | ||
.map(|(_, value)| value.clone()) | ||
.collect() | ||
} | ||
|
||
// Get all vaults including liquidated ones. | ||
pub async fn get_all_entries(&self) -> Vec<VaultData> { | ||
self.vault_data.read().await.iter().map(|(_, value)| value.clone()).collect() | ||
} | ||
|
||
|
@@ -163,6 +190,7 @@ impl VaultIdManager { | |
.read() | ||
.await | ||
.iter() | ||
.filter(|(_, value)| !value.liquidated) | ||
.map(|(vault_id, _)| vault_id.clone()) | ||
.collect() | ||
} | ||
|
@@ -174,6 +202,7 @@ impl VaultIdManager { | |
.read() | ||
.await | ||
.iter() | ||
.filter(|(_, value)| !value.liquidated) | ||
.map(|(vault_id, data)| (vault_id.clone(), data.stellar_wallet.clone())) | ||
.collect() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The reason I added this method is to have it into account for the future. Now,
get_vault
will bring the data even if the vault is liquidated. This impacts a few processes, namely:I think these are all processes that the liquidated vault should be able to perform anyway. This is the most critical difference about this change, simply replacing in those instances with
get_active_vault
will not modify the functionality, in case this assumptions are wrong.