diff --git a/config/config_test.go b/config/config_test.go index f93735eeb9..e41211212d 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -133,6 +133,10 @@ func Test_Defaults(t *testing.T) { path: "Sequencer.Finalizer.BatchMaxDeltaTimestamp", expectedValue: types.NewDuration(1800 * time.Second), }, + { + path: "Sequencer.Finalizer.FlushIdCheckInterval", + expectedValue: types.NewDuration(50 * time.Millisecond), + }, { path: "Sequencer.Finalizer.Metrics.Interval", expectedValue: types.NewDuration(60 * time.Minute), diff --git a/config/default.go b/config/default.go index f55feed513..e9fea2cc55 100644 --- a/config/default.go +++ b/config/default.go @@ -150,6 +150,7 @@ StateConsistencyCheckInterval = "5s" L2BlockMaxDeltaTimestamp = "3s" ResourceExhaustedMarginPct = 10 StateRootSyncInterval = "3600s" + FlushIdCheckInterval = "50ms" HaltOnBatchNumber = 0 SequentialBatchSanityCheck = false SequentialProcessL2Block = false diff --git a/config/environments/local/local.node.config.toml b/config/environments/local/local.node.config.toml index 436a0d84fa..376465b3c8 100644 --- a/config/environments/local/local.node.config.toml +++ b/config/environments/local/local.node.config.toml @@ -102,6 +102,7 @@ StateConsistencyCheckInterval = "5s" L2BlockMaxDeltaTimestamp = "3s" ResourceExhaustedMarginPct = 10 StateRootSyncInterval = "360s" + FlushIdCheckInterval = "50ms" HaltOnBatchNumber = 0 SequentialBatchSanityCheck = false SequentialProcessL2Block = false diff --git a/docs/config-file/node-config-doc.html b/docs/config-file/node-config-doc.html index 9a82ded83c..4dd037ac35 100644 --- a/docs/config-file/node-config-doc.html +++ b/docs/config-file/node-config-doc.html @@ -52,6 +52,8 @@
"300ms"
 

Default: "1h0m0s"Type: string

StateRootSyncInterval indicates how often the stateroot generated by the L2 block process will be synchronized with
the stateroot used in the tx-by-tx execution


Examples:

"1m"
 
"300ms"
+

Default: "50ms"Type: string

FlushIdCheckInterval is the time interval to get storedFlushID value from the executor/hashdb


Examples:

"1m"
+
"300ms"
 

Default: 0Type: integer

HaltOnBatchNumber specifies the batch number where the Sequencer will stop to process more transactions and generate new batches.
The Sequencer will halt after it closes the batch equal to this number


Default: falseType: boolean

SequentialBatchSanityCheck indicates if the reprocess of a closed batch (sanity check) must be done in a
sequential way (instead than in parallel)


Default: falseType: boolean

SequentialProcessL2Block indicates if the processing of a L2 Block must be done in the same finalizer go func instead
in the processPendingL2Blocks go func


Metrics is the config for the sequencer metrics
Default: "1h0m0s"Type: string

Interval is the interval of time to calculate sequencer metrics


Examples:

"1m"
 
"300ms"
 

Default: trueType: boolean

EnableLog is a flag to enable/disable metrics logs


StreamServerCfg is the config for the stream server
Default: 0Type: integer

Port to listen on


Default: ""Type: string

Filename of the binary data file


Default: 0Type: integer

Version of the binary data file


Default: 0Type: integer

ChainID is the chain ID


Default: falseType: boolean

Enabled is a flag to enable/disable the data streamer


Log is the log configuration
Default: ""Type: enum (of string)

Must be one of:

  • "production"
  • "development"

Default: ""Type: enum (of string)

Must be one of:

  • "debug"
  • "info"
  • "warn"
  • "error"
  • "dpanic"
  • "panic"
  • "fatal"

Type: array of string

Each item of this array must be:


Default: 0Type: integer

UpgradeEtrogBatchNumber is the batch number of the upgrade etrog


Configuration of the sequence sender service
Default: "5s"Type: string

WaitPeriodSendSequence is the time the sequencer waits until
trying to send a sequence to L1


Examples:

"1m"
diff --git a/docs/config-file/node-config-doc.md b/docs/config-file/node-config-doc.md
index ea312a6929..4e73bf792f 100644
--- a/docs/config-file/node-config-doc.md
+++ b/docs/config-file/node-config-doc.md
@@ -2084,6 +2084,7 @@ StateConsistencyCheckInterval="5s"
 | - [BatchMaxDeltaTimestamp](#Sequencer_Finalizer_BatchMaxDeltaTimestamp )                       | No      | string  | No         | -          | Duration                                                                                                                                                                                                      |
 | - [L2BlockMaxDeltaTimestamp](#Sequencer_Finalizer_L2BlockMaxDeltaTimestamp )                   | No      | string  | No         | -          | Duration                                                                                                                                                                                                      |
 | - [StateRootSyncInterval](#Sequencer_Finalizer_StateRootSyncInterval )                         | No      | string  | No         | -          | Duration                                                                                                                                                                                                      |
+| - [FlushIdCheckInterval](#Sequencer_Finalizer_FlushIdCheckInterval )                           | No      | string  | No         | -          | Duration                                                                                                                                                                                                      |
 | - [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.
The Sequencer will halt after it closes the batch equal to this number | | - [SequentialBatchSanityCheck](#Sequencer_Finalizer_SequentialBatchSanityCheck ) | No | boolean | No | - | SequentialBatchSanityCheck indicates if the reprocess of a closed batch (sanity check) must be done in a
sequential way (instead than in parallel) | | - [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
in the processPendingL2Blocks go func | @@ -2314,7 +2315,33 @@ the stateroot used in the tx-by-tx execution StateRootSyncInterval="1h0m0s" ``` -#### 10.7.11. `Sequencer.Finalizer.HaltOnBatchNumber` +#### 10.7.11. `Sequencer.Finalizer.FlushIdCheckInterval` + +**Title:** Duration + +**Type:** : `string` + +**Default:** `"50ms"` + +**Description:** FlushIdCheckInterval is the time interval to get storedFlushID value from the executor/hashdb + +**Examples:** + +```json +"1m" +``` + +```json +"300ms" +``` + +**Example setting the default value** ("50ms"): +``` +[Sequencer.Finalizer] +FlushIdCheckInterval="50ms" +``` + +#### 10.7.12. `Sequencer.Finalizer.HaltOnBatchNumber` **Type:** : `integer` @@ -2329,7 +2356,7 @@ The Sequencer will halt after it closes the batch equal to this number HaltOnBatchNumber=0 ``` -#### 10.7.12. `Sequencer.Finalizer.SequentialBatchSanityCheck` +#### 10.7.13. `Sequencer.Finalizer.SequentialBatchSanityCheck` **Type:** : `boolean` @@ -2344,7 +2371,7 @@ sequential way (instead than in parallel) SequentialBatchSanityCheck=false ``` -#### 10.7.13. `Sequencer.Finalizer.SequentialProcessL2Block` +#### 10.7.14. `Sequencer.Finalizer.SequentialProcessL2Block` **Type:** : `boolean` @@ -2359,7 +2386,7 @@ in the processPendingL2Blocks go func SequentialProcessL2Block=false ``` -#### 10.7.14. `[Sequencer.Finalizer.Metrics]` +#### 10.7.15. `[Sequencer.Finalizer.Metrics]` **Type:** : `object` **Description:** Metrics is the config for the sequencer metrics @@ -2369,7 +2396,7 @@ SequentialProcessL2Block=false | - [Interval](#Sequencer_Finalizer_Metrics_Interval ) | No | string | No | - | Duration | | - [EnableLog](#Sequencer_Finalizer_Metrics_EnableLog ) | No | boolean | No | - | EnableLog is a flag to enable/disable metrics logs | -##### 10.7.14.1. `Sequencer.Finalizer.Metrics.Interval` +##### 10.7.15.1. `Sequencer.Finalizer.Metrics.Interval` **Title:** Duration @@ -2395,7 +2422,7 @@ SequentialProcessL2Block=false Interval="1h0m0s" ``` -##### 10.7.14.2. `Sequencer.Finalizer.Metrics.EnableLog` +##### 10.7.15.2. `Sequencer.Finalizer.Metrics.EnableLog` **Type:** : `boolean` diff --git a/docs/config-file/node-config-schema.json b/docs/config-file/node-config-schema.json index dffb74f672..77d86762db 100644 --- a/docs/config-file/node-config-schema.json +++ b/docs/config-file/node-config-schema.json @@ -862,6 +862,16 @@ "300ms" ] }, + "FlushIdCheckInterval": { + "type": "string", + "title": "Duration", + "description": "FlushIdCheckInterval is the time interval to get storedFlushID value from the executor/hashdb", + "default": "50ms", + "examples": [ + "1m", + "300ms" + ] + }, "HaltOnBatchNumber": { "type": "integer", "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", diff --git a/sequencer/config.go b/sequencer/config.go index 8b813c52db..c0bfb8968d 100644 --- a/sequencer/config.go +++ b/sequencer/config.go @@ -83,6 +83,9 @@ type FinalizerCfg struct { // the stateroot used in the tx-by-tx execution StateRootSyncInterval types.Duration `mapstructure:"StateRootSyncInterval"` + // FlushIdCheckInterval is the time interval to get storedFlushID value from the executor/hashdb + FlushIdCheckInterval types.Duration `mapstructure:"FlushIdCheckInterval"` + // HaltOnBatchNumber specifies the batch number where the Sequencer will stop to process more transactions and generate new batches. // The Sequencer will halt after it closes the batch equal to this number HaltOnBatchNumber uint64 `mapstructure:"HaltOnBatchNumber"` diff --git a/sequencer/finalizer.go b/sequencer/finalizer.go index a06f2341fa..a7e884ac07 100644 --- a/sequencer/finalizer.go +++ b/sequencer/finalizer.go @@ -208,8 +208,15 @@ func (f *finalizer) updateProverIdAndFlushId(ctx context.Context) { f.storedFlushID = storedFlushID f.storedFlushIDCond.Broadcast() f.storedFlushIDCond.L.Unlock() + + // Exit the for loop o the storedFlushId is greater or equal that the lastPendingFlushID + if f.storedFlushID >= f.lastPendingFlushID { + break + } } } + + time.Sleep(f.cfg.FlushIdCheckInterval.Duration) } } } diff --git a/sequencer/l2block.go b/sequencer/l2block.go index 8370918106..bb141a7460 100644 --- a/sequencer/l2block.go +++ b/sequencer/l2block.go @@ -264,10 +264,12 @@ func (f *finalizer) processL2Block(ctx context.Context, l2Block *L2Block) error f.updateFlushIDs(batchResponse.FlushID, batchResponse.StoredFlushID) + var waitStoreL2Block time.Duration if f.pendingL2BlocksToStoreWG.Count() > 0 { startWait := time.Now() f.pendingL2BlocksToStoreWG.Wait() - log.Debugf("waiting for previous L2 block to be stored took: %v", time.Since(startWait)) + waitStoreL2Block = time.Since(startWait) + log.Debugf("waiting for previous L2 block to be stored took: %v", waitStoreL2Block) } f.addPendingL2BlockToStore(ctx, l2Block) @@ -278,9 +280,9 @@ func (f *finalizer) processL2Block(ctx context.Context, l2Block *L2Block) error } f.metrics.addL2BlockMetrics(l2Block.metrics) - log.Infof("processed L2 block %d [%d], batch: %d, deltaTimestamp: %d, timestamp: %d, l1InfoTreeIndex: %d, l1InfoTreeIndexChanged: %v, initialStateRoot: %s, newStateRoot: %s, txs: %d/%d, blockHash: %s, infoRoot: %s, counters: {used: %s, reserved: %s, needed: %s, high: %s}, contextId: %s", + log.Infof("processed L2 block %d [%d], batch: %d, deltaTimestamp: %d, timestamp: %d, l1InfoTreeIndex: %d, l1InfoTreeIndexChanged: %v, initialStateRoot: %s, newStateRoot: %s, txs: %d/%d, blockHash: %s, infoRoot: %s, waitStoreL2Block: %v, counters: {used: %s, reserved: %s, needed: %s, high: %s}, contextId: %s", blockResponse.BlockNumber, l2Block.trackingNum, l2Block.batch.batchNumber, l2Block.deltaTimestamp, l2Block.timestamp, l2Block.l1InfoTreeExitRoot.L1InfoTreeIndex, l2Block.l1InfoTreeExitRootChanged, initialStateRoot, l2Block.batchResponse.NewStateRoot, - len(l2Block.transactions), len(blockResponse.TransactionResponses), blockResponse.BlockHash, blockResponse.BlockInfoRoot, + len(l2Block.transactions), len(blockResponse.TransactionResponses), blockResponse.BlockHash, blockResponse.BlockInfoRoot, waitStoreL2Block, f.logZKCounters(batchResponse.UsedZkCounters), f.logZKCounters(batchResponse.ReservedZkCounters), f.logZKCounters(neededZKCounters), f.logZKCounters(l2Block.batch.finalHighReservedZKCounters), contextId) if f.cfg.Metrics.EnableLog { @@ -366,19 +368,21 @@ func (f *finalizer) executeL2Block(ctx context.Context, initialStateRoot common. func (f *finalizer) storeL2Block(ctx context.Context, l2Block *L2Block) error { startStoring := time.Now() + blockResponse := l2Block.batchResponse.BlockResponses[0] + log.Infof("storing L2 block %d [%d], batch: %d, deltaTimestamp: %d, timestamp: %d, l1InfoTreeIndex: %d, l1InfoTreeIndexChanged: %v, txs: %d/%d, blockHash: %s, infoRoot: %s", + blockResponse.BlockNumber, l2Block.trackingNum, l2Block.batch.batchNumber, l2Block.deltaTimestamp, l2Block.timestamp, l2Block.l1InfoTreeExitRoot.L1InfoTreeIndex, + l2Block.l1InfoTreeExitRootChanged, len(l2Block.transactions), len(blockResponse.TransactionResponses), blockResponse.BlockHash, blockResponse.BlockInfoRoot.String()) + // Wait until L2 block has been flushed/stored by the executor + startWaitFlushId := time.Now() f.storedFlushIDCond.L.Lock() for f.storedFlushID < l2Block.batchResponse.FlushID { f.storedFlushIDCond.Wait() } f.storedFlushIDCond.L.Unlock() + waitFlushId := time.Since(startWaitFlushId) // If the L2 block has txs now f.storedFlushID >= l2BlockToStore.flushId, we can store tx - blockResponse := l2Block.batchResponse.BlockResponses[0] - log.Infof("storing L2 block %d [%d], batch: %d, deltaTimestamp: %d, timestamp: %d, l1InfoTreeIndex: %d, l1InfoTreeIndexChanged: %v, txs: %d/%d, blockHash: %s, infoRoot: %s", - blockResponse.BlockNumber, l2Block.trackingNum, l2Block.batch.batchNumber, l2Block.deltaTimestamp, l2Block.timestamp, l2Block.l1InfoTreeExitRoot.L1InfoTreeIndex, - l2Block.l1InfoTreeExitRootChanged, len(l2Block.transactions), len(blockResponse.TransactionResponses), blockResponse.BlockHash, blockResponse.BlockInfoRoot.String()) - dbTx, err := f.stateIntf.BeginStateTransaction(ctx) if err != nil { return fmt.Errorf("error creating db transaction to store L2 block %d [%d], error: %v", blockResponse.BlockNumber, l2Block.trackingNum, err) @@ -505,11 +509,9 @@ func (f *finalizer) storeL2Block(ctx context.Context, l2Block *L2Block) error { f.workerIntf.DeleteTxPendingToStore(tx.Hash, tx.From) } - endStoring := time.Now() - - log.Infof("stored L2 block %d [%d], batch: %d, deltaTimestamp: %d, timestamp: %d, l1InfoTreeIndex: %d, l1InfoTreeIndexChanged: %v, txs: %d/%d, blockHash: %s, infoRoot: %s, time: %v", + log.Infof("stored L2 block %d [%d], batch: %d, deltaTimestamp: %d, timestamp: %d, l1InfoTreeIndex: %d, l1InfoTreeIndexChanged: %v, txs: %d/%d, blockHash: %s, infoRoot: %s, time: %v, waitFlushId: %v", blockResponse.BlockNumber, l2Block.trackingNum, l2Block.batch.batchNumber, l2Block.deltaTimestamp, l2Block.timestamp, l2Block.l1InfoTreeExitRoot.L1InfoTreeIndex, - l2Block.l1InfoTreeExitRootChanged, len(l2Block.transactions), len(blockResponse.TransactionResponses), blockResponse.BlockHash, blockResponse.BlockInfoRoot.String(), endStoring.Sub(startStoring)) + l2Block.l1InfoTreeExitRootChanged, len(l2Block.transactions), len(blockResponse.TransactionResponses), blockResponse.BlockHash, blockResponse.BlockInfoRoot.String(), time.Since(startStoring), waitFlushId) return nil } diff --git a/test/config/debug.node.config.toml b/test/config/debug.node.config.toml index ccd423daee..698164c866 100644 --- a/test/config/debug.node.config.toml +++ b/test/config/debug.node.config.toml @@ -101,6 +101,7 @@ StateConsistencyCheckInterval = "5s" L2BlockMaxDeltaTimestamp = "3s" ResourceExhaustedMarginPct = 10 StateRootSyncInterval = "120s" + FlushIdCheckInterval = "50ms" HaltOnBatchNumber = 0 SequentialBatchSanityCheck = false SequentialProcessL2Block = false diff --git a/test/config/test.node.config.toml b/test/config/test.node.config.toml index 506dde2466..4f743a7b0a 100644 --- a/test/config/test.node.config.toml +++ b/test/config/test.node.config.toml @@ -116,6 +116,7 @@ StateConsistencyCheckInterval = "5s" L2BlockMaxDeltaTimestamp = "4s" ResourceExhaustedMarginPct = 10 StateRootSyncInterval = "60s" + FlushIdCheckInterval = "50ms" HaltOnBatchNumber = 0 SequentialBatchSanityCheck = false SequentialProcessL2Block = false