Skip to content

Commit

Permalink
Merge branch 'main' into chore/post-ru-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wischli authored Oct 26, 2023
2 parents 8882a31 + 90d3cf9 commit b77fdc7
Show file tree
Hide file tree
Showing 19 changed files with 1,429 additions and 272 deletions.
2 changes: 2 additions & 0 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ fc-mapping-sync = { git = "https://github.com/PureStake/frontier", default-featu
fc-rpc = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.38" }
fc-rpc-core = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.38" }
fp-consensus = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.38" }
fp-rpc = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.38" }
fp-evm = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.38" }
fp-rpc = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.38" }
fp-storage = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.38" }
pallet-evm = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.38" }

Expand Down
9 changes: 5 additions & 4 deletions pallets/liquidity-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ pub mod pallet {
BalanceRatio = Self::BalanceRatio,
PoolId = Self::PoolId,
TrancheId = Self::TrancheId,
Moment = Seconds,
>;

/// The source of truth for investment permissions.
Expand Down Expand Up @@ -452,9 +453,8 @@ pub mod pallet {
// TODO(future): Once we diverge from 1-to-1 conversions for foreign and pool
// currencies, this price must be first converted into the currency_id and then
// re-denominated to 18 decimals (i.e. `Ratio` precision)
let price = T::TrancheTokenPrice::get(pool_id, tranche_id)
.ok_or(Error::<T>::MissingTranchePrice)?
.price;
let price_value = T::TrancheTokenPrice::get(pool_id, tranche_id)
.ok_or(Error::<T>::MissingTranchePrice)?;

// Check that the registered asset location matches the destination
match Self::try_get_wrapped_token(&currency_id)? {
Expand All @@ -474,7 +474,8 @@ pub mod pallet {
pool_id,
tranche_id,
currency,
price,
price: price_value.price,
computed_at: price_value.last_updated,
},
)?;

Expand Down
8 changes: 7 additions & 1 deletion pallets/liquidity-pools/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ where
tranche_id: TrancheId,
currency: u128,
price: Ratio,
/// The timestamp at which the price was computed
computed_at: Seconds,
},
/// Whitelist an address for the specified pair of pool and tranche token on
/// the target domain.
Expand Down Expand Up @@ -449,13 +451,15 @@ impl<
tranche_id,
currency,
price,
computed_at,
} => encoded_message(
self.call_type(),
vec![
encode_be(pool_id),
tranche_id.encode(),
encode_be(currency),
encode_be(price),
computed_at.to_be_bytes().to_vec(),
],
),
Message::UpdateMember {
Expand Down Expand Up @@ -751,6 +755,7 @@ impl<
tranche_id: decode::<16, _, _>(input)?,
currency: decode_be_bytes::<16, _, _>(input)?,
price: decode_be_bytes::<16, _, _>(input)?,
computed_at: decode_be_bytes::<8, _, _>(input)?,
}),
6 => Ok(Self::UpdateMember {
pool_id: decode_be_bytes::<8, _, _>(input)?,
Expand Down Expand Up @@ -1025,8 +1030,9 @@ mod tests {
tranche_id: default_tranche_id(),
currency: TOKEN_ID,
price: Ratio::one(),
computed_at: 1698131924,
},
"050000000000000001811acd5b3f17c06841c7e41e9e04cb1b0000000000000000000000000eb5ec7b00000000000000000de0b6b3a7640000",
"050000000000000001811acd5b3f17c06841c7e41e9e04cb1b0000000000000000000000000eb5ec7b00000000000000000de0b6b3a76400000000000065376fd4",
)
}

