This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Reward relayer on AH for E->S transfer #165
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,15 +41,14 @@ use envelope::Envelope; | |
use frame_support::{ | ||
traits::{ | ||
fungible::{Inspect, Mutate}, | ||
tokens::{Fortitude, Preservation}, | ||
tokens::{Fortitude, Precision, Preservation}, | ||
}, | ||
weights::WeightToFee, | ||
PalletError, | ||
}; | ||
use frame_system::ensure_signed; | ||
use scale_info::TypeInfo; | ||
use sp_core::H160; | ||
use sp_runtime::traits::Zero; | ||
use sp_std::vec; | ||
use xcm::prelude::{ | ||
send_xcm, Junction::*, Location, SendError as XcmpSendError, SendXcm, Xcm, XcmContext, XcmHash, | ||
|
@@ -58,8 +57,7 @@ use xcm_executor::traits::TransactAsset; | |
|
||
use snowbridge_core::{ | ||
inbound::{Message, VerificationError, Verifier}, | ||
sibling_sovereign_account, BasicOperatingMode, Channel, ChannelId, ParaId, PricingParameters, | ||
StaticLookup, | ||
BasicOperatingMode, Channel, ChannelId, ParaId, PricingParameters, StaticLookup, | ||
}; | ||
use snowbridge_router_primitives::{ | ||
inbound, | ||
|
@@ -263,25 +261,12 @@ pub mod pallet { | |
} | ||
})?; | ||
|
||
// Reward relayer from the sovereign account of the destination parachain, only if funds | ||
// are available | ||
let sovereign_account = sibling_sovereign_account::<T>(channel.para_id); | ||
let delivery_cost = Self::calculate_delivery_cost(message.encode().len() as u32); | ||
let amount = T::Token::reducible_balance( | ||
&sovereign_account, | ||
Preservation::Preserve, | ||
Fortitude::Polite, | ||
) | ||
.min(delivery_cost); | ||
if !amount.is_zero() { | ||
T::Token::transfer(&sovereign_account, &who, amount, Preservation::Preserve)?; | ||
} | ||
|
||
// Decode message into XCM | ||
let (xcm, fee) = | ||
match inbound::VersionedMessage::decode_all(&mut envelope.payload.as_ref()) { | ||
Ok(message) => T::MessageConverter::convert(envelope.message_id, message) | ||
.map_err(|e| Error::<T>::ConvertMessage(e))?, | ||
Ok(message) => | ||
T::MessageConverter::convert(envelope.message_id, message, who.clone()) | ||
.map_err(|e| Error::<T>::ConvertMessage(e))?, | ||
Err(_) => return Err(Error::<T>::InvalidPayload.into()), | ||
}; | ||
|
||
|
@@ -292,8 +277,14 @@ pub mod pallet { | |
fee | ||
); | ||
|
||
// Burning fees for teleport | ||
Self::burn_fees(channel.para_id, fee)?; | ||
// Burning fees from the relay for teleport | ||
T::Token::burn_from( | ||
&who, | ||
fee, | ||
Preservation::Preserve, | ||
Precision::BestEffort, | ||
Fortitude::Polite, | ||
)?; | ||
Comment on lines
+280
to
+287
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Burn fees from relayer instead of the Parachain sovereign. |
||
|
||
// Attempt to send XCM to a dest parachain | ||
let message_id = Self::send_xcm(xcm, channel.para_id)?; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,7 @@ pub trait ConvertMessage { | |
fn convert( | ||
message_id: H256, | ||
message: VersionedMessage, | ||
relayer: Self::AccountId, | ||
) -> Result<(Xcm<()>, Self::Balance), ConvertMessageError>; | ||
} | ||
|
||
|
@@ -145,14 +146,23 @@ where | |
fn convert( | ||
message_id: H256, | ||
message: VersionedMessage, | ||
relayer: AccountId, | ||
) -> Result<(Xcm<()>, Self::Balance), ConvertMessageError> { | ||
use Command::*; | ||
use VersionedMessage::*; | ||
match message { | ||
V1(MessageV1 { chain_id, command: RegisterToken { token, fee } }) => | ||
Ok(Self::convert_register_token(message_id, chain_id, token, fee)), | ||
V1(MessageV1 { chain_id, command: SendToken { token, destination, amount, fee } }) => | ||
Ok(Self::convert_send_token(message_id, chain_id, token, destination, amount, fee)), | ||
Ok(Self::convert_send_token( | ||
message_id, | ||
relayer, | ||
chain_id, | ||
token, | ||
destination, | ||
amount, | ||
fee, | ||
)), | ||
} | ||
} | ||
} | ||
|
@@ -224,6 +234,7 @@ where | |
|
||
fn convert_send_token( | ||
message_id: H256, | ||
relayer: AccountId, | ||
chain_id: u64, | ||
token: H160, | ||
destination: Destination, | ||
|
@@ -263,6 +274,12 @@ where | |
BuyExecution { fees: asset_hub_fee_asset, weight_limit: Unlimited }, | ||
DescendOrigin(PalletInstance(inbound_queue_pallet_index).into()), | ||
UniversalOrigin(GlobalConsensus(network)), | ||
// No matter what error it is just try to Deposit the asset to beneficiary without | ||
// trapped. | ||
SetErrorHandler(Xcm(vec![DepositAsset { | ||
assets: Definite(asset.clone().into()), | ||
beneficiary: beneficiary.clone(), | ||
}])), | ||
Comment on lines
+277
to
+282
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an extra |
||
ReserveAssetDeposited(asset.clone().into()), | ||
ClearOrigin, | ||
]; | ||
|
@@ -289,11 +306,16 @@ where | |
]); | ||
}, | ||
None => { | ||
// Deposit asset to beneficiary and all fees left to relayer | ||
instructions.extend(vec![ | ||
// Deposit both asset and fees to beneficiary so the fees will not get | ||
// trapped. Another benefit is when fees left more than ED on AssetHub could be | ||
// used to create the beneficiary account in case it does not exist. | ||
DepositAsset { assets: Wild(AllCounted(2)), beneficiary }, | ||
DepositAsset { | ||
assets: Definite(asset.clone().into()), | ||
beneficiary: beneficiary.clone(), | ||
}, | ||
DepositAsset { | ||
assets: Wild(AllCounted(2)), | ||
beneficiary: Location::from(relayer.into()), | ||
}, | ||
]); | ||
}, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the reward logic here, instead to reward relayer on AH with the fee token transfered from Ethereum.