Commit 0f1de29
authored
node: introduce settings to configure the number of events per miniblock (#4553)
## Changes
### Configuration (`crypto/config.go`)
- Added two new on-chain configuration keys:
- `stream.maxEventsPerMiniblock` - Maximum number of events per
miniblock
- `stream.maxTotalEventsSizePerMiniblock` - Maximum combined size (in
bytes) of all protobuf-encoded events
- Defined protocol-level defaults that also serve as hard limits:
- `MaxEventsPerMiniblockDefault = 15,000` events
- `StreamMaxTotalEventsSizePerMiniblockDefault = 10 MB`
- Added corresponding fields to `OnChainSettings` struct
### Event Selection (`minipool.go`)
- Modified `eventHashes()` and `eventHashesAsBytes()` to enforce
configured limits
- Implemented dual-limit logic:
- Stops at max event count, OR
- Stops when cumulative event size exceeds max size
- Events are selected in order until either limit is reached
### Proposal & Validation (`stream_view.go`, `stream.go`)
- Added `MiniblockEventLimits()` helper function that:
- Reads limits from on-chain settings
- Falls back to defaults if not configured
- Enforces protocol max limits even if on-chain values are higher
- Enhanced `ProposeNextMiniblock()` to reject proposals exceeding limits
- Added validation in `tryApplyCandidate()` to reject oversized
candidates before applying
### Testing (`replication_test.go`)
- Added `TestReplicatedMbProductionWithTooManyEvents` - validates max
event count enforcement
- Added `TestReplicatedMbProductionWithTooBigEvents` - validates max
total size enforcement
- Both tests verify that miniblocks are properly split when limits are
exceeded
## Behavior
**Before**: Miniblocks could contain unlimited events from the minipool,
potentially creating very large blocks
that impact network performance and blockchain transaction costs.
**After**: Miniblocks are capped at:
- Default: 15,000 events OR 10 MB total size (whichever is reached
first)
- Configurable via on-chain settings within protocol max limits
- Events exceeding limits remain in the minipool for subsequent
miniblocks
## Motivation
- **Network efficiency**: Prevents oversized miniblocks that strain
replication and storage
- **Cost control**: Limits on-chain registration transaction sizes
- **Configurability**: Operators can tune limits via on-chain settings
without code changes
- **Safety**: Hard-coded maximum limits prevent misconfiguration
## Testing
- ✅ New tests verify both limit types are enforced correctly
- ✅ Existing miniblock production tests still pass
- ✅ Tests confirm events properly overflow into subsequent miniblocks1 parent 47d620e commit 0f1de29
File tree
8 files changed
+383
-53
lines changed- core/node
- crypto
- events
8 files changed
+383
-53
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
73 | 80 | | |
74 | 81 | | |
75 | 82 | | |
76 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
77 | 92 | | |
78 | 93 | | |
79 | 94 | | |
| |||
170 | 185 | | |
171 | 186 | | |
172 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
173 | 194 | | |
174 | 195 | | |
175 | 196 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
128 | | - | |
129 | | - | |
| 130 | + | |
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
| |||
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
| 162 | + | |
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
166 | | - | |
| 168 | + | |
| 169 | + | |
167 | 170 | | |
| 171 | + | |
168 | 172 | | |
169 | | - | |
170 | | - | |
| 173 | + | |
171 | 174 | | |
172 | 175 | | |
173 | 176 | | |
| |||
181 | 184 | | |
182 | 185 | | |
183 | 186 | | |
184 | | - | |
| 187 | + | |
185 | 188 | | |
186 | 189 | | |
187 | | - | |
| 190 | + | |
188 | 191 | | |
189 | 192 | | |
190 | 193 | | |
| |||
212 | 215 | | |
213 | 216 | | |
214 | 217 | | |
| 218 | + | |
215 | 219 | | |
216 | 220 | | |
217 | 221 | | |
| |||
220 | 224 | | |
221 | 225 | | |
222 | 226 | | |
223 | | - | |
| 227 | + | |
| 228 | + | |
224 | 229 | | |
225 | 230 | | |
226 | 231 | | |
227 | | - | |
228 | | - | |
229 | | - | |
| 232 | + | |
| 233 | + | |
230 | 234 | | |
231 | 235 | | |
232 | 236 | | |
| 237 | + | |
233 | 238 | | |
234 | 239 | | |
235 | 240 | | |
236 | 241 | | |
237 | 242 | | |
238 | 243 | | |
| 244 | + | |
239 | 245 | | |
240 | 246 | | |
241 | | - | |
242 | 247 | | |
243 | 248 | | |
244 | 249 | | |
| |||
255 | 260 | | |
256 | 261 | | |
257 | 262 | | |
| 263 | + | |
| 264 | + | |
258 | 265 | | |
259 | 266 | | |
260 | 267 | | |
| |||
281 | 288 | | |
282 | 289 | | |
283 | 290 | | |
284 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
285 | 298 | | |
286 | 299 | | |
287 | 300 | | |
| |||
295 | 308 | | |
296 | 309 | | |
297 | 310 | | |
298 | | - | |
299 | | - | |
| 311 | + | |
| 312 | + | |
300 | 313 | | |
301 | 314 | | |
302 | | - | |
| 315 | + | |
303 | 316 | | |
304 | 317 | | |
305 | | - | |
306 | 318 | | |
307 | | - | |
| 319 | + | |
| 320 | + | |
308 | 321 | | |
309 | 322 | | |
310 | | - | |
311 | | - | |
| 323 | + | |
| 324 | + | |
312 | 325 | | |
313 | 326 | | |
314 | 327 | | |
315 | | - | |
316 | | - | |
317 | | - | |
| 328 | + | |
318 | 329 | | |
319 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
320 | 339 | | |
321 | | - | |
322 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
323 | 343 | | |
324 | | - | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
325 | 353 | | |
326 | | - | |
| 354 | + | |
| 355 | + | |
327 | 356 | | |
328 | 357 | | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
329 | 361 | | |
330 | 362 | | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
331 | 366 | | |
332 | | - | |
| 367 | + | |
333 | 368 | | |
334 | 369 | | |
335 | 370 | | |
336 | 371 | | |
337 | 372 | | |
338 | 373 | | |
339 | 374 | | |
340 | | - | |
| 375 | + | |
341 | 376 | | |
342 | 377 | | |
343 | 378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
83 | 86 | | |
84 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
85 | 106 | | |
86 | 107 | | |
| 108 | + | |
87 | 109 | | |
88 | 110 | | |
89 | 111 | | |
| |||
0 commit comments