Skip to content

Conversation

@sofia-bobbiesi
Copy link

@sofia-bobbiesi sofia-bobbiesi commented Sep 29, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Added a specific error for unresolved tip resolution and a dedicated error code.
    • Compiler initialization now includes chain point (slot/hash/timestamp) for accurate tip handling.
  • Tests

    • Adjusted test protocol text formatting.

@coderabbitai
Copy link

coderabbitai bot commented Sep 29, 2025

Walkthrough

The PR updates the TRP compiler initialization to construct a tx3_cardano::ChainPoint tip from the current StateStore (slot, hash, timestamp) and pass it to tx3_cardano::Compiler::new; it adds a TipNotResolved error variant and code, and a minor whitespace change in a test string.

Changes

Cohort / File(s) Summary
Compiler Tip Construction
crates/trp/src/compiler.rs
Import StateStore; in load_compiler read state/read_cursor, error if tip unresolved, extract slot and hash (hash default empty vec), load era summary and compute timestamp via slot_time(slot) * 1000, build tx3_cardano::ChainPoint { slot, hash, timestamp }, pass tip to tx3_cardano::Compiler::new alongside pparams and config (no public signature changes).
Error Handling
crates/trp/src/error.rs
Add Error::TipNotResolved variant and public constant CODE_TIP_NOT_RESOLVED: i32 = -32004; map the new variant to the code in error-to-code logic.
Test Whitespace
crates/trp/src/methods.rs
Inserted an additional blank line after the Receiver declaration in the SUBJECT_PROTOCOL test string (formatting only).

Sequence Diagram

sequenceDiagram
    participant LC as load_compiler
    participant SS as StateStore
    participant TC as tx3_cardano::Compiler

    LC->>SS: get state & read_cursor
    alt state or tip missing
        LC-->>LC: return Error::TipNotResolved
    else tip available
        LC->>SS: extract slot & hash
        LC->>SS: load era summary (for slot_time)
        LC-->>LC: compute timestamp = slot_time(slot) * 1000
        LC-->>LC: build ChainPoint{slot, hash, timestamp}
        LC->>TC: Compiler::new(pparams, config, tip)
        TC-->>LC: Compiler instance
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas to inspect closely:
    • StateStore read and tip-resolution logic in crates/trp/src/compiler.rs (ensure correct error conditions).
    • Timestamp derivation and units (multiplying slot_time by 1000) vs. tx3_cardano::ChainPoint expectations.
    • Construction shape of ChainPoint and its alignment with tx3_cardano::Compiler::new parameters.
    • Error mapping additions in crates/trp/src/error.rs.

Suggested reviewers

  • scarmuega

Poem

🐰 The compiler hops to find the tip,

slot and hash tucked in its grip,
a timestamp scaled with gentle care,
errors named so none despair,
I nibble code and dance in air.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title mentions 'posix time' but the changes focus on constructing and passing a ChainPoint tip with timestamp, error handling, and internal state management—not on writing validity ranges using posix time. Update the title to reflect the actual changes, such as 'Add ChainPoint tip construction in compiler' or 'Support ChainPoint with timestamp in compiler initialization'.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efa9fae and 7f3dfe7.

📒 Files selected for processing (1)
  • crates/trp/src/methods.rs (1 hunks)
🔇 Additional comments (1)
crates/trp/src/methods.rs (1)

194-194: LGTM - formatting change in test data.

This blank line adds whitespace to the test protocol definition without affecting functionality.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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

🧹 Nitpick comments (1)
crates/trp/src/error.rs (1)

56-58: Consider attaching diagnostics to TipNotResolved.

Carrying minimal context (e.g., had_cursor: bool, had_hash: bool, slot: Option) would ease client troubleshooting; you could also surface it via Error::data().

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73f9f47 and 6cbe3a5.

📒 Files selected for processing (4)
  • .gitignore (1 hunks)
  • crates/trp/src/compiler.rs (1 hunks)
  • crates/trp/src/error.rs (3 hunks)
  • crates/trp/src/methods.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
crates/trp/src/compiler.rs (2)
crates/core/src/lib.rs (2)
  • slot (490-490)
  • hash (491-491)
crates/cardano/src/eras.rs (1)
  • load_era_summary (186-198)
⏰ 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). (1)
  • GitHub Check: Check Build
🔇 Additional comments (6)
.gitignore (1)

5-5: LGTM; minor path check.

If this is for test artifacts (e.g., insta), double‑check whether the directory is “/snapshot” vs “/snapshots”.

crates/trp/src/methods.rs (1)

191-196: No functional impact.

Whitespace change in SUBJECT_PROTOCOL is fine; keeps formatting readable.

crates/trp/src/error.rs (2)

134-134: LGTM on code assignment.

CODE_TIP_NOT_RESOLVED (-32004) fits the existing custom error range.


156-157: Mapping looks correct.

TipNotResolved → CODE_TIP_NOT_RESOLVED as expected.

crates/trp/src/compiler.rs (2)

76-81: Tip construction is clear.

Struct assembly reads well; once units are confirmed and hash handling fixed, this looks solid.


72-75: Validate external ChainPoint.timestamp unit
Slot time is multiplied by 1 000 (ms), but tx3_cardano::ChainPoint.timestamp may expect seconds. We can’t confirm its unit locally—please verify in the tx3_cardano crate (e.g. in its docs or source) whether timestamp is POSIX seconds or milliseconds, and adjust/remove the * 1000 accordingly.

Comment on lines 68 to 71
let cursor = domain.state().read_cursor()?.ok_or(Error::TipNotResolved)?;
let slot = cursor.slot();
let hash = cursor.hash().map(|h| h.to_vec()).unwrap_or_default();

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Don’t default to empty hash; fail if missing.

An empty tip hash weakens correctness; prefer surfacing TipNotResolved when the hash isn’t available.

Apply this diff:

-    let cursor = domain.state().read_cursor()?.ok_or(Error::TipNotResolved)?;
-    let slot = cursor.slot();
-    let hash = cursor.hash().map(|h| h.to_vec()).unwrap_or_default();
+    let cursor = domain.state().read_cursor()?.ok_or(Error::TipNotResolved)?;
+    let slot = cursor.slot();
+    let hash = cursor.hash().map(|h| h.to_vec()).ok_or(Error::TipNotResolved)?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let cursor = domain.state().read_cursor()?.ok_or(Error::TipNotResolved)?;
let slot = cursor.slot();
let hash = cursor.hash().map(|h| h.to_vec()).unwrap_or_default();
let cursor = domain.state().read_cursor()?.ok_or(Error::TipNotResolved)?;
let slot = cursor.slot();
let hash = cursor.hash().map(|h| h.to_vec()).ok_or(Error::TipNotResolved)?;
🤖 Prompt for AI Agents
In crates/trp/src/compiler.rs around lines 68 to 71, the code currently defaults
to an empty tip hash which weakens correctness; instead, if cursor.hash() is
None return Error::TipNotResolved. Replace the unwrap_or_default behavior so
that you convert the Option<bytearray> from cursor.hash() into a Result,
returning Err(Error::TipNotResolved) when missing, and only then convert the
present hash to a Vec for use.

tx3_cardano::Config {
extra_fees: config.extra_fees,
},
tip,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this awaiting a pending release on tx3_cardano to work?

Copy link

@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

♻️ Duplicate comments (1)
crates/trp/src/compiler.rs (1)

56-69: Address the unresolved hash defaulting issue from previous review.

The hash extraction at line 59 still uses unwrap_or_default(), which was flagged in a previous review comment. As noted before, defaulting to an empty hash weakens correctness—if the hash is unavailable, the code should return Error::TipNotResolved instead.

Apply this diff to fail when hash is missing:

-    let hash = cursor.hash().map(|h| h.to_vec()).unwrap_or_default();
+    let hash = cursor.hash().map(|h| h.to_vec()).ok_or(Error::TipNotResolved)?;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a9a7c4a and efa9fae.

📒 Files selected for processing (1)
  • crates/trp/src/compiler.rs (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
crates/trp/src/compiler.rs (3)
src/adapters.rs (1)
  • state (77-79)
crates/core/src/lib.rs (3)
  • state (725-725)
  • slot (501-501)
  • hash (502-502)
crates/cardano/src/eras.rs (2)
  • state (203-203)
  • load_era_summary (186-198)
⏰ 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). (1)
  • GitHub Check: Check Build
