Skip to content

Commit

Permalink
Merge pull request #145 from sander2/chore/relay-pallet
Browse files Browse the repository at this point in the history
 chore: upgrade parachain with relay pallet & fix breaking test
  • Loading branch information
gregdhill authored Jul 7, 2021
2 parents a4446da + bb3fd11 commit 76caa1f
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 130 deletions.
150 changes: 75 additions & 75 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bitcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-

[dependencies.interbtc-bitcoin]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "bitcoin"
optional = true

Expand Down
34 changes: 17 additions & 17 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,69 +50,69 @@ parachain = { package = "polkadot-parachain", git = "https://github.com/parityte
# Dependencies for the testing utils for integration tests
substrate-subxt-client = { git = "https://github.com/interlay/substrate-subxt", rev = "ceef243f8700fb2f4ded9461a9d725af1a333aac", optional = true }
tempdir = {version = "0.3.7", optional = true }
btc-parachain = { git = "https://github.com/interlay/interbtc", rev = "46637ab87025e7df1bfd828d353d6e854183c2ac", features = ["aura-grandpa"], optional = true }
btc-parachain-service = { git = "https://github.com/interlay/interbtc", rev = "46637ab87025e7df1bfd828d353d6e854183c2ac", features = ["aura-grandpa"], optional = true }
btc-parachain = { git = "https://github.com/interlay/interbtc", rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c", features = ["aura-grandpa"], optional = true }
btc-parachain-service = { git = "https://github.com/interlay/interbtc", rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c", features = ["aura-grandpa"], optional = true }
bitcoin = { path = "../bitcoin", optional = true }
rand = { version = "0.7", optional = true }

[dependencies.module-bitcoin]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "bitcoin"

[dependencies.module-refund]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "refund"

[dependencies.module-btc-relay]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "btc-relay"

[dependencies.module-security]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "security"

[dependencies.module-staked-relayers]
[dependencies.module-relay]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
package = "staked-relayers"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "relay"

[dependencies.module-vault-registry]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "vault-registry"

[dependencies.module-exchange-rate-oracle-rpc-runtime-api]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "module-exchange-rate-oracle-rpc-runtime-api"

[dependencies.module-issue]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "issue"

[dependencies.module-redeem]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "redeem"

[dependencies.module-replace]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "replace"

[dependencies.module-exchange-rate-oracle]
git = "https://github.com/interlay/interbtc"
rev = "46637ab87025e7df1bfd828d353d6e854183c2ac"
rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c"
package = "exchange-rate-oracle"

[dev-dependencies]
substrate-subxt-client = { git = "https://github.com/interlay/substrate-subxt", rev = "ceef243f8700fb2f4ded9461a9d725af1a333aac" }
btc-parachain = { git = "https://github.com/interlay/interbtc", rev = "46637ab87025e7df1bfd828d353d6e854183c2ac", features = ["aura-grandpa"] }
btc-parachain-service = { git = "https://github.com/interlay/interbtc", rev = "46637ab87025e7df1bfd828d353d6e854183c2ac", features = ["aura-grandpa"] }
btc-parachain = { git = "https://github.com/interlay/interbtc", rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c", features = ["aura-grandpa"] }
btc-parachain-service = { git = "https://github.com/interlay/interbtc", rev = "c4e21c3b9f7f4ab2899e1221911ac044a5aa933c", features = ["aura-grandpa"] }
tempdir = "0.3.7"
env_logger = "0.8.3"
2 changes: 1 addition & 1 deletion runtime/src/integration/bitcoin_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(unused_imports)]
#![allow(unused_variables)]

use crate::{rpc::StakedRelayerPallet, BtcAddress, BtcRelayPallet, InterBtcParachain};
use crate::{rpc::RelayPallet, BtcAddress, BtcRelayPallet, InterBtcParachain};
use async_trait::async_trait;
use bitcoin::{
secp256k1::{rand::rngs::OsRng, PublicKey, Secp256k1, SecretKey},
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub use pallets::*;
pub use retry::{notify_retry, RetryPolicy};
pub use rpc::{
BtcRelayPallet, BtcTxFeesPerByte, CollateralBalancesPallet, ExchangeRateOraclePallet, FeePallet, InterBtcParachain,
IssuePallet, RedeemPallet, RefundPallet, ReplacePallet, SecurityPallet, StakedRelayerPallet, TimestampPallet,
UtilFuncs, VaultRegistryPallet,
IssuePallet, RedeemPallet, RefundPallet, RelayPallet, ReplacePallet, SecurityPallet, TimestampPallet, UtilFuncs,
VaultRegistryPallet,
};
pub use sp_arithmetic::{traits as FixedPointTraits, FixedI128, FixedPointNumber, FixedU128};
pub use sp_runtime;
Expand Down Expand Up @@ -139,7 +139,7 @@ impl btc_relay::BTCRelay for InterBtcRuntime {}

impl security::Security for InterBtcRuntime {}

impl staked_relayers::StakedRelayers for InterBtcRuntime {}
impl relay::Relay for InterBtcRuntime {}

impl vault_registry::VaultRegistry for InterBtcRuntime {}

Expand Down
4 changes: 2 additions & 2 deletions runtime/src/pallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ pub mod frame_system;
pub mod issue;
pub mod redeem;
pub mod refund;
pub mod relay;
pub mod replace;
pub mod security;
pub mod sla;
pub mod staked_relayers;
pub mod timestamp;
pub mod tokens;
pub mod utility;
Expand All @@ -19,9 +19,9 @@ pub use module_btc_relay::{BtcAddress, BtcPublicKey, RichBlockHeader, MAIN_CHAIN
pub use module_issue::{IssueRequest, IssueRequestStatus};
pub use module_redeem::{RedeemRequest, RedeemRequestStatus};
pub use module_refund::RefundRequest;
pub use module_relay::Error as RelayError;
pub use module_replace::{ReplaceRequest, ReplaceRequestStatus};
pub use module_security::{ErrorCode, StatusCode};
pub use module_staked_relayers::Error as StakedRelayersError;
pub use module_vault_registry::{Vault, VaultStatus};

pub use sp_core::{H160, H256, U256};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ use substrate_subxt::balances::Balances;
use substrate_subxt_proc_macro::{module, Call, Event};

#[module]
pub trait StakedRelayers: Core + Balances {}
pub trait Relay: Core + Balances {}

#[derive(Clone, Debug, PartialEq, Call, Encode)]
pub struct ReportVaultTheftCall<'a, T: StakedRelayers> {
pub struct ReportVaultTheftCall<'a, T: Relay> {
pub vault_id: &'a T::AccountId,
pub merkle_proof: &'a [u8],
pub raw_tx: &'a [u8],
}

#[derive(Clone, Debug, Eq, PartialEq, Event, Decode)]
pub struct VaultTheftEvent<T: StakedRelayers> {
pub struct VaultTheftEvent<T: Relay> {
pub vault_id: T::AccountId,
pub txid: T::H256Le,
}

#[derive(Clone, Debug, PartialEq, Call, Encode)]
pub struct InitializeCall<T: StakedRelayers> {
pub struct InitializeCall<T: Relay> {
pub _runtime: PhantomData<T>,
pub raw_block_header: RawBlockHeader,
pub block_height: BitcoinBlockHeight,
}

#[derive(Clone, Debug, PartialEq, Call, Encode)]
pub struct StoreBlockHeaderCall<T: StakedRelayers> {
pub struct StoreBlockHeaderCall<T: Relay> {
pub _runtime: PhantomData<T>,
pub raw_block_header: RawBlockHeader,
}
10 changes: 5 additions & 5 deletions runtime/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use substrate_subxt::{
use tokio::{sync::RwLock, time::delay_for};

use crate::{
btc_relay::*, conn::*, exchange_rate_oracle::*, fee::*, issue::*, pallets::*, redeem::*, refund::*, replace::*,
retry::*, security::*, staked_relayers::*, timestamp::*, tokens::*, types::*, utility::*, vault_registry::*,
AccountId, BlockNumber, CurrencyId, Error, InterBtcRuntime, BTC_RELAY_MODULE, STABLE_BITCOIN_CONFIRMATIONS,
btc_relay::*, conn::*, exchange_rate_oracle::*, fee::*, issue::*, pallets::*, redeem::*, refund::*, relay::*,
replace::*, retry::*, security::*, timestamp::*, tokens::*, types::*, utility::*, vault_registry::*, AccountId,
BlockNumber, CurrencyId, Error, InterBtcRuntime, BTC_RELAY_MODULE, STABLE_BITCOIN_CONFIRMATIONS,
STABLE_PARACHAIN_CONFIRMATIONS,
};

Expand Down Expand Up @@ -682,7 +682,7 @@ impl ExchangeRateOraclePallet for InterBtcParachain {
}

#[async_trait]
pub trait StakedRelayerPallet {
pub trait RelayPallet {
async fn report_vault_theft(&self, vault_id: &AccountId, merkle_proof: &[u8], raw_tx: &[u8]) -> Result<(), Error>;

async fn is_transaction_invalid(&self, vault_id: &AccountId, raw_tx: &[u8]) -> Result<bool, Error>;
Expand All @@ -695,7 +695,7 @@ pub trait StakedRelayerPallet {
}

#[async_trait]
impl StakedRelayerPallet for InterBtcParachain {
impl RelayPallet for InterBtcParachain {
/// Submit extrinsic to report vault theft, consumer should
/// first check `is_transaction_invalid` to ensure this call
/// succeeds.
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use super::{
BtcAddress, BtcPublicKey, BtcRelayPallet, CollateralBalancesPallet, ExchangeRateOraclePallet, FixedPointNumber,
FixedU128, ReplacePallet, SecurityPallet, StakedRelayerPallet, StatusCode, VaultRegistryPallet,
FixedU128, RelayPallet, ReplacePallet, SecurityPallet, StatusCode, VaultRegistryPallet,
};
use crate::{exchange_rate_oracle::SetExchangeRateEvent, integration::*, InterBtcRuntime};
use module_bitcoin::{
Expand Down
8 changes: 4 additions & 4 deletions vault/src/relay/issuing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::Error;
use async_trait::async_trait;
use runtime::{BtcRelayPallet, H256Le, InterBtcParachain, RawBlockHeader, StakedRelayerPallet};
use runtime::{BtcRelayPallet, H256Le, InterBtcParachain, RawBlockHeader, RelayPallet};

#[async_trait]
pub trait Issuing {
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Issuing for InterBtcParachain {
}

async fn initialize(&self, header: Vec<u8>, height: u32) -> Result<(), Error> {
StakedRelayerPallet::initialize_btc_relay(self, encode_raw_header(header)?, height)
RelayPallet::initialize_btc_relay(self, encode_raw_header(header)?, height)
.await
.map_err(Into::into)
}
Expand All @@ -75,14 +75,14 @@ impl Issuing for InterBtcParachain {
{
return Ok(());
}
StakedRelayerPallet::store_block_header(self, raw_block_header)
RelayPallet::store_block_header(self, raw_block_header)
.await
.map_err(Into::into)
}

#[tracing::instrument(name = "submit_block_header_batch", skip(self, headers))]
async fn submit_block_header_batch(&self, headers: Vec<Vec<u8>>) -> Result<(), Error> {
StakedRelayerPallet::store_block_headers(
RelayPallet::store_block_headers(
self,
headers
.iter()
Expand Down
10 changes: 5 additions & 5 deletions vault/src/vaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use futures::stream::{iter, StreamExt};
use runtime::{
pallets::vault_registry::{RegisterAddressEvent, RegisterVaultEvent},
AccountId, BtcAddress, BtcRelayPallet, Error as RuntimeError, H256Le, InterBtcParachain, InterBtcRuntime,
InterBtcVault, StakedRelayerPallet, VaultRegistryPallet,
InterBtcVault, RelayPallet, VaultRegistryPallet,
};
use service::Error as ServiceError;
use sp_core::crypto::Ss58Codec;
Expand Down Expand Up @@ -36,7 +36,7 @@ impl Vaults {
}
}

pub async fn report_vault_thefts<P: StakedRelayerPallet + BtcRelayPallet, B: BitcoinCoreApi + Clone>(
pub async fn report_vault_thefts<P: RelayPallet + BtcRelayPallet, B: BitcoinCoreApi + Clone>(
bitcoin_core: B,
btc_parachain: P,
btc_height: u32,
Expand All @@ -51,14 +51,14 @@ pub async fn report_vault_thefts<P: StakedRelayerPallet + BtcRelayPallet, B: Bit
}
}

pub struct VaultTheftMonitor<P: StakedRelayerPallet + BtcRelayPallet, B: BitcoinCoreApi + Clone> {
pub struct VaultTheftMonitor<P: RelayPallet + BtcRelayPallet, B: BitcoinCoreApi + Clone> {
bitcoin_core: B,
btc_parachain: P,
btc_height: u32,
vaults: Arc<Vaults>,
}

impl<P: StakedRelayerPallet + BtcRelayPallet, B: BitcoinCoreApi + Clone> VaultTheftMonitor<P, B> {
impl<P: RelayPallet + BtcRelayPallet, B: BitcoinCoreApi + Clone> VaultTheftMonitor<P, B> {
pub fn new(bitcoin_core: B, btc_parachain: P, btc_height: u32, vaults: Arc<Vaults>) -> Self {
Self {
bitcoin_core,
Expand Down Expand Up @@ -193,7 +193,7 @@ mod tests {
Provider {}

#[async_trait]
pub trait StakedRelayerPallet {
pub trait RelayPallet {
async fn report_vault_theft(
&self,
vault_id: &AccountId,
Expand Down
6 changes: 3 additions & 3 deletions vault/tests/relayer_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use futures::{
pin_mut, Future, FutureExt, SinkExt, StreamExt,
};
use runtime::{
pallets::staked_relayers::*,
pallets::relay::*,
substrate_subxt::{Event, PairSigner},
BtcAddress, BtcRelayPallet, ErrorCode, ExchangeRateOraclePallet, FeePallet, FixedPointNumber, FixedU128, H256Le,
InterBtcParachain, InterBtcRuntime, IssuePallet, RedeemPallet, ReplacePallet, StakedRelayerPallet, StatusCode,
UtilFuncs, VaultRegistryPallet,
InterBtcParachain, InterBtcRuntime, IssuePallet, RedeemPallet, RelayPallet, ReplacePallet, StatusCode, UtilFuncs,
VaultRegistryPallet,
};
use sp_core::H160;
use sp_keyring::AccountKeyring;
Expand Down
Loading

0 comments on commit 76caa1f

Please sign in to comment.