Fix TryFromIntError when deserializing P2P gossip messages with out-of-range nonce values#1830
Draft
Fix TryFromIntError when deserializing P2P gossip messages with out-of-range nonce values#1830
Conversation
Copilot
AI
changed the title
[WIP] Fix handling error for P2P actions
Fix TryFromIntError when deserializing P2P gossip messages with out-of-range nonce values
Dec 9, 2025
OCaml Reference Validation ResultsRepository: https://github.com/MinaProtocol/mina.git Click to see full validation output |
✓ Code Reference Verification PassedAll code references in the documentation have been verified successfully! Total references checked: 1 The documentation is in sync with the codebase on the |
…prot The issue occurred when binprot streams contained i64 values outside the i32 range. The binprot library reads all integers as i64 internally and uses try_from to convert to target types, which fails with TryFromIntError for out-of-range values. The fix changes Number<u32> and Number<u64> to read i64 directly and cast to the target type, avoiding the intermediate conversion that could fail. Writing still uses the original format to maintain wire compatibility. Added regression tests to verify the fix handles: - i64 values larger than i32::MAX - Negative i64 values - All existing test cases continue to pass Co-authored-by: dannywillems <6018454+dannywillems@users.noreply.github.com>
Clarify that the asymmetry between reading (accepting any i64) and writing (casting to signed type) is intentional for robustness and wire format compatibility with the OCaml implementation. Co-authored-by: dannywillems <6018454+dannywillems@users.noreply.github.com>
61d0324 to
37d64c5
Compare
Contributor
|
@copilot rebase |
Contributor
Author
Successfully rebased onto The rebased branch needs to be force-pushed to update the PR. The local branch is now based on develop@dd30271, but I'm unable to force-push directly. You may need to manually force-push or merge the changes. |
Copilot stopped work on behalf of
dannywillems due to an error
December 17, 2025 07:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix TryFromIntError when handling P2P gossip messages ✅
Issue Analysis
TryFromIntErrorwhen handlingP2pNetworkPubsubIncomingMessagetry_fromto convert to target typesRoot Cause
The issue occurs in the
Number<T>binprot reading implementation:binprot_number!(u32, i32)macro reads an i32 from binprot then casts to u32try_fromto convert to i32try_fromfails withTryFromIntErrorSolution Implemented ✅
Number<u32>andNumber<u64>that read i64 directlyDesign Decisions
The fix introduces intentional asymmetry between read and write:
Testing ✅
Security Analysis ✅
Files Changed
crates/p2p-messages/src/number.rs: Custom binprot implementations for Number and Number with comprehensive testsOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.