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

extend ensure_account_can_withdraw and fix transfer check#1978

Closed
gui1117 wants to merge 2 commits intomasterfrom
gui-withdraw
Closed

extend ensure_account_can_withdraw and fix transfer check#1978
gui1117 wants to merge 2 commits intomasterfrom
gui-withdraw

Conversation

@gui1117
Copy link
Contributor

@gui1117 gui1117 commented Mar 12, 2019

related to #1962

as pointed by @xlc here we don't check if account can withdraw the amount for the TransactionPayment reason.

so it fix it, improve ensure_account_can_withdraw syntax and remove _amount unused parameter from it.

I am not very sure of this, I may be wrong if TransactionPayment reason is considered a subset of Transfer reason.

@gui1117 gui1117 added A0-please_review Pull request needs code review. A4-gotissues A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Mar 12, 2019
who: &T::AccountId,
_amount: T::Balance,
reason: WithdrawReason,
reasons: impl Into<WithdrawReasons>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I never encounter this syntax before. Can I know where I can read more about this syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in parameter as far as I know it is same as if I have a generic in function T: Into<WithdrawReasons> and then reasons: T I don't have that much material maybe try to google impl trait

Copy link
Member

Choose a reason for hiding this comment

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

Incorrect - there should be just one WithdrawReason for any single withdraw,

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's say I want to create a runtime module that allow user to reserve and transfer in a single runtime call. How can do it? Call ensure_account_can_withdraw twice with different reasons before all the withdraws will not give the correct result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually calling

ensure_account_can_withdraw(who, Reserve | Transfer, new_free_balance)

is equivalent to

ensure_account_can_withdraw(who, Transfer, new_free_balance)
ensure_account_can_withdraw(who, Reserve, new_free_balance)

Self::ensure_account_can_withdraw(transactor, value, WithdrawReason::Transfer, new_from_balance)?;
Self::ensure_account_can_withdraw(
transactor,
WithdrawReason::Transfer | WithdrawReason::TransactionPayment,
Copy link
Member

Choose a reason for hiding this comment

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

This is not a transaction payment. Transaction payments happen specifically for inclusion of a transaction in the chain.

@gavofyork
Copy link
Member

gavofyork commented Mar 13, 2019

Removal of _value parameter is reasonable. However the rest of changes are in error.

@xlc
Copy link
Contributor

xlc commented Mar 13, 2019

Seems like me and @thiolliere have some misunderstanding of the meaning of transaction payment. @gavofyork can you provide some definitions of it?

To my understanding, transaction payment, is the transaction fee user have to pay to have the transaction included in the chain.
This can be made up with two parts:

  1. fee of inclusion of the the transaction, which is calculated with a base fee + transaction size * byte fee
  2. fee of additional storage / computation usage, in balance transfer case is account creation fee (addition storage usage) and transfer fee (storage read and write). In smart contract case, it is gas fee.

If my understanding is wrong, that only (1) is counted as transaction payment, then what is the (2) part? It is a fee charged to user. It is not value transferred to another account. Should there be another WithdrawReason?

@gui1117
Copy link
Contributor Author

gui1117 commented Mar 13, 2019

Yes that was thought indeed, then maybe (2) is actually just a Transfer reason

(I've been to fast into impl, this should have been discussed in the issue)

@gui1117 gui1117 added Z7-question Issue is a question. Closer should answer. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Mar 13, 2019
@xlc xlc mentioned this pull request Mar 14, 2019
@gavofyork
Copy link
Member

So WithdrawReason::Transfer is to be read "withdrawing from an account in the duty of executing the transfer function".

It doesn't relate to the balance of the total withdrawal that lands in the transfer destination's account.

@gui1117 gui1117 changed the title extend ensure_account_can_withdraw and fix transfer check Removal of _value parameter is reasonable Mar 14, 2019
@gui1117 gui1117 changed the title Removal of _value parameter is reasonable Removal of _value parameter in ensure_account_can_withdraw Mar 14, 2019
@gui1117 gui1117 closed this Mar 14, 2019
@gui1117 gui1117 changed the title Removal of _value parameter in ensure_account_can_withdraw extend ensure_account_can_withdraw and fix transfer check Mar 14, 2019
@gui1117 gui1117 deleted the gui-withdraw branch April 18, 2019 08:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Z7-question Issue is a question. Closer should answer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants