-
Notifications
You must be signed in to change notification settings - Fork 1
Revamp xcm for the reserver tranfer from substrate to Ethreum & Implement a custom exporter #160
Conversation
...arachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs
Outdated
Show resolved
Hide resolved
Ron to clarify I meant BridgeHub is the source |
058a948
to
3a79d45
Compare
let xcms = VersionedXcm::from(Xcm(vec![ | ||
WithdrawAsset(assets.clone().into()), | ||
SetFeesMode { jit_withdraw: true }, | ||
InitiateReserveWithdraw { |
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.
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.
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.
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 }, |
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.
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.
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.
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
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.
Can't the executor take fees from the holding register? DOT has already been transferred to the holding register after the execution of WithdrawAsset
.
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.
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.
80537ed
to
d489756
Compare
Move the reward logic to #162 and make this PR more focused on constructing/handling xcm. |
/// User fee for delivery cost on bridge hub. Leave some buffer here for avoid spamming | ||
pub const DefaultBridgeHubEthereumBaseFee: Balance = 1_000_000_000; |
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.
Should at least cover the execution cost of the fee on BH(i.e. the local portion).
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.
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
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.
The XCM fee estimation APIs will include the local fee, so we should be fine in that regard.
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.
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< |
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.
The custom FeeManager is not in used and removed, since AH is in the WaivedLocations no need to pay delivery cost for Ethreum transfer.
...arachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs
Outdated
Show resolved
Hide resolved
BridgeHubRococo::fund_accounts(vec![(assethub_sovereign.clone(), INITIAL_FUND)]); | ||
|
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.
Should remove this initial fund as there is no need to fund the sovereign here any more.
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); |
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.
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.
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.
Addressed in #167
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
https://docs.snowbridge.network/~/changes/HBJiUn5s4cV0iP3g68Sk/other/snowbridge-v2/unordered-delivery