Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Introduce weight refund #5584

Merged
merged 1 commit into from
Apr 11, 2020
Merged

Introduce weight refund #5584

merged 1 commit into from
Apr 11, 2020

Conversation

athei
Copy link
Member

@athei athei commented Apr 8, 2020

Related PRs

#5032 predecessor and replaced by this PR
#5458 Groundwork that allows dispatchables to return the actual weight consumed
#5540 Groundwork that allows SignedExtension to access the actual weight

Overview

This changes the CheckWeight and ChargeTransactionPayment signed extensions to refund portions of the annotated a priori maximum weight in their post_dispatch method. A Dispatchable has the ability (since #5458) to return the a posteriori weight that is lower than the annotated max weight. Here we make use of that information in order to do the actual refund.

Motivation

We want dispatchables to be able to refund portions it their static a priori weight maximum. The reason for that is that there are dispatchables where the average weight consumed differs from the maximum. Without a refund we are charging too much weight in some cases. An example is Currency::transfer which is heavier when it needs to create the target account. The average case might be that the account already exists where we are then overcharging.

This refunds weight and the weight bases fee back
to the sender of an extrinsic after the dispatch.
@athei athei added the A0-please_review Pull request needs code review. label Apr 8, 2020
@athei athei requested a review from gui1117 as a code owner April 8, 2020 15:04
@parity-cla-bot
Copy link

It looks like @athei signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

Err(_) => return Err(InvalidTransaction::Payment.into()),
}
}
// We do not recreate the account using the refund. The up front payment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@gavofyork gavofyork merged commit 18f0be7 into master Apr 11, 2020
@gavofyork gavofyork deleted the at-weight-refund-2 branch April 11, 2020 11:56
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests in a follow up, if any would be great 👍

@athei
Copy link
Member Author

athei commented Apr 12, 2020

You are right. I thought it was covered by the existing tests but no one is refunding anything right now. I will add some tests which test the refund.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants