Skip to content

fix: address rust tutorial issues from #191#192

Merged
Keinberger merged 7 commits into
mainfrom
kbg/fix/rust-tutorial-issues-191
Jun 5, 2026
Merged

fix: address rust tutorial issues from #191#192
Keinberger merged 7 commits into
mainfrom
kbg/fix/rust-tutorial-issues-191

Conversation

@Keinberger
Copy link
Copy Markdown
Collaborator

@Keinberger Keinberger commented Apr 28, 2026

Overview

Fixes the issues raised in #191 across the rust-client tutorials: removes the cwd-dependent MASM-loading and per-binary create_library pattern, migrates the tutorial note scripts to the v0.14.5 @note_script form, bumps both lockfiles to 0.14.5, and drops unused dependencies. The oracle tutorial is not reworked here — #201 already landed the live Pragma v14 oracle implementation on main, so this branch keeps #201's oracle code verbatim and only retags three oracle-tutorial code fences so the file can join the docs doctest suite (see the Oracle Tutorial Note).

Key Changes

  • create_library removal (non-oracle tutorials). Drops the per-binary create_library helper and compiles MASM through a single client.code_builder().with_linked_module(...) chain instead, avoiding the cross-source-manager handoff behind invalid source span. Applied across the counter-contract, FPI, mapping, and note-creation examples and their docs.
  • include_str! path fixes (non-oracle tutorials). Replaces cwd-relative Path::new("../masm/...") loading (which broke when users ran from their own project root) with include_str!, resolved at compile time relative to the source file.
  • @note_script v0.14.5 migration. Converts the three tutorial note scripts — masm/notes/{hash_preimage_note,iterative_output_note,network_increment_note}.masm — to the @note_script pub proc main library form now required by miden-protocol@0.14.5.
  • Lockfile + dependency cleanup. Bumps rust-client/Cargo.lock and docs/Cargo.lock to miden-{client,client-sqlite-store,protocol,standards}@0.14.5, and removes the unused serde, serde_json, and rand_chacha dependencies (and their stale tutorial [dependencies] snippets) from both Cargo.toml files.
  • Doctest coverage for the oracle tutorial. Adds docs/src/rust-client/oracle_tutorial.md to docs/src/lib.rs so its code blocks are exercised by the docs doctest suite.

Oracle Tutorial Note

The live Pragma oracle implementation now lives on main via #201, which updated oracle_data_query.rs, oracle_reader.masm, and the oracle tutorial prose for Pragma's deployed v0.14 oracle. This branch merges #201 and takes its versions as-is:

  • masm/accounts/oracle_reader.masm and rust-client/src/bin/oracle_data_query.rs are byte-identical to main — no diff.
  • docs/src/rust-client/oracle_tutorial.md's only change versus main is retagging three previously-untagged code fences so they are not compiled as Rust once the file is part of the doctest suite: the directory tree → text, the run command → bash, and the sample program output → text.

Verification

  • CI on the PR head: doc-tests, format-markdown, Build Documentation, Analyze (actions), Analyze (javascript-typescript), and CodeQL all passing; mergeStateStatus is CLEAN.
  • Local cargo check --locked in rust-client/: passed.
  • Local cargo test --doc --locked in docs/: 17 passed, 0 failed, 16 ignored.

Out of Scope

… wording

Reorder oracle_data_query.rs to compile the oracle reader contract and
tx script BEFORE the live Pragma storage walk, so a dead Pragma deployment
no longer blocks local verification of the template substitution and MASM
assembly path. Add three log lines (template substituted, component
compiled, tx_script compiled) so the verification script can classify
oracle import failure as TEMP PASS when the local compile path is healthy.

Add oracle_tutorial.md to docs/src/lib.rs for doctesting alongside the
other tutorial pages.

Strengthen the Pragma callout in oracle_tutorial.md: after Pragma
redeploys, the oracle account ID and GET_MEDIAN_PROC_HASH constant must
be re-verified; do not assume either survives a redeploy unchanged.

Apply prettier-formatting fixes to oracle_tutorial.md (italics syntax
and three fenced-block language hints).
Reorder the doc snippet in oracle_tutorial.md to match the runnable
oracle_data_query.rs: build and locally compile the oracle reader
contract and tx script BEFORE walking Pragma's storage, with the same
three progress println lines (template substituted, component compiled,
tx_script compiled). The doc and bin now read identically through the
local-compile path, so the tutorial accurately reflects how a dead
Pragma deployment surfaces (only the storage walk fails).

