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

Fix dynamic difficulty-driven fee #24

Open
aivve opened this issue Jan 27, 2021 · 3 comments
Open

Fix dynamic difficulty-driven fee #24

aivve opened this issue Jan 27, 2021 · 3 comments

Comments

@aivve
Copy link
Member

aivve commented Jan 27, 2021

The dynamically adjusting fee based on difficulty needs to be fixed and need to take into account possible POW change #21.

Now it uses an all-time avg. difficulty as a reference difficulty whereas it should use some selected difficulty at the point of time with the desired price to calculate the corresponding fee.

If new POW algo is introduced, this all-time difficulty will not be relevant.

Moreover, this all-time average difficulty is not from the initial equation F = S * A / D from whitepaper where, F​ — minimum transaction fee in native currency, KRB; S​ — starting fee in fiat equivalent, USD; A​ — Average difficulty constant, corresponding to the chosen level of fiat price; D​ — Current difficulty.

@aivve
Copy link
Member Author

aivve commented Jan 31, 2021

To work, this system requires stable and unchanging mining algo and/or stable and unchanging mining conditions, thus the development of ASICs rendered it completely useless. Although, the all-time avg. diff and reward as a reference look neat and is trailing, it may completely miss the shot. It builds up and incorporates avg. difficulty change caused by ASICs but I think it does not correspond to the price we want for the reference.

@aivve
Copy link
Member Author

aivve commented Jan 31, 2021

Anyways, even if it is left intact, upon algo change the historical avg. diff and reward should be calculated starting from the new algo height.

@aivve
Copy link
Member Author

aivve commented Feb 19, 2021

So, currently, minimal network fee is calculated according to this formula F = S * A / D where A​ as "Average difficulty constant, corresponding to the chosen level of fiat price" from whitepaper was replaced by "Average all-time difficulty", D is "average difficulty for the ~ last month" to make fee change smooth. To be exact it is D = E * 7 * 4, where E is "Expected number of blocks per day", i.e. ~ 4 weeks.

The fixed/static reference difficulty may not be correct because growing adoption may cause difficulty to grow, therefore maybe trailing avg difficulty (currently active and described above) is indeed a correct solution. Moreover, this way maybe it can adjust itself automatically without the need for intervention by devs, and perhaps even in such major changes in hashrate and difficulty as the advent of ASICs.

And, perhaps, in the case of algo change, average difficulty should be reset. It is because it is driven high by ASICs and will stay very high for a long time, and will not allow the fee to drop.

It can be done by deducing cumulative difficulty up to the point of hardfork, in other words start caclulating cumulative difficulty from the height of hardfork:

D = Dt - Dh

where D is the new reference difficulty we want, Dt is total cumulative difficulty, Dh is cumulative difficulty at the height of hardfork.

After the hardfork it should be calculated according to formula F = S * A / (Dt - Dh).

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

No branches or pull requests

1 participant