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
Better gas price engine algorithm #496
Comments
Hi All- you might be interested in looking as this code- its a much simpler version of the ethgasstation.info code - it works pretty well and is easy for anyone to run https://github.com/ethgasstation/gasstation-express-oracle |
Hey!
but in code it seems to be
It seems to be mistake in note, rather then code |
Could you please tell me what is this formula? Did you get it yourself or is it a ready one? |
@KarinaMojsievich it's something I worked out on a whiteboard. I don't recall the exact specifics. You'd have to read my post from above and figure it out. |
This comment has been minimized.
This comment has been minimized.
@raniama please do not spam a bunch of locations with the same question. See the links in my last response to you. |
Depends on #494
What needs to be done?
The algorithm used by https://ethgasstation.info/ is pretty solid for determining gas prices. Lets implement something similar
How can it be done?
Implement a new gas price engine (see #494 ) that uses the following algorithm to compute gas prices.
The algorithm will be configured with the following parameters:
N
be the number of historical blocks that should be sampled.P
be a number between [0-1] which represents the probability for gas price estimation. 0 meaning 0% probability and 1 meaning 100% probability.D
be the desired maximum wait time in seconds for the transaction to be mined.We then compute the following information by fetching data from the blockchain.
A
be the average block time for the lastN
blocks.M
be the set of miners from the lastN
blocks.For each miner in
M
compute:m.totalBlock
be the number of blocks mined by a given miner.m.minPrice
be the minimum gas price accepted for all transactions in all blocks mined by the given miner.g_max
be the maximum gas price for allm.minPrice
from the set of minersM
.g_min
be the minimum gas price for allm.minPrice
from the set of minersM
.Now we compute
B
, the maximum wait time in blocks using the formulaint(ceiling(D / A))
.Now we can use our computed data from the miners to compute the set of probabilities that a transaction will be included at each miner's min price. For a miner
x
leth
be the total number of blocks mined by all miners wherem.minPrice <= x.minPrice
. The probability is computed using the formula(1 - (N - h)/N) ** B
. Using this formula we can compute the set of probabilitiesp0, p1, ...
for each miner. Note that each probabilityp0
corresponds to a minerm0
. We also assume that these probabilities are ordered such thatp0 < p1, p1 < p2, ...
.Now compute the following values.
p_max
be the maximum probability from the set of probabilitiesp0, p1, ...
.p_min
be the minimum probability from the set of probabilitiesp0, p1, ...
.Now, to compute the gas price for a transaction to be included within
B
blocks with probabilityP
as follows.P
>p_max
, the gas price isg_max
P
<p_min
, the gas price isg_min
Otherwise, we find the location within
p0, p1, ...
such thatpn <= P <= pn+1
. The desired gas price can then be computed as follows.If
pn == pn+1
then the desired gas price is mn.minPrice. Otherwise...p_left
bepn
p_right
bepn+1
g_left
bemn.minPrice
g_right
bemn+1.minPrice
Below is an example implementation of this formula in python.
The text was updated successfully, but these errors were encountered: