Skip to content

Commit

Permalink
Modify RelayEncoder precompile to accept HRMP Cancel variant (moonbea…
Browse files Browse the repository at this point in the history
…m-foundation#2179)

* changed Cancel variant name

* added Cancel variant to RelayEncoder

* fixed parachain files within runtimes xcm_mock
  • Loading branch information
Agusrodri authored and imstar15 committed May 16, 2023
1 parent 6061042 commit 74e049b
Show file tree
Hide file tree
Showing 15 changed files with 2,810 additions and 2,443 deletions.
2 changes: 1 addition & 1 deletion pallets/xcm-transactor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ pub mod pallet {
HrmpOperation::Cancel {
channel_id,
open_requests,
} => T::HrmpEncoder::hrmp_encode_call(HrmpAvailableCalls::CancelOpenChannel(
} => T::HrmpEncoder::hrmp_encode_call(HrmpAvailableCalls::CancelOpenRequest(
channel_id,
open_requests,
)),
Expand Down
2 changes: 1 addition & 1 deletion pallets/xcm-transactor/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl HrmpEncodeCall for MockHrmpEncoder {
Ok(RelayCall::Hrmp(HrmpCall::Accept()).encode())
}
HrmpAvailableCalls::CloseChannel(_) => Ok(RelayCall::Hrmp(HrmpCall::Close()).encode()),
HrmpAvailableCalls::CancelOpenChannel(_, _) => {
HrmpAvailableCalls::CancelOpenRequest(_, _) => {
Ok(RelayCall::Hrmp(HrmpCall::Cancel()).encode())
}
}
Expand Down
10 changes: 10 additions & 0 deletions precompiles/relay-encoder/RelayEncoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,14 @@ interface RelayEncoder {
external
pure
returns (bytes memory result);

/// @dev Encode 'hrmp.cancel_open_request' relay call
/// @custom:selector 8fd5ce49
/// @param sender: The paraId of the sender
/// @param recipient: The paraId of the recipient
/// @param openRequests: The number of open requests
function encodeHrmpCancelOpenRequest(uint32 sender, uint32 recipient, uint32 openRequests)
external
pure
returns (bytes memory result);
}
27 changes: 27 additions & 0 deletions precompiles/relay-encoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,33 @@ where
.into();
Ok(encoded)
}

#[precompile::public("encodeHrmpCancelOpenRequest(uint32,uint32,uint32)")]
#[precompile::public("encode_hrmp_cancel_open_request(uint32,uint32,uint32)")]
#[precompile::view]
fn encode_hrmp_cancel_open_request(
handle: &mut impl PrecompileHandle,
sender: u32,
recipient: u32,
open_requests: u32,
) -> EvmResult<UnboundedBytes> {
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;

let encoded = RelayRuntime::hrmp_encode_call(HrmpAvailableCalls::CancelOpenRequest(
relay_chain::v2::HrmpChannelId {
sender: sender.into(),
recipient: recipient.into(),
},
open_requests,
))
.map_err(|_| {
RevertReason::custom("Non-implemented hrmp encoding for transactor")
.in_field("transactor")
})?
.as_slice()
.into();
Ok(encoded)
}
}

pub fn u256_to_relay_amount(value: U256) -> EvmResult<relay_chain::Balance> {
Expand Down
2 changes: 1 addition & 1 deletion precompiles/relay-encoder/src/test_relay_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl xcm_primitives::HrmpEncodeCall for TestEncoder {
xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => {
Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode())
}
xcm_primitives::HrmpAvailableCalls::CancelOpenChannel(a, b) => {
xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenChannel(a.clone(), b.clone())).encode())
}
}
Expand Down
2 changes: 1 addition & 1 deletion primitives/xcm/src/transactor_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum HrmpAvailableCalls {
InitOpenChannel(ParaId, u32, u32),
AcceptOpenChannel(ParaId),
CloseChannel(HrmpChannelId),
CancelOpenChannel(HrmpChannelId, u32),
CancelOpenRequest(HrmpChannelId, u32),
}

// Trait that the ensures we can encode a call with utility functions.
Expand Down
6 changes: 3 additions & 3 deletions runtime/moonbase/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ pub enum HrmpCall {
#[codec(index = 2u8)]
CloseChannel(HrmpChannelId),
#[codec(index = 6u8)]
CancelOpenChannel(HrmpChannelId, u32),
CancelOpenRequest(HrmpChannelId, u32),
}

#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
Expand Down Expand Up @@ -1010,8 +1010,8 @@ impl xcm_primitives::HrmpEncodeCall for MockHrmpEncoder {
xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => {
Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode())
}
xcm_primitives::HrmpAvailableCalls::CancelOpenChannel(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenChannel(a.clone(), b.clone())).encode())
xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenRequest(a.clone(), b.clone())).encode())
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/moonbeam/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ pub enum HrmpCall {
#[codec(index = 2u8)]
CloseChannel(HrmpChannelId),
#[codec(index = 6u8)]
CancelOpenChannel(HrmpChannelId, u32),
CancelOpenRequest(HrmpChannelId, u32),
}

