Skip to content
This repository has been archived by the owner on Feb 17, 2025. It is now read-only.

New gas price estimation + HashDB + Fork ID 5 SMC #2196

Merged
merged 44 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
238841b
wip
Psykepro May 23, 2023
6b25dea
update executor proto (#2122)
ToniRamirezM May 25, 2023
db73917
new smc
ARR552 Jun 12, 2023
8231e94
smc docker image
ARR552 Jun 12, 2023
e037fb1
merging feature/HashDB
Psykepro Jun 12, 2023
0d2e667
Merge branch 'feature/#2180_update_smc' into feature/new-gas-price-es…
Psykepro Jun 13, 2023
005bfcc
wip
Psykepro Jun 15, 2023
104809e
fixing comments.
Psykepro Jun 19, 2023
42dd793
Merge branch 'develop' into feature/new-gas-price-estimation
Psykepro Jun 19, 2023
652f87c
improve: adding missing safe check for L2 Min Gas Price.
Psykepro Jun 19, 2023
a33bfc4
fix: fixing eth-CallEcrecoverInvalidSignature.json 'expectedOldStateR…
Psykepro Jun 20, 2023
f9d7f11
improve: adding missing check in finalizer for old txs.
Psykepro Jun 20, 2023
238dd02
Merge branch 'develop' into feature/new-gas-price-estimation
Psykepro Jun 20, 2023
b4bd054
Optimize trace (#2183) (#2206)
ToniRamirezM Jun 20, 2023
fd98a0d
New image with geth1.12.0
ARR552 Jun 20, 2023
a7bcfce
Merge branch 'feature/#2180_update_smc' into feature/new-gas-price-es…
Psykepro Jun 20, 2023
cb67baa
geth1.11.5
ARR552 Jun 20, 2023
6caabaa
Merge branch 'feature/#2180_update_smc' into feature/new-gas-price-es…
Psykepro Jun 20, 2023
f83ab0c
fix: fixing contract addresses in configs.
Psykepro Jun 20, 2023
f9ac9e5
changing zkevm-mock-l1-network image to hermeznetwork/geth-zkevm-cont…
Psykepro Jun 21, 2023
f793599
Fix/group8 (#2211)
ToniRamirezM Jun 21, 2023
52ae6c0
smc
ARR552 Jun 21, 2023
277cada
genBlockNumb
ARR552 Jun 21, 2023
c44883f
use forkID while encoding/decoding txs (#2219)
ToniRamirezM Jun 23, 2023
6eca7e0
Add effective_gas_price to receipt (#2222)
ToniRamirezM Jun 26, 2023
0097eb9
merge develop
ToniRamirezM Jun 27, 2023
77cc055
fix sql
ToniRamirezM Jun 27, 2023
4fbb91a
fix sql
ToniRamirezM Jun 27, 2023
9fb166f
fix
ToniRamirezM Jun 27, 2023
2c6cd24
fix
ToniRamirezM Jun 27, 2023
ebfbb51
fix helper
ToniRamirezM Jun 27, 2023
6e39665
fix sql
ToniRamirezM Jun 27, 2023
3454ca8
change sql
ToniRamirezM Jun 27, 2023
f63c4d9
update prover image
ToniRamirezM Jun 27, 2023
dd8a654
update prover image
ToniRamirezM Jun 28, 2023
7037bb4
effective gas price comparation (#2234)
ToniRamirezM Jun 29, 2023
837f81c
solve conflicts
ToniRamirezM Jun 29, 2023
7eee697
fix conflicts
ToniRamirezM Jun 29, 2023
c190c7e
fix conflicts
ToniRamirezM Jun 29, 2023
e69a85c
make factors floats
ToniRamirezM Jun 30, 2023
2d866e3
fix gasprice
ToniRamirezM Jun 30, 2023
3a28e89
fix gasprice
ToniRamirezM Jun 30, 2023
22648f1
Merge branch 'develop' into feature/new-gas-price-estimation
ToniRamirezM Jun 30, 2023
e8a5389
merge develop and fix conflicts
ToniRamirezM Jun 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update executor proto (#2122)
* update executor proto

* gas price as string

Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
  • Loading branch information
ToniRamirezM authored and Psykepro committed Jun 5, 2023
commit 6b25deacd5e3ba84d203c547b48714a7c234e006
20 changes: 20 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ func Test_Defaults(t *testing.T) {
path: "Sequencer.Finalizer.TimestampResolution",
expectedValue: types.NewDuration(15 * time.Second),
},
{
path: "Sequencer.Finalizer.EffectiveGasPrice.BreakEvenGasPriceGuaranteedPeriod",
expectedValue: types.NewDuration(30 * time.Second),
},
{
path: "Sequencer.Finalizer.EffectiveGasPrice.MaxBreakEvenGasPriceDeviationPercentage",
expectedValue: uint64(10),
},
{
path: "Sequencer.DBManager.PoolRetrievalInterval",
expectedValue: types.NewDuration(500 * time.Millisecond),
Expand Down Expand Up @@ -342,6 +350,18 @@ func Test_Defaults(t *testing.T) {
path: "Pool.DB.MaxConns",
expectedValue: 200,
},
{
path: "Pool.EffectiveGasPrice.L1GasPricePercentageForL2MinPrice",
expectedValue: uint64(10),
},
{
path: "Pool.EffectiveGasPrice.ByteGasCost",
expectedValue: uint64(16),
},
{
path: "Pool.EffectiveGasPrice.MarginFactorPercentage",
expectedValue: uint64(10),
},
{
path: "RPC.Host",
expectedValue: "0.0.0.0",
Expand Down
7 changes: 7 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ PollMinAllowedGasPriceInterval = "15s"
Port = "5432"
EnableLog = false
MaxConns = 200
[Pool.EffectiveGasPrice]
L1GasPricePercentageForL2MinPrice = 10
ByteGasCost = 16
MarginFactorPercentage = 10

[Etherman]
URL = "http://localhost:8545"
Expand Down Expand Up @@ -99,6 +103,9 @@ MaxTxLifetime = "3h"
ClosingSignalsManagerWaitForCheckingForcedBatches = "10s"
ForcedBatchesFinalityNumberOfBlocks = 64
TimestampResolution = "15s"
[Sequencer.Finalizer.EffectiveGasPrice]
BreakEvenGasPriceGuaranteedPeriod = "30s"
MaxBreakEvenGasPriceDeviationPercentage = 10
[Sequencer.DBManager]
PoolRetrievalInterval = "500ms"
L2ReorgRetrievalInterval = "5s"
Expand Down
21 changes: 14 additions & 7 deletions config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ DefaultMinGasPriceAllowed = 1000000000
MinAllowedGasPriceInterval = "5m"
PollMinAllowedGasPriceInterval = "15s"
[Pool.DB]
User = "pool_user"
Password = "pool_password"
Name = "pool_db"
Host = "zkevm-pool-db"
Port = "5432"
EnableLog = false
MaxConns = 200
User = "pool_user"
Password = "pool_password"
Name = "pool_db"
Host = "zkevm-pool-db"
Port = "5432"
EnableLog = false
MaxConns = 200
[Pool.EffectiveGasPrice]
L1GasPricePercentageForL2MinPrice = 10
ByteGasCost = 16
MarginFactorPercentage = 10

[Etherman]
URL = "http://your.L1node.url"
Expand Down Expand Up @@ -89,6 +93,9 @@ MaxTxLifetime = "3h"
ClosingSignalsManagerWaitForCheckingForcedBatches = "10s"
ForcedBatchesFinalityNumberOfBlocks = 64
TimestampResolution = "15s"
[Sequencer.Finalizer.EffectiveGasPrice]
BreakEvenGasPriceGuaranteedPeriod = "30s"
MaxBreakEvenGasPriceDeviationPercentage = 10
[Sequencer.DBManager]
PoolRetrievalInterval = "500ms"
L2ReorgRetrievalInterval = "5s"
Expand Down
2 changes: 2 additions & 0 deletions event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const (
EventID_ExecutorRLPError EventID = "EXECUTOR RLP ERROR"
// EventID_FinalizerHalt is triggered when the finalizer halts
EventID_FinalizerHalt EventID = "FINALIZER HALT"
// EventID_FinalizerBreakEvenGasPriceBigDifference is triggered when the finalizer recalculates the break even gas price and detects a big difference
EventID_FinalizerBreakEvenGasPriceBigDifference EventID = "FINALIZER BREAK EVEN GAS PRICE BIG DIFFERENCE"

// Source_Node is the source of the event
Source_Node Source = "node"
Expand Down
22 changes: 0 additions & 22 deletions gasprice/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,4 @@ type Config struct {
Percentile int `mapstructure:"Percentile"`
UpdatePeriod types.Duration `mapstructure:"UpdatePeriod"`
Factor float64 `mapstructure:"Factor"`

// BreakEvenGasPriceCalcCfg is the configuration for the break even gas price calculation
BreakEvenGasPriceCalcCfg BreakEvenGasPriceCalculationCfg `mapstructure:"BreakEvenGasPriceCalculationCfg"`
}

// BreakEvenGasPriceCalculationCfg has parameters for the gas price calculation.
// TODO: Add config tests
type BreakEvenGasPriceCalculationCfg struct {
// L1GasPricePercentageForL2MinPrice is the percentage of the L1 gas price that will be used as the L2 min gas price
L1GasPricePercentageForL2MinPrice uint64 `mapstructure:"L1GasPricePercentageForL2MinPrice"`

// ByteGasCost is the gas cost per byte
ByteGasCost uint64 `mapstructure:"ByteGasCost"`

// MarginFactorPercentage is the margin factor percentage to be added to the L2 min gas price
MarginFactorPercentage uint64 `mapstructure:"MarginFactorPercentage"`

// TxPriceGuaranteePeriod is the period of time that the gas price will be guaranteed
TxPriceGuaranteePeriod types.Duration `mapstructure:"TxPriceGuaranteePeriod"`

// MaxBreakEvenGasPriceDeviationPercentage is the max allowed deviation percentage BreakEvenGasPrice on re-calculation
MaxBreakEvenGasPriceDeviationPercentage float64 `mapstructure:"MaxBreakEvenGasPriceDeviationPercentage"`
}
26 changes: 26 additions & 0 deletions jsonrpc/mocks/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions pool/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ type Config struct {
// PollMinAllowedGasPriceInterval is the interval to poll the suggested min gas price for a tx
PollMinAllowedGasPriceInterval types.Duration `mapstructure:"PollMinAllowedGasPriceInterval"`

// GasPriceEstimationCfg is the configuration for the gas price estimation
GasPriceEstimationCfg GasPriceEstimationConfig `mapstructure:"GasPriceEstimationConfig"`
// EffectiveGasPrice is the configuration for the break even and effective gas price calculation
EffectiveGasPrice EffectiveGasPrice `mapstructure:"EffectiveGasPrice"`
}

// GasPriceEstimationConfig has parameters for the gas price calculation.
// TODO: Add config tests
type GasPriceEstimationConfig struct {
// EffectiveGasPrice has parameters for the effective gas price calculation.
type EffectiveGasPrice struct {
// L1GasPricePercentageForL2MinPrice is the percentage of the L1 gas price that will be used as the L2 min gas price
L1GasPricePercentageForL2MinPrice uint64 `mapstructure:"L1GasPricePercentageForL2MinPrice"`

Expand All @@ -44,7 +43,4 @@ type GasPriceEstimationConfig struct {

// MarginFactorPercentage is the margin factor percentage to be added to the L2 min gas price
MarginFactorPercentage uint64 `mapstructure:"MarginFactorPercentage"`

// TxPriceGuaranteePeriod is the period of time that the gas price will be guaranteed
TxPriceGuaranteePeriod types.Duration `mapstructure:"TxPriceGuaranteePeriod"`
}
110 changes: 92 additions & 18 deletions pool/pgpoolstorage/pgpoolstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"errors"
"math/big"
"time"

"github.com/0xPolygonHermez/zkevm-node/db"
Expand Down Expand Up @@ -125,7 +126,7 @@ func (p *PostgresPoolStorage) AddTx(ctx context.Context, tx pool.Transaction) er
fromAddress,
tx.IsWIP,
tx.IP,
tx.BreakEvenGasPrice); err != nil {
tx.BreakEvenGasPrice.String()); err != nil {
return err
}
return nil
Expand All @@ -141,10 +142,10 @@ func (p *PostgresPoolStorage) GetTxsByStatus(ctx context.Context, status pool.Tx
sql string
)
if limit == 0 {
sql = "SELECT encoded, status, received_at, is_wip, ip, failed_reason FROM pool.transaction WHERE status = $1 ORDER BY gas_price DESC"
sql = "SELECT encoded, status, received_at, is_wip, ip, failed_reason, break_even_gas_price FROM pool.transaction WHERE status = $1 ORDER BY gas_price DESC"
rows, err = p.db.Query(ctx, sql, status.String())
} else {
sql = "SELECT encoded, status, received_at, is_wip, ip, failed_reason FROM pool.transaction WHERE status = $1 ORDER BY gas_price DESC LIMIT $2"
sql = "SELECT encoded, status, received_at, is_wip, ip, failed_reason, break_even_gas_price FROM pool.transaction WHERE status = $1 ORDER BY gas_price DESC LIMIT $2"
rows, err = p.db.Query(ctx, sql, status.String(), limit)
}
if err != nil {
Expand All @@ -169,15 +170,37 @@ func (p *PostgresPoolStorage) GetTxsByStatus(ctx context.Context, status pool.Tx
// if limit = 0, then there is no limit
func (p *PostgresPoolStorage) GetNonWIPTxsByStatus(ctx context.Context, status pool.TxStatus, limit uint64) ([]pool.Transaction, error) {
var (
rows pgx.Rows
err error
sql string
rows pgx.Rows
err error
sql string
encoded, ip, breakEvenGasPriceAsStr string
failedReason *string
cumulativeGasUsed uint64
usedKeccakHashes, usedPoseidonHashes, usedPoseidonPaddings,
usedMemAligns, usedArithmetics, usedBinaries, usedSteps uint32
receivedAt time.Time
isWIP, ok bool
)
sql = `SELECT
encoded,
cumulative_gas_used,
used_keccak_hashes,
used_poseidon_hashes,
used_poseidon_paddings,
used_mem_aligns,
used_arithmetics,
used_binaries,
used_steps,
received_at,
is_wip,
ip,
failed_reason,
break_even_gas_price
FROM pool.transaction WHERE is_wip IS FALSE and status = $1 ORDER BY gas_price DESC`
if limit == 0 {
sql = "SELECT encoded, status, received_at, is_wip, ip, failed_reason FROM pool.transaction WHERE is_wip IS FALSE and status = $1 ORDER BY gas_price DESC"
rows, err = p.db.Query(ctx, sql, status.String())
} else {
sql = "SELECT encoded, status, received_at, is_wip, ip, failed_reason FROM pool.transaction WHERE is_wip IS FALSE and status = $1 ORDER BY gas_price DESC LIMIT $2"
sql += " LIMIT $2"
rows, err = p.db.Query(ctx, sql, status.String(), limit)
}
if err != nil {
Expand All @@ -187,11 +210,56 @@ func (p *PostgresPoolStorage) GetNonWIPTxsByStatus(ctx context.Context, status p

txs := make([]pool.Transaction, 0, len(rows.RawValues()))
for rows.Next() {
tx, err := scanTx(rows)
err := rows.Scan(
&encoded,
&cumulativeGasUsed,
&usedKeccakHashes,
&usedPoseidonHashes,
&usedPoseidonPaddings,
&usedMemAligns,
&usedArithmetics,
&usedBinaries,
&usedSteps,
&receivedAt,
&isWIP,
&ip,
&failedReason,
&breakEvenGasPriceAsStr,
)

if err != nil {
return nil, err
}
txs = append(txs, *tx)
tx := pool.Transaction{}
b, err := hex.DecodeHex(encoded)
if err != nil {
return nil, err
}
if err := tx.UnmarshalBinary(b); err != nil {
return nil, err
}

tx.Status = status
tx.ZKCounters = state.ZKCounters{
CumulativeGasUsed: cumulativeGasUsed,
UsedKeccakHashes: usedKeccakHashes,
UsedPoseidonHashes: usedPoseidonHashes,
UsedPoseidonPaddings: usedPoseidonPaddings,
UsedMemAligns: usedMemAligns,
UsedArithmetics: usedArithmetics,
UsedBinaries: usedBinaries,
UsedSteps: usedSteps,
}
tx.ReceivedAt = receivedAt
tx.IsWIP = isWIP
tx.IP = ip
tx.FailedReason = failedReason
tx.BreakEvenGasPrice, ok = new(big.Int).SetString(breakEvenGasPriceAsStr, 10)
if !ok {
return nil, errors.New("invalid break even gas price")
}

txs = append(txs, tx)
}

return txs, nil
Expand Down Expand Up @@ -235,7 +303,8 @@ func (p *PostgresPoolStorage) GetTxs(ctx context.Context, filterStatus pool.TxSt
received_at,
nonce,
is_wip,
ip
ip,
break_even_gas_price
FROM
pool.transaction p1
WHERE
Expand Down Expand Up @@ -263,7 +332,8 @@ func (p *PostgresPoolStorage) GetTxs(ctx context.Context, filterStatus pool.TxSt
received_at,
nonce,
is_wip,
ip
ip,
break_even_gas_price
FROM
pool.transaction p1
WHERE
Expand All @@ -278,14 +348,13 @@ func (p *PostgresPoolStorage) GetTxs(ctx context.Context, filterStatus pool.TxSt
}

var (
encoded, status, ip string
receivedAt time.Time
cumulativeGasUsed uint64

encoded, status, ip, breakEvenGasPriceAsStr string
receivedAt time.Time
cumulativeGasUsed uint64
usedKeccakHashes, usedPoseidonHashes, usedPoseidonPaddings,
usedMemAligns, usedArithmetics, usedBinaries, usedSteps uint32
nonce uint64
isWIP bool
nonce uint64
isWIP, ok bool
)

args := []interface{}{filterStatus, minGasPrice, limit}
Expand Down Expand Up @@ -314,6 +383,7 @@ func (p *PostgresPoolStorage) GetTxs(ctx context.Context, filterStatus pool.TxSt
&nonce,
&isWIP,
&ip,
&breakEvenGasPriceAsStr,
)

if err != nil {
Expand Down Expand Up @@ -342,6 +412,10 @@ func (p *PostgresPoolStorage) GetTxs(ctx context.Context, filterStatus pool.TxSt
}
tx.IsWIP = isWIP
tx.IP = ip
tx.BreakEvenGasPrice, ok = new(big.Int).SetString(breakEvenGasPriceAsStr, 10)
if !ok {
return nil, errors.New("invalid break even gas price")
}

txs = append(txs, tx)
}
Expand Down
Loading