Replace stale 'trading_pair requirement' wording with 'pair_word' to
match the actual function-signature argument.
Copy link
Copy Markdown
Collaborator

@partylikeits1983 partylikeits1983 left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for doing this.

Leaving a conditional approval, I'd remove all the comment references to that VM issue/PR, its irrelevant context for a future reader / consumer of the tutorials & examples. There are more references to vm #2778 than what I listed below

// Compile the account code into `AccountComponent` with one storage slot.
// Using `client.code_builder()` makes the assembler share the client's
// persisted source manager, which keeps debug spans coherent for any
// libraries that link against this code later (see miden-vm#2778).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you refactor this comment to not reference the VM PR?


// Compile the script with the counter contract code linked as a dynamic
// module on the same `CodeBuilder`. This shares the client's source
// manager between parsing and assembly, which is what miden-vm#2778
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here

Comment thread rust-client/src/bin/mapping_example.rs Outdated
// Compile the transaction script with the library.
// Compile the transaction script with the account code linked as a
// module on the same `CodeBuilder` chain (avoids the source-span
// mismatch from miden-vm#2778).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit:


// Link the counter contract code into the same `CodeBuilder` chain that
// compiles the script, so the assembler shares the client's persisted
// source manager (avoids the source-span mismatch from miden-vm#2778).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit


// Compile the note script with the counter contract library
// Compile the note script with the counter contract code linked as a
// module on the same `CodeBuilder` chain (avoids miden-vm#2778).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit


// Link the counter contract code into the same `CodeBuilder` chain that
// compiles the script, so the assembler shares the client's persisted
// source manager (avoids the source-span mismatch from miden-vm#2778).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit


// Compile the note script with the counter contract library
// Compile the note script with the counter contract code linked as a
// module on the same `CodeBuilder` chain (avoids miden-vm#2778).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit


// Link the counter contract code into the same `CodeBuilder` chain that
// compiles the script, so the assembler shares the client's persisted
// source manager (avoids the source-span mismatch from miden-vm#2778).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit


// Compile the note script with the counter contract library
// Compile the note script with the counter contract code linked as a
// module on the same `CodeBuilder` chain (avoids miden-vm#2778).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit


// Compile the script against the counter contract code via a single
// `CodeBuilder` chain so the assembler shares the client's persisted
// source manager (avoids the source-span mismatch from miden-vm#2778).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit

Address partylikeits1983 review on PR #192: drop `miden-vm#2778` and
related internal-VM context from future-facing tutorial and example
comments. Behavior is unchanged (the `client.code_builder()
.with_linked_module(...)` path is preserved); only the rationale text
in comments is reduced to the tutorial-relevant local fact (the
contract code is linked into the same `CodeBuilder` chain that
compiles the script or note).

Affected: 6 rust-client binaries and 6 mirrored tutorial doc snippets.
@Keinberger
Copy link
Copy Markdown
Collaborator Author

Requesting re-review from @partylikeits1983

Brings in:
- #184 fix: refactor miden-bank tutorial test flow and init guard progression
- #196 docs: fix duplicate 'a' in oracle tutorial

Conflict in docs/src/rust-client/oracle_tutorial.md: both sides applied
the #196 typo fix (removing the duplicate 'a'). HEAD additionally ends
the sentence with a period. Kept HEAD's version (typo fix + period) so
both intents are preserved.
Brings in:
- #201 fix: update oracle tutorial for Pragma's v14 oracle deployment

Conflicts in the three oracle files (docs/src/rust-client/oracle_tutorial.md,
masm/accounts/oracle_reader.masm, rust-client/src/bin/oracle_data_query.rs):
resolved by taking main's #201 version, which supersedes this PR's earlier
oracle work with values verified against Pragma's live v14 deployment. The
PR's other changes (create_library removal, include_str! path fixes,
@note_script v0.14.5 migration, dependency cleanup) are preserved unchanged.

oracle_tutorial.md additionally re-tags three code blocks that main left
untagged (directory tree and sample output -> text, run command -> bash).
This PR wires oracle_tutorial.md into the docs doctest harness
(docs/src/lib.rs); without the tags those blocks compile as Rust doctests and
fail. The tags restore green doc-tests and change no oracle content.
@Keinberger Keinberger merged commit 914dd0f into main Jun 5, 2026
6 checks passed
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