2

Can you please explain the reasoning for choosing the following coefficient p and q for the WeightToFeePolynomial in Polkadot?

    pub struct WeightToFee;
    impl WeightToFeePolynomial for WeightToFee {
        type Balance = Balance;
        fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
            // in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
            let p = super::currency::CENTS;
            let q = 10 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
            smallvec![WeightToFeeCoefficient {
                degree: 1,
                negative: false,
                coeff_frac: Perbill::from_rational(p % q, q),
                coeff_integer: p / q,
            }]
        }

Questions:

  1. Why is P set super::currency::CENTS and q is set to 10 * Balance::from(ExtrinsicBaseWeight::get().ref_time());?

  2. What is the reasoning for choosing these values to calculate the weight to fee instead of a 1-to-1 mapping using the IdentityFee?

  3. Why is Balance::from(ExtrinsicBaseWeight::get().ref_time()) multiplied by 10 in q?

1

1 Answer 1

3
  1. As stated in the comment:

    // in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT

    This is just an arbitrary choice that one extrinsic should cost whatever CENT represents in the system. There is no hard science here, and ultimately a combination of the dynamic weight to fee coefficient + base fees and all that will be figured out by supply and demand.

    What you want to do here, is just figure out how many extrinsics could fit in a block, and approximately how much people should pay at a minimum to fill a whole block with their transactions.

    Choosing a number too low will make your fees very low, but your network easy to attack. A number too high will make your fees higher than they need to be to protect your network. Usually you can only know what these numbers should be through measuring activity on the network, and probably will need to be updated anyway, as all fees on all long running networks have done.

  2. 1-to-1 mapping is an awful choice because you assume that Weight, which is some arbitrary unit of measurement, is 1-1 with your network token, which is also arbitrary. It will almost never be the case these two things align. Instead, as we do here, we compare the size of an average extrinsic, and say that a user must pay at least some minimum amount of our network token. These are things that are in your control, and should have some high level relationship.

  3. We want 1 / 10 cent = 1 base extrinsic. To make the math better for whatever reason, perhaps to ensure that CENT does not saturate before we do the calculations, we do 1 / (10 * base extrinsic). Its all the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.