Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom implementation for MaxEncodingLen #1800

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pallets/liquidity-pools-gateway/routers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ pallet-evm = { workspace = true }

# Custom crates
cfg-traits = { workspace = true }
cfg-types = { workspace = true }

# Local pallets
pallet-ethereum-transaction = { workspace = true }
pallet-liquidity-pools-gateway = { workspace = true }

[dev-dependencies]
cfg-types = { workspace = true, default-features = true }
lazy_static = { workspace = true }

cumulus-primitives-core = { workspace = true, default-features = true }
Expand All @@ -65,7 +65,6 @@ pallet-balances = { workspace = true, default-features = true }
default = ["std"]
std = [
"parity-scale-codec/std",
"cfg-types/std",
"cfg-traits/std",
"cfg-mocks/std",
"hex/std",
Expand Down
36 changes: 2 additions & 34 deletions pallets/liquidity-pools-gateway/routers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ use scale_info::TypeInfo;
use sp_core::{bounded::BoundedVec, ConstU32, H160, H256, U256};
use sp_runtime::traits::{BlakeTwo256, Hash};
use sp_std::{boxed::Box, marker::PhantomData, vec::Vec};
use staging_xcm::{
latest::{MultiLocation, OriginKind},
VersionedMultiLocation,
};
use staging_xcm::{latest::OriginKind, VersionedMultiLocation};

#[cfg(test)]
mod mock;
Expand Down Expand Up @@ -303,7 +300,7 @@ where

/// XcmDomain gathers all the required fields to build and send remote
/// calls to a specific XCM-based Domain.
#[derive(Debug, Encode, Decode, Clone, PartialEq, Eq, TypeInfo)]
#[derive(Debug, Encode, Decode, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
pub struct XcmDomain<CurrencyId> {
/// The XCM multilocation of the domain.
pub location: Box<VersionedMultiLocation>,
Expand Down Expand Up @@ -346,32 +343,3 @@ pub struct XcmTransactInfo {
pub max_weight: Weight,
pub transact_extra_weight_signed: Option<Weight>,
}

/// NOTE: Remove this custom implementation once the following underlying data
/// implements MaxEncodedLen:
/// * Polkadot Repo: xcm::VersionedMultiLocation
/// * PureStake Repo: pallet_xcm_transactor::Config<Self = T>::CurrencyId
impl<CurrencyId> MaxEncodedLen for XcmDomain<CurrencyId>
where
XcmDomain<CurrencyId>: Encode,
{
fn max_encoded_len() -> usize {
// The domain's `VersionedMultiLocation` (custom bound)
MultiLocation::max_encoded_len()
// From the enum wrapping of `VersionedMultiLocation` for the XCM domain location.
.saturating_add(1)
// From the enum wrapping of `VersionedMultiLocation` for the asset fee location.
.saturating_add(1)
// The ethereum xcm call index (default bound)
.saturating_add(BoundedVec::<
u8,
ConstU32<{ xcm_primitives::MAX_ETHEREUM_XCM_INPUT_SIZE }>,
>::max_encoded_len())
// The contract address (default bound)
.saturating_add(H160::max_encoded_len())
// The fee currency (custom bound)
.saturating_add(cfg_types::tokens::CurrencyId::max_encoded_len())
// The XcmTransactInfo
.saturating_add(XcmTransactInfo::max_encoded_len())
}
}
27 changes: 1 addition & 26 deletions pallets/liquidity-pools/src/routers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum Router<CurrencyId> {

/// XcmDomain gathers all the required fields to build and send remote
/// calls to a specific XCM-based Domain.
#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo)]
#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct XcmDomain<CurrencyId> {
/// the xcm multilocation of the domain
Expand All @@ -33,28 +33,3 @@ pub struct XcmDomain<CurrencyId> {
/// The max gas_limit we want to propose for a remote evm execution
pub max_gas_limit: u64,
}

// NOTE: Remove this custom implementation once the following underlying data
// implements MaxEncodedLen:
/// * Polkadot Repo: xcm::VersionedMultiLocation
/// * PureStake Repo: pallet_xcm_transactor::Config<Self = T>::CurrencyId
impl<CurrencyId> MaxEncodedLen for XcmDomain<CurrencyId>
where
XcmDomain<CurrencyId>: Encode,
{
fn max_encoded_len() -> usize {
// The domain's `VersionedMultiLocation` (custom bound)
staging_xcm::latest::MultiLocation::max_encoded_len()
// From the enum wrapping of `VersionedMultiLocation`
.saturating_add(1)
// The ethereum xcm call index (default bound)
.saturating_add(BoundedVec::<
u8,
ConstU32<{ xcm_primitives::MAX_ETHEREUM_XCM_INPUT_SIZE }>,
>::max_encoded_len())
// The contract address (default bound)
.saturating_add(H160::max_encoded_len())
// The fee currency (custom bound)
.saturating_add(cfg_types::tokens::CurrencyId::max_encoded_len())
}
}
27 changes: 1 addition & 26 deletions pallets/pool-system/src/pool_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub struct PoolParameters {
pub max_nav_age: Seconds,
}

#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct PoolChanges<Rate, StringLimit, MaxTranches>
where
StringLimit: Get<u32>,
Expand All @@ -160,31 +160,6 @@ where
pub max_nav_age: Change<Seconds>,
}

// NOTE: Can be removed once orml_traits::Change impls MaxEncodedLen
// https://github.com/open-web3-stack/open-runtime-module-library/pull/867
impl<Rate, StringLimit, MaxTranches> MaxEncodedLen for PoolChanges<Rate, StringLimit, MaxTranches>
where
StringLimit: Get<u32>,
MaxTranches: Get<u32>,
PoolChanges<Rate, StringLimit, MaxTranches>: Encode,
BoundedVec<TrancheUpdate<Rate>, MaxTranches>: MaxEncodedLen,
BoundedVec<TrancheMetadata<StringLimit>, MaxTranches>: MaxEncodedLen,
Seconds: MaxEncodedLen,
{
fn max_encoded_len() -> usize {
// The tranches (default bound)
BoundedVec::<TrancheUpdate<Rate>, MaxTranches>::max_encoded_len()
// The tranche metadata (default bound)
.saturating_add(
BoundedVec::<TrancheMetadata<StringLimit>, MaxTranches>::max_encoded_len(),
)
// The min epoc time and max nav age (default bounds)
.saturating_add(Seconds::max_encoded_len().saturating_mul(2))
// From the `Change` enum which wraps all four fields of Self
.saturating_add(4)
}
}

/// Information about the deposit that has been taken to create a pool
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
pub struct PoolDepositInfo<AccountId, Balance> {
Expand Down
Loading