🔇 Additional comments (1)
crates/trp/src/compiler.rs (1)

4-4: LGTM: Import addition is necessary.

The StateStore import is correctly added to support the read_cursor() call introduced in the tip construction logic.

Comment on lines 71 to 77
let compiler = tx3_cardano::Compiler::new(
pparams,
tx3_cardano::Config {
extra_fees: config.extra_fees,
},
tip,
);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify tx3_cardano dependency version supports this API.

The compiler is now correctly instantiated with the tip argument. However, a previous comment questioned whether this change depends on a pending tx3_cardano release. Please confirm that version 0.11.4 (currently specified) supports the three-argument Compiler::new signature.


🏁 Script executed:

#!/bin/bash
# Verify tx3_cardano::Compiler::new signature supports the tip argument

# Search for the Compiler::new usage to confirm the signature matches
rg -nP --type=rust 'tx3_cardano::Compiler::new' -A 5

# Check Cargo.toml for tx3_cardano version
fd -e toml Cargo.toml --exec rg -n 'tx3_cardano'

Length of output: 340



---

🏁 Script executed:

```shell
#!/bin/bash
# Find all Cargo.toml files and search for tx3_cardano dependency
fd -type f -name "Cargo.toml" --exec rg -n 'tx3_cardano' {} +

Length of output: 170


🏁 Script executed:

#!/bin/bash
# Also check the root Cargo.toml specifically
cat Cargo.toml | head -100

Length of output: 2925


🏁 Script executed:

#!/bin/bash
# And the crates/trp Cargo.toml specifically
cat crates/trp/Cargo.toml | head -150

Length of output: 1323


🌐 Web query:

tx3-cardano 0.11.4 Compiler::new API signature tip parameter

💡 Result:

Do you want the exact Rust signature (types) for Compiler::new in tx3-cardano v0.11.4, or a link to the docs/source where it's defined?


🌐 Web query:

tx3-cardano crates.io version history releases

💡 Result:

You can view tx3-cardano's version history/releases on these pages:

  • Crates.io (versions tab) — official release list. See the crate page on crates.io. [1]
  • docs.rs — per-version documentation (examples: v0.11.4, v0.11.3). [2][3]
  • GitHub (tx3/tx3 repo) — source and tags/releases. [4]

References

  1. crates.io crate page for tx3-cardano.
  2. docs.rs — tx3-cardano v0.11.4.
  3. docs.rs — tx3-cardano v0.11.3.
  4. tx3-lang / tx3 on GitHub.

🌐 Web query:

tx3-cardano Compiler struct new method docs.rs 0.11.4

💡 Result:

The Compiler::new signature and implementation (tx3-cardano v0.11.4):

pub fn new(pparams: PParams, config: Config) -> Self

It constructs a Compiler with the given pparams and config and initializes latest_tx_body to None. [1]

Sources: tx3-cardano 0.11.4 source (lib.rs). [1]


🌐 Web query:

tx3-cardano Compiler new tip parameter version changelog

💡 Result:

Do you mean the tx3-cardano compiler change that added a new "tip" (or "new tip") parameter? Which specific details do you want: the version that introduced it, the exact changelog entry, or a link to the release/commit?


Update tx3_cardano dependency version to support the tip parameter.

The code at lines 71-76 calls Compiler::new with three arguments (pparams, config, tip), but tx3-cardano v0.11.4's Compiler::new signature only accepts two arguments: pparams and config. This is a compilation error. You must upgrade the tx3-cardano version in crates/trp/Cargo.toml to a version that supports the tip parameter, or revert the code to use the two-argument signature.

🤖 Prompt for AI Agents
In crates/trp/src/compiler.rs around lines 71-77, the call to
tx3_cardano::Compiler::new(pparams, config, tip) uses a three-argument signature
that is not available in the currently pinned tx3_cardano version; either update
the tx3_cardano dependency in crates/trp/Cargo.toml to a version that exposes
the three-argument Compiler::new (and run cargo update) or change this call back
to the two-argument form Compiler::new(pparams, config) to match the current
dependency; modify Cargo.toml to the compatible version if you need the tip
behavior, otherwise revert the call to the two-argument signature and adjust any
downstream code accordingly.

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