Skip to content

P2ID note builder (inicio review)#8

Open
VAIBHAVJINDAL3012 wants to merge 5 commits into
nextfrom
vaibhav/p2id-note-builder
Open

P2ID note builder (inicio review)#8
VAIBHAVJINDAL3012 wants to merge 5 commits into
nextfrom
vaibhav/p2id-note-builder

Conversation

@VAIBHAVJINDAL3012

@VAIBHAVJINDAL3012 VAIBHAVJINDAL3012 commented Jun 24, 2026

Copy link
Copy Markdown

Summary

Full P2ID note builder branch (vaibhav/p2id-note-builder @ 104ac301), for review in inicio-labs. This mirrors upstream 0xMiden/protocol#3126 and includes the changes addressing PhilippGackstatter's review.

Contents

  • P2idNote struct + bon typestate builder (P2idNote::builder()); P2ID notes now require at least one asset.
  • Review fixes: NoteError::other instead of a dedicated MissingAsset variant; removed the hand-rolled create_p2id_note_exact helper (builder inlined at 9 sites); dropped two low-value tests; deduped CHANGELOG.

Verified: make format-check + scoped test suite, 1193 tests, 0 failures.

Summary by CodeRabbit

  • Breaking Changes
    • Updated P2idNote creation: use the new P2idNote builder flow (P2idNote::builder()) and convert the built value into a final Note via Note::from.
  • New Features
    • Enhanced note building with fluent methods for adding assets/attachments, and generating serial numbers.
  • Bug Fixes
    • Enforced validation that P2idNote must include at least one asset (rejects invalid builds).
  • Tests
    • Updated kernel and script tests to construct notes using the new builder approach, with some test scenarios switched to P2ANY notes.

Replace the `P2idNote` marker type and its `P2idNote::create` factory with a
`P2idNote` struct built via a `bon` typestate builder (`P2idNote::builder()`):

- `.sender()`, `.target()`, and a serial number (`.serial_number()` or
  `.generate_serial_number(rng)`) are required; `.note_type()` defaults to
  private and attachments are optional.
- `.asset()`/`.assets()` and `.attachment()`/`.attachments()` append items.
- P2ID notes must now carry at least one asset, enforced in `new()` via the
  new `NoteError::MissingAsset`.
- `From<P2idNote> for Note` converts infallibly.

Migrate all `P2idNote::create` call sites to the builder. Incidental 0-asset
P2ID notes in kernel tests move to P2ANY (which legitimately carries no
assets), preserving the 0-asset coverage.

Part of 0xMiden#2283
- Drop the builder usage description from `P2idNote::new` docs; the typestate
  builder is self-documenting.
- Trim redundant tails from the builder extension method docs.
- Remove the "Use P2ANY ..." rationalization comments across the kernel tests
  and the P2ANY reference in the `setup_test` doc comment.
- Assert the note type against `NoteType::default()` instead of a hardcoded
  `NoteType::Private` in the minimal-builder test.
- Add a `compile_fail` doctest showing `.serial_number()` and
  `.generate_serial_number()` are mutually exclusive at compile time.
Per review feedback, remove the `compile_fail` doctest (and its explanation) on
`generate_serial_number`; the typestate already enforces that the serial number
cannot be set twice.
- Use `NoteError::other` instead of adding a dedicated `MissingAsset` variant to
  the protocol crate; the "at least one asset" rule is a standards concern.
- Remove the hand-rolled `create_p2id_note_exact` helper and inline the builder
  (with `.serial_number()`) at all 9 call sites.
- Drop the low-value `builder_generates_serial_number` and
  `into_note_preserves_assets` tests; exercise `generate_serial_number` inside
  `builder_accumulates_assets` instead.
- Remove the 5 duplicate CHANGELOG entries the rebase re-inserted.
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c7caab5e-d010-449f-ba5f-8a8a708db619

📥 Commits

Reviewing files that changed from the base of the PR and between 104ac30 and 7dd36d7.

