Commit db7a34b
XcmPaymentApi::query_weight_to_asset_fee simple common impl (#8281)
# Description
Add a common implementation for
`XcmPaymentApi::query_weight_to_asset_fee` to `pallet-xcm`.
This PR is a simple alternative to #8202 (which could still be useful
for other reasons).
It uses a workaround instead of a big refactoring.
The workaround is:
Computes the weight cost using the provided `WeightTrader`.
This function is supposed to be used ONLY in
`XcmPaymentApi::query_weight_to_asset_fee`
Runtime API implementation, as it can introduce a massive change to the
total issuance.
The provided `WeightTrader` must be the same as the one used in the
XcmExecutor to ensure
uniformity in the weight cost calculation.
NOTE: Currently this function uses a workaround that should be good
enough for all practical
uses: passes `u128::MAX / 2 == 2^127` of the specified asset to the
`WeightTrader` as
payment and computes the weight cost as the difference between this and
the unspent amount.
Some weight traders could add the provided payment to some account's
balance. However,
it should practically never result in overflow because even currencies
with a lot of decimal digits
(say 18) usually have the total issuance of billions (`x * 10^9`) or
trillions (`x * 10^12`) at max,
much less than `2^127 / 10^18 =~ 1.7 * 10^20` (170 billion billion).
Thus, any account's balance
most likely holds less than `2^127`, so adding `2^127` won't result in
`u128` overflow.
## Integration
The Runtime builders can use the `query_weight_to_asset_fee` provided by
`pallet-xcm` in
their XcmPaymentApi implementation.
---------
Co-authored-by: Adrian Catangiu <adrian@parity.io>1 parent ceca6c5 commit db7a34b
27 files changed
Lines changed: 455 additions & 352 deletions
File tree
- cumulus/parachains/runtimes
- assets
- asset-hub-rococo
- src
- tests
- asset-hub-westend
- src
- tests
- test-utils/src
- bridge-hubs
- bridge-hub-rococo
- src
- tests
- bridge-hub-westend
- src
- tests
- collectives/collectives-westend
- src
- tests
- coretime
- coretime-rococo
- src
- tests
- coretime-westend
- src
- tests
- people
- people-rococo
- src
- tests
- people-westend
- src
- tests
- test-utils/src
- testing/penpal/src
- polkadot
- runtime
- rococo/src
- westend/src
- xcm/pallet-xcm/src
- tests
- prdoc
Lines changed: 6 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
1556 | 1556 | | |
1557 | 1557 | | |
1558 | 1558 | | |
1559 | | - | |
1560 | | - | |
1561 | | - | |
1562 | | - | |
1563 | | - | |
1564 | | - | |
1565 | | - | |
1566 | | - | |
1567 | | - | |
1568 | | - | |
1569 | | - | |
1570 | | - | |
1571 | | - | |
1572 | | - | |
1573 | | - | |
1574 | | - | |
1575 | | - | |
1576 | | - | |
1577 | | - | |
1578 | | - | |
1579 | | - | |
1580 | | - | |
1581 | | - | |
1582 | | - | |
1583 | | - | |
1584 | | - | |
1585 | | - | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
1586 | 1564 | | |
1587 | 1565 | | |
1588 | 1566 | | |
| |||
Lines changed: 13 additions & 49 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
91 | 90 | | |
92 | 91 | | |
93 | 92 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | 93 | | |
141 | 94 | | |
142 | 95 | | |
| |||
845 | 798 | | |
846 | 799 | | |
847 | 800 | | |
848 | | - | |
| 801 | + | |
849 | 802 | | |
850 | 803 | | |
851 | 804 | | |
| |||
920 | 873 | | |
921 | 874 | | |
922 | 875 | | |
923 | | - | |
| 876 | + | |
924 | 877 | | |
925 | 878 | | |
926 | 879 | | |
| |||
1365 | 1318 | | |
1366 | 1319 | | |
1367 | 1320 | | |
| 1321 | + | |
1368 | 1322 | | |
1369 | 1323 | | |
1370 | 1324 | | |
1371 | 1325 | | |
1372 | 1326 | | |
1373 | 1327 | | |
| 1328 | + | |
1374 | 1329 | | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
1375 | 1339 | | |
Lines changed: 6 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
1694 | 1694 | | |
1695 | 1695 | | |
1696 | 1696 | | |
1697 | | - | |
1698 | | - | |
1699 | | - | |
1700 | | - | |
1701 | | - | |
1702 | | - | |
1703 | | - | |
1704 | | - | |
1705 | | - | |
1706 | | - | |
1707 | | - | |
1708 | | - | |
1709 | | - | |
1710 | | - | |
1711 | | - | |
1712 | | - | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
1717 | | - | |
1718 | | - | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
1722 | | - | |
1723 | | - | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
1724 | 1702 | | |
1725 | 1703 | | |
1726 | 1704 | | |
| |||
Lines changed: 14 additions & 49 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | 94 | | |
141 | 95 | | |
142 | 96 | | |
| |||
944 | 898 | | |
945 | 899 | | |
946 | 900 | | |
947 | | - | |
| 901 | + | |
948 | 902 | | |
949 | 903 | | |
950 | 904 | | |
| |||
1014 | 968 | | |
1015 | 969 | | |
1016 | 970 | | |
1017 | | - | |
| 971 | + | |
1018 | 972 | | |
1019 | 973 | | |
1020 | 974 | | |
| |||
1423 | 1377 | | |
1424 | 1378 | | |
1425 | 1379 | | |
| 1380 | + | |
1426 | 1381 | | |
1427 | 1382 | | |
1428 | 1383 | | |
1429 | 1384 | | |
1430 | 1385 | | |
1431 | 1386 | | |
| 1387 | + | |
1432 | 1388 | | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
1433 | 1398 | | |
1434 | 1399 | | |
1435 | 1400 | | |
| |||
0 commit comments