#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
Expand Down Expand Up @@ -980,8 +980,8 @@ impl xcm_primitives::HrmpEncodeCall for MockHrmpEncoder {
xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => {
Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode())
}
xcm_primitives::HrmpAvailableCalls::CancelOpenChannel(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenChannel(a.clone(), b.clone())).encode())
xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenRequest(a.clone(), b.clone())).encode())
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/moonriver/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ pub enum HrmpCall {
#[codec(index = 2u8)]
CloseChannel(HrmpChannelId),
#[codec(index = 6u8)]
CancelOpenChannel(HrmpChannelId, u32),
CancelOpenRequest(HrmpChannelId, u32),
}

#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
Expand Down Expand Up @@ -988,8 +988,8 @@ impl xcm_primitives::HrmpEncodeCall for MockHrmpEncoder {
xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => {
Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode())
}
xcm_primitives::HrmpAvailableCalls::CancelOpenChannel(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenChannel(a.clone(), b.clone())).encode())
xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenRequest(a.clone(), b.clone())).encode())
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions runtime/relay-encoder/src/kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub enum HrmpCall {
#[codec(index = 2u8)]
CloseChannel(HrmpChannelId),
#[codec(index = 6u8)]
CancelOpenChannel(HrmpChannelId, u32),
CancelOpenRequest(HrmpChannelId, u32),
}

pub struct KusamaEncoder;
Expand Down Expand Up @@ -115,8 +115,8 @@ impl xcm_primitives::HrmpEncodeCall for KusamaEncoder {
xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => {
Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode())
}
xcm_primitives::HrmpAvailableCalls::CancelOpenChannel(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenChannel(a.clone(), b.clone())).encode())
xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenRequest(a.clone(), b.clone())).encode())
}
}
}
Expand Down Expand Up @@ -580,7 +580,7 @@ mod tests {

assert_eq!(
<KusamaEncoder as xcm_primitives::HrmpEncodeCall>::hrmp_encode_call(
xcm_primitives::HrmpAvailableCalls::CancelOpenChannel(
xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(
channel_id.clone(),
open_requests
)
Expand Down
8 changes: 4 additions & 4 deletions runtime/relay-encoder/src/polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub enum HrmpCall {
#[codec(index = 2u8)]
CloseChannel(HrmpChannelId),
#[codec(index = 6u8)]
CancelOpenChannel(HrmpChannelId, u32),
CancelOpenRequest(HrmpChannelId, u32),
}

pub struct PolkadotEncoder;
Expand Down Expand Up @@ -117,8 +117,8 @@ impl xcm_primitives::HrmpEncodeCall for PolkadotEncoder {
xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => {
Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode())
}
xcm_primitives::HrmpAvailableCalls::CancelOpenChannel(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenChannel(a.clone(), b.clone())).encode())
xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenRequest(a.clone(), b.clone())).encode())
}
}
}
Expand Down Expand Up @@ -582,7 +582,7 @@ mod tests {

assert_eq!(
<PolkadotEncoder as xcm_primitives::HrmpEncodeCall>::hrmp_encode_call(
xcm_primitives::HrmpAvailableCalls::CancelOpenChannel(
xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(
channel_id.clone(),
open_requests
)
Expand Down
8 changes: 4 additions & 4 deletions runtime/relay-encoder/src/westend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub enum HrmpCall {
#[codec(index = 2u8)]
CloseChannel(HrmpChannelId),
#[codec(index = 6u8)]
CancelOpenChannel(HrmpChannelId, u32),
CancelOpenRequest(HrmpChannelId, u32),
}

pub struct WestendEncoder;
Expand Down Expand Up @@ -116,8 +116,8 @@ impl xcm_primitives::HrmpEncodeCall for WestendEncoder {
xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => {
Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode())
}
xcm_primitives::HrmpAvailableCalls::CancelOpenChannel(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenChannel(a.clone(), b.clone())).encode())
xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => {
Ok(RelayCall::Hrmp(HrmpCall::CancelOpenRequest(a.clone(), b.clone())).encode())
}
}
}
Expand Down Expand Up @@ -580,7 +580,7 @@ mod tests {

assert_eq!(
<WestendEncoder as xcm_primitives::HrmpEncodeCall>::hrmp_encode_call(
xcm_primitives::HrmpAvailableCalls::CancelOpenChannel(
xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(
channel_id.clone(),
open_requests
)
Expand Down
27 changes: 25 additions & 2 deletions tests/contracts/compiled/RelayEncoder.json

Large diffs are not rendered by default.

Loading

0 comments on commit 74e049b

Please sign in to comment.