Skip to content

Commit 4819aa4

Browse files
committed
Consolidated some logic
1 parent 05d11b8 commit 4819aa4

1 file changed

Lines changed: 9 additions & 21 deletions

File tree

crates/pbs/src/mev_boost/get_header.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,17 @@ pub async fn get_header<S: BuilderApiState>(
8282
}
8383

8484
// Use the minimum of the time left and the user provided timeout header
85-
let max_timeout_ms = match req_headers.get(HEADER_TIMEOUT_MS) {
86-
Some(user_header_value) => match user_header_value.to_str() {
87-
Ok(user_timeout_string) => match user_timeout_string.parse::<u64>() {
88-
Ok(user_timeout) => {
89-
if user_timeout == 0 {
90-
warn!("user-supplied timeout header is 0, using {max_timeout_ms}ms");
91-
max_timeout_ms
92-
} else {
93-
user_timeout.min(max_timeout_ms)
94-
}
95-
}
96-
Err(e) => {
97-
warn!("cannot parse user-supplied timeout header '{user_timeout_string}', using {max_timeout_ms}ms ({e})");
98-
max_timeout_ms
99-
}
100-
},
101-
Err(e) => {
102-
warn!("invalid user-supplied timeout header, using {max_timeout_ms}ms ({e})");
85+
let max_timeout_ms = req_headers
86+
.get(HEADER_TIMEOUT_MS)
87+
.map(|header| match header.to_str().ok().and_then(|v| v.parse::<u64>().ok()) {
88+
None | Some(0) => {
89+
// Header can't be stringified, or parsed, or it's set to 0
90+
warn!(?header, "invalid user-supplied timeout header, using {max_timeout_ms}ms");
10391
max_timeout_ms
10492
}
105-
},
106-
None => max_timeout_ms,
107-
};
93+
Some(user_timeout) => user_timeout.min(max_timeout_ms),
94+
})
95+
.unwrap_or(max_timeout_ms);
10896

10997
// prepare headers, except for start time which is set in `send_one_get_header`
11098
let mut send_headers = HeaderMap::new();

0 commit comments

Comments
 (0)