Commit fd42619
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 8009033 commit fd42619
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 | |
|---|---|---|---|
| |||
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | 336 | | |
| 337 | + | |
346 | 338 | | |
347 | 339 | | |
348 | 340 | | |
| |||
383 | 375 | | |
384 | 376 | | |
385 | 377 | | |
386 | | - | |
387 | | - | |
388 | | - | |
| 378 | + | |
| 379 | + | |
389 | 380 | | |
390 | 381 | | |
391 | 382 | | |
| |||
456 | 447 | | |
457 | 448 | | |
458 | 449 | | |
459 | | - | |
460 | | - | |
| 450 | + | |
| 451 | + | |
461 | 452 | | |
462 | | - | |
463 | | - | |
| 453 | + | |
| 454 | + | |
464 | 455 | | |
465 | 456 | | |
466 | 457 | | |
467 | 458 | | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
490 | 470 | | |
491 | 471 | | |
492 | 472 | | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
499 | 479 | | |
500 | 480 | | |
501 | 481 | | |
502 | 482 | | |
503 | | - | |
504 | | - | |
| 483 | + | |
505 | 484 | | |
506 | 485 | | |
507 | 486 | | |
| 487 | + | |
508 | 488 | | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
517 | 494 | | |
518 | 495 | | |
519 | 496 | | |
| |||
526 | 503 | | |
527 | 504 | | |
528 | 505 | | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
535 | 512 | | |
536 | 513 | | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | 514 | | |
547 | | - | |
548 | 515 | | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
556 | 525 | | |
557 | | - | |
558 | | - | |
559 | | - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
560 | 536 | | |
561 | 537 | | |
562 | 538 | | |
| |||
| 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