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 call index from the cross-chain interface #961

Merged
merged 131 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 130 commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
fe22333
Support reserve deposit for control operations
yrong Aug 29, 2023
2d28b2b
Pay as agent_owner
yrong Aug 29, 2023
ffa44a7
Add AgentAccountDescription converter
yrong Aug 31, 2023
80a750c
Merge branch 'main' into ron/oak-sno-624
yrong Aug 31, 2023
33f6ab8
Revamp smoke test config fee for control operations
yrong Aug 31, 2023
6cc82e5
Add SovereignAccountOf to runtime config
yrong Aug 31, 2023
3e5e9ff
Merge branch 'main' into ron/oak-sno-624
yrong Sep 4, 2023
e9be7d4
Fix format
yrong Sep 4, 2023
e2946ee
More refactor
yrong Sep 4, 2023
cb6f6aa
Configurable base fee plus static per-operation fee multiplier
yrong Sep 5, 2023
614e429
Update smoke test accordingly
yrong Sep 5, 2023
ec7814b
Update cumulus
yrong Sep 5, 2023
2f939cd
Merge branch 'main' into ron/oak-sno-624
yrong Sep 7, 2023
e777666
Fix format
yrong Sep 7, 2023
a2ffa5d
Remove call index from the cross-chain interface
yrong Sep 8, 2023
b1854ca
Update test fixture
yrong Sep 8, 2023
b114082
Fix format
yrong Sep 8, 2023
8830961
Merge branch 'main' into ron/oak-sno-624
yrong Sep 11, 2023
3fef8b4
Configurable dispatch_gas
yrong Sep 12, 2023
d02f041
Update relayer
yrong Sep 12, 2023
aac06fc
Merge branch 'ron/oak-23' into ron/oak-sno-624
yrong Sep 12, 2023
353c21e
Refactor to charge fee for outbound commands
yrong Sep 13, 2023
7caed3e
More refactor
yrong Sep 13, 2023
77ebfb6
Update cargo.lock
yrong Sep 13, 2023
1694b38
Chore
yrong Sep 13, 2023
58fa4d7
Fix clippy
yrong Sep 13, 2023
82d2ed5
Chore format
yrong Sep 13, 2023
aca2309
Update cumulus
yrong Sep 13, 2023
0b1d744
Reward message relayer
yrong Sep 13, 2023
6aa80cc
Fix smoke tests
yrong Sep 13, 2023
755d50f
Set default dispatch gas
yrong Sep 14, 2023
63b7221
Fix for origin of control operations & Charge fee without gas cost
yrong Sep 14, 2023
a473f06
Update parachain/pallets/outbound-queue/src/lib.rs
yrong Sep 14, 2023
50a0b79
Update parachain/pallets/outbound-queue/src/lib.rs
yrong Sep 14, 2023
c834c49
Specify the fee for xcm export & upfront charge for create_agent only
yrong Sep 14, 2023
b3522cd
Remove deprecated config
yrong Sep 15, 2023
b6abf68
Fix format
yrong Sep 15, 2023
f976e1e
Set decent default for outbound configs
yrong Sep 15, 2023
16f89d2
Make create-channel upfront charged & start template relayer for othe…
yrong Sep 15, 2023
febc0a1
Disable base fee for sudo operations
yrong Sep 15, 2023
7477cc1
Merge branch 'main' into ron/oak-sno-624
yrong Sep 15, 2023
5fbbfb9
Update gas cost
yrong Sep 18, 2023
86c3ffc
Fix cargo tarpaulin
yrong Sep 18, 2023
488491b
Update RegisterCallIndex as runtime const
yrong Sep 19, 2023
ca06b35
Merge branch 'main' into ron/oak-30
yrong Sep 19, 2023
fdee5c2
Fix cargo tarpaulin
yrong Sep 18, 2023
dc4d898
Update cumulus
yrong Sep 22, 2023
0c4921c
Update cumulus
yrong Sep 22, 2023
3b784b2
Add OutboundFeeConfig
yrong Sep 22, 2023
4399ed0
Fund template sovereign account
yrong Sep 22, 2023
b477887
Rename as agent_location
yrong Sep 22, 2023
8870326
Fix clippy
yrong Sep 22, 2023
460e10d
Validate ticket with gas check
yrong Sep 22, 2023
448963a
Move the charge logic to control pallet & More refactor
yrong Sep 22, 2023
e8308f8
Fix clippy
yrong Sep 22, 2023
9d2594c
Disable format temporarily for less distraction
yrong Sep 22, 2023
f2350c1
Refactor estimate by message
yrong Sep 22, 2023
19e03e7
More refactor
yrong Sep 23, 2023
24e1ec1
Fix clippy
yrong Sep 23, 2023
2bcd6be
Introduce VersionedMessageToXcmConverter
yrong Sep 23, 2023
66fa4aa
Fix clippy
yrong Sep 23, 2023
8fbb705
More cleanup
yrong Sep 26, 2023
f531c71
Fix test & Remove format
yrong Sep 26, 2023
7bfae29
Add estimate rpc
yrong Sep 26, 2023
3175e02
Estimate by command index & Add smoke test accordingly
yrong Sep 27, 2023
0e61abe
Fix upgrade test
yrong Sep 27, 2023
1d160b0
Initialize with more funds & Add script for fund
yrong Sep 27, 2023
8455abc
Update contracts/test/Gateway.t.sol
yrong Sep 27, 2023
b46f889
Rename event as OutboundFeeConfigUpdated
yrong Sep 27, 2023
98aafba
Merge branch 'ron/oak-sno-624' of https://github.com/Snowfork/snowbri…
yrong Sep 27, 2023
6aed8d0
For comment
yrong Sep 27, 2023
c8cd91e
Chore
yrong Sep 27, 2023
309ce5a
Refactor with structured OriginInfo
yrong Sep 27, 2023
4a8730d
Clean derive macros
yrong Sep 27, 2023
dd6a21f
Leave enough space for upgrade
yrong Sep 27, 2023
a6649d8
Runtime api for compute_fee_reward
yrong Sep 27, 2023
6dfe502
Use TreasuryAccount more specific
yrong Sep 28, 2023
aab0ec0
Improve comments
yrong Sep 28, 2023
2db5125
Improve smoke test
yrong Sep 28, 2023
d8ced19
Update smoketest/src/helper.rs
yrong Sep 28, 2023
cde7c8d
Update smoketest/src/helper.rs
yrong Sep 28, 2023
9d99217
Some cleanup
yrong Sep 28, 2023
586b8b8
Update cumulus
yrong Sep 28, 2023
ef3395e
Merge branch 'ron/oak-sno-624' of https://github.com/Snowfork/snowbri…
yrong Sep 28, 2023
378ca74
Test for fee with config changed
yrong Sep 28, 2023
9a905a4
A thin shell wrapper funding agent
yrong Sep 28, 2023
05abc2c
More tests
yrong Sep 28, 2023
a664567
foo
vgeddes Sep 29, 2023
154c906
foo
vgeddes Oct 2, 2023
4a1da14
fix tests
vgeddes Oct 2, 2023
6a93a29
compilation works
vgeddes Oct 3, 2023
7223158
Update cumulus
vgeddes Oct 3, 2023
bf777fd
improve benchmarks
vgeddes Oct 3, 2023
77a0cb3
fix benchmarks
vgeddes Oct 4, 2023
8017f96
update cumulus
vgeddes Oct 4, 2023
d6eeedf
fix clippy errors
vgeddes Oct 4, 2023
3a0ef5b
Update Cargo.lock
vgeddes Oct 4, 2023
cdd5576
update cumulus
vgeddes Oct 4, 2023
f986743
Remove obsolete fee estimation code
vgeddes Oct 4, 2023
dc0d5c9
Use full polkadot repository URL in Cargo.toml
vgeddes Oct 4, 2023
7c6f69a
Update cumulus fix for smoke test
yrong Oct 5, 2023
670632b
Fix format
yrong Oct 5, 2023
f868e29
Merge branch 'vincent/outbound-fees' into ron/oak-30
yrong Oct 5, 2023
8df7f90
Introduce VersionedMessageToXcmConverter
yrong Sep 23, 2023
e09444b
Fix xcm instruction
yrong Oct 5, 2023
6b29295
Chore
yrong Oct 5, 2023
2a9633b
remove relayers for template node
vgeddes Oct 7, 2023
707593d
Improve the implementation of the control pallet
vgeddes Oct 8, 2023
2be28f9
fix broken bindings generator for smoketests
vgeddes Oct 8, 2023
71c1159
update cumulus submodule
vgeddes Oct 8, 2023
2b84f6b
Update benchmarks
vgeddes Oct 8, 2023
41ecd8a
Fix clippy
yrong Oct 9, 2023
8a00986
Cleanup
yrong Oct 9, 2023
84bed37
Revert "remove relayers for template node"
yrong Oct 9, 2023
3365c1b
Fix agent id
yrong Oct 9, 2023
f5f1bd8
Merge branch 'vincent/outbound-fees' of https://github.com/Snowfork/s…
yrong Oct 9, 2023
18a90eb
Update inbound MessageConverter
yrong Oct 9, 2023
3f924b1
Add runtime api for generating agent ids
vgeddes Oct 9, 2023
6e9dfd3
Improve benchmarking code
vgeddes Oct 9, 2023
f0309c9
Fix for smoke test to create agent
yrong Oct 10, 2023
5c80f91
Merge branch 'vincent/outbound-fees' into ron/oak-30
yrong Oct 10, 2023
2526725
Update cumulus
yrong Oct 10, 2023
a0a3ac2
mark some config items as pallet constants
vgeddes Oct 10, 2023
1d75ffc
Some polish
yrong Oct 10, 2023
3904a32
Polish
yrong Oct 10, 2023
12824ba
Minor improvements to reward logic in Gateway
vgeddes Oct 10, 2023
40e60f2
Improve Gateway tests
vgeddes Oct 10, 2023
58558e5
update cumulus submodule
vgeddes Oct 10, 2023
4b5a4b7
Merge branch 'vincent/outbound-fees' into ron/oak-30
yrong Oct 11, 2023
194c7dd
Merge branch 'main' into ron/oak-30
yrong Oct 17, 2023
6d37669
Fix convert
yrong Oct 17, 2023
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
7 changes: 2 additions & 5 deletions contracts/src/Assets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,14 @@ library Assets {

/// @dev Enqueues a create native token message to substrate.
/// @param token The ERC20 token address.
function registerToken(address token, bytes2 createTokenCallID)
external
returns (bytes memory payload, uint256 extraFee)
{
yrong marked this conversation as resolved.
Show resolved Hide resolved
function registerToken(address token) external returns (bytes memory payload, uint256 extraFee) {
AssetsStorage.Layout storage $ = AssetsStorage.layout();

if (!token.isContract()) {
revert InvalidToken();
}

payload = SubstrateTypes.RegisterToken(address(this), token, createTokenCallID);
payload = SubstrateTypes.RegisterToken(address(this), token);
extraFee = $.registerTokenFee;

emit TokenRegistrationSent(token);
Expand Down
3 changes: 1 addition & 2 deletions contracts/src/DeployScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ contract DeployScript is Script {
bridgeHubParaID,
bridgeHubAgentID,
assetHubParaID,
assetHubAgentID,
bytes2(vm.envBytes("CREATE_CALL_INDEX"))
assetHubAgentID
);

bytes memory initParams = abi.encode(
Expand Down
9 changes: 3 additions & 6 deletions contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ contract Gateway is IGateway, IInitializable {
// AssetHub
ParaID internal immutable ASSET_HUB_PARA_ID;
bytes32 internal immutable ASSET_HUB_AGENT_ID;
bytes2 internal immutable CREATE_TOKEN_CALL_ID;

// Fixed amount of gas used outside the gas metering in submitInbound
uint256 BASE_GAS_USED = 31000;
Expand Down Expand Up @@ -75,8 +74,7 @@ contract Gateway is IGateway, IInitializable {
ParaID bridgeHubParaID,
bytes32 bridgeHubAgentID,
ParaID assetHubParaID,
bytes32 assetHubAgentID,
bytes2 createTokenCallID
bytes32 assetHubAgentID
) {
if (
bridgeHubParaID == ParaID.wrap(0) || bridgeHubAgentID == 0 || assetHubParaID == ParaID.wrap(0)
Expand All @@ -92,7 +90,6 @@ contract Gateway is IGateway, IInitializable {
BRIDGE_HUB_AGENT_ID = bridgeHubAgentID;
ASSET_HUB_PARA_ID = assetHubParaID;
ASSET_HUB_AGENT_ID = assetHubAgentID;
CREATE_TOKEN_CALL_ID = createTokenCallID;
}

/// @dev Submit a message from Polkadot for verification and dispatch
Expand Down Expand Up @@ -418,7 +415,7 @@ contract Gateway is IGateway, IInitializable {

// Register a token on AssetHub
function registerToken(address token) external payable {
(bytes memory payload, uint256 extraFee) = Assets.registerToken(token, CREATE_TOKEN_CALL_ID);
(bytes memory payload, uint256 extraFee) = Assets.registerToken(token);

_submitOutbound(ASSET_HUB_PARA_ID, payload, extraFee);
}
Expand Down Expand Up @@ -528,7 +525,7 @@ contract Gateway is IGateway, IInitializable {
}

/// @dev Define the dust threshold as the minimum cost to transfer ether between accounts
function dustThreshold() view internal returns (uint256) {
function dustThreshold() internal view returns (uint256) {
return 21000 * tx.gasprice;
}

Expand Down
9 changes: 2 additions & 7 deletions contracts/src/SubstrateTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,13 @@ library SubstrateTypes {
* `NativeTokensMessage::Create`
*/
// solhint-disable-next-line func-name-mixedcase
function RegisterToken(address gateway, address token, bytes2 createCallIndex)
internal
view
returns (bytes memory)
{
yrong marked this conversation as resolved.
Show resolved Hide resolved
function RegisterToken(address gateway, address token) internal view returns (bytes memory) {
return bytes.concat(
bytes1(0x00),
ScaleCodec.encodeU64(uint64(block.chainid)),
bytes1(0x00),
SubstrateTypes.H160(gateway),
SubstrateTypes.H160(token),
createCallIndex
SubstrateTypes.H160(token)
);
}

Expand Down
35 changes: 21 additions & 14 deletions contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ contract GatewayTest is Test {
bridgeHubParaID,
bridgeHubAgentID,
assetHubParaID,
assetHubAgentID,
bytes2(0x3500)
assetHubAgentID
);
gateway = new GatewayProxy(
address(gatewayLogic),
Expand Down Expand Up @@ -158,7 +157,9 @@ contract GatewayTest is Test {

hoax(relayer, 1 ether);
IGateway(address(gateway)).submitInbound(
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward), proof, makeMockProof()
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward),
proof,
makeMockProof()
);
}

Expand All @@ -169,14 +170,18 @@ contract GatewayTest is Test {

hoax(relayer, 1 ether);
IGateway(address(gateway)).submitInbound(
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward), proof, makeMockProof()
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward),
proof,
makeMockProof()
);

// try to replay the message
vm.expectRevert(Gateway.InvalidNonce.selector);
hoax(relayer, 1 ether);
IGateway(address(gateway)).submitInbound(
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward), proof, makeMockProof()
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward),
proof,
makeMockProof()
);
}

Expand All @@ -200,7 +205,9 @@ contract GatewayTest is Test {

hoax(relayer, 1 ether);
IGateway(address(gateway)).submitInbound(
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward), proof, makeMockProof()
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward),
proof,
makeMockProof()
);
}

Expand All @@ -221,7 +228,9 @@ contract GatewayTest is Test {

uint256 startGas = gasleft();
IGateway(address(gateway)).submitInbound(
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward), proof, makeMockProof()
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward),
proof,
makeMockProof()
);
uint256 endGas = gasleft();
uint256 estimatedActualRefundAmount = (startGas - endGas) * tx.gasprice;
Expand All @@ -245,7 +254,9 @@ contract GatewayTest is Test {

hoax(relayer, 1 ether);
IGateway(address(gateway)).submitInbound(
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward), proof, makeMockProof()
InboundMessage(bridgeHubParaID, 1, command, params, maxDispatchGas, maxRefund, reward),
proof,
makeMockProof()
);

assertEq(address(bridgeHubAgent).balance, 0 ether);
Expand Down Expand Up @@ -525,9 +536,7 @@ contract GatewayTest is Test {
emit TokenRegistrationSent(address(token));

vm.expectEmit(true, false, false, false);
emit OutboundMessageAccepted(
assetHubParaID, 1, SubstrateTypes.RegisterToken(address(gateway), address(token), bytes2(0x3500))
);
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.RegisterToken(address(gateway), address(token)));

IGateway(address(gateway)).registerToken{value: 2 ether}(address(token));
}
Expand All @@ -537,9 +546,7 @@ contract GatewayTest is Test {
emit TokenRegistrationSent(address(token));

vm.expectEmit(true, false, false, false);
emit OutboundMessageAccepted(
assetHubParaID, 1, SubstrateTypes.RegisterToken(address(gateway), address(token), bytes2(0x3500))
);
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.RegisterToken(address(gateway), address(token)));

uint256 totalFee = baseFee + registerNativeTokenFee;
uint256 balanceBefore = address(this).balance;
Expand Down
15 changes: 2 additions & 13 deletions contracts/test/mocks/GatewayMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,8 @@ contract GatewayMock is Gateway {
ParaID bridgeHubParaID,
bytes32 bridgeHubHubAgentID,
ParaID assetHubParaID,
bytes32 assetHubHubAgentID,
bytes2 createTokenCallID
)
Gateway(
beefyClient,
agentExecutor,
bridgeHubParaID,
bridgeHubHubAgentID,
assetHubParaID,
assetHubHubAgentID,
createTokenCallID
)
{}
bytes32 assetHubHubAgentID
) Gateway(beefyClient, agentExecutor, bridgeHubParaID, bridgeHubHubAgentID, assetHubParaID, assetHubHubAgentID) {}

function agentExecutePublic(bytes calldata params) external {
this.agentExecute(params);
Expand Down
2 changes: 1 addition & 1 deletion cumulus
1 change: 1 addition & 0 deletions parachain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions parachain/pallets/control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ pub mod pallet {
///
/// Fee required: Yes
///
/// This extrinsic is permissionless, so a fee is charged to prevent spamming and pay
/// for execution costs on the remote side.
///
/// The message is sent over the bridge on BridgeHub's own channel to the Gateway.
///
/// - `origin`: Must be `MultiLocation`
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::create_channel())]
Expand Down
5 changes: 4 additions & 1 deletion parachain/pallets/inbound-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "master"
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master", default-features = false }

xcm = { git = "https://github.com/paritytech/polkadot.git", branch = "master", default-features = false }
xcm-builder = { git = "https://github.com/paritytech/polkadot.git", branch = "master", default-features = false }
bp-runtime = { git = "https://github.com/Snowfork/cumulus.git", branch = "snowbridge", default-features = false }

snowbridge-core = { path = "../../primitives/core", default-features = false }
Expand Down Expand Up @@ -63,6 +64,7 @@ std = [
"snowbridge-router-primitives/std",
"ethabi/std",
"xcm/std",
"xcm-builder/std",
"bp-runtime/std",
]
runtime-benchmarks = [
Expand All @@ -72,5 +74,6 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"hex-literal",
"rlp",
"snowbridge-beacon-primitives"
"snowbridge-beacon-primitives",
"xcm-builder/runtime-benchmarks",
]
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn make_create_message() -> InboundQueueTest {
receipts_root: hex!("a2686fe1aa2f66ada774373ced7952f3591a7830b9161eec5d16149747253779").into(),
},
message: Message {
data: hex!("f8fb94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000034000f000000000000000057a2d4ff0c3866d96556884bf09fecdd7ccd530c87d1f7fdfee7f651fabc8bfcb6e086c278b77a7d3500000000000000000000000000").to_vec(),
data: hex!("f8fb94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000032000f0000000000000000eda338e4dc46038493b885327842fd3e301cab3987d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000000000000000000000000000").to_vec(),
proof: Proof {
block_hash: hex!("565f5dc872af9351abd1ba4974753169a98f028ef2c2ef3bb6d4eea4c6519eac").into(),
tx_index: 0,
Expand Down
20 changes: 14 additions & 6 deletions parachain/pallets/inbound-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ use sp_core::H160;
use sp_runtime::traits::AccountIdConversion;
use sp_std::convert::TryFrom;
use xcm::v3::{
send_xcm, Junction::*, Junctions::*, MultiLocation, SendError as XcmpSendError, XcmHash,
send_xcm, Junction::*, Junctions::*, MultiLocation, SendError as XcmpSendError, SendXcm,
XcmHash,
};

use envelope::Envelope;
use snowbridge_core::{
inbound::{Message, Verifier},
ParaId,
};
use snowbridge_router_primitives::inbound;
use snowbridge_router_primitives::{
inbound,
inbound::{ConvertMessage, ConvertMessageError},
};
pub use weights::WeightInfo;

type BalanceOf<T> =
Expand All @@ -51,11 +55,9 @@ pub mod pallet {

use super::*;

use bp_runtime::{BasicOperatingMode, OwnedBridgeModule};
use frame_support::{pallet_prelude::*, traits::tokens::Preservation};
use frame_system::pallet_prelude::*;
use xcm::v3::SendXcm;

use bp_runtime::{BasicOperatingMode, OwnedBridgeModule};

#[pallet::pallet]
pub struct Pallet<T>(_);
Expand Down Expand Up @@ -87,6 +89,9 @@ pub mod pallet {
#[pallet::constant]
type GatewayAddress: Get<H160>;

/// Convert inbound message to XCM
type MessageConverter: ConvertMessage;
yrong marked this conversation as resolved.
Show resolved Hide resolved

#[cfg(feature = "runtime-benchmarks")]
type Helper: BenchmarkHelper<Self>;
}
Expand Down Expand Up @@ -126,6 +131,8 @@ pub mod pallet {
Send(SendError),
/// Operational mode errors
OperationalMode(bp_runtime::OwnedBridgeModuleError),
/// Message conversion error
ConvertMessage(ConvertMessageError),
}

#[derive(Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo, PalletError)]
Expand Down Expand Up @@ -218,7 +225,8 @@ pub mod pallet {

// Decode message into XCM
let xcm = match inbound::VersionedMessage::decode_all(&mut envelope.payload.as_ref()) {
Ok(inbound::VersionedMessage::V1(message_v1)) => message_v1.into(),
Ok(message) => T::MessageConverter::convert(message)
.map_err(|e| Error::<T>::ConvertMessage(e))?,
Err(_) => return Err(Error::<T>::InvalidPayload.into()),
};

Expand Down
Loading
Loading