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

Add Existence Requirement to Transfer #3986

Closed
joepetrowski opened this issue Oct 31, 2019 · 1 comment · Fixed by #4000
Closed

Add Existence Requirement to Transfer #3986

joepetrowski opened this issue Oct 31, 2019 · 1 comment · Fixed by #4000
Labels
J0-enhancement An additional feature request. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder Z6-mentor An easy task where a mentor is available. Please indicate in the issue who the mentor could be.

Comments

@joepetrowski
Copy link
Contributor

joepetrowski commented Oct 31, 2019

We should add a parameter to transfer in the Balances module so that the sender can prefer to have the transaction fail rather than have the account reaped.

Currently, extrinsics pay an inclusion_fee = base_fee + byte_fee + weight_fee. This is charged prior to execution of the extrinsic and doesn't know anything about the internal logic of the extrinsic.

The inclusion fee is updated for block N+1 based on the weight of block N compared to the target weight according to TargetedFeeAdjustment so you can calculate the inclusion fee for the next block. However, it is possible that a transaction is in the pool for several blocks before inclusion. The sender may intend to leave enough balance to keep the account but have it reaped.

Users

This is a problem for exchanges who manage thousands of accounts. Not having this feature makes them leave a large margin of safety on ED to prevent nonce reset. This is undesirable because it represents a lot of wasted capital.

Example

As a concrete example, imagine the following scenario:

balance = 10
ED = 1
current_inclusion_fee = 1
next_block_inclusion_fee = 1.5

The user attempts to transfer 7 tokens, but the extrinsic is in the pool for several blocks and the inclusion_fee increases to 2.1. Substrate then:

  • Takes the inclusion fee
  • Executes the extrinsic, leaving balance = 0.9 and reaping the account

The user should be able to add an optional parameter to transfer to avoid executing the transaction if it would lead to the account getting reaped.

@joepetrowski joepetrowski added J0-enhancement An additional feature request. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder labels Oct 31, 2019
@kianenigma kianenigma added the Z6-mentor An easy task where a mentor is available. Please indicate in the issue who the mentor could be. label Nov 1, 2019
@joepetrowski
Copy link
Contributor Author

joepetrowski commented Nov 1, 2019

Some further thinking based on:

///   diff = (previous_block_weight - target_weight)
///   v = 0.00004
///   next_weight = weight * (1 + (v . diff) + (v . diff)^2 / 2)

If you try to find the maximum value this could take, set:

target_weight = 0
previous_block_weight = 1
=> diff = 1

(1 + (v . diff) + (v . diff)^2 / 2) = 1 + 0.00004 + 0.00004^2/2 = 1.00004

Now create a mortal extrinsic with a life of n blocks:

max_inclusion_fee = current_fee * 1.00004^n
Using the default n = 50
=> max_inclusion_fee = 1.002 * current_fee

So, you can in fact bound the fee you would pay.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J0-enhancement An additional feature request. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder Z6-mentor An easy task where a mentor is available. Please indicate in the issue who the mentor could be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants