Skip to content

Preview conformance fixes #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 12, 2025
Merged

Preview conformance fixes #333

merged 2 commits into from
Jul 12, 2025

Conversation

KtorZ
Copy link
Contributor

@KtorZ KtorZ commented Jul 11, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved serialization of IPv6 addresses to output a standardized string format instead of raw bytes, enhancing readability and compatibility.
  • Refactor

    • Updated protocol version logic in tests to explicitly handle multiple network types and epochs, providing clearer and more robust network-specific behavior.

Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Walkthrough

Alright mate, here’s the lowdown: The serialization of IPv6 addresses in the WrapRelay struct got a bit of a remix—now it formats those bytes into a proper IPv6 string after shuffling the bytes around. Over in the tests, the protocol_version function got a more explicit match for different networks, with some cases now panicking instead of defaulting.

Changes

File(s) Change Summary
crates/amaru-kernel/src/lib.rs Modified IPv6 serialization: rearranges 4-byte chunks, builds an Ipv6Addr, serializes as string instead of raw bytes.
crates/amaru/tests/summary.rs Refactored protocol_version to use explicit match arms for networks; removed default, added unimplemented!() panics.

Poem

G’day to bytes that flip and twirl,
IPv6 now struts, no longer in a whirl.
Protocols matched with a keen, sharp eye,
If you’re not Preprod or Preview, you’ll get a panicked reply!
Like Mario grabbing a star,
These changes shine bright, near and far.
Cheers to code that’s fair dinkum and neat—onward, mates, to the next feat! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

s.serialize_field(
"ipv6",
&format!("{}", std::net::Ipv6Addr::from(bytes)),
)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's the best choice long-term for sharing those snapshots but... IPv6 are currently encoded according to RFC 5952: http://tools.ietf.org/html/rfc5952 😅 ... we should probably just stick with hex-encoded bytes for the tests even if they're really cute.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ee71b7 and b5fb14d.

📒 Files selected for processing (2)
  • crates/amaru-kernel/src/lib.rs (1 hunks)
  • crates/amaru/tests/summary.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
crates/amaru-kernel/src/lib.rs (1)
Learnt from: stevana
PR: pragma-org/amaru#236
File: simulation/amaru-sim/src/simulator/generate.rs:141-145
Timestamp: 2025-06-03T06:31:57.736Z
Learning: In the amaru project, the team prefers to use as_bytes() instead of hex::decode() for converting hash and header strings to bytes in simulation/amaru-sim/src/simulator/generate.rs, even though they appear to be hex-encoded strings.
crates/amaru/tests/summary.rs (4)
Learnt from: rkuhn
PR: pragma-org/amaru#263
File: crates/amaru-consensus/src/consensus/store.rs:220-223
Timestamp: 2025-06-14T16:38:35.449Z
Learning: In `NetworkName::Preprod.into()` when converting to `&EraHistory`, the From implementation returns a static reference to a constant value, not a temporary. This makes it safe to return directly from functions expecting `&EraHistory` without storing it in a struct field.
Learnt from: abailly
PR: pragma-org/amaru#195
File: simulation/amaru-sim/src/simulator/mod.rs:167-182
Timestamp: 2025-04-22T09:18:19.893Z
Learning: In the Amaru consensus pipeline refactor, ValidateHeader::handle_roll_forward returns a Result<PullEvent, ConsensusError>, not ValidateHeaderEvent as might be expected from the older code structure.
Learnt from: stevana
PR: pragma-org/amaru#210
File: simulation/amaru-sim/src/simulator/simulate.rs:264-277
Timestamp: 2025-05-12T14:21:27.470Z
Learning: The team plans to replace the out-of-process test in `simulation/amaru-sim/src/simulator/simulate.rs` with an in-process NodeHandle implementation in the future, eliminating the need for hard-coded binary paths (`../../target/debug/echo`) and making tests more reliable.
Learnt from: jeluard
PR: pragma-org/amaru#69
File: crates/amaru/src/ledger/state/diff_epoch_reg.rs:112-117
Timestamp: 2025-01-21T15:32:17.911Z
Learning: When suggesting code changes in Rust, always verify that the types align correctly, especially when dealing with references and Options. The `Fold::Registered` variant in `diff_epoch_reg.rs` expects a reference `&'a V`, so unwrapping an `Option<&V>` requires only a single `.expect()`.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build on windows-latest with target x86_64-pc-windows-msvc
  • GitHub Check: Snapshots (preprod, 1, 10.1.4)
  • GitHub Check: Coverage
🔇 Additional comments (1)
crates/amaru/tests/summary.rs (1)

141-158: Nice Refactor—Just Double-Check Those Epoch Boundaries

This match expression is spot on—each network variant is crystal clear, and the unimplemented!() stubs for Mainnet and Testnet are way better than a sneaky default. It reads smoother than a Tarantino monologue!

Before we deck this out, let’s make sure those hard-fork epochs actually line up with the Nov 6, 2024 v10 jump you found:

• Epoch::from(180) (Preprod) — does that correspond to the 00:00 UTC Nov 6, 2024 boundary for Preprod’s v9→v10?
• Epoch::from(741) (Preview) — is that the same instant for Preview’s fork?

If those numbers map to the Conway-era switch at 00:00 UTC Nov 6, 2024, you’re golden—otherwise, tweak them so the tests level up correctly. 🎮

Comment on lines +446 to +455
let bytes: [u8; 16] = [
ipv6[3], ipv6[2], ipv6[1], ipv6[0], // 1st fragment
ipv6[7], ipv6[6], ipv6[5], ipv6[4], // 2nd fragment
ipv6[11], ipv6[10], ipv6[9], ipv6[8], // 3rd fragment
ipv6[15], ipv6[14], ipv6[13], ipv6[12], // 4th fragment
];
s.serialize_field(
"ipv6",
&format!("{}", std::net::Ipv6Addr::from(bytes)),
)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Fair dinkum, that's a substantial change to IPv6 serialization logic!

This refactor switches from raw byte serialization to a formatted string representation with some gnarly byte reordering. The logic reverses each 4-byte fragment before creating the Ipv6Addr - looks like endianness correction or network byte order handling, which is solid as a rock.

However, this change is significant enough that it could affect protocol compatibility. The byte shuffling pattern is quite specific and needs to align with whatever spec you're conforming to.


🏁 Script executed:

#!/bin/bash
# Description: Search for other IPv6 serialization patterns in the codebase to ensure consistency

# Search for other IPv6 handling patterns
rg -A 5 -B 5 "ipv6.*serialize|Ipv6Addr" --type rust

# Look for any tests that might cover this serialization
rg -A 10 -B 5 "SingleHostAddr.*ipv6|ipv6.*SingleHostAddr" --type rust

Length of output: 2399


Ensure correct IPv6 byte order and add unit tests

This new serialization does a four-byte reverse dance before feeding into Ipv6Addr::from, which is neat but a touch fiddly. Let’s be sure we’re not sending some hobbiton-sized mis-endian packet:

  • Confirm this chunked reverse (LE→BE per u32) actually matches the protocol spec for your stored format.
  • Add focused unit tests for a few canonical addresses (e.g. ::1, fe80::1, a random full-address) to catch any mix-ups.
  • Consider simplifying by interpreting the 16-byte array as a u128 and using u128::from_be_bytes(…) with Ipv6Addr::from—less manual shuffling, fewer gremlins.

Let’s lock down that endianness so no one ends up racing across the outback trying to debug a backwards IPv6!

🤖 Prompt for AI Agents
In crates/amaru-kernel/src/lib.rs around lines 446 to 455, the current IPv6 byte
reordering before serialization is complex and may cause endianness errors.
Verify that the four-byte reversed order matches the protocol specification for
the stored format. To fix, add unit tests for known IPv6 addresses like ::1,
fe80::1, and a full random address to ensure correct serialization.
Additionally, simplify the code by converting the 16-byte array directly into a
u128 using u128::from_be_bytes and then create the Ipv6Addr from that,
eliminating manual byte shuffling and reducing potential errors.

Copy link

codecov bot commented Jul 11, 2025

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/amaru-kernel/src/lib.rs 0.00% 4 Missing ⚠️
Files with missing lines Coverage Δ
crates/amaru-kernel/src/lib.rs 61.84% <0.00%> (+0.59%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jeluard jeluard self-requested a review July 12, 2025 04:54
@jeluard jeluard merged commit e7c1032 into main Jul 12, 2025
12 of 13 checks passed
@jeluard jeluard deleted the preview-conformance-fixes branch July 12, 2025 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants