paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.87k stars 684 forks source link

Figure out a way for chains to advertise their weight fee schedule #868

Open KiChjang opened 2 years ago

KiChjang commented 2 years ago

When we do asset teleportation or reserve asset transfers, we currently use the local chain's weigher as a guesstimate of how much weight the destination chain needs in order to execute the XCM that was sent to it:

https://github.com/paritytech/polkadot/blob/53568d0fee6719b7c681310e5d82b2631a8395f3/xcm/pallet-xcm/src/lib.rs#L853-L869

This is clearly not an accurate weight, as the source weigher may weigh each XCM instruction differently from the destination weigher. We'd like to thus find a mechanism for the destination weigher to let the source chain know about its weight fee schedule.

Files: xcm/pallet-xcm/src/lib.rs, xcm/xcm-builder/src/weight.rs

KiChjang commented 2 years ago

One of the solutions that came up was to do something similar to version negotiation -- have each chain keep a local copy of the fee schedule of each reachable destination, and have it be dynamically updated every time a chain updates its own XCM weights by making the updated chain advertise its updated schedule to every reachable destination.

The problem with this method as pointed out by Gav is that the weight may be polynomial, and as such may depend upon multiple inputs, and the fee schedule here assumes that every item on the schedule is a constant. This may not be the case if we know how to model the fee structure beforehand, and make it extensible to different mathematical formulas for new weight calculations.