Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Revamp xcm for the reserver tranfer from substrate to Ethreum & Implement a custom exporter #160

Closed
wants to merge 7 commits into from

Conversation

yrong
Copy link

@yrong yrong commented Jul 18, 2024

To use the low level execute call directly to replace the reserve_transfer_asset which has limitations.

More context in https://matrix.to/#/!gxqZwOyvhLstCgPJHO:matrix.parity.io/$uMy6wP7SCEpBbYAYbwqGU4Z2VjIpM6Gvv-4MxgVKJJM?via=matrix.parity.io&via=parity.io&via=matrix.org

New Fee flow

  1. User bonds an estimated DOT fee on BridgeHub, that has previously been calculated off-chain
  2. BridgeHub commits the message for delivery to Ethereum
  3. Relayer sends message to our Gateway contract on Ethereum.
  4. Relayer sends proof-of-delivery back to BridgeHub
  5. BridgeHub gives bonded fee to relayer

https://docs.snowbridge.network/~/changes/HBJiUn5s4cV0iP3g68Sk/other/snowbridge-v2/unordered-delivery

@vgeddes
Copy link

vgeddes commented Jul 19, 2024

Ron to clarify I meant BridgeHub is the source

@yrong yrong force-pushed the ron/custom-execute-transfer branch from 058a948 to 3a79d45 Compare July 19, 2024 09:28
@yrong yrong changed the title Use low level execute directly Use low level execute call for reserve based tranfer Jul 19, 2024
@yrong yrong changed the title Use low level execute call for reserve based tranfer Lock fee on BH and pay reward to relay Jul 21, 2024
let xcms = VersionedXcm::from(Xcm(vec![
WithdrawAsset(assets.clone().into()),
SetFeesMode { jit_withdraw: true },
InitiateReserveWithdraw {
Copy link

@vgeddes vgeddes Jul 22, 2024

Choose a reason for hiding this comment

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

OK, this looks good, fairly simple 👍

Can you check what we would need for Polkadot-native assets? I suspect its TransferReserveAsset with the destination being our gateway contract.

Copy link
Author

@yrong yrong Jul 23, 2024

Choose a reason for hiding this comment

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

I suspect its TransferReserveAsset

Exactly.

destination being our gateway contract.

Currently the destination is always (Location::new(2, [GlobalConsensus(Ethereum { chain_id: CHAIN_ID })])


let xcms = VersionedXcm::from(Xcm(vec![
WithdrawAsset(assets.clone().into()),
SetFeesMode { jit_withdraw: true },
Copy link

Choose a reason for hiding this comment

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

Why SetFeesMode instead of BuyExecution? I think the user should have an opportunity to pass the necessary fee amounts after estimating fees using the XCM dry run extrinsic.

Also they want to deprecate SetFeesMode in polkadot-fellows/xcm-format#57.

Copy link
Author

@yrong yrong Jul 23, 2024

Choose a reason for hiding this comment

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

The fee asset(DOT) is already included in WithdrawAsset(assets.clone().into()), actually we transfer 2 kinds of assets to Ethereum(DOT and WETH) and use DOT to pay for the delivery cost on BH.

The SetFeesMode is taking the delivery cost on AH from user for InitiateReserveWithdraw, suggest to run the test case with

RUST_LOG=xcm=trace cargo test -p bridge-hub-rococo-integration-tests --lib tests::snowbridge::send_weth_asset_from_asset_hub_to_ethereum -- --nocapture

and check logs as follows for detail:

...
2024-07-23T02:04:58.003798Z TRACE xcm::fees: taking fee: Assets([Asset { id: AssetId(Location { parents: 1, interior: Here }), fun: Fungible(1106266603) }]) from origin_ref: Some(Location { parents: 0, interior: X1([AccountId32 { network: Some(Rococo), id: [142, 175, 4, 21, 22, 135, 115, 99, 38, 201, 254, 161, 126, 37, 252, 82, 135, 97, 54, 147, 201, 18, 144, 156, 178, 38, 170, 71, 148, 242, 106, 72] }]) }) in fees_mode: FeesMode { jit_withdraw: true } for a reason: InitiateReserveWithdraw

Copy link

@vgeddes vgeddes Jul 23, 2024

Choose a reason for hiding this comment

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

Can't the executor take fees from the holding register? DOT has already been transferred to the holding register after the execution of WithdrawAsset.

Copy link
Author

Choose a reason for hiding this comment

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

We can but I don't see benefit for adding an extra BuyExecution if SetFeesMode can work here.

Btw: polkadot-fellows/xcm-format#57 is closed so it won't impact and I expect more on polkadot-fellows/RFCs#105 which is another story.

@yrong yrong force-pushed the ron/custom-execute-transfer branch from 80537ed to d489756 Compare July 23, 2024 00:44
@yrong
Copy link
Author

yrong commented Jul 23, 2024

Move the reward logic to #162 and make this PR more focused on constructing/handling xcm.

@yrong yrong changed the title Lock fee on BH and pay reward to relay Revamp xcm for the reserver tranfer from substrate to Ethreeum direction Jul 23, 2024
@yrong yrong changed the title Revamp xcm for the reserver tranfer from substrate to Ethreeum direction Revamp xcm for the reserver tranfer from substrate to Ethreum Jul 23, 2024
Comment on lines 638 to 639
/// User fee for delivery cost on bridge hub. Leave some buffer here for avoid spamming
pub const DefaultBridgeHubEthereumBaseFee: Balance = 1_000_000_000;
Copy link
Author

@yrong yrong Jul 23, 2024

Choose a reason for hiding this comment

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

Should at least cover the execution cost of the fee on BH(i.e. the local portion).

Copy link

Choose a reason for hiding this comment

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

Ah, we should not bake this constant into AH. BH needs to estimate it on-chain, and then our off-chain UX needs to query it in order to estimate the total fees required

Copy link

Choose a reason for hiding this comment

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

The XCM fee estimation APIs will include the local fee, so we should be fine in that regard.

Copy link
Author

@yrong yrong Jul 24, 2024

Choose a reason for hiding this comment

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

The fee config here will also be used to BuyExecution for the xcm on BH which can't be zero.

It should at least cover the xcm execution cost(e.g. The ExportMessage instruction) but I would suggest to leave some buffer to also include the submit cost(i.e. the local portion) here to ensure our OutboundQueue not spammed.

Btw: it's very tiny here so IMO it's acceptable trade-off continue to be estimated on-chain with considerable buffer for this portion. Somehow mirrors the fee configuration on Ethreum side which we won't remove.

@@ -205,7 +203,7 @@ impl xcm_executor::Config for XcmConfig {
type SubscriptionService = PolkadotXcm;
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type FeeManager = XcmFeeManagerFromComponentsBridgeHub<
type FeeManager = XcmFeeManagerFromComponents<
Copy link
Author

Choose a reason for hiding this comment

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

The custom FeeManager is not in used and removed, since AH is in the WaivedLocations no need to pay delivery cost for Ethreum transfer.

@yrong yrong marked this pull request as ready for review July 29, 2024 11:30
Comment on lines 391 to 392
BridgeHubRococo::fund_accounts(vec![(assethub_sovereign.clone(), INITIAL_FUND)]);

Copy link
Author

Choose a reason for hiding this comment

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

Should remove this initial fund as there is no need to fund the sovereign here any more.

Comment on lines 510 to 512
let free_balance_of_sovereign_on_bh_after =
<BridgeHubRococo as BridgeHubRococoPallet>::Balances::free_balance(assethub_sovereign);
assert_eq!(free_balance_of_sovereign_on_bh_after, 955613334);
Copy link
Author

@yrong yrong Jul 29, 2024

Choose a reason for hiding this comment

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

Currently there is no need to fund the sovereign account on BH any more as we will use a InitiateTeleport instruction for an instant top up.

As we may notice after the test there is still some fee left unused in the sov account. So bad guys can leverage that to ignore the InitiateTeleport instruction later.

Another issue for current impl is that we have to charge twice from user for the DefaultBridgeHubEthereumBaseFee, one for the InitiateTeleport for an instant top up as mentioned before, the other for the delivery cost here sending the remote xcm of InitiateReserveWithdraw to Ethreum through BH for the Export.

Can run RUST_LOG=xcm=trace cargo test -p bridge-hub-rococo-integration-tests --lib tests::snowbridge::send_weth_asset_from_asset_hub_to_ethereum -- --nocapture for the execution path.

Copy link
Author

Choose a reason for hiding this comment

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

Addressed in #167

@yrong yrong changed the title Revamp xcm for the reserver tranfer from substrate to Ethreum Revamp xcm for the reserver tranfer from substrate to Ethreum & Implement a custom exporter Aug 1, 2024
@yrong yrong closed this Aug 22, 2024
@yrong yrong added the xcm label Aug 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants