Commit a81cf27
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).
## Issues Fixed
### Version Offset Encoding Mismatch
- 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
### Version Cache Data Structure
- 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++
### Serialization/Deserialization
- Fixed Decodable impl to read version when offset=0 (not offset=7)
- Added MissingVersion error variant for proper error handling
## Changes
### dashcore (dash/src/network/message_headers2.rs)
- 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
### dash-spv
- Enabled headers2 in handshake negotiation
- Enabled headers2 in sync manager
- Fixed phase transition when receiving empty headers2 response
- Re-enabled has_headers2_peer() check
## Testing
- 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]>1 parent 5d182ab commit a81cf27
File tree
6 files changed
+739
-156
lines changed- dash-spv/src
- network
- sync
- headers
- dash
- src/network
- tests
6 files changed
+739
-156
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 | | |
| |||
1296 | 1297 | | |
1297 | 1298 | | |
1298 | 1299 | | |
1299 | | - | |
1300 | | - | |
1301 | | - | |
| 1300 | + | |
1302 | 1301 | | |
1303 | 1302 | | |
1304 | 1303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
412 | 412 | | |
413 | 413 | | |
414 | 414 | | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | 415 | | |
| 416 | + | |
425 | 417 | | |
426 | 418 | | |
427 | 419 | | |
| |||
462 | 454 | | |
463 | 455 | | |
464 | 456 | | |
465 | | - | |
466 | | - | |
467 | | - | |
| 457 | + | |
| 458 | + | |
468 | 459 | | |
469 | 460 | | |
470 | 461 | | |
| |||
535 | 526 | | |
536 | 527 | | |
537 | 528 | | |
538 | | - | |
539 | | - | |
| 529 | + | |
| 530 | + | |
540 | 531 | | |
541 | | - | |
542 | | - | |
| 532 | + | |
| 533 | + | |
543 | 534 | | |
544 | 535 | | |
545 | 536 | | |
546 | 537 | | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
569 | 549 | | |
570 | 550 | | |
571 | 551 | | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
578 | 558 | | |
579 | 559 | | |
580 | 560 | | |
581 | 561 | | |
582 | | - | |
583 | | - | |
| 562 | + | |
584 | 563 | | |
585 | 564 | | |
586 | 565 | | |
| 566 | + | |
587 | 567 | | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
596 | 573 | | |
597 | 574 | | |
598 | 575 | | |
| |||
605 | 582 | | |
606 | 583 | | |
607 | 584 | | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
614 | 591 | | |
615 | 592 | | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | 593 | | |
626 | | - | |
627 | 594 | | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
635 | 604 | | |
636 | | - | |
637 | | - | |
638 | | - | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
639 | 615 | | |
640 | 616 | | |
641 | 617 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
315 | | - | |
| 315 | + | |
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
326 | 331 | | |
327 | 332 | | |
328 | 333 | | |
329 | 334 | | |
330 | | - | |
| 335 | + | |
331 | 336 | | |
332 | 337 | | |
333 | 338 | | |
| |||
0 commit comments