Skip to content

Commit

Permalink
fix: don't start the vault if liquidated
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <[email protected]>
  • Loading branch information
gregdhill committed Mar 9, 2021
1 parent 731c3ad commit 20d8e00
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions runtime/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/pallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 14 additions & 5 deletions runtime/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PolkaBtcVault, Error> {
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()),
}
}

Expand Down

0 comments on commit 20d8e00

Please sign in to comment.