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

Handle XCM delivery fees for ExportMessage #999

Merged
merged 19 commits into from
Nov 10, 2023
Merged

Conversation

alistair-singh
Copy link
Contributor

@alistair-singh alistair-singh commented Nov 8, 2023

Resolves: SNO-669
Polkadot-Sdk companion: Snowfork/polkadot-sdk#23

@alistair-singh alistair-singh marked this pull request as ready for review November 8, 2023 20:11
Copy link

codecov bot commented Nov 8, 2023

Codecov Report

Attention: 43 lines in your changes are missing coverage. Please review.

Comparison is base (6b59223) 82.82% compared to head (d4202de) 81.13%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #999      +/-   ##
==========================================
- Coverage   82.82%   81.13%   -1.70%     
==========================================
  Files          51       52       +1     
  Lines        2073     2115      +42     
  Branches       72       72              
==========================================
- Hits         1717     1716       -1     
- Misses        341      384      +43     
  Partials       15       15              
Flag Coverage Δ
rust 81.18% <8.51%> (-2.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
parachain/pallets/outbound-queue/src/lib.rs 95.55% <ø> (ø)
parachain/primitives/core/src/outbound.rs 82.75% <ø> (ø)
parachain/primitives/router/src/inbound/mod.rs 55.95% <100.00%> (-0.52%) ⬇️
parachain/primitives/router/src/outbound/mod.rs 90.09% <ø> (ø)
...in/pallets/outbound-queue/src/send_message_impl.rs 92.30% <33.33%> (-7.70%) ⬇️
parachain/primitives/core/src/lib.rs 66.66% <0.00%> (-33.34%) ⬇️
parachain/runtime/runtime-common/src/lib.rs 0.00% <0.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

parachain/pallets/outbound-queue/src/lib.rs Show resolved Hide resolved
parachain/primitives/core/src/outbound.rs Outdated Show resolved Hide resolved
parachain/primitives/core/src/outbound.rs Outdated Show resolved Hide resolved
parachain/primitives/core/src/lib.rs Show resolved Hide resolved
parachain/primitives/core/src/outbound.rs Outdated Show resolved Hide resolved
parachain/pallets/control/src/tests.rs Show resolved Hide resolved
parachain/primitives/core/src/outbound.rs Outdated Show resolved Hide resolved
parachain/pallets/outbound-queue/src/send_message_impl.rs Outdated Show resolved Hide resolved
>(PhantomData<(TokenLocation, EthereumNetwork, ReceiverAccount, AssetTransactor, OutboundQueue)>);
/// to Snowbridge and splits it between the origin parachains sovereign and the system
/// treasury account specified by `ReceiverAmount`.
pub struct XcmExportFeeToSnowbridge<TokenLocation, EthereumNetwork, AssetTransactor, OutboundQueue>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we should call this SnowbridgeXcmFeeHandler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to XcmExportFeeToSibling

>(PhantomData<(TokenLocation, EthereumNetwork, ReceiverAccount, AssetTransactor, OutboundQueue)>);
/// to Snowbridge and splits it between the origin parachains sovereign and the system
/// treasury account specified by `ReceiverAmount`.
pub struct XcmExportFeeToSnowbridge<TokenLocation, EthereumNetwork, AssetTransactor, OutboundQueue>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should rename OutboundQueue to FeeProvider, to be more generic.

Copy link
Contributor Author

@alistair-singh alistair-singh Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 50a27fc

//!
//! Common traits and types shared by runtimes.
#![cfg_attr(not(feature = "std"), no_std)]

use bp_rococo::AccountId;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to have a dependency on this crate, which is very specific to ParityBridge. See my other comment below related to this.

Copy link
Contributor Author

@alistair-singh alistair-singh Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 50a27fc

TokenLocation: Get<MultiLocation>,
EthereumNetwork: Get<NetworkId>,
AssetTransactor: TransactAsset,
OutboundQueue: SendMessageFeeProvider<Balance = bp_rococo::Balance>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we should rather directly add Balance as a generic parameter instead of adding a dependency on the bp_rococo crate.

Suggested change
OutboundQueue: SendMessageFeeProvider<Balance = bp_rococo::Balance>,
Balance: BaseArithmetic + Unsigned + Copy
OutboundQueue: SendMessageFeeProvider<Balance = Balance>,

Copy link
Contributor Author

@alistair-singh alistair-singh Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 50a27fc

);

impl<
TokenLocation: Get<MultiLocation>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TokenLocation: Get<MultiLocation>,
FeeAssetLocation: Get<MultiLocation>,

Copy link
Contributor Author

@alistair-singh alistair-singh Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 50a27fc

(snowbridge_export, maybe_para_sovereign, maybe_total_supplied_fee)
{
let remote_fee = total_fee.saturating_sub(OutboundQueue::local_fee());
if remote_fee > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to my reading, If remote_fee is zero (not likely to happen in practice), the conditional code block is skipped, and the local component of the fees is not deposited into the treasury?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local component is sent to the next fee handler.

if let (true, Some(para_sovereign), Some((fee_index, total_fee))) =
(snowbridge_export, maybe_para_sovereign, maybe_total_supplied_fee)
{
let remote_fee = total_fee.saturating_sub(OutboundQueue::local_fee());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something, but it seems instead of substracting, you may want to split the total fee into local and remote components, and handle them separately?

I'm also not seeing the local component of the fees being deposited into the treasury.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local component is sent to the next fee handler. We only syphon off the remote fee and explicitly send it to the sibling sovereign.

/// to Snowbridge and splits off the local remote fee and deposits it to the origin
/// parachain sovereign account. The local fee is then returned back to be handled by
/// the next fee handler in the chain. Most likely the treasury account.
pub struct XcmExportFeeToSnowbridge<TokenLocation, EthereumNetwork, AssetTransactor, OutboundQueue>(
Copy link
Collaborator

@vgeddes vgeddes Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a general question - How is this XcmExportFeeToSnowbridge type intended to be wired up in the runtime, assuming ParityBridge also has a fee handler which it needs to install.

I'm assuming there will be some kind of tuple or something:

type FeeManager = (XcmExportFeeToParityBridge, XcmExportFeeToSnowbridge)

I guess I'm just worried that the two fee handlers will conflict in some manner.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it's type FeeManager = (XcmExportFeeToSnowbridge,XcmExportFeeToParityBridge)

The HandleFee impl for Tuple as following
https://github.com/Snowfork/polkadot-sdk/blob/f56aaf93e36117392e61e48a59e66ae764d697ff/polkadot/xcm/xcm-builder/src/fee_handling.rs#L40-L56

so remote fee to assethub sovereign and the leftover(i.e. local fee) to treasury.

parachain/primitives/runtime-common/src/lib.rs Outdated Show resolved Hide resolved
);

// Get the parachain sovereign from the `context`.
let maybe_para_sovereign = if let Some(XcmContext {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if XcmContext is None, we should perhaps exit early, and allow the next fee handler to process the fee. This may make the code look a bit cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e0d356f

@vgeddes vgeddes changed the title Fee manager Handle XCM fees for ExportMessage Nov 9, 2023
@vgeddes vgeddes changed the title Handle XCM fees for ExportMessage Handle XCM delivery fees for ExportMessage Nov 9, 2023
Copy link
Collaborator

@vgeddes vgeddes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@alistair-singh alistair-singh merged commit 618e61b into main Nov 10, 2023
6 checks passed
@alistair-singh alistair-singh deleted the alistair/fee-manager branch November 10, 2023 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants