From 9a7747cec23e3422c7e9a0057a28d97e1ffdbe21 Mon Sep 17 00:00:00 2001 From: Hugo CAILLARD <911307+hugocaillard@users.noreply.github.com> Date: Wed, 9 Jul 2025 16:34:41 +0200 Subject: [PATCH 1/3] chore: upgrade time crate --- Cargo.lock | 203 +++-------------------------- clarity/Cargo.toml | 4 - stacks-common/Cargo.toml | 4 - stacks-common/src/util/mod.rs | 4 +- stackslib/Cargo.toml | 5 +- stackslib/src/net/http/response.rs | 7 +- stackslib/src/net/http/tests.rs | 14 +- 7 files changed, 41 insertions(+), 200 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e339da2589..1f82034132 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -399,12 +399,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base-x" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" - [[package]] name = "base64" version = "0.12.3" @@ -621,7 +615,6 @@ dependencies = [ "serde_stacker", "slog", "stacks-common", - "time 0.2.27", ] [[package]] @@ -669,12 +662,6 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" -[[package]] -name = "const_fn" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" - [[package]] name = "core-foundation" version = "0.9.4" @@ -752,7 +739,7 @@ dependencies = [ "curve25519-dalek-derive", "digest 0.10.7", "fiat-crypto", - "rustc_version 0.4.0", + "rustc_version", "serde", "subtle", "zeroize", @@ -787,9 +774,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.11" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" dependencies = [ "powerfmt", ] @@ -840,12 +827,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - [[package]] name = "doc-comment" version = "0.3.3" @@ -1286,7 +1267,7 @@ dependencies = [ "http 0.2.11", "httpdate", "mime", - "sha1 0.10.6", + "sha1", ] [[package]] @@ -1645,9 +1626,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libflate" @@ -2261,12 +2242,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" version = "1.0.78" @@ -2581,7 +2556,7 @@ dependencies = [ "futures", "futures-timer", "rstest_macros", - "rustc_version 0.4.0", + "rustc_version", ] [[package]] @@ -2593,7 +2568,7 @@ dependencies = [ "cfg-if 1.0.0", "proc-macro2", "quote", - "rustc_version 0.4.0", + "rustc_version", "syn 1.0.109", "unicode-ident", ] @@ -2606,7 +2581,7 @@ checksum = "45f80dcc84beab3a327bbe161f77db25f336a1452428176787c8c79ac79d7073" dependencies = [ "quote", "rand 0.8.5", - "rustc_version 0.4.0", + "rustc_version", "syn 1.0.109", ] @@ -2631,22 +2606,13 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.21", + "semver", ] [[package]] @@ -2787,27 +2753,12 @@ dependencies = [ "cc", ] -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - [[package]] name = "semver" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.196" @@ -2897,15 +2848,6 @@ dependencies = [ "syn 2.0.58", ] -[[package]] -name = "sha1" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" -dependencies = [ - "sha1_smol", -] - [[package]] name = "sha1" version = "0.10.6" @@ -2917,12 +2859,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sha1_smol" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" - [[package]] name = "sha2" version = "0.9.9" @@ -3021,7 +2957,7 @@ dependencies = [ "serde", "serde_json", "slog", - "time 0.3.36", + "time", ] [[package]] @@ -3034,7 +2970,7 @@ dependencies = [ "slog", "term", "thread_local", - "time 0.3.36", + "time", ] [[package]] @@ -3123,7 +3059,6 @@ dependencies = [ "slog", "slog-json", "slog-term", - "time 0.2.27", "toml", "winapi 0.3.9", ] @@ -3245,76 +3180,18 @@ dependencies = [ "stx-genesis", "tempfile", "tikv-jemallocator", - "time 0.2.27", + "time", "toml", "url", "winapi 0.3.9", ] -[[package]] -name = "standback" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" -dependencies = [ - "version_check", -] - [[package]] name = "stdext" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6012f6ef4d674ce7021a8b0f5093f7e339f54d4ba04fc1f9c901659459b4f35b" -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version 0.2.3", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "serde_derive", - "syn 1.0.109", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2", - "quote", - "serde", - "serde_derive", - "serde_json", - "sha1 0.6.1", - "syn 1.0.109", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" - [[package]] name = "strsim" version = "0.11.0" @@ -3466,24 +3343,9 @@ dependencies = [ [[package]] name = "time" -version = "0.2.27" +version = "0.3.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" -dependencies = [ - "const_fn", - "libc", - "standback", - "stdweb", - "time-macros 0.1.1", - "version_check", - "winapi 0.3.9", -] - -[[package]] -name = "time" -version = "0.3.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" dependencies = [ "deranged", "itoa", @@ -3493,48 +3355,25 @@ dependencies = [ "powerfmt", "serde", "time-core", - "time-macros 0.2.18", + "time-macros", ] [[package]] name = "time-core" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" - -[[package]] -name = "time-macros" -version = "0.1.1" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", -] +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" [[package]] name = "time-macros" -version = "0.2.18" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" dependencies = [ "num-conv", "time-core", ] -[[package]] -name = "time-macros-impl" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "standback", - "syn 1.0.109", -] - [[package]] name = "tiny_http" version = "0.12.0" @@ -3722,7 +3561,7 @@ dependencies = [ "httparse", "log", "rand 0.8.5", - "sha1 0.10.6", + "sha1", "thiserror", "url", "utf-8", diff --git a/clarity/Cargo.toml b/clarity/Cargo.toml index 9077834a70..37b3f0ed6f 100644 --- a/clarity/Cargo.toml +++ b/clarity/Cargo.toml @@ -37,10 +37,6 @@ rusqlite = { workspace = true, optional = true } version = "1.0" features = ["arbitrary_precision", "unbounded_depth"] -[dependencies.time] -version = "0.2.23" -features = ["std"] - [dev-dependencies] assert-json-diff = "1.0.0" mutants = "0.0.3" diff --git a/stacks-common/Cargo.toml b/stacks-common/Cargo.toml index a1a27ba6bf..45afb08452 100644 --- a/stacks-common/Cargo.toml +++ b/stacks-common/Cargo.toml @@ -68,10 +68,6 @@ workspace = true version = "4.1.3" features = ["serde"] -[dependencies.time] -version = "0.2.23" -features = ["std"] - [target.'cfg(not(target_family = "wasm"))'.dependencies] secp256k1 = { version = "0.24.3", features = ["serde", "recovery"] } diff --git a/stacks-common/src/util/mod.rs b/stacks-common/src/util/mod.rs index ca12c85901..1765817f29 100644 --- a/stacks-common/src/util/mod.rs +++ b/stacks-common/src/util/mod.rs @@ -34,8 +34,8 @@ pub mod vrf; use std::fs::File; use std::io::{BufReader, BufWriter, Write}; use std::path::Path; -use std::time::{SystemTime, UNIX_EPOCH}; -use std::{error, fmt, thread, time}; +use std::time::{self, SystemTime, UNIX_EPOCH}; +use std::{error, fmt, thread}; /// Given a relative path inside the Cargo workspace, return the absolute path #[cfg(any(test, feature = "testing"))] diff --git a/stackslib/Cargo.toml b/stackslib/Cargo.toml index c8f4a1fa7f..0e277f165a 100644 --- a/stackslib/Cargo.toml +++ b/stackslib/Cargo.toml @@ -52,6 +52,7 @@ libstackerdb = { path = "../libstackerdb" } siphasher = "0.3.7" hashbrown = { workspace = true } rusqlite = { workspace = true } +time = "0.3.41" toml = { workspace = true } [target.'cfg(not(any(target_os = "macos",target_os="windows", target_arch = "arm" )))'.dependencies] @@ -77,10 +78,6 @@ features = ["serde", "recovery"] [dependencies.ed25519-dalek] workspace = true -[dependencies.time] -version = "0.2.23" -features = ["std"] - [dev-dependencies] assert-json-diff = "1.0.0" stdext = "0.3.1" diff --git a/stackslib/src/net/http/response.rs b/stackslib/src/net/http/response.rs index abb21c984d..4fede7445e 100644 --- a/stackslib/src/net/http/response.rs +++ b/stackslib/src/net/http/response.rs @@ -17,7 +17,6 @@ use std::collections::{BTreeMap, HashSet}; use std::fmt; use std::io::{Read, Write}; -use std::time::SystemTime; use stacks_common::codec::{Error as CodecError, StacksMessageCodec}; use stacks_common::deps_common::httparse; @@ -348,8 +347,10 @@ impl HttpResponsePreamble { /// Get an RFC 7231 date that represents the current time fn rfc7231_now() -> String { - let now = time::PrimitiveDateTime::from(SystemTime::now()); - now.format("%a, %b %-d %-Y %-H:%M:%S GMT") + time::OffsetDateTime::now_utc() + .format(&time::format_description::well_known::Rfc2822) + .unwrap() + .replace("+0000", "GMT") } /// Read from a stream until we see '\r\n\r\n', with the purpose of reading an HTTP preamble. diff --git a/stackslib/src/net/http/tests.rs b/stackslib/src/net/http/tests.rs index 3952187a4f..9ef0037d38 100644 --- a/stackslib/src/net/http/tests.rs +++ b/stackslib/src/net/http/tests.rs @@ -16,6 +16,7 @@ use std::collections::BTreeMap; +use regex; use stacks_common::codec::{Error as CodecError, StacksMessageCodec}; use stacks_common::types::net::{PeerAddress, PeerHost}; @@ -146,7 +147,7 @@ fn test_parse_http_request_preamble_ok() { ("POST asdf HTTP/1.1\r\nHost: core.blockstack.org\r\nConnection: close\r\nFoo: Bar\r\n\r\n", HttpRequestPreamble::from_headers(HttpVersion::Http11, "POST".to_string(), "asdf".to_string(), "core.blockstack.org".to_string(), 80, false, vec!["foo".to_string()], vec!["Bar".to_string()])), ("POST asdf HTTP/1.1\r\nHost: core.blockstack.org\r\nFoo: Bar\r\nConnection: close\r\n\r\n", - HttpRequestPreamble::from_headers(HttpVersion::Http11, "POST".to_string(), "asdf".to_string(), "core.blockstack.org".to_string(), 80, false, vec!["foo".to_string()], vec!["Bar".to_string()])) + HttpRequestPreamble::from_headers(HttpVersion::Http11, "POST".to_string(), "asdf".to_string(), "core.blockstack.org".to_string(), 80, false, vec!["foo".to_string()], vec!["Bar".to_string()])) ]; for (data, request) in tests.iter() { @@ -391,6 +392,17 @@ fn test_http_response_preamble_headers() { "Content-Type is missing" ); assert!(txt.find("Date: ").is_some(), "Date header is missing"); + + // old format + // let date_regex = regex::Regex::new( + // r"Date: [A-Za-z]{3}, [A-Za-z]{3} \d{1,2} \d{4} \d{2}:\d{2}:\d{2} GMT\r\n", + // ) + // .unwrap(); + // new format rfc7231 + let date_regex = + regex::Regex::new(r"Date: [A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT\r\n") + .unwrap(); + assert!(date_regex.is_match(&txt), "Date header format is incorrect"); assert!(txt.find("foo: bar\r\n").is_some(), "foo header is missing"); assert!( txt.find("Access-Control-Allow-Origin: *\r\n").is_some(), From 002a681c85d2e4e850991fab1d65f9a56a983b0a Mon Sep 17 00:00:00 2001 From: Hugo CAILLARD <911307+hugocaillard@users.noreply.github.com> Date: Wed, 9 Jul 2025 22:19:26 +0200 Subject: [PATCH 2/3] fix: rfc7231 date format in http headers --- stackslib/src/net/http/response.rs | 8 ++++---- stackslib/src/net/http/tests.rs | 13 +++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/stackslib/src/net/http/response.rs b/stackslib/src/net/http/response.rs index 4fede7445e..774740e292 100644 --- a/stackslib/src/net/http/response.rs +++ b/stackslib/src/net/http/response.rs @@ -346,11 +346,11 @@ impl HttpResponsePreamble { } /// Get an RFC 7231 date that represents the current time -fn rfc7231_now() -> String { +fn rfc7231_now() -> Result { time::OffsetDateTime::now_utc() .format(&time::format_description::well_known::Rfc2822) - .unwrap() - .replace("+0000", "GMT") + .map(|date| date.replace("+0000", "GMT")) + .map_err(|e| CodecError::GenericError(format!("Failed to format RFC 7231 date: {:?}", e))) } /// Read from a stream until we see '\r\n\r\n', with the purpose of reading an HTTP preamble. @@ -388,7 +388,7 @@ impl StacksMessageCodec for HttpResponsePreamble { if !self.headers.contains_key("date") { fd.write_all("Date: ".as_bytes()) .map_err(CodecError::WriteError)?; - fd.write_all(rfc7231_now().as_bytes()) + fd.write_all(rfc7231_now()?.as_bytes()) .map_err(CodecError::WriteError)?; fd.write_all("\r\n".as_bytes()) .map_err(CodecError::WriteError)?; diff --git a/stackslib/src/net/http/tests.rs b/stackslib/src/net/http/tests.rs index 9ef0037d38..e9e4661587 100644 --- a/stackslib/src/net/http/tests.rs +++ b/stackslib/src/net/http/tests.rs @@ -393,16 +393,13 @@ fn test_http_response_preamble_headers() { ); assert!(txt.find("Date: ").is_some(), "Date header is missing"); - // old format - // let date_regex = regex::Regex::new( - // r"Date: [A-Za-z]{3}, [A-Za-z]{3} \d{1,2} \d{4} \d{2}:\d{2}:\d{2} GMT\r\n", - // ) - // .unwrap(); - // new format rfc7231 - let date_regex = + let rfc7231_date_regex = regex::Regex::new(r"Date: [A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT\r\n") .unwrap(); - assert!(date_regex.is_match(&txt), "Date header format is incorrect"); + assert!( + rfc7231_date_regex.is_match(&txt), + "Date header format is incorrect" + ); assert!(txt.find("foo: bar\r\n").is_some(), "foo header is missing"); assert!( txt.find("Access-Control-Allow-Origin: *\r\n").is_some(), From 52fb3d3c686fe1ef9762fa5c563cd736d0f5b435 Mon Sep 17 00:00:00 2001 From: Hugo CAILLARD <911307+hugocaillard@users.noreply.github.com> Date: Wed, 9 Jul 2025 22:22:40 +0200 Subject: [PATCH 3/3] chore: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c976fae82..09a0911103 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE ## Unreleased +- The HTTP `Date` header in responses now strictly follows RFC7231. + ### Changed - When a previous block commit is unable to be RBFed, the miner will now just wait for it to be confirmed instead of submitting a new block commit which breaks the miner's UTXO chain.