Skip to content

Commit

Permalink
Merge pull request #24 from interlay/greg/feat/vault-health
Browse files Browse the repository at this point in the history
feat: check for old redeem requests in vault system health check
  • Loading branch information
sander2 authored Mar 3, 2021
2 parents ab4f3b1 + 7715d59 commit b7cf1e9
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 71 deletions.
85 changes: 35 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tokio = { version = "0.2.22", features = ["full"] }
runtime = { path = "../runtime" }
bitcoin = { path = "../bitcoin", features = ["cli"] }
thiserror = "1.0"
jsonrpc-http-server = "16.0.0"
jsonrpc-http-server = "17.0.0"
jsonrpsee = "0.1.0"
parity-scale-codec = "2.0.0"
serde_json = "1.0.57"
Expand Down
12 changes: 11 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ pub const MINIMUM_STAKE: u128 = 100;
pub const TX_FEES: u128 = 2000000000;
pub const PLANCK_PER_DOT: u128 = 10000000000;

pub const MILLISECS_PER_BLOCK: u64 = 6000;

// These time units are defined in number of blocks.
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;

pub type Balance = u128;

#[derive(Debug, Clone, Eq, PartialEq)]
Expand All @@ -62,12 +68,16 @@ impl Runtime for PolkaBtcRuntime {
}
}

/// An index to a block.
pub type BlockNumber = u32;

/// Some way of identifying an account on the chain.
pub type AccountId = <<MultiSignature as Verify>::Signer as IdentifyAccount>::AccountId;

// TODO: use types from actual runtime
impl system::System for PolkaBtcRuntime {
type Index = u32;
type BlockNumber = u32;
type BlockNumber = BlockNumber;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
Expand Down
8 changes: 7 additions & 1 deletion runtime/src/pallets/redeem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ pub struct RedeemRequestsStore<T: Redeem> {
pub redeem_id: T::H256,
}

#[derive(Clone, Debug, Eq, PartialEq, Store, Encode)]
pub struct RedeemPeriodStore<T: Redeem> {
#[store(returns = T::BlockNumber)]
pub _runtime: PhantomData<T>,
}

#[derive(Clone, Debug, PartialEq, Call, Encode)]
pub struct SetRedeemPeriodCall<T: Redeem> {
pub period: u32,
pub period: T::BlockNumber,
pub _runtime: PhantomData<T>,
}
4 changes: 2 additions & 2 deletions runtime/src/pallets/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub struct CancelReplaceEvent<T: Replace> {

#[derive(Clone, Debug, Eq, PartialEq, Store, Encode)]
pub struct ReplacePeriodStore<T: Replace> {
#[store(returns = u32)]
#[store(returns = T::BlockNumber)]
pub _runtime: PhantomData<T>,
}

Expand All @@ -116,6 +116,6 @@ pub struct ReplaceRequestsStore<T: Replace> {

#[derive(Clone, Debug, PartialEq, Call, Encode)]
pub struct SetReplacePeriodCall<T: Replace> {
pub period: u32,
pub period: T::BlockNumber,
pub _runtime: PhantomData<T>,
}
14 changes: 12 additions & 2 deletions runtime/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use substrate_subxt::{
use tokio::sync::RwLock;
use tokio::time::{delay_for, timeout};

use crate::balances_dot::*;
use crate::btc_relay::*;
use crate::exchange_rate_oracle::*;
use crate::fee::*;
Expand All @@ -41,6 +40,7 @@ use crate::types::*;
use crate::vault_registry::*;
use crate::Error;
use crate::PolkaBtcRuntime;
use crate::{balances_dot::*, BlockNumber};

use crate::error::{IoErrorKind, WsNewDnsError, WsNewError};

Expand Down Expand Up @@ -137,6 +137,10 @@ impl PolkaBtcProvider {
Ok(self.ext_client.block_hash(None).await?)
}

pub async fn get_latest_block(&self) -> Result<Option<PolkaBtcBlock>, Error> {
Ok(self.ext_client.block::<H256>(None).await?)
}

/// Fetch all active vaults.
pub async fn get_all_vaults(&self) -> Result<Vec<PolkaBtcVault>, Error> {
let mut vaults = Vec::new();
Expand Down Expand Up @@ -1121,6 +1125,8 @@ pub trait RedeemPallet {
account_id: AccountId,
) -> Result<Vec<(H256, PolkaBtcRedeemRequest)>, Error>;

async fn get_redeem_period(&self) -> Result<BlockNumber, Error>;

async fn set_redeem_period(&self, period: u32) -> Result<(), Error>;
}

Expand Down Expand Up @@ -1194,7 +1200,11 @@ impl RedeemPallet for PolkaBtcProvider {
Ok(result)
}

async fn set_redeem_period(&self, period: u32) -> Result<(), Error> {
async fn get_redeem_period(&self) -> Result<BlockNumber, Error> {
Ok(self.ext_client.redeem_period(None).await?)
}

async fn set_redeem_period(&self, period: BlockNumber) -> Result<(), Error> {
Ok(self
.sudo(SetRedeemPeriodCall {
period,
Expand Down
3 changes: 3 additions & 0 deletions runtime/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use sp_runtime::generic::{Block, SignedBlock};
use substrate_subxt::system::System;

use crate::pallets::{
Expand All @@ -10,6 +11,8 @@ pub type AccountId = <PolkaBtcRuntime as System>::AccountId;

pub type PolkaBtcHeader = <PolkaBtcRuntime as System>::Header;

pub type PolkaBtcBlock = SignedBlock<Block<PolkaBtcHeader, <PolkaBtcRuntime as System>::Extrinsic>>;

pub type PolkaBtcVault = Vault<
AccountId,
<PolkaBtcRuntime as System>::BlockNumber,
Expand Down
4 changes: 2 additions & 2 deletions staked-relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ serde = "1.0.116"
relayer-core = { git = "https://gitlab.com/interlay/relayer-core", rev = "9043ce35a1e00bc5a65d4d3d0433c2535f679bc0" }
runtime = { path = "../runtime" }
bitcoin = { path = "../bitcoin", features = ["cli"] }
jsonrpc-http-server = "16.0.0"
jsonrpc-http-server = "17.0.0"
backoff = { version = "0.2.1", features = ["tokio"] }
jsonrpc-core-client = { version = "16.0.0", features = ["http", "tls"] }
jsonrpc-core-client = { version = "17.0.0", features = ["http", "tls"] }

# Substrate dependencies
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }
Expand Down
2 changes: 1 addition & 1 deletion testdata-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ hex = "0.4.2"
serde = { version = "1.0.101", features = ["derive"] }
serde_json = "1.0.59"
reqwest = {version = "0.10.9", features = ["json"] }
jsonrpc-core = "16.0.0"
jsonrpc-core = "17.0.0"
futures = "0.3.5"

# Substrate dependencies
Expand Down
6 changes: 3 additions & 3 deletions vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ serde = "1.0.116"
serde_json = { version = "1.0.57", features = ["raw_value"] }
hex = "0.4.2"
parity-scale-codec = "2.0.0"
jsonrpc-http-server = "16.0.0"
jsonrpc-core = "16.0.0"
jsonrpc-http-server = "17.0.0"
jsonrpc-core = "17.0.0"
futures = "0.3.5"
async-trait = "0.1.40"
sha2 = "0.8.2"
jsonrpc-core-client = { version = "16.0.0", features = ["http", "tls"] }
jsonrpc-core-client = { version = "17.0.0", features = ["http", "tls"] }

# Substrate dependencies
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }
Expand Down
Loading

0 comments on commit b7cf1e9

Please sign in to comment.