Skip to content

Commit

Permalink
Add l2block/interval metrics. Use timeoutCond when waiting for worker…
Browse files Browse the repository at this point in the history
  • Loading branch information
agnusmor authored Feb 28, 2024
1 parent 7ab2507 commit b7ebf6d
Show file tree
Hide file tree
Showing 41 changed files with 411 additions and 1,827 deletions.
8 changes: 8 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ func Test_Defaults(t *testing.T) {
path: "Sequencer.Finalizer.BatchMaxDeltaTimestamp",
expectedValue: types.NewDuration(10 * time.Second),
},
{
path: "Sequencer.Finalizer.Metrics.Interval",
expectedValue: types.NewDuration(60 * time.Minute),
},
{
path: "Sequencer.Finalizer.Metrics.EnableLog",
expectedValue: true,
},
{
path: "Sequencer.StreamServer.Port",
expectedValue: uint16(0),
Expand Down
3 changes: 3 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ StateConsistencyCheckInterval = "5s"
HaltOnBatchNumber = 0
SequentialBatchSanityCheck = false
SequentialProcessL2Block = true
[Sequencer.Finalizer.Metrics]
Interval = "60m"
EnableLog = true
[Sequencer.StreamServer]
Port = 0
Filename = ""
Expand Down
3 changes: 3 additions & 0 deletions config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ StateConsistencyCheckInterval = "5s"
HaltOnBatchNumber = 0
SequentialBatchSanityCheck = false
SequentialProcessL2Block = true
[Sequencer.Finalizer.Metrics]
Interval = "60m"
EnableLog = true
[Sequencer.StreamServer]
Port = 0
Filename = ""
Expand Down
4 changes: 3 additions & 1 deletion docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,7 @@ StateConsistencyCheckInterval="5s"
| - [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 |
| - [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) |
| - [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 |
| - [Metrics](#Sequencer_Finalizer_Metrics ) | No | object | No | - | Metrics is the config for the sequencer metrics |

#### <a name="Sequencer_Finalizer_ForcedBatchesTimeout"></a>10.7.1. `Sequencer.Finalizer.ForcedBatchesTimeout`

Expand Down Expand Up @@ -2155,6 +2156,56 @@ in the processPendingL2Blocks go func
SequentialProcessL2Block=true
```

#### <a name="Sequencer_Finalizer_Metrics"></a>10.7.13. `[Sequencer.Finalizer.Metrics]`

**Type:** : `object`
**Description:** Metrics is the config for the sequencer metrics

| Property | Pattern | Type | Deprecated | Definition | Title/Description |
| ------------------------------------------------------ | ------- | ------- | ---------- | ---------- | -------------------------------------------------- |
| - [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 |

##### <a name="Sequencer_Finalizer_Metrics_Interval"></a>10.7.13.1. `Sequencer.Finalizer.Metrics.Interval`

**Title:** Duration

**Type:** : `string`

**Default:** `"1h0m0s"`

**Description:** Interval is the interval of time to calculate sequencer metrics

**Examples:**

```json
"1m"
```

```json
"300ms"
```

**Example setting the default value** ("1h0m0s"):
```
[Sequencer.Finalizer.Metrics]
Interval="1h0m0s"
```

##### <a name="Sequencer_Finalizer_Metrics_EnableLog"></a>10.7.13.2. `Sequencer.Finalizer.Metrics.EnableLog`

**Type:** : `boolean`

**Default:** `true`

**Description:** EnableLog is a flag to enable/disable metrics logs

**Example setting the default value** (true):
```
[Sequencer.Finalizer.Metrics]
EnableLog=true
```

### <a name="Sequencer_StreamServer"></a>10.8. `[Sequencer.StreamServer]`

**Type:** : `object`
Expand Down
22 changes: 22 additions & 0 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,28 @@
"type": "boolean",
"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",
"default": true
},
"Metrics": {
"properties": {
"Interval": {
"type": "string",
"title": "Duration",
"description": "Interval is the interval of time to calculate sequencer metrics",
"default": "1h0m0s",
"examples": [
"1m",
"300ms"
]
},
"EnableLog": {
"type": "boolean",
"description": "EnableLog is a flag to enable/disable metrics logs",
"default": true
}
},
"additionalProperties": false,
"type": "object",
"description": "Metrics is the config for the sequencer metrics"
}
},
"additionalProperties": false,
Expand Down
14 changes: 1 addition & 13 deletions sequencer/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/0xPolygonHermez/zkevm-node/event"
"github.com/0xPolygonHermez/zkevm-node/hex"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/sequencer/metrics"
"github.com/0xPolygonHermez/zkevm-node/state"
stateMetrics "github.com/0xPolygonHermez/zkevm-node/state/metrics"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -145,11 +144,6 @@ func (f *finalizer) initWIPBatch(ctx context.Context) {

// finalizeWIPBatch closes the current batch and opens a new one, potentially processing forced batches between the batch is closed and the resulting new empty batch
func (f *finalizer) finalizeWIPBatch(ctx context.Context, closeReason state.ClosingReason) {
start := time.Now()
defer func() {
metrics.ProcessingTime(time.Since(start))
}()

prevTimestamp := f.wipL2Block.timestamp
prevL1InfoTreeIndex := f.wipL2Block.l1InfoTreeExitRoot.L1InfoTreeIndex

Expand Down Expand Up @@ -185,7 +179,6 @@ func (f *finalizer) closeAndOpenNewWIPBatch(ctx context.Context, closeReason sta
startWait := time.Now()
f.pendingL2BlocksToProcessWG.Wait()
elapsed := time.Since(startWait)
stateMetrics.ExecutorProcessingTime(string(stateMetrics.SequencerCallerLabel), elapsed)
log.Debugf("waiting for pending L2 blocks to be processed took: %v", elapsed)

// Wait until all L2 blocks are store
Expand Down Expand Up @@ -370,11 +363,6 @@ func (f *finalizer) batchSanityCheck(ctx context.Context, batchNum uint64, initi
return nil, ErrGetBatchByNumber
}

caller := stateMetrics.DiscardCallerLabel
if f.cfg.SequentialBatchSanityCheck {
caller = stateMetrics.SequencerCallerLabel
}

batchRequest := state.ProcessRequest{
BatchNumber: batch.BatchNumber,
L1InfoRoot_V2: state.GetMockL1InfoRoot(),
Expand All @@ -384,7 +372,7 @@ func (f *finalizer) batchSanityCheck(ctx context.Context, batchNum uint64, initi
TimestampLimit_V2: uint64(time.Now().Unix()),
ForkID: f.stateIntf.GetForkIDByBatchNumber(batch.BatchNumber),
SkipVerifyL1InfoRoot_V2: true,
Caller: caller,
Caller: stateMetrics.DiscardCallerLabel,
}
batchRequest.L1InfoTreeData_V2, _, _, err = f.stateIntf.GetL1InfoTreeDataFromBatchL2Data(ctx, batch.BatchL2Data, nil)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions sequencer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,16 @@ type FinalizerCfg struct {
// SequentialProcessL2Block indicates if the processing of a L2 Block must be done in the same finalizer go func instead
// in the processPendingL2Blocks go func
SequentialProcessL2Block bool `mapstructure:"SequentialProcessL2Block"`

// Metrics is the config for the sequencer metrics
Metrics MetricsCfg `mapstructure:"Metrics"`
}

// MetricsCfg contains the sequencer metrics configuration properties
type MetricsCfg struct {
// Interval is the interval of time to calculate sequencer metrics
Interval types.Duration `mapstructure:"Interval"`

// EnableLog is a flag to enable/disable metrics logs
EnableLog bool `mapstructure:"EnableLog"`
}
Loading

0 comments on commit b7ebf6d

Please sign in to comment.