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
Descend to user origin & Burn fee from the user #168
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
64fcff1
Custom send trait
yrong 877dd15
Custom exporter
yrong b0d3044
Merge branch 'ron/custom-send' into ron/custom-exporter
yrong 80a7457
Burn fee for sending xcm with teleport
yrong d53fa6e
Move export payment out and burn it
yrong c66d955
Merge branch 'ron/custom-send' into ron/custom-exporter
yrong 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
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
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 |
---|---|---|
|
@@ -461,7 +461,7 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorLocat | |
fn validate( | ||
dest: &mut Option<Location>, | ||
msg: &mut Option<Xcm<()>>, | ||
_source: Option<&Location>, | ||
source: Option<&Location>, | ||
) -> SendResult<Router::Ticket> { | ||
let d = dest.as_ref().ok_or(MissingArgument)?; | ||
let devolved = | ||
|
@@ -478,6 +478,11 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorLocat | |
return Err(NotApplicable) | ||
}; | ||
|
||
// Ensure the export fee configured is not None. | ||
let payments: xcm::prelude::Assets = | ||
if let Some(ref payment) = maybe_payment { Some(payment.clone().into()) } else { None } | ||
.ok_or(NotApplicable)?; | ||
|
||
// `xcm` should already end with `SetTopic` - if it does, then extract and derive into | ||
// an onward topic ID. | ||
let maybe_forward_id = match xcm.last() { | ||
|
@@ -491,12 +496,16 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorLocat | |
let export_instruction = | ||
ExportMessage { network: remote_network, destination: remote_location, xcm }; | ||
|
||
let sender = if let Some(origin) = source { Some(origin.clone().interior) } else { None } | ||
.ok_or(NotApplicable)?; | ||
|
||
let mut message = Xcm(if let Some(ref payment) = maybe_payment { | ||
let fees = payment | ||
.clone() | ||
.reanchored(&bridge, &UniversalLocation::get()) | ||
.map_err(|_| Unroutable)?; | ||
vec![ | ||
DescendOrigin(sender), | ||
ReceiveTeleportedAsset(fees.clone().into()), | ||
BuyExecution { fees, weight_limit: Unlimited }, | ||
Comment on lines
+499
to
510
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. In custom exporter we add |
||
// `SetAppendix` ensures that `fees` are not trapped in any case, for example, when | ||
|
@@ -517,11 +526,8 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorLocat | |
|
||
// We then send a normal message to the bridge asking it to export the prepended | ||
// message to the remote chain. | ||
let (v, mut cost, _) = validate_send::<Router>(bridge, message, None)?; | ||
if let Some(bridge_payment) = maybe_payment { | ||
cost.push(bridge_payment); | ||
} | ||
Ok((v, cost, None)) | ||
let (v, cost, _) = validate_send::<Router>(bridge, message, None)?; | ||
Ok((v, cost, Some(payments))) | ||
} | ||
|
||
fn deliver(ticket: Router::Ticket) -> Result<XcmHash, SendError> { | ||
|
@@ -727,7 +733,7 @@ pub mod bridging { | |
parameter_types! { | ||
/// User fee for delivery cost on bridge hub. Leave some buffer here for avoid spamming | ||
/// should cover at least the BuyExecution on BH | ||
pub const DefaultBridgeHubEthereumBaseFee: Balance = 48_000_000; | ||
pub const DefaultBridgeHubEthereumBaseFee: Balance = 60_000_000; | ||
pub storage BridgeHubEthereumBaseFee: Balance = DefaultBridgeHubEthereumBaseFee::get(); | ||
pub SiblingBridgeHubWithEthereumInboundQueueInstance: Location = Location::new( | ||
1, | ||
|
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
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
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 |
---|---|---|
|
@@ -387,8 +387,12 @@ impl<Config: config::Config> XcmExecutor<Config> { | |
reason = ?reason, | ||
"Sending msg", | ||
); | ||
let (ticket, fee, _) = validate_send::<Config::XcmSender>(dest, msg, self.origin_ref())?; | ||
self.take_fee(fee, reason)?; | ||
let (ticket, fee, fee_to_burn) = | ||
validate_send::<Config::XcmSender>(dest, msg, self.origin_ref())?; | ||
self.take_fee(fee, reason.clone())?; | ||
if let Some(fee_to_burn) = fee_to_burn { | ||
self.burn_fee(fee_to_burn, reason)?; | ||
} | ||
Comment on lines
+390
to
+395
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. Make |
||
Config::XcmSender::deliver(ticket).map_err(Into::into) | ||
} | ||
|
||
|
@@ -494,6 +498,30 @@ impl<Config: config::Config> XcmExecutor<Config> { | |
Ok(()) | ||
} | ||
|
||
fn burn_fee(&mut self, fee: Assets, reason: FeeReason) -> XcmResult { | ||
if Config::FeeManager::is_waived(self.origin_ref(), reason.clone()) { | ||
return Ok(()) | ||
} | ||
tracing::trace!( | ||
target: "xcm::fees", | ||
?fee, | ||
origin_ref = ?self.origin_ref(), | ||
fees_mode = ?self.fees_mode, | ||
?reason, | ||
"Burning fees", | ||
); | ||
if self.fees_mode.jit_withdraw { | ||
let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?; | ||
for asset in fee.inner() { | ||
Config::AssetTransactor::withdraw_asset(&asset, origin, Some(&self.context))?; | ||
} | ||
fee | ||
} else { | ||
self.holding.try_take(fee.into()).map_err(|_| XcmError::NotHoldingFees)?.into() | ||
}; | ||
Ok(()) | ||
} | ||
|
||
/// Calculates what `local_querier` would be from the perspective of `destination`. | ||
fn to_querier( | ||
local_querier: Option<Location>, | ||
|
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.
Add the source location(optional) to
SendXcm
trait so that we canDescendOrigin
to the souce location(i.e. user) later.#169 as prerequisite which is a breaking change.