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

Fix the surplus weight calculation of the Transact XCM instruction #7620

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

TorstenStueber
Copy link

The Transact XCM instruction determines a surplus weight. This surplus weight is meant to be execution weight that has been estimated too high and whose according fee has already been spent from the holding account (through a previous BuyExecution instruction) and that should be refunded later (through refund_surplus).

The Transact instruction deals with three different weights:

  • The require_weight_at_most parameter of the Transact instruction. The Config::Weigher parameter of the Polkadot relay chain uses this value as a basis for calculating the upfront weight and the previously executed BuyExecution instruction determines its fee based on this weight (this comment even states that this is assumed for all chains).
  • The weight of the dispatch info of the call (stored in the variable weight)
  • The actual weight of the call, determined from its post dispatch info, stored in the variable actual_weight.

Currently the weight surplus is defines as weight.saturating_sub(actual_weight), but given the above definitions it should clearly be require_weight_at_most.saturating_sub(actual_weight).

Fix the surplus weight calculation of `Transact`
Copy link
Contributor

@KiChjang KiChjang left a comment

Choose a reason for hiding this comment

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

Great find! Given the code comment right below it, this sounds like the correct fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants