Skip to content

Commit

Permalink
Merge pull request #320 from gregdhill/chore/runtime-1.18.0
Browse files Browse the repository at this point in the history
chore: upgrade to runtime 1.18.0
  • Loading branch information
sander2 authored Jul 29, 2022
2 parents bc4c0a5 + a921dc6 commit 85a4be1
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 195 deletions.
131 changes: 36 additions & 95 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 @@ -35,7 +35,7 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-

[dependencies.interbtc-bitcoin]
git = "https://github.com/interlay/interbtc"
rev = "83454651807743e0a590ddee4c7b2e1a520a37c7"
rev = "2ddb5eba6fdb42125805bf15d8a4caf30556e0ab"
package = "bitcoin"
optional = true

Expand Down
10 changes: 5 additions & 5 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,27 @@ bitcoin = { path = "../bitcoin"}

# Dependencies for the testing utils for integration tests
tempdir = { version = "0.3.7", optional = true }
interbtc = { package = "interbtc-standalone", git = "https://github.com/interlay/interbtc", rev = "83454651807743e0a590ddee4c7b2e1a520a37c7", optional = true }
interbtc = { package = "interbtc-standalone", git = "https://github.com/interlay/interbtc", rev = "2ddb5eba6fdb42125805bf15d8a4caf30556e0ab", optional = true }
rand = { version = "0.7", optional = true }

[dependencies.primitives]
git = "https://github.com/interlay/interbtc"
rev = "83454651807743e0a590ddee4c7b2e1a520a37c7"
rev = "2ddb5eba6fdb42125805bf15d8a4caf30556e0ab"
package = "interbtc-primitives"

[dependencies.module-bitcoin]
git = "https://github.com/interlay/interbtc"
rev = "83454651807743e0a590ddee4c7b2e1a520a37c7"
rev = "2ddb5eba6fdb42125805bf15d8a4caf30556e0ab"
package = "bitcoin"

[dependencies.module-btc-relay]
git = "https://github.com/interlay/interbtc"
rev = "83454651807743e0a590ddee4c7b2e1a520a37c7"
rev = "2ddb5eba6fdb42125805bf15d8a4caf30556e0ab"
package = "btc-relay"

[dependencies.module-oracle-rpc-runtime-api]
git = "https://github.com/interlay/interbtc"
rev = "83454651807743e0a590ddee4c7b2e1a520a37c7"
rev = "2ddb5eba6fdb42125805bf15d8a4caf30556e0ab"
package = "module-oracle-rpc-runtime-api"

[dev-dependencies]
Expand Down
Binary file modified runtime/metadata-parachain-interlay-testnet.scale
Binary file not shown.
Binary file modified runtime/metadata-parachain-interlay.scale
Binary file not shown.
Binary file modified runtime/metadata-parachain-kintsugi-testnet.scale
Binary file not shown.
Binary file modified runtime/metadata-parachain-kintsugi.scale
Binary file not shown.
Binary file modified runtime/metadata-standalone.scale
Binary file not shown.
4 changes: 1 addition & 3 deletions runtime/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use jsonrpsee::core::Error as JsonRpseeError;

