Skip to content

Commit

Permalink
Merge pull request #149 from gregdhill/chore/upgrade-parachain
Browse files Browse the repository at this point in the history
chore: upgrade parachain to 0.8.0
  • Loading branch information
gregdhill authored Jul 14, 2021
2 parents 4488628 + 0f15129 commit 2caf0a1
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 1,368 deletions.
1,665 changes: 332 additions & 1,333 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 = "f556917a852d68e39005297a878acf72fbce0c68"
rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb"
package = "bitcoin"
optional = true

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ mod tests {
Block {
txdata: transactions.into_iter().map(dummy_tx).collect(),
header: BlockHeader {
version: 1,
version: 4,
bits: 0,
nonce: 0,
time: 0,
Expand Down
31 changes: 14 additions & 17 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ testing-utils = [
"substrate-subxt/client",
"substrate-subxt-client",
"tempdir",
"btc-parachain",
"btc-parachain-service",
"interbtc",
"bitcoin",
"rand",
]
Expand Down Expand Up @@ -50,69 +49,67 @@ 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 = "3db5ecbd1ca00ecc02d2e8a511aad77445ef0a33", optional = true }
tempdir = {version = "0.3.7", optional = true }
btc-parachain = { git = "https://github.com/interlay/interbtc", rev = "f556917a852d68e39005297a878acf72fbce0c68", features = ["aura-grandpa"], optional = true }
btc-parachain-service = { git = "https://github.com/interlay/interbtc", rev = "f556917a852d68e39005297a878acf72fbce0c68", features = ["aura-grandpa"], optional = true }
interbtc = { package = "interbtc-standalone", git = "https://github.com/interlay/interbtc", rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb", optional = true }
bitcoin = { path = "../bitcoin", optional = true }
rand = { version = "0.7", optional = true }

[dependencies.module-bitcoin]
git = "https://github.com/interlay/interbtc"
rev = "f556917a852d68e39005297a878acf72fbce0c68"
rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb"
package = "bitcoin"

[dependencies.module-refund]
git = "https://github.com/interlay/interbtc"
rev = "f556917a852d68e39005297a878acf72fbce0c68"
rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb"
package = "refund"

[dependencies.module-btc-relay]
git = "https://github.com/interlay/interbtc"
rev = "f556917a852d68e39005297a878acf72fbce0c68"
rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb"
package = "btc-relay"

[dependencies.module-security]
git = "https://github.com/interlay/interbtc"
rev = "f556917a852d68e39005297a878acf72fbce0c68"
rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb"
package = "security"

[dependencies.module-relay]
git = "https://github.com/interlay/interbtc"
rev = "f556917a852d68e39005297a878acf72fbce0c68"
rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb"
package = "relay"

[dependencies.module-vault-registry]
git = "https://github.com/interlay/interbtc"
rev = "f556917a852d68e39005297a878acf72fbce0c68"
rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb"
package = "vault-registry"

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

[dependencies.module-issue]
git = "https://github.com/interlay/interbtc"
rev = "f556917a852d68e39005297a878acf72fbce0c68"
rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb"
package = "issue"

[dependencies.module-redeem]
git = "https://github.com/interlay/interbtc"
rev = "f556917a852d68e39005297a878acf72fbce0c68"
rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb"
package = "redeem"

[dependencies.module-replace]
git = "https://github.com/interlay/interbtc"
rev = "f556917a852d68e39005297a878acf72fbce0c68"
rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb"
package = "replace"

[dependencies.module-exchange-rate-oracle]
git = "https://github.com/interlay/interbtc"
rev = "f556917a852d68e39005297a878acf72fbce0c68"
rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb"
package = "exchange-rate-oracle"

[dev-dependencies]
substrate-subxt-client = { git = "https://github.com/interlay/substrate-subxt", rev = "3db5ecbd1ca00ecc02d2e8a511aad77445ef0a33" }
btc-parachain = { git = "https://github.com/interlay/interbtc", rev = "f556917a852d68e39005297a878acf72fbce0c68", features = ["aura-grandpa"] }
btc-parachain-service = { git = "https://github.com/interlay/interbtc", rev = "f556917a852d68e39005297a878acf72fbce0c68", features = ["aura-grandpa"] }
interbtc = { package = "interbtc-standalone", git = "https://github.com/interlay/interbtc", rev = "39565ae0a5402a00dc1f222ea322a13303cab9fb" }
tempdir = "0.3.7"
env_logger = "0.8.3"
4 changes: 2 additions & 2 deletions runtime/src/integration/bitcoin_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl MockBitcoinCore {
transaction.clone(),
],
header: BlockHeader {
version: 2,
version: 4,
merkle_root: Default::default(),
bits: BlockHeader::compact_target_from_u256(&target),
nonce: 0,
Expand Down Expand Up @@ -183,7 +183,7 @@ impl MockBitcoinCore {
value: reward,
}],
lock_time: height,
version: 1,
version: 2,
}
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/src/integration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn default_provider_client(key: AccountKeyring) -> (SubxtClient, TempD
path: tmp.path().join("keystore"),
password: None,
},
chain_spec: btc_parachain::chain_spec::development_config(),
chain_spec: interbtc::chain_spec::development_config(),
role: Role::Authority(key),
telemetry: None,
wasm_method: WasmExecutionMethod::Compiled,
Expand All @@ -70,7 +70,7 @@ pub async fn default_provider_client(key: AccountKeyring) -> (SubxtClient, TempD
let mut service_config = config.into_service_config();
service_config.offchain_worker.enabled = true;

let (task_manager, rpc_handlers) = btc_parachain_service::new_full(service_config).unwrap();
let (task_manager, rpc_handlers) = interbtc::service::new_full(service_config).unwrap();
let client = SubxtClient::new(task_manager, rpc_handlers);

let root_provider = setup_provider(client.clone(), AccountKeyring::Alice).await;
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/pallets/vault_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct WithdrawCollateralEvent<T: VaultRegistry> {

#[derive(Clone, Debug, Eq, PartialEq, Store, Encode)]
pub struct VaultsStore<T: VaultRegistry> {
#[store(returns = Vault<T::AccountId, T::BlockNumber, T::Wrapped, T::Collateral, T::SignedFixedPoint>)]
#[store(returns = Vault<T::AccountId, T::BlockNumber, T::Wrapped, T::Collateral>)]
pub _runtime: PhantomData<T>,
pub account_id: T::AccountId,
}
Expand Down
15 changes: 15 additions & 0 deletions runtime/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,8 @@ pub trait VaultRegistryPallet {
async fn get_required_collateral_for_wrapped(&self, amount_btc: u128) -> Result<u128, Error>;

async fn get_required_collateral_for_vault(&self, vault_id: AccountId) -> Result<u128, Error>;

async fn get_vault_total_collateral(&self, vault_id: AccountId) -> Result<u128, Error>;
}

#[async_trait]
Expand Down Expand Up @@ -1368,6 +1370,19 @@ impl VaultRegistryPallet for InterBtcParachain {

Ok(result.amount)
}

async fn get_vault_total_collateral(&self, vault_id: AccountId) -> Result<u128, Error> {
let head = self.get_latest_block_hash().await?;
let result: BalanceWrapper<_> = self
.rpc_client
.request(
"vaultRegistry_getVaultTotalCollateral",
&[to_json_value(vault_id)?, to_json_value(head)?],
)
.await?;

Ok(result.amount)
}
}

#[async_trait]
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async fn test_btc_relay() {
let mut height = 0;

let block = BlockBuilder::new()
.with_version(2)
.with_version(4)
.with_coinbase(&address, 50, 3)
.with_timestamp(1588813835)
.mine(U256::from(2).pow(254.into()))
Expand All @@ -134,7 +134,7 @@ async fn test_btc_relay() {

let block = BlockBuilder::new()
.with_previous_hash(block_hash)
.with_version(2)
.with_version(4)
.with_coinbase(&address, 50, height - 1)
.with_timestamp(1588813835)
.mine(U256::from(2).pow(254.into()))
Expand Down
9 changes: 2 additions & 7 deletions runtime/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ pub type InterBtcBalance = <InterBtcRuntime as Core>::Balance;

pub type InterBtcBlock = SignedBlock<Block<InterBtcHeader, <InterBtcRuntime as System>::Extrinsic>>;

pub type InterBtcVault = Vault<
AccountId,
BlockNumber,
<InterBtcRuntime as Core>::Wrapped,
<InterBtcRuntime as Core>::Collateral,
<InterBtcRuntime as Core>::SignedFixedPoint,
>;
pub type InterBtcVault =
Vault<AccountId, BlockNumber, <InterBtcRuntime as Core>::Wrapped, <InterBtcRuntime as Core>::Collateral>;

pub type InterBtcIssueRequest =
IssueRequest<AccountId, BlockNumber, <InterBtcRuntime as Core>::Wrapped, <InterBtcRuntime as Core>::Collateral>;
Expand Down
8 changes: 6 additions & 2 deletions vault/src/collateral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn lock_required_collateral<P: VaultRegistryPallet + CollateralBalance
return Err(Error::RuntimeError(runtime::Error::VaultNotFound));
}

let actual_collateral = vault.backing_collateral;
let actual_collateral = parachain_rpc.get_vault_total_collateral(vault_id.clone()).await?;

let (required_collateral, maximum_collateral) = future::try_join(
async { Ok(parachain_rpc.get_required_collateral_for_vault(vault_id).await?) },
Expand Down Expand Up @@ -163,6 +163,7 @@ mod tests {
async fn register_address(&self, btc_address: BtcAddress) -> Result<(), RuntimeError>;
async fn get_required_collateral_for_wrapped(&self, amount_btc: u128) -> Result<u128, RuntimeError>;
async fn get_required_collateral_for_vault(&self, vault_id: AccountId) -> Result<u128, RuntimeError>;
async fn get_vault_total_collateral(&self, vault_id: AccountId) -> Result<u128, RuntimeError>;
}

#[async_trait]
Expand Down Expand Up @@ -191,12 +192,15 @@ mod tests {
parachain_rpc.expect_get_vault().returning(move |x| {
Ok(InterBtcVault {
id: x,
backing_collateral: actual,
status: VaultStatus::Active(true),
..Default::default()
})
});

parachain_rpc
.expect_get_vault_total_collateral()
.returning(move |_| Ok(actual));

parachain_rpc
}
#[tokio::test]
Expand Down
1 change: 1 addition & 0 deletions vault/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ mod tests {
async fn register_address(&self, btc_address: BtcAddress) -> Result<(), RuntimeError>;
async fn get_required_collateral_for_wrapped(&self, amount_btc: u128) -> Result<u128, RuntimeError>;
async fn get_required_collateral_for_vault(&self, vault_id: AccountId) -> Result<u128, RuntimeError>;
async fn get_vault_total_collateral(&self, vault_id: AccountId) -> Result<u128, RuntimeError>;
}

#[async_trait]
Expand Down
1 change: 1 addition & 0 deletions vault/src/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ mod tests {
async fn register_address(&self, btc_address: BtcAddress) -> Result<(), RuntimeError>;
async fn get_required_collateral_for_wrapped(&self, amount_btc: u128) -> Result<u128, RuntimeError>;
async fn get_required_collateral_for_vault(&self, vault_id: AccountId) -> Result<u128, RuntimeError>;
async fn get_vault_total_collateral(&self, vault_id: AccountId) -> Result<u128, RuntimeError>;
}

#[async_trait]
Expand Down

0 comments on commit 2caf0a1

Please sign in to comment.