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

Commit d555d65

Browse files
authored
Cherry-pick #3669: Add WriteTimeout config parameter to StreamServer (#3690)
* Add WriteTimeout config parameter to StreamServer (#3669) * Add WriteTimeout config parameter to StreamServer. Update DS library * update doc * update default value for StreamServer.WriteTimeout config parameter. Increase buffer for datastream channel * fix doc * fix config test * fix doc
1 parent 68fb048 commit d555d65

16 files changed

+62
-9
lines changed

config/config_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ func Test_Defaults(t *testing.T) {
169169
path: "Sequencer.StreamServer.Version",
170170
expectedValue: uint8(0),
171171
},
172+
{
173+
path: "Sequencer.StreamServer.WriteTimeout",
174+
expectedValue: types.NewDuration(5 * time.Second),
175+
},
172176
{
173177
path: "Sequencer.StreamServer.Enabled",
174178
expectedValue: false,

config/default.go

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ StateConsistencyCheckInterval = "5s"
163163
Port = 0
164164
Filename = ""
165165
Version = 0
166+
WriteTimeout = "5s"
166167
Enabled = false
167168
168169
[SequenceSender]

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

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ StateConsistencyCheckInterval = "5s"
112112
[Sequencer.StreamServer]
113113
Port = 0
114114
Filename = ""
115+
WriteTimeout = "5s"
115116
Enabled = false
116117

117118
[SequenceSender]

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

+3-1
Large diffs are not rendered by default.

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

+27
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,7 @@ EnableLog=true
24872487
| - [Enabled](#Sequencer_StreamServer_Enabled ) | No | boolean | No | - | Enabled is a flag to enable/disable the data streamer |
24882488
| - [Log](#Sequencer_StreamServer_Log ) | No | object | No | - | Log is the log configuration |
24892489
| - [UpgradeEtrogBatchNumber](#Sequencer_StreamServer_UpgradeEtrogBatchNumber ) | No | integer | No | - | UpgradeEtrogBatchNumber is the batch number of the upgrade etrog |
2490+
| - [WriteTimeout](#Sequencer_StreamServer_WriteTimeout ) | No | string | No | - | Duration |
24902491

24912492
#### <a name="Sequencer_StreamServer_Port"></a>10.9.1. `Sequencer.StreamServer.Port`
24922493

@@ -2624,6 +2625,32 @@ Must be one of:
26242625
UpgradeEtrogBatchNumber=0
26252626
```
26262627

2628+
#### <a name="Sequencer_StreamServer_WriteTimeout"></a>10.9.8. `Sequencer.StreamServer.WriteTimeout`
2629+
2630+
**Title:** Duration
2631+
2632+
**Type:** : `string`
2633+
2634+
**Default:** `"5s"`
2635+
2636+
**Description:** WriteTimeout is the TCP write timeout when sending data to a datastream client
2637+
2638+
**Examples:**
2639+
2640+
```json
2641+
"1m"
2642+
```
2643+
2644+
```json
2645+
"300ms"
2646+
```
2647+
2648+
**Example setting the default value** ("5s"):
2649+
```
2650+
[Sequencer.StreamServer]
2651+
WriteTimeout="5s"
2652+
```
2653+
26272654
## <a name="SequenceSender"></a>11. `[SequenceSender]`
26282655

26292656
**Type:** : `object`

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

+10
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,16 @@
998998
"type": "integer",
999999
"description": "UpgradeEtrogBatchNumber is the batch number of the upgrade etrog",
10001000
"default": 0
1001+
},
1002+
"WriteTimeout": {
1003+
"type": "string",
1004+
"title": "Duration",
1005+
"description": "WriteTimeout is the TCP write timeout when sending data to a datastream client",
1006+
"default": "5s",
1007+
"examples": [
1008+
"1m",
1009+
"300ms"
1010+
]
10011011
}
10021012
},
10031013
"additionalProperties": false,

go.mod

+1-1
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.20240527085154-ca3561dd370b
6+
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4
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

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
3939
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
4040
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
4141
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
42-
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-0.20240527085154-ca3561dd370b h1:BzQRXbSnW7BsFvJrnZbCgnxD5+nCGyrYUgqH+3vsnrM=
43-
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-0.20240527085154-ca3561dd370b/go.mod h1:0QkAXcFa92mFJrCbN3UPUJGJYes851yEgYHLONnaosE=
42+
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4 h1:+4K+xSzv0ImbK30B/T9FauNTrTFUmWcNKYhIgwsE4C4=
43+
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4/go.mod h1:0QkAXcFa92mFJrCbN3UPUJGJYes851yEgYHLONnaosE=
4444
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
4545
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
4646
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=

sequencer/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type StreamServerCfg struct {
5252
Log log.Config `mapstructure:"Log"`
5353
// UpgradeEtrogBatchNumber is the batch number of the upgrade etrog
5454
UpgradeEtrogBatchNumber uint64 `mapstructure:"UpgradeEtrogBatchNumber"`
55+
// WriteTimeout is the TCP write timeout when sending data to a datastream client
56+
WriteTimeout types.Duration `mapstructure:"WriteTimeout"`
5557
}
5658

5759
// FinalizerCfg contains the finalizer's configuration properties

sequencer/l2block.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ func (f *finalizer) processL2Block(ctx context.Context, l2Block *L2Block) error
244244
if subOverflow { // Sanity check, this cannot happen as reservedZKCounters should be >= that usedZKCounters
245245
return fmt.Errorf("error subtracting L2 block %d [%d] needed resources from the batch %d, overflow resource: %s, batch bytes: %d, L2 block bytes: %d, counters: {batch: %s, used: %s, reserved: %s, needed: %s, high: %s}",
246246
blockResponse.BlockNumber, l2Block.trackingNum, l2Block.batch.batchNumber, overflowResource, l2Block.batch.finalRemainingResources.Bytes, batchL2DataSize,
247-
f.logZKCounters(l2Block.batch.finalRemainingResources.ZKCounters), f.logZKCounters(batchResponse.UsedZkCounters), f.logZKCounters(batchResponse.ReservedZkCounters), f.logZKCounters(neededZKCounters), f.logZKCounters(l2Block.batch.imHighReservedZKCounters))
247+
f.logZKCounters(l2Block.batch.finalRemainingResources.ZKCounters), f.logZKCounters(batchResponse.UsedZkCounters), f.logZKCounters(batchResponse.ReservedZkCounters), f.logZKCounters(neededZKCounters), f.logZKCounters(l2Block.batch.finalHighReservedZKCounters))
248248
}
249249

250250
l2Block.batch.finalHighReservedZKCounters = newHighZKCounters
251251
l2Block.highReservedZKCounters = l2Block.batch.finalHighReservedZKCounters
252252
} else {
253253
overflowLog := fmt.Sprintf("L2 block %d [%d] needed resources exceeds the remaining batch %d resources, overflow resource: %s, batch bytes: %d, L2 block bytes: %d, counters: {batch: %s, used: %s, reserved: %s, needed: %s, high: %s}",
254254
blockResponse.BlockNumber, l2Block.trackingNum, l2Block.batch.batchNumber, overflowResource, l2Block.batch.finalRemainingResources.Bytes, batchL2DataSize,
255-
f.logZKCounters(l2Block.batch.finalRemainingResources.ZKCounters), f.logZKCounters(batchResponse.UsedZkCounters), f.logZKCounters(batchResponse.ReservedZkCounters), f.logZKCounters(neededZKCounters), f.logZKCounters(l2Block.batch.imHighReservedZKCounters))
255+
f.logZKCounters(l2Block.batch.finalRemainingResources.ZKCounters), f.logZKCounters(batchResponse.UsedZkCounters), f.logZKCounters(batchResponse.ReservedZkCounters), f.logZKCounters(neededZKCounters), f.logZKCounters(l2Block.batch.finalHighReservedZKCounters))
256256

257257
f.LogEvent(ctx, event.Level_Warning, event.EventID_ReservedZKCountersOverflow, overflowLog, nil)
258258

sequencer/sequencer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
const (
20-
datastreamChannelBufferSize = 20
20+
datastreamChannelBufferSize = 50
2121
)
2222

2323
// Sequencer represents a sequencer
@@ -72,7 +72,7 @@ func (s *Sequencer) Start(ctx context.Context) {
7272

7373
// Start stream server if enabled
7474
if s.cfg.StreamServer.Enabled {
75-
s.streamServer, err = datastreamer.NewServer(s.cfg.StreamServer.Port, s.cfg.StreamServer.Version, s.cfg.StreamServer.ChainID, state.StreamTypeSequencer, s.cfg.StreamServer.Filename, &s.cfg.StreamServer.Log)
75+
s.streamServer, err = datastreamer.NewServer(s.cfg.StreamServer.Port, s.cfg.StreamServer.Version, s.cfg.StreamServer.ChainID, state.StreamTypeSequencer, s.cfg.StreamServer.Filename, s.cfg.StreamServer.WriteTimeout.Duration, &s.cfg.StreamServer.Log)
7676
if err != nil {
7777
log.Fatalf("failed to create stream server, error: %v", err)
7878
}

test/config/debug.node.config.toml

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ StateConsistencyCheckInterval = "5s"
112112
Port = 6900
113113
Filename = "/datastreamer/datastream.bin"
114114
Version = 1
115+
WriteTimeout = "5s"
115116
Enabled = true
116117

117118
[SequenceSender]

test/config/test.node.config.toml

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ StateConsistencyCheckInterval = "5s"
128128
Filename = "/datastreamer/datastream.bin"
129129
Version = 1
130130
ChainID = 1337
131+
WriteTimeout = "5s"
131132
Enabled = true
132133

133134
[SequenceSender]

tools/datastreamer/config/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/0xPolygonHermez/zkevm-data-streamer/datastreamer"
99
"github.com/0xPolygonHermez/zkevm-data-streamer/log"
10+
"github.com/0xPolygonHermez/zkevm-node/config/types"
1011
"github.com/0xPolygonHermez/zkevm-node/db"
1112
"github.com/0xPolygonHermez/zkevm-node/state/runtime/executor"
1213
"github.com/mitchellh/mapstructure"
@@ -48,6 +49,8 @@ type StreamServerCfg struct {
4849
Log log.Config `mapstructure:"Log"`
4950
// UpgradeEtrogBatchNumber is the batch number of the upgrade etrog
5051
UpgradeEtrogBatchNumber uint64 `mapstructure:"UpgradeEtrogBatchNumber"`
52+
// WriteTimeout is the TCP write timeout when sending data to a datastream client
53+
WriteTimeout types.Duration `mapstructure:"WriteTimeout"`
5154
}
5255

5356
// Config is the configuration for the tool

tools/datastreamer/config/tool.config.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Port = 6901
77
Filename = "datastream.bin"
88
Version = 3
99
ChainID = 1440
10+
WriteTimeout = "5s"
1011
UpgradeEtrogBatchNumber = 0
1112

1213
[StateDB]

tools/datastreamer/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func main() {
184184

185185
func initializeStreamServer(c *config.Config) (*datastreamer.StreamServer, error) {
186186
// Create a stream server
187-
streamServer, err := datastreamer.NewServer(c.Offline.Port, c.Offline.Version, c.Offline.ChainID, state.StreamTypeSequencer, c.Offline.Filename, &c.Log)
187+
streamServer, err := datastreamer.NewServer(c.Offline.Port, c.Offline.Version, c.Offline.ChainID, state.StreamTypeSequencer, c.Offline.Filename, c.Offline.WriteTimeout.Duration, &c.Log)
188188
if err != nil {
189189
return nil, err
190190
}

0 commit comments

Comments
 (0)