payment_queryInfo: Make it work with WeightV2 (#12633)

* `payment_queryInfo`: Make it work with `WeighV2`

The runtime api for querying the payment info depends on the `Weight` type and broke for old
runtimes that still use the `WeighV1`. This pull requests fixes this by:

1. Bumping the version of the runtime api.
2. Making the node side code use the correct runtime api function depending on the version of the
runtime api.
3. Make the RPC always return `WeighV1`.

Users of the api should switch to `state_call` and decide based on the version of the runtime api
which `Weight` type is being returned.

* Fix tests

* Review comment
This commit is contained in:
Bastian Köcher
2022-11-08 11:33:43 +01:00
committed by GitHub
parent 2e22312140
commit ec6a428ade
7 changed files with 61 additions and 16 deletions
@@ -24,7 +24,7 @@ use serde::{Deserialize, Serialize};
use sp_runtime::traits::{AtLeast32BitUnsigned, Zero};
use sp_std::prelude::*;
use frame_support::{dispatch::DispatchClass, weights::Weight};
use frame_support::dispatch::DispatchClass;
/// The base fee and adjusted weight and length fees constitute the _inclusion fee_.
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
@@ -94,9 +94,15 @@ impl<Balance: AtLeast32BitUnsigned + Copy> FeeDetails<Balance> {
#[derive(Eq, PartialEq, Encode, Decode, Default)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
#[cfg_attr(feature = "std", serde(bound(serialize = "Balance: std::fmt::Display")))]
#[cfg_attr(feature = "std", serde(bound(deserialize = "Balance: std::str::FromStr")))]
pub struct RuntimeDispatchInfo<Balance> {
#[cfg_attr(
feature = "std",
serde(bound(serialize = "Balance: std::fmt::Display, Weight: Serialize"))
)]
#[cfg_attr(
feature = "std",
serde(bound(deserialize = "Balance: std::str::FromStr, Weight: Deserialize<'de>"))
)]
pub struct RuntimeDispatchInfo<Balance, Weight = frame_support::weights::Weight> {
/// Weight of this dispatch.
pub weight: Weight,
/// Class of this dispatch.
@@ -131,6 +137,7 @@ mod serde_balance {
#[cfg(test)]
mod tests {
use super::*;
use frame_support::weights::Weight;
#[test]
fn should_serialize_and_deserialize_properly_with_string() {