use crate::{metadata::DispatchError, types::*, BTC_RELAY_MODULE, ISSUE_MODULE, RELAY_MODULE, SYSTEM_MODULE};
use crate::{metadata::DispatchError, types::*, BTC_RELAY_MODULE, ISSUE_MODULE, SYSTEM_MODULE};
use codec::Error as CodecError;
use jsonrpsee::{client_transport::ws::WsHandshakeError, core::error::Error as RequestError, types::error::CallError};
use prometheus::Error as PrometheusError;
Expand Down Expand Up @@ -30,8 +30,6 @@ pub enum Error {
VaultNotFound,
#[error("Vault has been liquidated")]
VaultLiquidated,
#[error("Vault has stolen BTC")]
VaultCommittedTheft,
#[error("Channel closed unexpectedly")]
ChannelClosed,
#[error("Cannot replace existing transaction")]
Expand Down
1 change: 0 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ pub const BLOCK_INTERVAL: Duration = Duration::from_millis(MILLISECS_PER_BLOCK);

pub const BTC_RELAY_MODULE: &str = "BTCRelay";
pub const ISSUE_MODULE: &str = "Issue";
pub const RELAY_MODULE: &str = "Relay";
pub const SECURITY_MODULE: &str = "Security";
pub const SYSTEM_MODULE: &str = "System";

Expand Down
38 changes: 7 additions & 31 deletions runtime/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ cfg_if::cfg_if! {
const DEFAULT_SPEC_NAME: &str = "interbtc-standalone";
pub const SS58_PREFIX: u16 = 42;
} else if #[cfg(feature = "parachain-metadata-interlay")] {
const DEFAULT_SPEC_VERSION: RangeInclusive<u32> = 1017000..=1017000;
const DEFAULT_SPEC_VERSION: RangeInclusive<u32> = 1018000..=1018000;
const DEFAULT_SPEC_NAME: &str = "interlay-parachain";
pub const SS58_PREFIX: u16 = 2032;
} else if #[cfg(feature = "parachain-metadata-kintsugi")] {
const DEFAULT_SPEC_VERSION: RangeInclusive<u32> = 1017000..=1017000;
const DEFAULT_SPEC_VERSION: RangeInclusive<u32> = 1018000..=1018000;
const DEFAULT_SPEC_NAME: &str = "kintsugi-parachain";
pub const SS58_PREFIX: u16 = 2092;
} else if #[cfg(feature = "parachain-metadata-interlay-testnet")] {
const DEFAULT_SPEC_VERSION: RangeInclusive<u32> = 1017000..=1017000;
const DEFAULT_SPEC_VERSION: RangeInclusive<u32> = 1018000..=1018000;
const DEFAULT_SPEC_NAME: &str = "testnet-interlay";
pub const SS58_PREFIX: u16 = 2032;
} else if #[cfg(feature = "parachain-metadata-kintsugi-testnet")] {
const DEFAULT_SPEC_VERSION: RangeInclusive<u32> = 1017000..=1017000;
const DEFAULT_SPEC_VERSION: RangeInclusive<u32> = 1018000..=1018000;
// fun workaround to migrate allowed spec name
struct ThisOrThat<'a>(&'a str, &'a str);
impl<'a> PartialEq<String> for ThisOrThat<'a> {
Expand Down Expand Up @@ -1016,7 +1016,7 @@ impl RelayPallet for InterBtcParachain {
self.with_unique_signer(|signer| async move {
self.api
.tx()
.relay()
.btc_relay()
.initialize(header.clone(), height)
.sign_and_submit_then_watch_default(&signer)
.await
Expand All @@ -1034,7 +1034,7 @@ impl RelayPallet for InterBtcParachain {
self.with_unique_signer(|signer| async move {
self.api
.tx()
.relay()
.btc_relay()
.store_block_header(header.clone())
.sign_and_submit_then_watch_default(&signer)
.await
Expand All @@ -1052,7 +1052,7 @@ impl RelayPallet for InterBtcParachain {
headers
.into_iter()
.map(|raw_block_header| {
EncodedCall::Relay(metadata::runtime_types::relay::pallet::Call::store_block_header {
EncodedCall::BTCRelay(metadata::runtime_types::btc_relay::pallet::Call::store_block_header {
raw_block_header,
})
})
Expand Down Expand Up @@ -1510,8 +1510,6 @@ pub trait VaultRegistryPallet {

async fn register_public_key(&self, public_key: BtcPublicKey) -> Result<(), Error>;

async fn register_address(&self, vault_id: &VaultId, btc_address: BtcAddress) -> Result<(), Error>;

async fn get_required_collateral_for_wrapped(
&self,
amount_btc: u128,
Expand All @@ -1535,18 +1533,13 @@ impl VaultRegistryPallet for InterBtcParachain {
/// # 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: &VaultId) -> Result<InterBtcVault, Error> {
let head = self.get_latest_block_hash().await?;
match self.api.storage().vault_registry().vaults(vault_id, head).await? {
Some(InterBtcVault {
status: VaultStatus::Liquidated,
..
}) => Err(Error::VaultLiquidated),
Some(InterBtcVault {
status: VaultStatus::CommittedTheft,
..
}) => Err(Error::VaultCommittedTheft),
Some(vault) if &vault.id == vault_id => Ok(vault),
_ => Err(Error::VaultNotFound),
}
Expand Down Expand Up @@ -1666,23 +1659,6 @@ impl VaultRegistryPallet for InterBtcParachain {
Ok(())
}

/// Register a new BTC address, useful for change addresses.
///
/// # Arguments
/// * `btc_address` - the new btc address of the vault
async fn register_address(&self, vault_id: &VaultId, btc_address: BtcAddress) -> Result<(), Error> {
self.with_unique_signer(|signer| async move {
self.api
.tx()
.vault_registry()
.register_address(vault_id.currencies.clone(), btc_address)
.sign_and_submit_then_watch_default(&signer)
.await
})
.await?;
Ok(())
}

/// Custom RPC that calculates the exact collateral required to cover the BTC amount.
///
/// # Arguments
Expand Down
3 changes: 1 addition & 2 deletions runtime/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ mod metadata_aliases {
};
pub type InterBtcVault =
metadata::runtime_types::vault_registry::types::Vault<AccountId, BlockNumber, Balance, CurrencyId, FixedU128>;
pub use metadata::runtime_types::vault_registry::types::Wallet;
pub type InterBtcRichBlockHeader = metadata::runtime_types::btc_relay::types::RichBlockHeader<BlockNumber>;
pub type BitcoinBlockHeight = u32;

Expand Down Expand Up @@ -80,7 +79,7 @@ mod metadata_aliases {
pub use metadata::runtime_types::{
btc_relay::pallet::Error as BtcRelayPalletError, frame_system::pallet::Error as SystemPalletError,
issue::pallet::Error as IssuePalletError, redeem::pallet::Error as RedeemPalletError,
relay::pallet::Error as RelayPalletError, security::pallet::Error as SecurityPalletError,
security::pallet::Error as SecurityPalletError,
};

pub use metadata::runtime_types::bitcoin::types::H256Le;
Expand Down
13 changes: 3 additions & 10 deletions vault/src/collateral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ mod tests {
use super::*;
use async_trait::async_trait;
use runtime::{
AccountId, Balance, BtcAddress, BtcPublicKey, CurrencyId, Error as RuntimeError, InterBtcVault, Token, Wallet,
DOT, IBTC,
AccountId, Balance, BtcAddress, BtcPublicKey, CurrencyId, Error as RuntimeError, InterBtcVault, Token, DOT,
IBTC,
};

macro_rules! assert_ok {
Expand Down Expand Up @@ -178,7 +178,6 @@ mod tests {
async fn withdraw_collateral(&self, vault_id: &VaultId, amount: u128) -> Result<(), RuntimeError>;
async fn get_public_key(&self) -> Result<Option<BtcPublicKey>, RuntimeError>;
async fn register_public_key(&self, public_key: BtcPublicKey) -> Result<(), RuntimeError>;
async fn register_address(&self, vault_id: &VaultId, btc_address: BtcAddress) -> Result<(), RuntimeError>;
async fn get_required_collateral_for_wrapped(&self, amount_btc: u128, collateral_currency: CurrencyId) -> Result<u128, RuntimeError>;
async fn get_required_collateral_for_vault(&self, vault_id: VaultId) -> Result<u128, RuntimeError>;
async fn get_vault_total_collateral(&self, vault_id: VaultId) -> Result<u128, RuntimeError>;
Expand Down Expand Up @@ -211,9 +210,6 @@ mod tests {
parachain_rpc.expect_get_vault().returning(move |x| {
Ok(InterBtcVault {
id: x.clone(),
wallet: Wallet {
addresses: Default::default(),
},
status: VaultStatus::Active(true),
banned_until: None,
secure_collateral_threshold: None,
Expand Down Expand Up @@ -342,10 +338,7 @@ mod tests {
parachain_rpc.expect_get_vault().returning(move |x| {
Ok(InterBtcVault {
id: x.clone(),
wallet: Wallet {
addresses: Default::default(),
},
status: VaultStatus::CommittedTheft,
status: VaultStatus::Liquidated,
banned_until: None,
secure_collateral_threshold: None,
to_be_issued_tokens: 0,
Expand Down
2 changes: 0 additions & 2 deletions vault/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub enum Error {
InsufficientFunds,
#[error("Failed to load or create bitcoin wallet: {0}")]
WalletInitializationFailure(BitcoinError),
#[error("Transaction contains more than one return-to-self uxto")]
TooManyReturnToSelfAddresses,
#[error("Mathematical operation caused an overflow")]
ArithmeticOverflow,
#[error("Mathematical operation caused an underflow")]
Expand Down
26 changes: 0 additions & 26 deletions vault/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,31 +244,6 @@ impl Request {
let recipient = tx.recipient.clone();
tracing::info!("Sending bitcoin to {}", recipient);

let return_to_self_addresses = tx
.transaction
.extract_output_addresses()
.into_iter()
.filter(|x| x != &self.btc_address)
.collect::<Vec<_>>();

// register return-to-self address if it exists
match return_to_self_addresses.as_slice() {
[] => {} // no return-to-self
[address] => {
// one return-to-self address, make sure it is registered
let wallet = parachain_rpc.get_vault(&vault_id).await?.wallet;
if !wallet.addresses.contains(address) {
let readable_address = address
.encode_str(btc_rpc.network())
.unwrap_or(format!("{:?}", address));
tracing::info!("Registering address {:?}", readable_address);
parachain_rpc.register_address(&vault_id, *address).await?;
tracing::debug!("Successfully registered address {:?}", readable_address);
}
}
_ => return Err(Error::TooManyReturnToSelfAddresses),
};

let txid = btc_rpc.send_transaction(tx).await?;

loop {
Expand Down Expand Up @@ -601,7 +576,6 @@ mod tests {
async fn withdraw_collateral(&self, vault_id: &VaultId, amount: u128) -> Result<(), RuntimeError>;
async fn get_public_key(&self) -> Result<Option<BtcPublicKey>, RuntimeError>;
async fn register_public_key(&self, public_key: BtcPublicKey) -> Result<(), RuntimeError>;
async fn register_address(&self, vault_id: &VaultId, btc_address: BtcAddress) -> Result<(), RuntimeError>;
async fn get_required_collateral_for_wrapped(&self, amount_btc: u128, collateral_currency: CurrencyId) -> Result<u128, RuntimeError>;
async fn get_required_collateral_for_vault(&self, vault_id: VaultId) -> Result<u128, RuntimeError>;
async fn get_vault_total_collateral(&self, vault_id: VaultId) -> Result<u128, RuntimeError>;
Expand Down
6 changes: 1 addition & 5 deletions vault/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ mod tests {
use runtime::{
AccountId, AssetMetadata, Balance, BlockNumber, BtcAddress, BtcPublicKey, CurrencyId, Error as RuntimeError,
ErrorCode, InterBtcIssueRequest, InterBtcRedeemRequest, InterBtcRefundRequest, InterBtcReplaceRequest,
InterBtcVault, RequestIssueEvent, StatusCode, Token, VaultId, VaultStatus, Wallet, DOT, H256, IBTC, INTR,
InterBtcVault, RequestIssueEvent, StatusCode, Token, VaultId, VaultStatus, DOT, H256, IBTC, INTR,
};
use std::collections::BTreeSet;

Expand Down Expand Up @@ -763,7 +763,6 @@ mod tests {
async fn withdraw_collateral(&self, vault_id: &VaultId, amount: u128) -> Result<(), RuntimeError>;
async fn get_public_key(&self) -> Result<Option<BtcPublicKey>, RuntimeError>;
async fn register_public_key(&self, public_key: BtcPublicKey) -> Result<(), RuntimeError>;
async fn register_address(&self, vault_id: &VaultId, btc_address: BtcAddress) -> Result<(), RuntimeError>;
async fn get_required_collateral_for_wrapped(&self, amount_btc: u128, collateral_currency: CurrencyId) -> Result<u128, RuntimeError>;
async fn get_required_collateral_for_vault(&self, vault_id: VaultId) -> Result<u128, RuntimeError>;
async fn get_vault_total_collateral(&self, vault_id: VaultId) -> Result<u128, RuntimeError>;
Expand Down Expand Up @@ -958,9 +957,6 @@ mod tests {
parachain_rpc.expect_get_vault().returning(move |x| {
Ok(InterBtcVault {
id: x.clone(),
wallet: Wallet {
addresses: Default::default(),
},
status: VaultStatus::Active(true),
banned_until: None,
secure_collateral_threshold: None,
Expand Down
1 change: 0 additions & 1 deletion vault/src/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ mod tests {
async fn withdraw_collateral(&self, vault_id: &VaultId, amount: u128) -> Result<(), RuntimeError>;
async fn get_public_key(&self) -> Result<Option<BtcPublicKey>, RuntimeError>;
async fn register_public_key(&self, public_key: BtcPublicKey) -> Result<(), RuntimeError>;
async fn register_address(&self, vault_id: &VaultId, btc_address: BtcAddress) -> Result<(), RuntimeError>;
async fn get_required_collateral_for_wrapped(&self, amount_btc: u128, collateral_currency: CurrencyId) -> Result<u128, RuntimeError>;
async fn get_required_collateral_for_vault(&self, vault_id: VaultId) -> Result<u128, RuntimeError>;
async fn get_vault_total_collateral(&self, vault_id: VaultId) -> Result<u128, RuntimeError>;
Expand Down
10 changes: 1 addition & 9 deletions vault/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,6 @@ impl<BCA: BitcoinCoreApi + Clone + Send + Sync + 'static> VaultIdManager<BCA> {
vault_id.pretty_print()
);
}
Err(Error::RuntimeError(RuntimeError::VaultCommittedTheft)) => {
tracing::error!(
"[{}] Vault committed theft -- not going to process events for this vault.",
vault_id.pretty_print()
);
}
Ok(_) => {
self.add_vault_id(vault_id.clone()).await?;
}
Expand Down Expand Up @@ -763,9 +757,7 @@ impl VaultService {
let vault_id = self.get_vault_id(*collateral_currency);

match is_vault_registered(&self.btc_parachain, &vault_id).await {
Err(Error::RuntimeError(RuntimeError::VaultLiquidated))
| Err(Error::RuntimeError(RuntimeError::VaultCommittedTheft))
| Ok(true) => {
Err(Error::RuntimeError(RuntimeError::VaultLiquidated)) | Ok(true) => {
tracing::info!(
"[{}] Not registering vault -- already registered",
vault_id.pretty_print()
Expand Down
4 changes: 0 additions & 4 deletions vault/tests/vault_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,6 @@ async fn test_refund_succeeds() {
.find_transaction(|tx| tx.get_op_return() == Some(refund_request.refund_id))
.await
.unwrap();

// make the vault register the input used in that transaction
let input_address = tx.extract_input_addresses::<BtcAddress>()[0];
assert_ok!(vault_provider.register_address(&vault_id, input_address).await);
};

test_service(refund_service, fut_user).await;
Expand Down

0 comments on commit 85a4be1

Please sign in to comment.