paritytech / polkadot-sdk

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

Make Origin accessible in weight calculation #355

Open athei opened 4 years ago

athei commented 4 years ago

Currently, inside the weight calculation attribute #[weight = { ... }] one has access to the arguments of the annotated function with the exception of Origin. It is conceivable that having that available comes in handy.

stale[bot] commented 3 years ago

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

kylezs commented 8 months ago

Plus one, this would be very useful for us right now! I had just assumed it was possible until the compiler informed me otherwise :(

kianenigma commented 3 weeks ago

Adding mentor to this to encourage it being done. It will be tipped.

gui1117 commented 6 days ago

With transaction extensions the origin for the call of an extrinsic is not longer determined by the extrinsic type (signed, for signed extrinsic, none for inherent and unsigned), instead the origin of the call is the result of the transaction extension pipeline.

A transaction extension might validate and return a signed origin, some other might validate return another origin.

So it is difficult to determine the origin to calculate the pre dispatch weight.

For now any call which would require the origin information to give weights can put the origin as an argument of the call and ensure the origin given as an argument is equal to the origin of the call. Or have different calls for different origin.