-
Notifications
You must be signed in to change notification settings - Fork 724
New gas price estimation + HashDB + Fork ID 5 SMC #2196
Conversation
* update executor proto * gas price as string Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
…timation Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
a892877
to
005bfcc
Compare
Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
d438ffa
to
bec2576
Compare
Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
* add effective_gas_used to receipt * fix * fix * fix sql * fix
* effective gas price comparation * rename function * fix * refactor * linter * fix * update prover image * update prover image * refactor * refactor gas prices * refactor gas prices * fix * fix test * fix test * fix test * fix test * fix test * fix test * fix test * fix test * fix test * fix test * fix test * fix test * fix test * fix test * mutex * fix test * do not return error on l1gas=0 * remove commented code * refactor
func newDefaultGasPriceSuggester(ctx context.Context, cfg Config, pool poolInterface) *DefaultGasPricer { | ||
// Apply factor to calculate l1 gasPrice | ||
factorAsPercentage := int64(cfg.Factor * 100) // nolint:gomnd | ||
factor := big.NewInt(factorAsPercentage) | ||
defaultGasPriceDivByFactor := new(big.Int).Div(new(big.Int).SetUint64(cfg.DefaultGasPriceWei), factor) | ||
|
||
gpe := &DefaultGasPricer{ | ||
ctx: ctx, | ||
cfg: cfg, | ||
pool: pool, | ||
l1GasPrice: new(big.Int).Mul(defaultGasPriceDivByFactor, big.NewInt(100)).Uint64(), // nolint:gomnd | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thin it is not neccessary do the multiplication by 100 because later we divide by 100 and multiply by 100 to remove the percentage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to be able to do big.Int arithmetics
factorAsPercentage := int64(cfg.Factor * 100) // nolint:gomnd | ||
factor := big.NewInt(factorAsPercentage) | ||
defaultGasPriceDivByFactor := new(big.Int).Div(new(big.Int).SetUint64(cfg.DefaultGasPriceWei), factor) | ||
l1GasPrice := new(big.Int).Mul(defaultGasPriceDivByFactor, big.NewInt(100)).Uint64() // nolint:gomnd | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thin it is not neccessary do the multiplication by 100 because later we divide by 100 and multiply by 100 to remove the percentage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to be able to do big.Int arithmetics
gasprice/lastnbatches.go
Outdated
// Store gasPrices | ||
factorAsPercentage := int64(g.cfg.Factor * 100) // nolint:gomnd | ||
factor := big.NewInt(factorAsPercentage) | ||
l1GasPrice := new(big.Int).Div(g.lastPrice, factor) | ||
err = g.pool.SetGasPrices(g.ctx, g.lastPrice.Uint64(), l1GasPrice.Uint64()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I think the l1GasPrice value that we store on db is incorrect because is 100 times less than the real value
Closes #1763
Closes #2067
Closes #2178
Closes #2180
Closes #2098
New config parameters:
[Pool]
IntervalToRefreshGasPrices = "5s"
[Pool.EffectiveGasPrice]
L1GasPriceFactor = 0.25
ByteGasCost = 16
MarginFactor = 1
[Sequencer]
[Sequencer.EffectiveGasPrice]
MaxBreakEvenGasPriceDeviationPercentage = 10
Enabled = false
What does this PR do?
Pre-execution of Transactions
Formula for Calculation (In Pool)
TotalTxPrice = GasUsed * L2MinGasPrice + DataLengthInBytes * byteGasCost * L1GasPrice
BreakEvenGasPrice = TotalTxPrice / GasUsed * marginFactor
(The sequencer is to use the lower value among regular GasPrice and BreakEvenGasPrice.)
Store breakEvenGasPrice in the pool transactions table
L2MinGasPrice = Configuration parameter % L1 Gas price
byteGasCost = 16 (gas per byte in the storage)
MarginFactor: configurable constant = 1.1
Guarantee this price for 30 seconds
Transaction Execution (in Sequencer)
Attack Protection
BatchL2Data
Sequencer
Example GasPrice >= BreakEvenGasPRice
gasPrice * (b + 1)/256
computePercentatge(gasPrice, breakEvenGasPRice) return bytes1
--> [0, 255]gasPrice * (b - 1)/255
71 WeiExample GasPrice < BreakEvenGasPrice
----> increase
eth_gasPrice
RPC endpointReviewers