Expand Down
24 changes: 1 addition & 23 deletions runtime/altair/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,9 @@ mod asset_registry {
use sp_std::{vec, vec::Vec};
use xcm::{v3::prelude::*, VersionedMultiLocation};

pub const ALTAIR_ASSET_LOC_COUNT: u32 = 5;
pub const ALTAIR_ASSET_METADATA_COUNT: u32 = 5;

pub struct AltairAssets;
impl runtime_common::migrations::asset_registry_xcmv3::AssetsToMigrate for AltairAssets {
fn get_assets_to_migrate(
loc_count: u32,
meta_count: u32,
) -> Vec<(
CurrencyId,
orml_asset_registry::AssetMetadata<Balance, CustomMetadata>,
)> {
match (loc_count, meta_count) {
(loc, meta)
if (loc, meta) == (ALTAIR_ASSET_LOC_COUNT, ALTAIR_ASSET_METADATA_COUNT) =>
{
Self::get_altair_assets()
}
_ => vec![],
}
}
}

impl AltairAssets {
pub fn get_altair_assets() -> Vec<(
fn get_assets_to_migrate() -> Vec<(
CurrencyId,
orml_asset_registry::AssetMetadata<Balance, CustomMetadata>,
)> {
Expand Down
6 changes: 4 additions & 2 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ homepage = "https://centrifuge.io/"
repository = "https://github.com/centrifuge/centrifuge-chain"

[dependencies]
hex-literal = { version = "0.3.4", default-features = false }
serde = { version = "1.0.119" }
smallvec = "1.6.1"
hex-literal = { version = "0.3.4", default-features = false }

# Substrate dependencies
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
Expand Down Expand Up @@ -76,7 +76,7 @@ log = "0.4"
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }

[dev-dependencies]
cfg-mocks = { path = "../../libs/mocks", features = ["runtime-benchmarks", "std"] }
cfg-mocks = { path = "../../libs/mocks" }
pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.38" }

Expand Down Expand Up @@ -157,6 +157,7 @@ runtime-benchmarks = [
"xcm-executor/runtime-benchmarks",
"orml-asset-registry/runtime-benchmarks",
"polkadot-parachain/runtime-benchmarks",
"cfg-mocks/runtime-benchmarks",
]

on-chain-release-build = [
Expand Down Expand Up @@ -190,4 +191,5 @@ try-runtime = [
"pallet-investments/try-runtime",
"parachain-info/try-runtime",
"orml-asset-registry/try-runtime",
"cfg-mocks/try-runtime",
]
69 changes: 36 additions & 33 deletions runtime/common/src/migrations/asset_registry_xcmv3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ impl<
// Complexity: 2 reads
let (loc_count, meta_count) = Self::get_key_counts();

if Self::check_key_counts(loc_count, meta_count).is_err() {
return RocksDbWeight::get().reads(loc_count.saturating_add(meta_count).into());
}

// Complexity: O(loc_count) writes
let result = orml_asset_registry::LocationToAssetId::<T>::clear(loc_count, None);
match result.maybe_cursor {
Expand Down Expand Up @@ -96,28 +100,26 @@ impl<
result.loops,
);

let assets = Assets::get_assets_to_migrate();
log::info!(
"💎 AssetRegistryMultilocationToXCMV3: Starting migration of {:?} assets",
Assets::get_assets_to_migrate(loc_count, meta_count)
.iter()
.len()
assets.iter().len()
);

// Complexity: O(meta_count + loc_count) writes
Assets::get_assets_to_migrate(loc_count, meta_count)
.into_iter()
.for_each(|(asset_id, asset_metadata)| {
log::debug!("Migrating asset: {:?}", asset_id);
orml_asset_registry::Pallet::<T>::do_register_asset_without_asset_processor(
asset_metadata.into(),
asset_id.into(),
)
.map_err(|e| log::error!("Failed to register asset id: {:?}", e))
.ok();
});
assets.into_iter().for_each(|(asset_id, asset_metadata)| {
log::debug!("Migrating asset: {:?}", asset_id);
orml_asset_registry::Pallet::<T>::do_register_asset_without_asset_processor(
asset_metadata.into(),
asset_id.into(),
)
.map_err(|e| log::error!("Failed to register asset id: {:?}", e))
.ok();
});

log::info!("💎 AssetRegistryMultilocationToXCMV3: on_runtime_upgrade: completed!");
RocksDbWeight::get().reads_writes(
2,
loc_count.saturating_add(meta_count).into(),
loc_count
.saturating_add(meta_count)
.saturating_mul(2)
Expand All @@ -130,19 +132,7 @@ impl<
log::info!("💎 AssetRegistryMultilocationToXCMV3: pre-upgrade: started");
let (loc_count, meta_count) = Self::get_key_counts();

match (loc_count, meta_count) {
(loc, meta)
if (loc, meta) == (EXPECTED_MAINNET_LOC_COUNT, EXPECTED_MAINNET_META_COUNT) =>
{
Ok(())
}
(loc, meta)
if (loc, meta) == (EXPECTED_TESTNET_LOC_COUNT, EXPECTED_TESTNET_META_COUNT) =>
{
Ok(())
}
_ => Err("💎 AssetRegistryMultilocationToXCMV3: Unexpected counters"),
}?;
Self::check_key_counts(loc_count, meta_count)?;

log::info!("💎 AssetRegistryMultilocationToXCMV3: pre-upgrade: done");
Ok((loc_count, meta_count).encode())
Expand Down Expand Up @@ -185,7 +175,7 @@ impl<
{
fn get_key_counts() -> (u32, u32) {
// let loc_count =
// orml_asset_registry::LocationToAssetId::<T>::iter_keys().count() as u32;
// orml_asset_registry::LocationToAssetId::<T>::iter_keys().count() as u32;
// let meta_count = orml_asset_registry::Metadata::<T>::iter_keys().count() as
// u32;
let loc_count = Self::count_storage_keys(
Expand All @@ -206,6 +196,22 @@ impl<
(loc_count, meta_count)
}

fn check_key_counts(loc_count: u32, meta_count: u32) -> Result<(), &'static str> {
match (loc_count, meta_count) {
(loc, meta)
if (loc, meta) == (EXPECTED_MAINNET_LOC_COUNT, EXPECTED_MAINNET_META_COUNT) =>
{
Ok(())
}
(loc, meta)
if (loc, meta) == (EXPECTED_TESTNET_LOC_COUNT, EXPECTED_TESTNET_META_COUNT) =>
{
Ok(())
}
_ => Err("💎 AssetRegistryMultilocationToXCMV3: Unexpected counters"),
}
}

pub fn count_storage_keys(prefix: &[u8]) -> u32 {
let mut count = 0;
let mut next_key = prefix.to_vec();
Expand All @@ -225,10 +231,7 @@ impl<
}

pub trait AssetsToMigrate {
fn get_assets_to_migrate(
loc_count: u32,
meta_count: u32,
) -> Vec<(
fn get_assets_to_migrate() -> Vec<(
CurrencyId,
orml_asset_registry::AssetMetadata<Balance, CustomMetadata>,
)>;
Expand Down
17 changes: 9 additions & 8 deletions runtime/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,35 @@ frame-benchmarking = { git = "https://github.com/paritytech/substrate", optional
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }
pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
pallet-democracy = { git = "https://github.com/paritytech//substrate", rev = "bcff60a227d455d95b4712b6cb356ce56b1ff672" }
pallet-preimage = { git = "https://github.com/paritytech//substrate", rev = "bcff60a227d455d95b4712b6cb356ce56b1ff672" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }
pallet-uniques = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }
pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }

pallet-uniques = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }

## Substrate-Primitives
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
#sp-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
fp-self-contained = { git = "https://github.com/PureStake/frontier", branch = "moonbeam-polkadot-v0.9.38" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-consensus-slots = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
fp-self-contained = { git = "https://github.com/PureStake/frontier", branch = "moonbeam-polkadot-v0.9.38" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }

## Substrate-Client
node-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
#sc-consensus-uncles = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
Expand All @@ -67,8 +68,8 @@ rococo-runtime = { git = "https://github.com/paritytech/polkadot", branch = "rel
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" }

# Cumulus
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" }
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" }
cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" }
cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" }

Expand Down Expand Up @@ -119,8 +120,8 @@ pallet-order-book = { path = "../../pallets/order-book" }
pallet-permissions = { path = "../../pallets/permissions" }
pallet-pool-registry = { path = "../../pallets/pool-registry" }
pallet-pool-system = { path = "../../pallets/pool-system" }
pallet-rewards = { path = "../../pallets/rewards" }
pallet-restricted-tokens = { path = "../../pallets/restricted-tokens" }
pallet-rewards = { path = "../../pallets/rewards" }

pallet-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
pallet-xcm-transactor = { git = "https://github.com/PureStake/moonbeam", default-features = false, rev = "00b3e3d97806e889b02e1bcb4b69e65433dd805d" }
Expand Down
Loading

0 comments on commit b77fdc7

Please sign in to comment.