-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace chrono with time 0.3 (backport to 0.23.x) (#1036)
* Replace dependency on chrono with time 0.3 Changes in tendermint: Change Time implementation to crate time. chrono has soundness issues (see RUSTSEC-2020-0159) and does not seem to be actively maintained. Ensure Time can only have values that are valid for Google protobuf Timestamp messages. Add ErrorDetail variant DateOutOfRange to report when this restriction is not met. Remove conversions between Time and chrono::DateTime, replacing them with conversions from/to time::OffsetDateTime. Conversion from time::OffsetDateTime is made fallible with a TryFrom impl. Add Time methods checked_add and checked_sub. These should be used instead of the overloaded operators that broke the operator convention by returning a Result. Changes in tendermint-pbt-gen: Change the time stragegies and helpers to produce time::OffsetDateTime values. Add strategies to generate date-time values and RFC 3339 strings in the range valid for protobuf Timestamp messages. Changes in tendermint-proto: Provide another helper in the serializers::timestamp module, one that formats into a provided fmt::Write object. Changes in tendermint-rpc: Use `OffsetDateTime` and `Date` types provided by the `time` crate in query operands instead of their `chrono` counterparts. * Harden Timestamp conversions and serde Require the timestamp to be in the validity range (years 1-9999 in UTC) and the nanosecond member value to not exceed 999_999_999. Rename ErrorDetail::TimestampOverflow to TimestampNanosOutOfRange, because the old variant was not very informative (the chained TryFromIntError did not help) and we also use it for the above-range case now which is not an overflow. * Changelog entry about changed error variants * Restore nanosecond range check in Time::from_unix_timestamp Add a unit test to exercise the check. * proto: Improve timestamp::fmt_as_rfc3339_nanos - More ergonomic signature - A non-allocating implementation * Fix component name in changelog for 1030-remove-chrono Co-authored-by: Thane Thomson <thane@informal.systems> * time: Use Self instead of the type name in methods Co-authored-by: Thane Thomson <thane@informal.systems> * Comment on the inner representation of `Time` * Don't alias crate time in testgen * Document the Time::from_utc helper Co-authored-by: Thane Thomson <thane@informal.systems>
- Loading branch information
1 parent
c64cbaa
commit aef23ed
Showing
23 changed files
with
565 additions
and
245 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
.changelog/unreleased/breaking-changes/1030-remove-chrono.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
- `[tendermint]` Reform `tendermint::Time` | ||
([#1030](https://github.com/informalsystems/tendermint-rs/issues/1030)): | ||
* The struct content is made private. | ||
* The range of acceptable values is restricted to years 1-9999 | ||
(as reckoned in UTC). | ||
* Removed conversions from/to `chrono::DateTime<chrono::Utc>`. | ||
* Changes in error variants: removed `TimestampOverflow`, replaced with | ||
`TimestampNanosOutOfRange`; removed `ChronoParse`, replaced with `TimeParse`. | ||
- `[tendermint-rpc]` Use `OffsetDateTime` and `Date` types provided by the `time` crate | ||
in query operands instead of their `chrono` counterparts. | ||
([#1030](https://github.com/informalsystems/tendermint-rs/issues/1030)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
- Remove dependencies on the `chrono` crate. | ||
([#1030](https://github.com/informalsystems/tendermint-rs/issues/1030)) | ||
- `[tendermint]` Improve `tendermint::Time` | ||
([#1030](https://github.com/informalsystems/tendermint-rs/issues/1030)): | ||
* Restrict the validity range of `Time` to dates with years in the range | ||
1-9999, to match the specification of protobuf message `Timestamp`. | ||
Add an `ErrorDetail` variant `DateOutOfRange` to report when this | ||
restriction is not met. | ||
* Added a conversion to, and a fallible conversion from, | ||
`OffsetDateTime` of the `time` crate. | ||
* Added `Time` methods `checked_add` and `checked_sub`. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.