Skip to content

test(dpp): run deep value serialization tests on a large stack - #4725

Merged
QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/optimistic-mirzakhani-8954e9
Sep 13, 2026
Merged

QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/optimistic-mirzakhani-8954e9

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

On v4.2-dev, state_transition::serialization::tests::document_batch_rejects_excessive_value_depth_during_decode overflows libtest's default 2 MiB per-test thread stack and aborts the entire dpp lib test binary under plain cargo test:

cargo test -p dpp --all-features --lib -- document_batch_rejects_excessive_value_depth_during_decode --test-threads=1
-> "has overflowed its stack" / "fatal runtime error: stack overflow, aborting"

CI does not see this because the Rust job runs nextest, which executes each test in its own process on the 8 MiB main thread.

The overflow is not in the decoder. Instrumenting the test shows it aborts inside serialize_to_bytes(), before decoding starts: Value's Decode and first_depth_exceeding are iterative, but Value still derives Encode, PartialEq and drop glue, which recurse once per nesting level. A RUST_MIN_STACK sweep puts the 300-deep encode between 2.0 and 2.25 MiB, roughly 7 KiB per level in debug builds. The sibling document_batch_value_depth_limits_align_between_decode_and_validation (256 deep, encode + PartialEq + drop) overflows at 1.75 MiB and passes at 2 MiB, so it had under 12% headroom; lowering the failing test from 300 to 257 levels would only have bought that same thin margin.

What was done?

Added a small on_deep_value_stack helper to the test module that runs a closure on a std::thread::Builder thread with an explicit 16 MiB stack and re-raises any panic via resume_unwind, so assertion failures still fail the test. Both deep-value tests are wrapped in it. The 300-deep value, the first_data_depth_exceeding(256) == Some(257) assertion and the value nesting depth 257 exceeds maximum 256 decode error check are unchanged; the rest of the diff is rustfmt re-indentation (git diff -w shows the real change).

Swept every Rust package for fold/loop-built nested Values: only these two tests build them recursively. The validate_document depth tests (257 containers, no encode) pass even at a 1 MiB stack, and the rs-platform-value tests (4k to 10k deep) build their bytes by hand and only exercise iterative paths.

How Has This Been Tested?

  • cargo test -p dpp --all-features --lib -- state_transition::serialization::tests --test-threads=1 at the default stack: 21 passed (previously aborted the binary at test 13).
  • Both deep tests also pass with RUST_MIN_STACK=1048576 (1 MiB), so they no longer depend on the harness thread size at all.
  • Negative check: temporarily changing Some(257) to Some(258) reports FAILED with the assertion output, confirming panic propagation from the spawned thread; reverted.
  • cargo fmt --check clean.

Side observation, outside this PR: in debug builds, encoding a validation-passing 256-deep document costs about 1.8 MiB of stack, close to Tokio's 2 MiB worker default. Release frames are far smaller so it is not a production concern, but an iterative Encode for Value (mirroring the decoder) would remove the recursion entirely.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

`document_batch_rejects_excessive_value_depth_during_decode` overflowed
libtest's default 2 MiB per-test thread and aborted the whole `dpp` lib
test binary under plain `cargo test`. The overflow is not in the decoder,
which is iterative: it happens in `serialize_to_bytes()`, because `Value`
derives `Encode` (and `PartialEq` and drop glue) that recurse once per
nesting level, at roughly 7 KiB per level in debug builds. The sibling
256-deep round-trip test had under 12% headroom on the same budget.
nextest runs each test on the 8 MiB main thread, so CI never saw it.

Run both deep-value tests on a spawned thread with an explicit 16 MiB
stack, re-raising any panic so assertion failures still fail the test.
The depth assertions and the decode error check are unchanged.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 13, 2026
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: a2cabbf5-a681-48db-b0d3-61f4ff7871e6

📥 Commits

Reviewing files that changed from the base of the PR and between d02e988 and 3c66e50.

📒 Files selected for processing (1)
  • packages/rs-dpp/src/state_transition/serialization.rs

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.

@thepastaclaw

thepastaclaw commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Queued for automated review — 2nd in line, estimated start in ~25 min (commit 3c66e50)
Estimated review time once started: ~50 min (two-phase automated review; median of recent runs).

  • Request priority review — tick this box and the review moves to the front of the queue.

@QuantumExplorer QuantumExplorer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed

@QuantumExplorer
QuantumExplorer merged commit d8e0801 into v4.2-dev Sep 13, 2026
15 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/optimistic-mirzakhani-8954e9 branch September 13, 2026 15:36
@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.76923% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.34%. Comparing base (d02e988) to head (3c66e50).
⚠️ Report is 1 commits behind head on v4.2-dev.

Files with missing lines Patch % Lines
...kages/rs-dpp/src/state_transition/serialization.rs 80.76% 20 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v4.2-dev    #4725      +/-   ##
============================================
- Coverage     81.18%   79.34%   -1.85%     
============================================
  Files          2827     2827              
  Lines        389838   396924    +7086     
============================================
- Hits         316501   314945    -1556     
- Misses        73337    81979    +8642     
Components Coverage Δ
dpp 76.62% <80.76%> (-6.84%) ⬇️
drive 81.97% <ø> (-0.09%) ⬇️
drive-abci 83.13% <ø> (-0.08%) ⬇️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 64.85% <ø> (-1.24%) ⬇️
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 32.46% <ø> (-0.22%) ⬇️
🚀 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.

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