Repository navigation
fix(rpc): don't panic when printing out-of-range timestamp or since values - #689
Merged
chenyukang merged 1 commit intoNov 9, 2026
Conversation
quake
approved these changes
Nov 3, 2026
Contributor
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟢 Approval recommended
The change is narrowly focused on making RPC timestamp/since formatting more robust by replacing panicking conversions with fallible handling and adding targeted unit tests, with no active issues indicated.
No open issues 🎉
What changed in this PR
This pull request hardens RPC primitive formatting in ckb-cli to avoid panics when an RPC endpoint returns malformed or out-of-range timestamp / since values, ensuring the CLI can still print responses safely.
Changes:
- Replace
unwrap()-based timestamp conversions with fallible handling and stable “invalid timestamp” output. - Gracefully handle invalid
sincemetric flags and unrepresentable timestamp-since values with explicit “invalid since” formatting. - Add unit tests to ensure these cases do not panic and valid values still render as expected.
| File | Summary |
|---|---|
src/utils/rpc/primitive.rs |
Makes timestamp/since string formatting resilient to out-of-range/invalid RPC-provided values and adds regression tests. |
Review effort: Balanced
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.
What problem does this PR solve?
timestamp_to_stringandsince_to_stringinsrc/utils/rpc/primitive.rsformat values from RPC responses withunwrap()on fallible conversions:Local.timestamp_millis_opt(..).unwrap()for header, sync state and banned address timestamps;Since::extract_metric().unwrap()andLocal.timestamp_opt(..).unwrap()for inputsincevalues.A timestamp outside the range chrono can represent, or a
sincewith an invalid metric flag, makes ckb-cli panic while printing the response. Honest nodes do not return such values, but an RPC endpoint the user connects to can, and the CLI exits instead of showing the result.What is changed and how it works?
timestamp_to_stringprints<value> (invalid timestamp)when the value cannot be converted to a local time.since_to_stringprints0x<value> (invalid since)for an unknown metric flag, andtimestamp(<value>, invalid)for a timestamp since that cannot be converted.Check List
Tests
test_out_of_range_timestamp_does_not_panicandtest_invalid_since_does_not_panicinsrc/utils/rpc/primitive.rs.cargo clippy --all-targets -- -D warningspasses.Side effects
Release note