Skip to content

Commit

Permalink
Improve effective gas price implementation (RPC filter, gasprice/bala…
Browse files Browse the repository at this point in the history
…nce opcodes flags, new formula) (0xPolygonHermez#2690)

* initial changes related to revision of effective gas price implementation

* Use EffectiveGasPriceLog struct to log/store EGP calculation details

* added egp tests and logs. Update executor proto

* implementation EGP for RPC (0xPolygonHermez#2652)

* implementation EGP for RPC

* added additional fields to EGPLog. Several fixes

* use BreakEvenFactor instead or pct margin. RPC egp-log changed

* fix white spaces

* fix lint and doc

* change pool egp logs

* fix nil evaluation on pool.StoreTx

* Revert "fix nil evaluation on pool.StoreTx"

This reverts commit 958a41f.

* fix pgstatestorage tests

* fix config doc

* added HasOpCode e2e test

* Added HasOpCode e2e test. Improve logs. Fixes

* Fix finalizer tests

* change egp checks

* fix PR review comments

* fix new error handling (0xPolygonHermez#2737)

---------

Co-authored-by: Joan Esteban <[email protected]>
Co-authored-by: Toni Ramírez <[email protected]>
  • Loading branch information
3 people authored Oct 31, 2023
1 parent 8c349ee commit d16f73d
Show file tree
Hide file tree
Showing 53 changed files with 2,071 additions and 909 deletions.
48 changes: 28 additions & 20 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,6 @@ func Test_Defaults(t *testing.T) {
path: "Sequencer.Finalizer.TimestampResolution",
expectedValue: types.NewDuration(10 * time.Second),
},
{
path: "Sequencer.EffectiveGasPrice.MaxBreakEvenGasPriceDeviationPercentage",
expectedValue: uint64(10),
},
{
path: "Sequencer.EffectiveGasPrice.L1GasPriceFactor",
expectedValue: float64(0.25),
},
{
path: "Sequencer.EffectiveGasPrice.ByteGasCost",
expectedValue: uint64(16),
},
{
path: "Sequencer.EffectiveGasPrice.MarginFactor",
expectedValue: float64(1),
},
{
path: "Sequencer.EffectiveGasPrice.Enabled",
expectedValue: false,
},
{
path: "Sequencer.DBManager.PoolRetrievalInterval",
expectedValue: types.NewDuration(500 * time.Millisecond),
Expand Down Expand Up @@ -281,6 +261,34 @@ func Test_Defaults(t *testing.T) {
path: "Pool.GlobalQueue",
expectedValue: uint64(1024),
},
{
path: "Pool.EffectiveGasPrice.Enabled",
expectedValue: false,
},
{
path: "Pool.EffectiveGasPrice.L1GasPriceFactor",
expectedValue: float64(0.25),
},
{
path: "Pool.EffectiveGasPrice.ByteGasCost",
expectedValue: uint64(16),
},
{
path: "Pool.EffectiveGasPrice.ZeroByteGasCost",
expectedValue: uint64(4),
},
{
path: "Pool.EffectiveGasPrice.NetProfit",
expectedValue: float64(1),
},
{
path: "Pool.EffectiveGasPrice.BreakEvenFactor",
expectedValue: float64(1.1),
},
{
path: "Pool.EffectiveGasPrice.FinalDeviationPct",
expectedValue: uint64(10),
},
{
path: "Pool.DB.User",
expectedValue: "pool_user",
Expand Down
16 changes: 9 additions & 7 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ MinAllowedGasPriceInterval = "5m"
PollMinAllowedGasPriceInterval = "15s"
AccountQueue = 64
GlobalQueue = 1024
[Pool.DB]
[Pool.EffectiveGasPrice]
Enabled = false
L1GasPriceFactor = 0.25
ByteGasCost = 16
ZeroByteGasCost = 4
NetProfit = 1
BreakEvenFactor = 1.1
FinalDeviationPct = 10
[Pool.DB]
User = "pool_user"
Password = "pool_password"
Name = "pool_db"
Expand Down Expand Up @@ -128,12 +136,6 @@ MaxTxLifetime = "3h"
[Sequencer.DBManager]
PoolRetrievalInterval = "500ms"
L2ReorgRetrievalInterval = "5s"
[Sequencer.EffectiveGasPrice]
MaxBreakEvenGasPriceDeviationPercentage = 10
L1GasPriceFactor = 0.25
ByteGasCost = 16
MarginFactor = 1
Enabled = false
[Sequencer.StreamServer]
Port = 0
Filename = ""
Expand Down
14 changes: 8 additions & 6 deletions config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ MaxTxDataBytesSize=100000
DefaultMinGasPriceAllowed = 1000000000
MinAllowedGasPriceInterval = "5m"
PollMinAllowedGasPriceInterval = "15s"
[Pool.EffectiveGasPrice]
Enabled = false
L1GasPriceFactor = 0.25
ByteGasCost = 16
ZeroByteGasCost = 4
NetProfit = 1
BreakEvenFactor = 1.1
FinalDeviationPct = 10
[Pool.DB]
User = "pool_user"
Password = "pool_password"
Expand Down Expand Up @@ -88,12 +96,6 @@ MaxTxLifetime = "3h"
[Sequencer.DBManager]
PoolRetrievalInterval = "500ms"
L2ReorgRetrievalInterval = "5s"
[Sequencer.EffectiveGasPrice]
MaxBreakEvenGasPriceDeviationPercentage = 10
L1GasPriceFactor = 0.25
ByteGasCost = 16
MarginFactor = 1
Enabled = false
[Sequencer.StreamServer]
Port = 0
Filename = ""
Expand Down
6 changes: 5 additions & 1 deletion db/migrations/state/0011.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ CREATE INDEX IF NOT EXISTS log_topic1_idx ON state.log (topic1);
CREATE INDEX IF NOT EXISTS log_topic2_idx ON state.log (topic2);
CREATE INDEX IF NOT EXISTS log_topic3_idx ON state.log (topic3);

ALTER TABLE state.transaction ADD COLUMN egp_log JSONB;

-- +migrate Down
DROP INDEX IF EXISTS state.l2block_created_at_idx;

DROP INDEX IF EXISTS state.log_log_index_idx;
DROP INDEX IF EXISTS state.log_topic0_idx;
DROP INDEX IF EXISTS state.log_topic1_idx;
DROP INDEX IF EXISTS state.log_topic2_idx;
DROP INDEX IF EXISTS state.log_topic3_idx;
DROP INDEX IF EXISTS state.log_topic3_idx;

ALTER TABLE state.transaction DROP COLUMN egp_log;
14 changes: 14 additions & 0 deletions db/migrations/state/0011_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func (m migrationTest0011) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB)
assert.NoError(t, row.Scan(&result))
assert.Equal(t, 1, result)
}

// Check column egp_log exists in state.transactions table
const getFinalDeviationColumn = `SELECT count(*) FROM information_schema.columns WHERE table_name='transaction' and column_name='egp_log'`
row := db.QueryRow(getFinalDeviationColumn)
var result int
assert.NoError(t, row.Scan(&result))
assert.Equal(t, 1, result)
}

func (m migrationTest0011) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB) {
Expand All @@ -52,6 +59,13 @@ func (m migrationTest0011) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB
assert.NoError(t, row.Scan(&result))
assert.Equal(t, 0, result)
}

// Check column egp_log doesn't exists in state.transactions table
const getFinalDeviationColumn = `SELECT count(*) FROM information_schema.columns WHERE table_name='transaction' and column_name='egp_log'`
row := db.QueryRow(getFinalDeviationColumn)
var result int
assert.NoError(t, row.Scan(&result))
assert.Equal(t, 0, result)
}

func TestMigration0011(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

Loading

0 comments on commit d16f73d

Please sign in to comment.