Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Runtime): Refund allowance to the access keys #2742

Merged
merged 9 commits into from
Jun 2, 2020

Conversation

evgenykuzyakov
Copy link
Collaborator

@evgenykuzyakov evgenykuzyakov commented May 28, 2020

Fixes: #2523

This PR introduces access keys allowance refunds using the old Receipt refund data structure by reusing existing fields.

Right now the refund receipt is identified by a receipt with the predecessor_id == "system". These are special type of receipts that don't cost any gas and also don't generate refunds themselves.

This change reuses existing fields from the ActionReceipt such as signer_id and signer_public_key to distinguish between Gas Refunds and Deposit Refunds.
Gas refunds are refunds for the unused amount of Gas, while the Deposit Refunds are for the deposit amounts attached to transfer and function_call actions as well as refund for an action of deleting the account.

New Gas Refund Receipts also have the predecessor_id == "system", but signer_id == receiver_id (because gas refunds always sent to the signer). While Deposit refunds still have signer_id == "system". This allows to distinguish between Gas vs Deposit refunds.

The Gas Refund also uses the original signer_public_key to be able to identify the access key needed to refund the unused gas potion of the allowance.

When the Gas refund receipt arrives to the account, the original access key that signed the transaction that spawned this receipt might have been changed (e.g. using delete_key/add_key). This means that in some situation the gas refund towards the allowance can't be made, so we use best effort to refund the allowance, even if the access key is different.

  • TODO: Spec update

Spec update: near/NEPs#75

Test plan

  • Modified the test that covers function call access key and verified that it generated the refund.
  • CI

@gitpod-io
Copy link

gitpod-io bot commented May 28, 2020

Copy link
Collaborator

@bowenwang1996 bowenwang1996 left a comment

Choose a reason for hiding this comment

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

Please don't forget to bump protocol version.

runtime/runtime/src/actions.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@bowenwang1996 bowenwang1996 left a comment

Choose a reason for hiding this comment

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

Epic 🚀

@nearprotocol-bulldozer nearprotocol-bulldozer bot merged commit be20d99 into master Jun 2, 2020
@nearprotocol-bulldozer nearprotocol-bulldozer bot deleted the return-allowance branch June 2, 2020 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access key allowance get charged for max allowed gas for tx instead what was spent
4 participants