Commit a86c5b6
fix: Fix compressed headers protocol compatibility with Dash Core (#256)
* fix(headers2): Fix compressed headers protocol compatibility with Dash Core
This commit fixes critical incompatibilities between the Rust headers2
implementation and the C++ Dash Core reference implementation (DIP-0025).
- C++ uses offset=0 for "version not in cache" (full version present)
- C++ uses offset=1-7 for "version at position offset-1 in cache"
- Rust incorrectly used offset=7 for uncompressed, offset=0-6 for cached
- Now matches C++ semantics exactly
- C++ uses std::list with MRU (Most Recently Used) reordering
- Rust used a circular buffer without MRU reordering
- Changed to Vec<i32> with proper MRU behavior matching C++
- Fixed Decodable impl to read version when offset=0 (not offset=7)
- Added MissingVersion error variant for proper error handling
- Rewrote CompressionState to use Vec with MRU reordering
- Fixed compress() to use offset=0 for uncompressed versions
- Fixed decompress() to handle C++ offset semantics
- Updated Decodable to read version when offset=0
- Added comprehensive tests for C++ compatibility
- Enabled headers2 in handshake negotiation
- Enabled headers2 in sync manager
- Fixed phase transition when receiving empty headers2 response
- Re-enabled has_headers2_peer() check
- Added headers2_compatibility_test.rs with 12 tests verifying:
- Version offset C++ semantics
- MRU cache reordering behavior
- Flag bit semantics
- Serialization format compatibility
- Cross-implementation compatibility
- All existing tests pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* feat(network): Add support for Headers2 in peer selection logic
This commit enhances the PeerNetworkManager to include support for the Headers2 protocol. It introduces logic to prefer peers that advertise Headers2 support when selecting a sync peer. The changes ensure that the current sync peer is updated accordingly, improving compatibility and efficiency in header synchronization.
- Added logic to check for Headers2 support in peer selection.
- Updated existing sync peer selection to prioritize peers with Headers2 capabilities.
- Ensured proper logging when a new sync peer is selected for Headers2.
This update aligns with ongoing efforts to improve protocol compatibility and performance in the network manager.
* refactor(headers2): Address code review feedback
- Consolidate redundant if/else blocks in compression state initialization
(reduces 5 async lock acquisitions to 1)
- Simplify block locator construction (both branches returned vec![hash])
- Change process_headers to take &[CompressedHeader] instead of Vec to
avoid cloning headers during sync
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor(sync): Unify header sync finalization for regular and compressed headers
- Extract `finalize_headers_sync` helper to eliminate duplicated phase update logic
- Return decompressed header count from `handle_headers2_message` so both paths
can track `headers_downloaded` and `headers_per_second` stats uniformly
- Remove special-case handling that skipped stats for compressed headers
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor(sync): Change handle_headers_message to take &[BlockHeader] instead of Vec
Avoids unnecessary cloning of headers vector when passing to the handler.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor(headers2): Remove speculative genesis decompression comment
The defensive fallback mechanism (headers2_failed flag) is kept, but
the speculative comment about genesis compression state issues is removed.
With the C++ compatibility fix, this scenario should not occur.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix(clippy): Remove needless borrows after slice refactor
Variables are already references from slice/iter, no need to borrow again.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: clippy warning
---------
Co-authored-by: Claude Opus 4.5 <[email protected]>1 parent 705cdf6 commit a86c5b6
File tree
7 files changed
+799
-237
lines changed- dash-spv/src
- network
- sync
- headers2
- headers
- dash
- src/network
- tests
7 files changed
+799
-237
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
256 | | - | |
| 255 | + | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
317 | 320 | | |
318 | 321 | | |
319 | 322 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | 426 | | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
435 | 437 | | |
436 | 438 | | |
437 | 439 | | |
438 | | - | |
439 | 440 | | |
440 | 441 | | |
441 | 442 | | |
| |||
779 | 780 | | |
780 | 781 | | |
781 | 782 | | |
| 783 | + | |
782 | 784 | | |
783 | 785 | | |
784 | 786 | | |
| |||
806 | 808 | | |
807 | 809 | | |
808 | 810 | | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
809 | 842 | | |
810 | 843 | | |
811 | 844 | | |
| |||
1060 | 1093 | | |
1061 | 1094 | | |
1062 | 1095 | | |
| 1096 | + | |
1063 | 1097 | | |
1064 | 1098 | | |
1065 | 1099 | | |
| |||
1296 | 1330 | | |
1297 | 1331 | | |
1298 | 1332 | | |
1299 | | - | |
1300 | | - | |
1301 | | - | |
| 1333 | + | |
1302 | 1334 | | |
1303 | 1335 | | |
1304 | 1336 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
| 321 | + | |
347 | 322 | | |
348 | 323 | | |
349 | 324 | | |
| |||
381 | 356 | | |
382 | 357 | | |
383 | 358 | | |
384 | | - | |
385 | | - | |
386 | | - | |
| 359 | + | |
| 360 | + | |
387 | 361 | | |
388 | 362 | | |
389 | 363 | | |
| |||
454 | 428 | | |
455 | 429 | | |
456 | 430 | | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
462 | 436 | | |
463 | 437 | | |
464 | 438 | | |
465 | 439 | | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
504 | 455 | | |
505 | 456 | | |
| 457 | + | |
506 | 458 | | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
515 | 464 | | |
516 | 465 | | |
517 | 466 | | |
| |||
524 | 473 | | |
525 | 474 | | |
526 | 475 | | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
536 | 484 | | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
546 | 492 | | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
| 493 | + | |
554 | 494 | | |
555 | | - | |
556 | | - | |
557 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
558 | 499 | | |
559 | 500 | | |
560 | 501 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
132 | | - | |
133 | | - | |
| 131 | + | |
| 132 | + | |
134 | 133 | | |
135 | 134 | | |
136 | 135 | | |
| |||
230 | 229 | | |
231 | 230 | | |
232 | 231 | | |
233 | | - | |
| 232 | + | |
234 | 233 | | |
235 | 234 | | |
236 | 235 | | |
| |||
261 | 260 | | |
262 | 261 | | |
263 | 262 | | |
264 | | - | |
| 263 | + | |
265 | 264 | | |
266 | 265 | | |
267 | 266 | | |
| |||
0 commit comments