Skip to content

Commit d16f73d

Browse files
agnusmorjoanestebanrToniRamirezM
authored
Improve effective gas price implementation (RPC filter, gasprice/balance opcodes flags, new formula) (0xPolygon#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 (0xPolygon#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 (0xPolygon#2737) --------- Co-authored-by: Joan Esteban <129153821+joanestebanr@users.noreply.github.com> Co-authored-by: Toni Ramírez <58293609+ToniRamirezM@users.noreply.github.com>
1 parent 8c349ee commit d16f73d

53 files changed

Lines changed: 2071 additions & 909 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config/config_test.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,6 @@ func Test_Defaults(t *testing.T) {
104104
path: "Sequencer.Finalizer.TimestampResolution",
105105
expectedValue: types.NewDuration(10 * time.Second),
106106
},
107-
{
108-
path: "Sequencer.EffectiveGasPrice.MaxBreakEvenGasPriceDeviationPercentage",
109-
expectedValue: uint64(10),
110-
},
111-
{
112-
path: "Sequencer.EffectiveGasPrice.L1GasPriceFactor",
113-
expectedValue: float64(0.25),
114-
},
115-
{
116-
path: "Sequencer.EffectiveGasPrice.ByteGasCost",
117-
expectedValue: uint64(16),
118-
},
119-
{
120-
path: "Sequencer.EffectiveGasPrice.MarginFactor",
121-
expectedValue: float64(1),
122-
},
123-
{
124-
path: "Sequencer.EffectiveGasPrice.Enabled",
125-
expectedValue: false,
126-
},
127107
{
128108
path: "Sequencer.DBManager.PoolRetrievalInterval",
129109
expectedValue: types.NewDuration(500 * time.Millisecond),
@@ -281,6 +261,34 @@ func Test_Defaults(t *testing.T) {
281261
path: "Pool.GlobalQueue",
282262
expectedValue: uint64(1024),
283263
},
264+
{
265+
path: "Pool.EffectiveGasPrice.Enabled",
266+
expectedValue: false,
267+
},
268+
{
269+
path: "Pool.EffectiveGasPrice.L1GasPriceFactor",
270+
expectedValue: float64(0.25),
271+
},
272+
{
273+
path: "Pool.EffectiveGasPrice.ByteGasCost",
274+
expectedValue: uint64(16),
275+
},
276+
{
277+
path: "Pool.EffectiveGasPrice.ZeroByteGasCost",
278+
expectedValue: uint64(4),
279+
},
280+
{
281+
path: "Pool.EffectiveGasPrice.NetProfit",
282+
expectedValue: float64(1),
283+
},
284+
{
285+
path: "Pool.EffectiveGasPrice.BreakEvenFactor",
286+
expectedValue: float64(1.1),
287+
},
288+
{
289+
path: "Pool.EffectiveGasPrice.FinalDeviationPct",
290+
expectedValue: uint64(10),
291+
},
284292
{
285293
path: "Pool.DB.User",
286294
expectedValue: "pool_user",

config/default.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ MinAllowedGasPriceInterval = "5m"
4444
PollMinAllowedGasPriceInterval = "15s"
4545
AccountQueue = 64
4646
GlobalQueue = 1024
47-
[Pool.DB]
47+
[Pool.EffectiveGasPrice]
48+
Enabled = false
49+
L1GasPriceFactor = 0.25
50+
ByteGasCost = 16
51+
ZeroByteGasCost = 4
52+
NetProfit = 1
53+
BreakEvenFactor = 1.1
54+
FinalDeviationPct = 10
55+
[Pool.DB]
4856
User = "pool_user"
4957
Password = "pool_password"
5058
Name = "pool_db"
@@ -128,12 +136,6 @@ MaxTxLifetime = "3h"
128136
[Sequencer.DBManager]
129137
PoolRetrievalInterval = "500ms"
130138
L2ReorgRetrievalInterval = "5s"
131-
[Sequencer.EffectiveGasPrice]
132-
MaxBreakEvenGasPriceDeviationPercentage = 10
133-
L1GasPriceFactor = 0.25
134-
ByteGasCost = 16
135-
MarginFactor = 1
136-
Enabled = false
137139
[Sequencer.StreamServer]
138140
Port = 0
139141
Filename = ""

config/environments/local/local.node.config.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ MaxTxDataBytesSize=100000
3737
DefaultMinGasPriceAllowed = 1000000000
3838
MinAllowedGasPriceInterval = "5m"
3939
PollMinAllowedGasPriceInterval = "15s"
40+
[Pool.EffectiveGasPrice]
41+
Enabled = false
42+
L1GasPriceFactor = 0.25
43+
ByteGasCost = 16
44+
ZeroByteGasCost = 4
45+
NetProfit = 1
46+
BreakEvenFactor = 1.1
47+
FinalDeviationPct = 10
4048
[Pool.DB]
4149
User = "pool_user"
4250
Password = "pool_password"
@@ -88,12 +96,6 @@ MaxTxLifetime = "3h"
8896
[Sequencer.DBManager]
8997
PoolRetrievalInterval = "500ms"
9098
L2ReorgRetrievalInterval = "5s"
91-
[Sequencer.EffectiveGasPrice]
92-
MaxBreakEvenGasPriceDeviationPercentage = 10
93-
L1GasPriceFactor = 0.25
94-
ByteGasCost = 16
95-
MarginFactor = 1
96-
Enabled = false
9799
[Sequencer.StreamServer]
98100
Port = 0
99101
Filename = ""

db/migrations/state/0011.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ CREATE INDEX IF NOT EXISTS log_topic1_idx ON state.log (topic1);
77
CREATE INDEX IF NOT EXISTS log_topic2_idx ON state.log (topic2);
88
CREATE INDEX IF NOT EXISTS log_topic3_idx ON state.log (topic3);
99

10+
ALTER TABLE state.transaction ADD COLUMN egp_log JSONB;
11+
1012
-- +migrate Down
1113
DROP INDEX IF EXISTS state.l2block_created_at_idx;
1214

1315
DROP INDEX IF EXISTS state.log_log_index_idx;
1416
DROP INDEX IF EXISTS state.log_topic0_idx;
1517
DROP INDEX IF EXISTS state.log_topic1_idx;
1618
DROP INDEX IF EXISTS state.log_topic2_idx;
17-
DROP INDEX IF EXISTS state.log_topic3_idx;
19+
DROP INDEX IF EXISTS state.log_topic3_idx;
20+
21+
ALTER TABLE state.transaction DROP COLUMN egp_log;

db/migrations/state/0011_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ func (m migrationTest0011) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB)
3232
assert.NoError(t, row.Scan(&result))
3333
assert.Equal(t, 1, result)
3434
}
35+
36+
// Check column egp_log exists in state.transactions table
37+
const getFinalDeviationColumn = `SELECT count(*) FROM information_schema.columns WHERE table_name='transaction' and column_name='egp_log'`
38+
row := db.QueryRow(getFinalDeviationColumn)
39+
var result int
40+
assert.NoError(t, row.Scan(&result))
41+
assert.Equal(t, 1, result)
3542
}
3643

3744
func (m migrationTest0011) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB) {
@@ -52,6 +59,13 @@ func (m migrationTest0011) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB
5259
assert.NoError(t, row.Scan(&result))
5360
assert.Equal(t, 0, result)
5461
}
62+
63+
// Check column egp_log doesn't exists in state.transactions table
64+
const getFinalDeviationColumn = `SELECT count(*) FROM information_schema.columns WHERE table_name='transaction' and column_name='egp_log'`
65+
row := db.QueryRow(getFinalDeviationColumn)
66+
var result int
67+
assert.NoError(t, row.Scan(&result))
68+
assert.Equal(t, 0, result)
5569
}
5670

5771
func TestMigration0011(t *testing.T) {

docs/config-file/node-config-doc.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)