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

Inbound queue v2 #3

Closed
wants to merge 25 commits into from
Closed

Conversation

claravanstaden
Copy link
Owner

Resolves: SNO-1164

@claravanstaden
Copy link
Owner Author

@yrong would appreciate an early review here. 🙏🏻

Comment on lines 108 to 110
let fee_value = 1_000_000_000u128; // TODO needs to be dry-run to get the fee but also
// need to add a fee here for the dry run... Chicken/egg problem?
let fee: Asset = (fee_asset, fee_value).into();
Copy link

@yrong yrong Nov 8, 2024

Choose a reason for hiding this comment

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

IIUC the dry_run on BH is to convert the InboundMessage to a XCM. Then UI can dry run that XCM on AH for the cost.

So IMO InboundMessage should contain the fee like V1 before, it can be zero for estimation, after that filled in with the result for calling the Gateway contract from UX.

Copy link
Owner Author

Choose a reason for hiding this comment

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

@yrong do you think the AH execution fee (which can be 0 for estimation) should be added as a field in MessageV2?

Copy link
Owner Author

Choose a reason for hiding this comment

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

@vgeddes or how did you imagine the AH execution fee be specified? I see there is a fee added for register token (which is the foreign asset creation deposit) but no other place in the contracts to specify the AH execution fee. Iiuc this will be the flow:

  • Inbound queue runtime API to convert command to XCM
  • UX takes XCM and dry-runs the XCM on AH to get fee
  • UX takes fee number and adds it to the command, emits OutboundEvent

I don't see such a fee parameter in the contract code, so just wanna get your thoughts on this.

Copy link

Choose a reason for hiding this comment

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

Another option as mentioned in #3 (comment)

@claravanstaden claravanstaden changed the base branch from outbound-queue-v2 to snowbridge-v2 November 18, 2024 07:39
@claravanstaden claravanstaden changed the base branch from snowbridge-v2 to outbound-queue-v2 November 18, 2024 07:40
bridges/snowbridge/pallets/inbound-queue-v2/src/lib.rs Outdated Show resolved Hide resolved

const MINIMUM_DEPOSIT: u128 = 1;
const LOG_TARGET: &str = "snowbridge-router-primitives";

/// Messages from Ethereum are versioned. This is because in future,
/// we may want to evolve the protocol so that the ethereum side sends XCM messages directly.
/// Instead having BridgeHub transcode the messages into XCM.
#[derive(Clone, Encode, Decode, RuntimeDebug)]
pub enum VersionedMessage {
Copy link

Choose a reason for hiding this comment

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

This versioned type is unused in V2, in the sense that the ethereum contracts do not send it.

Copy link
Owner Author

Choose a reason for hiding this comment

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

@vgeddes I wonder why we don't version the message this time around, I made a comment about it here too: yrong#4 (comment)

bridges/snowbridge/primitives/router/src/inbound/v2.rs Outdated Show resolved Hide resolved
bridges/snowbridge/primitives/router/src/inbound/v2.rs Outdated Show resolved Hide resolved

let fee_asset = Location::new(1, Here);
let fee_value = 1_000_000_000u128; // TODO get from command
Copy link

Choose a reason for hiding this comment

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

As I noted in a previous comment, this fee should also be burnt from the relayers account on BH.

Some other notes:

  • Should make the fee configurable via runtime config, ie add T::XcmPrologueFee: Balance pallet config
  • Add to your TODOs to implement an XCM simulation test that calculates an appropriate minimum fee, assuming the worst case where a maximum of eight assets are supplied. Then we add 2x buffer on top of that minimum.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Should make the fee configurable via runtime config, ie add T::XcmPrologueFee: Balance pallet config

Can we make this fee configurable? Iirc we cannot, because it could include arbitrary instructions such as Transact. I explained the flow as I see it should work over here: #3 (comment)

Copy link

@yrong yrong Nov 21, 2024

Choose a reason for hiding this comment

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

Can we make this fee configurable? Iirc we cannot, because it could include arbitrary instructions such as Transact. I explained the flow as I see it should work over here: #3 (comment)

Yeah, I still think InboundMessage should contain the fee like V1 before with AssetId including.

But there is also another option to make it configurable, A Nmap storage item on BH something like:

Destination Operation FeeId FeeAmount
AH TransferENA WETH 0.0001
AH TransferENA DOT 0.01
AH TransferPNA DOT 0.01
Moonbeam TransferENA GLMR 0.1
Moonbeam Call_Contract_Method_1 GLMR 0.5
Moonbeam Call_Contract_Method_2 GLMR 10
  • Destination chain can config multiple assets as fee. e.g. for TransferENA to AH both WETH and DOT can be configured as fee.
  • For multiple hop operations the fee is total of the execution cost on AH and on destination chain. e.g. for TransferENA to Moonbeam the fee is 0.0001 WETH + 0.1 GLMR
  • Operations with Destination to AH should be configured with governance call from Polkadot
  • Operations with Destination to Moonbeam should be configured with governance call from Moonbeam

IMO this is doer-able because

  • fee on Substrate is very limited and invariable, comparing with the fee on Ethereum side, so dry_run every time may not be necessary
  • we can add SetAppendix(DepositToBeneficiary) and return the extra fee to end user, so set a high fee safe enough is not a big deal

Copy link
Owner Author

Choose a reason for hiding this comment

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

That's an interesting idea @yrong. It could work. I think the main downside to this (from my perspective) is that many governance calls will be a pain to do. It will require more invention from our team's side, more coordination with other teams.

What is your concern with the dry-run approach? Isn't runtime API calls free so there's no cost to doing the estimation?

Copy link

Choose a reason for hiding this comment

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

I still think InboundMessage should contain the fee like V1 before but with AssetId including.

Yeah, that's why I still prefer this.

Copy link
Owner Author

Choose a reason for hiding this comment

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

@vgeddes let me know what you think too.

Copy link

@vgeddes vgeddes Nov 21, 2024

Choose a reason for hiding this comment

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

I think there's a misunderstanding here how fees are supposed to be paid on AH. Please read again the API docs for IGateway.sendMessage:

// The `xcm` should contain the necessary instructions to:
// 1. Pay XCM execution fees for `xcm`, either from assets in holding,
//    or from the sovereign account of `msg.sender`.
// 2. Handle the assets in holding, either depositing them into
//    some account, or forwarding them to another destination.

Or in other words, its the users responsibility to provide assets and xcm instructions to cover fees. I.e the user-provided xcm can contain PayFee instructions.

Please let me know if there is anything that I should clarify about this.

Its only the fixed xcm prologue that requires a small fixed fee to be teleported by the relayer account on BH. To cover the first few instructions which are prepending to the users xcm.

Our governance messages for registering ENA tokens will use the same API.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I see, thanks for clearing it up @vgeddes. I will add it.

@claravanstaden claravanstaden marked this pull request as ready for review November 20, 2024 11:14
claravanstaden and others added 3 commits November 20, 2024 13:23
Co-authored-by: Vincent Geddes <117534+vgeddes@users.noreply.github.com>
Co-authored-by: Vincent Geddes <117534+vgeddes@users.noreply.github.com>
Co-authored-by: Vincent Geddes <117534+vgeddes@users.noreply.github.com>
@claravanstaden claravanstaden changed the base branch from outbound-queue-v2 to snowbridge-v2 November 20, 2024 13:05
@claravanstaden claravanstaden changed the base branch from snowbridge-v2 to outbound-queue-v2 November 21, 2024 07:32
@claravanstaden
Copy link
Owner Author

Closing in favour of #4. The diff in this PR included changes already made in another PR, so it was hard to see the true diff.

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