From 20d8e00b4daac8b9b5ff87e11945cb841de04905 Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Tue, 9 Mar 2021 17:08:22 +0000 Subject: [PATCH] fix: don't start the vault if liquidated Signed-off-by: Gregory Hill --- runtime/src/error.rs | 4 ++++ runtime/src/lib.rs | 2 +- runtime/src/pallets/mod.rs | 2 +- runtime/src/rpc.rs | 19 ++++++++++++++----- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/runtime/src/error.rs b/runtime/src/error.rs index 04dcf6706..feadf82bf 100644 --- a/runtime/src/error.rs +++ b/runtime/src/error.rs @@ -25,6 +25,10 @@ pub enum Error { BlockNotFound, #[error("Could not get vault")] VaultNotFound, + #[error("Vault has been liquidated")] + VaultLiquidated, + #[error("Vault has stolen BTC")] + VaultCommittedTheft, #[error("Channel closed unexpectedly")] ChannelClosed, diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5ac8a43f0..1894d384f 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -37,7 +37,7 @@ use substrate_subxt::system::SystemEventTypeRegistry; use substrate_subxt::EventTypeRegistry; use substrate_subxt::{balances, extrinsic::DefaultExtra, sudo, system, Runtime}; pub use types::*; -use vault_registry::VaultStatus; +pub use vault_registry::VaultStatus; use parachain::primitives::{Id as ParaId, RelayChainBlockNumber}; use xcm::v0::{Error as XcmError, NetworkId}; diff --git a/runtime/src/pallets/mod.rs b/runtime/src/pallets/mod.rs index b6f326a43..6b2bf2ba8 100644 --- a/runtime/src/pallets/mod.rs +++ b/runtime/src/pallets/mod.rs @@ -24,7 +24,7 @@ pub use refund::RefundRequest; pub use replace::ReplaceRequest; pub use security::{ErrorCode, StatusCode}; pub use staked_relayers::StatusUpdate; -pub use vault_registry::Vault; +pub use vault_registry::{Vault, VaultStatus}; use parity_scale_codec::{Codec, EncodeLike}; use sp_arithmetic::traits::Saturating; diff --git a/runtime/src/rpc.rs b/runtime/src/rpc.rs index 3c08bb80e..8d25116a3 100644 --- a/runtime/src/rpc.rs +++ b/runtime/src/rpc.rs @@ -1468,13 +1468,22 @@ impl VaultRegistryPallet for PolkaBtcProvider { /// /// # Errors /// * `VaultNotFound` - if the rpc returned a default value rather than the vault we want + /// * `VaultLiquidated` - if the vault is liquidated + /// * `VaultCommittedTheft` - if the vault is stole BTC async fn get_vault(&self, vault_id: AccountId) -> Result { let head = self.get_latest_block_hash().await?; - let vault: PolkaBtcVault = self.ext_client.vaults(vault_id.clone(), head).await?; - if vault.id == vault_id { - Ok(vault) - } else { - Err(Error::VaultNotFound) + match self.ext_client.vaults(vault_id.clone(), head).await { + Ok(PolkaBtcVault { + status: VaultStatus::Liquidated, + .. + }) => Err(Error::VaultLiquidated), + Ok(PolkaBtcVault { + status: VaultStatus::CommittedTheft, + .. + }) => Err(Error::VaultCommittedTheft), + Ok(vault) if vault.id == vault_id => Ok(vault), + Ok(_) => Err(Error::VaultNotFound), + Err(err) => Err(err.into()), } }