paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.com/
1.89k stars 696 forks source link

Strongly type the returned unspent weight in `TransactionExtension` #5668

Open georgepisaltu opened 2 months ago

georgepisaltu commented 2 months ago

Follow up on #3685

In the TransactionExtension interface, the post_dispatch_details interface returns a Weight. This is specifically the amount of unspent weight by the transaction relative to the worst case weight estimated in TransactionExtension::weight.

As per this comment, the returned weight is usually the actual weight used, like in call dispatch. This can lead to confusion for developers, so we should introduce a type around the returned Weight to clearly make them different, without a default or From/Into so that the dev has to see the type.

fn post_dispatch_details(...) -> Result<Unspent, TransactionValidityError> {
   // snip
   Ok(Unspent::new(calculated_unspent_weight))
}