📒 Files selected for processing (1)
  • crates/miden-testing/src/utils.rs
💤 Files with no reviewable changes (1)
  • crates/miden-testing/src/utils.rs

📝 Walkthrough

Walkthrough

The PR replaces the placeholder P2idNote marker with a builder-backed struct, adds From<P2idNote> for Note, removes the old exact-note helper, and updates tests and fixtures to use the new construction paths.

Changes

P2idNote builder migration

Layer / File(s) Summary
P2idNote type and conversion
crates/miden-standards/src/note/p2id.rs, CHANGELOG.md
P2idNote gains stored fields, a builder-oriented constructor, accessors, builder extensions, From<P2idNote> for Note, and builder tests; the changelog records the API replacement.
Shared note helpers
crates/miden-testing/src/utils.rs, crates/miden-testing/src/mock_chain/chain_builder.rs
The exact-note testing helper is removed, imports are simplified, and MockChainBuilder::add_p2id_note now builds notes through P2idNote::builder().
Batch and block notes
crates/miden-testing/src/kernel_tests/batch/proposed_batch.rs, crates/miden-testing/src/kernel_tests/block/proposed_block_errors.rs, crates/miden-testing/src/kernel_tests/block/proposed_block_success.rs, crates/miden-testing/src/kernel_tests/block/proven_block_success.rs
Batch and block tests switch empty-asset notes to add_p2any_note, and proven-block output notes are rebuilt with P2idNote::builder() and Note::from.
Transaction setup and input notes
crates/miden-testing/src/kernel_tests/tx/mod.rs, crates/miden-testing/src/kernel_tests/tx/test_input_note.rs
The transaction setup stores a P2ANY zero-asset note, and the input-note assertions read that fixture for sender, storage, serial number, and asset-info checks.
Output note builders
crates/miden-testing/src/kernel_tests/tx/test_account_interface.rs, crates/miden-testing/src/kernel_tests/tx/test_output_note.rs
Output-note tests rebuild expected P2idNote values with the builder, and the zero-asset output fixture in test_get_assets now uses the P2ANY note.
Transaction summary notes
crates/miden-testing/src/kernel_tests/tx/test_tx.rs
Transaction-summary tests stop using P2idNote::create, create notes through the P2ANY helper, and update the expected partial output note to match the new note value.
Auth, agglayer, and swap notes
crates/miden-testing/tests/agglayer/bridge_in.rs, crates/miden-testing/tests/auth/*, crates/miden-testing/tests/scripts/swap.rs
Bridge-in, hybrid multisig, multisig, multisig smart, and swap tests construct expected P2ID notes directly with P2idNote::builder() and Note::from.
Faucet and script notes
crates/miden-testing/tests/scripts/faucet.rs, crates/miden-testing/tests/scripts/p2id.rs, crates/miden-testing/tests/scripts/send_note.rs
Faucet, P2ID, and send-note tests build expected P2ID notes with P2idNote::builder() and Note::from, including parameterized serial numbers, attachments, and note types.

Sequence Diagram(s)

sequenceDiagram
  participant P2idNoteBuilder
  participant P2idNote
  participant NoteAssets
  participant NoteAttachments
  participant BuiltNote
  P2idNoteBuilder->>P2idNoteBuilder: set sender, target, assets, attachments, note type, serial number
  P2idNoteBuilder->>P2idNote: build()
  P2idNote->>NoteAssets: validate assets
  P2idNote->>NoteAttachments: validate attachments
  P2idNote-->>BuiltNote: convert via From<P2idNote>
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I hopped through builders, neat and new,
with assets packed and serials true.
From P2ID notes to paths that glow,
I twitch my nose and watch them flow.
✨ The burrow hums: hop, build, go!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: introducing the P2ID note builder, though the trailing phrase adds unnecessary noise.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch vaibhav/p2id-note-builder

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.

Left over from removing `create_p2id_note_exact`; clippy (-D warnings) flagged it.
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.

1 participant