Skip to content

Commit

Permalink
remove custom implementation for MaxEncodingLen
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Apr 5, 2024
1 parent 37afbc2 commit 332cb6b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 88 deletions.
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,14 +34,14 @@ 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]
lazy_static = { workspace = true }
cfg-types = { workspace = true, default-features = 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 @@ -147,7 +147,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 @@ -159,31 +159,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

0 comments on commit 332cb6b

Please sign in to comment.