Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@ concurrency:

jobs:
rust:
name: cargo test + release build
# Pinned to macos-latest to match the developer environment that produced
# the green local Layer 1 pass. charon-executor's
# submit_returns_connection_lost_when_transport_fails is platform-sensitive
# on Linux runners — see issue #322. Flip back to ubuntu-latest once the
# classifier in crates/charon-executor/src/submit.rs is broadened.
runs-on: macos-latest
name: cargo fmt + clippy + test + release
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Cache cargo
uses: Swatinem/rust-cache@v2

- name: cargo fmt --all -- --check
run: cargo fmt --all -- --check

- name: cargo clippy --workspace --all-targets --locked -- -D warnings
run: cargo clippy --workspace --all-targets --locked -- -D warnings

- name: cargo test --workspace --locked
run: cargo test --workspace --locked

Expand Down
35 changes: 17 additions & 18 deletions crates/charon-scanner/src/token_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ const META_MAX_ATTEMPTS: usize = 5;
// `fetch_with_retry` is sound only if the loop body executes at
// least once. A zero attempt cap would skip the loop and hit the
// unreachable, which would be a bug, not a panic-by-design.
const _: () = assert!(
META_MAX_ATTEMPTS >= 1,
"META_MAX_ATTEMPTS must be >= 1"
);
const _: () = assert!(META_MAX_ATTEMPTS >= 1, "META_MAX_ATTEMPTS must be >= 1");

/// Initial backoff before the first retry. Doubles every failed
/// attempt up to `META_MAX_ATTEMPTS`.
Expand Down Expand Up @@ -131,11 +128,7 @@ fn is_transient(err: &(impl std::fmt::Debug + ?Sized)) -> bool {
/// as permanent. `op_name` and `token` are only used for the warn
/// log on retry, so the operator can correlate dropped markets to
/// upstream blips.
async fn fetch_with_retry<F, Fut, T, E>(
op_name: &str,
token: Address,
mut op: F,
) -> Result<T, E>
async fn fetch_with_retry<F, Fut, T, E>(op_name: &str, token: Address, mut op: F) -> Result<T, E>
where
F: FnMut() -> Fut,
Fut: std::future::Future<Output = Result<T, E>>,
Expand Down Expand Up @@ -285,7 +278,9 @@ mod tests {
assert!(is_transient(&"http error: status 429 Too Many Requests"));
// Upstream LB 5xx (overload / brief out-of-rotation).
assert!(is_transient(&"upstream error: status 502 Bad Gateway"));
assert!(is_transient(&"upstream error: status 503 Service Unavailable"));
assert!(is_transient(
&"upstream error: status 503 Service Unavailable"
));
assert!(is_transient(&"upstream error: status 504 Gateway Timeout"));
// Generic JSON-RPC throttle codes.
assert!(is_transient(&"rpc error: code: -32603 internal error"));
Expand Down Expand Up @@ -314,12 +309,11 @@ mod tests {
#[tokio::test(start_paused = true)]
async fn fetch_with_retry_returns_first_ok() {
let mut calls = 0_usize;
let result: Result<u8, &'static str> =
fetch_with_retry("test", Address::ZERO, || {
calls += 1;
async move { Ok::<u8, &'static str>(42) }
})
.await;
let result: Result<u8, &'static str> = fetch_with_retry("test", Address::ZERO, || {
calls += 1;
async move { Ok::<u8, &'static str>(42) }
})
.await;
assert_eq!(result, Ok(42));
assert_eq!(calls, 1);
}
Expand All @@ -332,7 +326,9 @@ mod tests {
let attempt = calls;
async move {
if attempt < 3 {
Err(format!("http error: status 429 Too Many Requests (attempt {attempt})"))
Err(format!(
"http error: status 429 Too Many Requests (attempt {attempt})"
))
} else {
Ok(7)
}
Expand Down Expand Up @@ -395,7 +391,10 @@ mod tests {
})
.await;
assert!(result.is_err());
assert_eq!(calls, 2, "permanent error must short-circuit further retries");
assert_eq!(
calls, 2,
"permanent error must short-circuit further retries"
);
}

#[tokio::test(start_paused = true)]
Expand Down
Loading