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

Commit 8d5cf96

Browse files
authored
Sequencer L2 block parallel processing improvements (#3604)
* wip * first implementation of parallel sequencer optmizations and L2 block reorg management * Close sipBatch (if needed) when processing reorg. Halt when 2 consecuties reorgs (same L2 block) * Return error when reserved counters overflow on l2 block process. Log used/reserved counters when closing wip batch * added logs to analyze blocking issue when storing L2 block * Fix unlock mutex in addTxTracker. Set wipTx to nil in RestoreTxsPendingToStore * add high reserved resorces in wipBatch * store high reserved counter on statedb.batch table * Return contextId in ProcessBatchV2 * fix synchornizer test * Set SequentialProcessL2Block to false by default. Update node config documentation * fix non-e2e tests * fix finalizer tests * remove unused code * test * Fix sequencer loadFromPool gofunc. Fix docker compose variables
1 parent e261069 commit 8d5cf96

Some content is hidden

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

41 files changed

+1208
-497
lines changed

config/config_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ func Test_Defaults(t *testing.T) {
101101
path: "Sequencer.Finalizer.ResourceExhaustedMarginPct",
102102
expectedValue: uint32(10),
103103
},
104+
{
105+
path: "Sequencer.Finalizer.StateRootSyncInterval",
106+
expectedValue: types.NewDuration(3600 * time.Second),
107+
},
104108
{
105109
path: "Sequencer.Finalizer.ForcedBatchesL1BlockConfirmations",
106110
expectedValue: uint64(64),
@@ -127,7 +131,7 @@ func Test_Defaults(t *testing.T) {
127131
},
128132
{
129133
path: "Sequencer.Finalizer.BatchMaxDeltaTimestamp",
130-
expectedValue: types.NewDuration(10 * time.Second),
134+
expectedValue: types.NewDuration(1800 * time.Second),
131135
},
132136
{
133137
path: "Sequencer.Finalizer.Metrics.Interval",

config/default.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ StateConsistencyCheckInterval = "5s"
146146
ForcedBatchesCheckInterval = "10s"
147147
L1InfoTreeL1BlockConfirmations = 64
148148
L1InfoTreeCheckInterval = "10s"
149-
BatchMaxDeltaTimestamp = "10s"
149+
BatchMaxDeltaTimestamp = "1800s"
150150
L2BlockMaxDeltaTimestamp = "3s"
151151
ResourceExhaustedMarginPct = 10
152+
StateRootSyncInterval = "3600s"
152153
HaltOnBatchNumber = 0
153154
SequentialBatchSanityCheck = false
154-
SequentialProcessL2Block = true
155+
SequentialProcessL2Block = false
155156
[Sequencer.Finalizer.Metrics]
156157
Interval = "60m"
157158
EnableLog = true

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ StateConsistencyCheckInterval = "5s"
101101
BatchMaxDeltaTimestamp = "120s"
102102
L2BlockMaxDeltaTimestamp = "3s"
103103
ResourceExhaustedMarginPct = 10
104+
StateRootSyncInterval = "360s"
104105
HaltOnBatchNumber = 0
105106
SequentialBatchSanityCheck = false
106-
SequentialProcessL2Block = true
107+
SequentialProcessL2Block = false
107108
[Sequencer.Finalizer.Metrics]
108109
Interval = "60m"
109110
EnableLog = true

db/migrations/state/0021.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- +migrate Up
2+
ALTER TABLE state.batch
3+
ADD COLUMN high_reserved_counters JSONB;
4+
5+
-- +migrate Down
6+
ALTER TABLE state.batch
7+
DROP COLUMN high_reserved_counters;

db/migrations/state/0021_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package migrations_test
2+
3+
import (
4+
"database/sql"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
type migrationTest0021 struct{}
11+
12+
func (m migrationTest0021) InsertData(db *sql.DB) error {
13+
const insertBatch0 = `
14+
INSERT INTO state.batch (batch_num, global_exit_root, local_exit_root, acc_input_hash, state_root, timestamp, coinbase, raw_txs_data, forced_batch_num, wip)
15+
VALUES (0,'0x0000', '0x0000', '0x0000', '0x0000', now(), '0x0000', null, null, true)`
16+
17+
// insert batch
18+
_, err := db.Exec(insertBatch0)
19+
if err != nil {
20+
return err
21+
}
22+
23+
return nil
24+
}
25+
26+
func (m migrationTest0021) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB) {
27+
var result int
28+
29+
// Check column high_reserved_counters exists in state.batch table
30+
const getColumn = `SELECT count(*) FROM information_schema.columns WHERE table_name='batch' and column_name='high_reserved_counters'`
31+
row := db.QueryRow(getColumn)
32+
assert.NoError(t, row.Scan(&result))
33+
assert.Equal(t, 1, result)
34+
35+
const insertBatch0 = `
36+
INSERT INTO state.batch (batch_num, global_exit_root, local_exit_root, acc_input_hash, state_root, timestamp, coinbase, raw_txs_data, forced_batch_num, wip, high_reserved_counters)
37+
VALUES (1,'0x0001', '0x0001', '0x0001', '0x0001', now(), '0x0001', null, null, true, '{"Steps": 1890125}')`
38+
39+
// insert batch 1
40+
_, err := db.Exec(insertBatch0)
41+
assert.NoError(t, err)
42+
43+
const insertBatch1 = `
44+
INSERT INTO state.batch (batch_num, global_exit_root, local_exit_root, acc_input_hash, state_root, timestamp, coinbase, raw_txs_data, forced_batch_num, wip, high_reserved_counters)
45+
VALUES (2,'0x0002', '0x0002', '0x0002', '0x0002', now(), '0x0002', null, null, false, '{"Steps": 1890125}')`
46+
47+
// insert batch 2
48+
_, err = db.Exec(insertBatch1)
49+
assert.NoError(t, err)
50+
}
51+
52+
func (m migrationTest0021) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB) {
53+
var result int
54+
55+
// Check column high_reserved_counters doesn't exists in state.batch table
56+
const getCheckedColumn = `SELECT count(*) FROM information_schema.columns WHERE table_name='batch' and column_name='high_reserved_counters'`
57+
row := db.QueryRow(getCheckedColumn)
58+
assert.NoError(t, row.Scan(&result))
59+
assert.Equal(t, 0, result)
60+
}
61+
62+
func TestMigration0021(t *testing.T) {
63+
runMigrationTest(t, 21, migrationTest0021{})
64+
}

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

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

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

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,7 @@ StateConsistencyCheckInterval="5s"
20832083
| - [L1InfoTreeCheckInterval](#Sequencer_Finalizer_L1InfoTreeCheckInterval ) | No | string | No | - | Duration |
20842084
| - [BatchMaxDeltaTimestamp](#Sequencer_Finalizer_BatchMaxDeltaTimestamp ) | No | string | No | - | Duration |
20852085
| - [L2BlockMaxDeltaTimestamp](#Sequencer_Finalizer_L2BlockMaxDeltaTimestamp ) | No | string | No | - | Duration |
2086+
| - [StateRootSyncInterval](#Sequencer_Finalizer_StateRootSyncInterval ) | No | string | No | - | Duration |
20862087
| - [HaltOnBatchNumber](#Sequencer_Finalizer_HaltOnBatchNumber ) | No | integer | No | - | HaltOnBatchNumber specifies the batch number where the Sequencer will stop to process more transactions and generate new batches.<br />The Sequencer will halt after it closes the batch equal to this number |
20872088
| - [SequentialBatchSanityCheck](#Sequencer_Finalizer_SequentialBatchSanityCheck ) | No | boolean | No | - | SequentialBatchSanityCheck indicates if the reprocess of a closed batch (sanity check) must be done in a<br />sequential way (instead than in parallel) |
20882089
| - [SequentialProcessL2Block](#Sequencer_Finalizer_SequentialProcessL2Block ) | No | boolean | No | - | SequentialProcessL2Block indicates if the processing of a L2 Block must be done in the same finalizer go func instead<br />in the processPendingL2Blocks go func |
@@ -2216,7 +2217,7 @@ ForcedBatchesCheckInterval="10s"
22162217

22172218
**Default:** `"10s"`
22182219

2219-
**Description:** L1InfoTreeCheckInterval is the wait time to check if the L1InfoRoot has been updated
2220+
**Description:** L1InfoTreeCheckInterval is the time interval to check if the L1InfoRoot has been updated
22202221

22212222
**Examples:**
22222223

@@ -2240,7 +2241,7 @@ L1InfoTreeCheckInterval="10s"
22402241

22412242
**Type:** : `string`
22422243

2243-
**Default:** `"10s"`
2244+
**Default:** `"30m0s"`
22442245

22452246
**Description:** BatchMaxDeltaTimestamp is the resolution of the timestamp used to close a batch
22462247

@@ -2254,10 +2255,10 @@ L1InfoTreeCheckInterval="10s"
22542255
"300ms"
22552256
```
22562257

2257-
**Example setting the default value** ("10s"):
2258+
**Example setting the default value** ("30m0s"):
22582259
```
22592260
[Sequencer.Finalizer]
2260-
BatchMaxDeltaTimestamp="10s"
2261+
BatchMaxDeltaTimestamp="30m0s"
22612262
```
22622263

22632264
#### <a name="Sequencer_Finalizer_L2BlockMaxDeltaTimestamp"></a>10.7.9. `Sequencer.Finalizer.L2BlockMaxDeltaTimestamp`
@@ -2286,7 +2287,34 @@ BatchMaxDeltaTimestamp="10s"
22862287
L2BlockMaxDeltaTimestamp="3s"
22872288
```
22882289

2289-
#### <a name="Sequencer_Finalizer_HaltOnBatchNumber"></a>10.7.10. `Sequencer.Finalizer.HaltOnBatchNumber`
2290+
#### <a name="Sequencer_Finalizer_StateRootSyncInterval"></a>10.7.10. `Sequencer.Finalizer.StateRootSyncInterval`
2291+
2292+
**Title:** Duration
2293+
2294+
**Type:** : `string`
2295+
2296+
**Default:** `"1h0m0s"`
2297+
2298+
**Description:** StateRootSyncInterval indicates how often the stateroot generated by the L2 block process will be synchronized with
2299+
the stateroot used in the tx-by-tx execution
2300+
2301+
**Examples:**
2302+
2303+
```json
2304+
"1m"
2305+
```
2306+
2307+
```json
2308+
"300ms"
2309+
```
2310+
2311+
**Example setting the default value** ("1h0m0s"):
2312+
```
2313+
[Sequencer.Finalizer]
2314+
StateRootSyncInterval="1h0m0s"
2315+
```
2316+
2317+
#### <a name="Sequencer_Finalizer_HaltOnBatchNumber"></a>10.7.11. `Sequencer.Finalizer.HaltOnBatchNumber`
22902318

22912319
**Type:** : `integer`
22922320

@@ -2301,7 +2329,7 @@ The Sequencer will halt after it closes the batch equal to this number
23012329
HaltOnBatchNumber=0
23022330
```
23032331

2304-
#### <a name="Sequencer_Finalizer_SequentialBatchSanityCheck"></a>10.7.11. `Sequencer.Finalizer.SequentialBatchSanityCheck`
2332+
#### <a name="Sequencer_Finalizer_SequentialBatchSanityCheck"></a>10.7.12. `Sequencer.Finalizer.SequentialBatchSanityCheck`
23052333

23062334
**Type:** : `boolean`
23072335

@@ -2316,22 +2344,22 @@ sequential way (instead than in parallel)
23162344
SequentialBatchSanityCheck=false
23172345
```
23182346

2319-
#### <a name="Sequencer_Finalizer_SequentialProcessL2Block"></a>10.7.12. `Sequencer.Finalizer.SequentialProcessL2Block`
2347+
#### <a name="Sequencer_Finalizer_SequentialProcessL2Block"></a>10.7.13. `Sequencer.Finalizer.SequentialProcessL2Block`
23202348

23212349
**Type:** : `boolean`
23222350

2323-
**Default:** `true`
2351+
**Default:** `false`
23242352

23252353
**Description:** SequentialProcessL2Block indicates if the processing of a L2 Block must be done in the same finalizer go func instead
23262354
in the processPendingL2Blocks go func
23272355

2328-
**Example setting the default value** (true):
2356+
**Example setting the default value** (false):
23292357
```
23302358
[Sequencer.Finalizer]
2331-
SequentialProcessL2Block=true
2359+
SequentialProcessL2Block=false
23322360
```
23332361

2334-
#### <a name="Sequencer_Finalizer_Metrics"></a>10.7.13. `[Sequencer.Finalizer.Metrics]`
2362+
#### <a name="Sequencer_Finalizer_Metrics"></a>10.7.14. `[Sequencer.Finalizer.Metrics]`
23352363

23362364
**Type:** : `object`
23372365
**Description:** Metrics is the config for the sequencer metrics
@@ -2341,7 +2369,7 @@ SequentialProcessL2Block=true
23412369
| - [Interval](#Sequencer_Finalizer_Metrics_Interval ) | No | string | No | - | Duration |
23422370
| - [EnableLog](#Sequencer_Finalizer_Metrics_EnableLog ) | No | boolean | No | - | EnableLog is a flag to enable/disable metrics logs |
23432371

2344-
##### <a name="Sequencer_Finalizer_Metrics_Interval"></a>10.7.13.1. `Sequencer.Finalizer.Metrics.Interval`
2372+
##### <a name="Sequencer_Finalizer_Metrics_Interval"></a>10.7.14.1. `Sequencer.Finalizer.Metrics.Interval`
23452373

23462374
**Title:** Duration
23472375

@@ -2367,7 +2395,7 @@ SequentialProcessL2Block=true
23672395
Interval="1h0m0s"
23682396
```
23692397

2370-
##### <a name="Sequencer_Finalizer_Metrics_EnableLog"></a>10.7.13.2. `Sequencer.Finalizer.Metrics.EnableLog`
2398+
##### <a name="Sequencer_Finalizer_Metrics_EnableLog"></a>10.7.14.2. `Sequencer.Finalizer.Metrics.EnableLog`
23712399

23722400
**Type:** : `boolean`
23732401

docs/config-file/node-config-schema.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@
825825
"L1InfoTreeCheckInterval": {
826826
"type": "string",
827827
"title": "Duration",
828-
"description": "L1InfoTreeCheckInterval is the wait time to check if the L1InfoRoot has been updated",
828+
"description": "L1InfoTreeCheckInterval is the time interval to check if the L1InfoRoot has been updated",
829829
"default": "10s",
830830
"examples": [
831831
"1m",
@@ -836,7 +836,7 @@
836836
"type": "string",
837837
"title": "Duration",
838838
"description": "BatchMaxDeltaTimestamp is the resolution of the timestamp used to close a batch",
839-
"default": "10s",
839+
"default": "30m0s",
840840
"examples": [
841841
"1m",
842842
"300ms"
@@ -852,6 +852,16 @@
852852
"300ms"
853853
]
854854
},
855+
"StateRootSyncInterval": {
856+
"type": "string",
857+
"title": "Duration",
858+
"description": "StateRootSyncInterval indicates how often the stateroot generated by the L2 block process will be synchronized with\nthe stateroot used in the tx-by-tx execution",
859+
"default": "1h0m0s",
860+
"examples": [
861+
"1m",
862+
"300ms"
863+
]
864+
},
855865
"HaltOnBatchNumber": {
856866
"type": "integer",
857867
"description": "HaltOnBatchNumber specifies the batch number where the Sequencer will stop to process more transactions and generate new batches.\nThe Sequencer will halt after it closes the batch equal to this number",
@@ -865,7 +875,7 @@
865875
"SequentialProcessL2Block": {
866876
"type": "boolean",
867877
"description": "SequentialProcessL2Block indicates if the processing of a L2 Block must be done in the same finalizer go func instead\nin the processPendingL2Blocks go func",
868-
"default": true
878+
"default": false
869879
},
870880
"Metrics": {
871881
"properties": {

event/event.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ const (
5050
EventID_ReservedZKCountersOverflow EventID = "RESERVED ZKCOUNTERS OVERFLOW"
5151
// EventID_InvalidInfoRoot is triggered when an invalid l1InfoRoot was synced
5252
EventID_InvalidInfoRoot EventID = "INVALID INFOROOT"
53+
// EventID_L2BlockReorg is triggered when a L2 block reorg has happened in the sequencer
54+
EventID_L2BlockReorg EventID = "L2 BLOCK REORG"
5355
// Source_Node is the source of the event
5456
Source_Node Source = "node"
5557

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/0xPolygonHermez/zkevm-node
33
go 1.21
44

55
require (
6-
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-0.20240422135400-0df0d27226b3
6+
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-0.20240426122934-6f47d2485fc1
77
github.com/didip/tollbooth/v6 v6.1.2
88
github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127
99
github.com/ethereum/go-ethereum v1.13.11

0 commit comments

Comments
 (0)