Commit 9b56c04
committed
feat(network): complete request-response codec implementation (Phase 2 Task 2.2)
Phase 2 Task 2.2: Complete request-response codec implementation
Implements full request-response protocol support with SSZ serialization:
1. **BlockCodec Implementation**:
- Implemented libp2p RequestResponseCodec trait for BlockCodec
- SSZ-based read/write for requests and responses
- Length-prefixed framing (4-byte big-endian length prefix)
- Size validation (1MB request limit, 10MB response limit)
- Protocol type: &'static str ("/alys/block/1.0.0") for libp2p 0.25.3 compatibility
2. **AlysNetworkBehaviour Updates**:
- Added request_response: Behaviour<BlockCodec> field
- Initialized request-response behavior with BlockCodec
- Protocol support: Full duplex (/alys/block/1.0.0)
- Updated event enum with new request-response events:
* BlockRequestReceived (replaces old RequestReceived)
* BlockResponseReceived
* RequestSent
* ResponseSent
* RequestFailed
- Implemented From<Event<BlockRequest, BlockResponse>> for event conversion
3. **SwarmCommand Handler Implementation**:
- SendRequest: Calls swarm.behaviour_mut().request_response.send_request()
- SendResponse: Calls swarm.behaviour_mut().request_response.send_response()
- Both handlers properly integrated in swarm polling task select! loop
4. **Event Handling in handle_network_event**:
- BlockRequestReceived: Sends error response (Phase 3 will integrate with ChainActor)
- BlockResponseReceived: Handles Blocks/ChainStatus/Error variants
- RequestSent: Logs and records metrics
- ResponseSent: Logs and records metrics
- RequestFailed: Penalizes peer reputation
5. **swarm_factory.rs Updates**:
- Added request_response behavior initialization
- Consistent codec configuration across behaviour.rs and swarm_factory.rs
6. **libp2p 0.25.3 Compatibility Fixes**:
- Protocol type: &'static str instead of StreamProtocol
- RequestId instead of InboundRequestId/OutboundRequestId
- SSZ DecodeError formatting with {:?} instead of {}
7. **Test Fixture Updates**:
- Removed obsolete RequestReceived event from test fixtures
- Added PeerIdentified event for test coverage
Files modified:
- app/src/actors_v2/network/protocols/request_response.rs (codec implementation)
- app/src/actors_v2/network/behaviour.rs (event types, From implementations)
- app/src/actors_v2/network/network_actor.rs (handler updates)
- app/src/actors_v2/network/swarm_factory.rs (behavior initialization)
- app/src/actors_v2/testing/network/fixtures.rs (test data fixes)
**Verification**:
- Phase 1 integration test passes ✅
- Code compiles with 0 errors (warnings only)
- Request-response protocol fully functional in swarm
- Ready for Phase 3 integration with ChainActor/SyncActor1 parent 4fd88cd commit 9b56c04
File tree
19 files changed
+18334
-38
lines changed- app/src/actors_v2
- network
- protocols
- testing/network
- docs/v2_alpha
- actors
- chain
- network
- rpc
19 files changed
+18334
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
35 | 44 | | |
36 | | - | |
37 | | - | |
38 | | - | |
| 45 | + | |
| 46 | + | |
39 | 47 | | |
40 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
41 | 58 | | |
42 | 59 | | |
43 | 60 | | |
| |||
118 | 135 | | |
119 | 136 | | |
120 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
121 | 149 | | |
122 | 150 | | |
123 | 151 | | |
124 | 152 | | |
| 153 | + | |
125 | 154 | | |
126 | 155 | | |
127 | 156 | | |
| |||
243 | 272 | | |
244 | 273 | | |
245 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
336 | | - | |
337 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
338 | 374 | | |
339 | 375 | | |
340 | 376 | | |
341 | | - | |
342 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
343 | 413 | | |
344 | 414 | | |
345 | | - | |
346 | | - | |
347 | | - | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
348 | 422 | | |
349 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
350 | 431 | | |
351 | 432 | | |
352 | 433 | | |
| |||
700 | 781 | | |
701 | 782 | | |
702 | 783 | | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
707 | 796 | | |
708 | 797 | | |
709 | | - | |
710 | | - | |
711 | | - | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
712 | 808 | | |
713 | 809 | | |
714 | 810 | | |
| |||
0 commit comments