Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: apply stable rustfmt #2106

Merged
merged 2 commits into from
Nov 8, 2024
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
37 changes: 5 additions & 32 deletions .github/workflows/ci-pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,12 @@ jobs:
fetch-depth: 0
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2023-03-01
components: rustfmt, clippy
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2023-07-23
components: rustfmt, clippy
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2024-03-26
components: rustfmt, clippy
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2024-08-04
components: rustfmt, clippy
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.66.1
components: rustfmt, clippy
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.73.0
components: rustfmt, clippy
- uses: actions-rs/toolchain@v1
with:
profile: minimal
profile: default
toolchain: 1.82.0
components: rustfmt, clippy
- name: Install Rust versions
run: |
rustup install 1.66.1
rustup install 1.73.0
- name: Install protoc
uses: arduino/setup-protoc@v3
- uses: actions/checkout@v4
Expand Down
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repos:
- id: cargo-fmt-remote-executor
name: Cargo format for remote executor
language: "rust"
entry: cargo +nightly-2023-03-01 fmt --manifest-path ./governance/remote_executor/Cargo.toml --all -- --config-path rustfmt.toml
entry: cargo +1.66.1 fmt --manifest-path ./governance/remote_executor/Cargo.toml --all
pass_filenames: false
files: governance/remote_executor
- id: cargo-clippy-remote-executor
Expand All @@ -52,7 +52,7 @@ repos:
- id: cargo-fmt-cosmwasm
name: Cargo format for cosmwasm contract
language: "rust"
entry: cargo +nightly-2023-03-01 fmt --manifest-path ./target_chains/cosmwasm/Cargo.toml --all -- --config-path rustfmt.toml
entry: cargo +1.82.0 fmt --manifest-path ./target_chains/cosmwasm/Cargo.toml --all
pass_filenames: false
files: target_chains/cosmwasm
- id: cargo-clippy-cosmwasm
Expand All @@ -65,7 +65,7 @@ repos:
- id: cargo-fmt-hermes
name: Cargo format for Hermes
language: "rust"
entry: cargo +nightly-2024-03-26 fmt --manifest-path ./apps/hermes/server/Cargo.toml --all -- --config-path rustfmt.toml
entry: cargo +1.82.0 fmt --manifest-path ./apps/hermes/server/Cargo.toml --all
pass_filenames: false
files: apps/hermes
- id: cargo-clippy-hermes
Expand All @@ -78,7 +78,7 @@ repos:
- id: cargo-fmt-fortuna
name: Cargo format for Fortuna
language: "rust"
entry: cargo +nightly-2023-07-23 fmt --manifest-path ./apps/fortuna/Cargo.toml --all -- --config-path rustfmt.toml
entry: cargo +1.82.0 fmt --manifest-path ./apps/fortuna/Cargo.toml --all
pass_filenames: false
files: apps/fortuna
- id: cargo-clippy-fortuna
Expand All @@ -91,7 +91,7 @@ repos:
- id: cargo-fmt-message-buffer
name: Cargo format for message buffer contract
language: "rust"
entry: cargo +nightly-2023-03-01 fmt --manifest-path ./pythnet/message_buffer/Cargo.toml --all -- --config-path rustfmt.toml
entry: cargo +1.66.1 fmt --manifest-path ./pythnet/message_buffer/Cargo.toml --all
pass_filenames: false
files: pythnet/message_buffer
- id: cargo-clippy-message-buffer
Expand All @@ -104,7 +104,7 @@ repos:
- id: cargo-fmt-pythnet-sdk
name: Cargo format for pythnet SDK
language: "rust"
entry: cargo +nightly-2024-08-04 fmt --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --all -- --config-path rustfmt.toml
entry: cargo +1.82.0 fmt --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --all
pass_filenames: false
files: pythnet/pythnet_sdk
- id: cargo-clippy-pythnet-sdk
Expand All @@ -117,7 +117,7 @@ repos:
- id: cargo-fmt-pyth-solana-receiver
name: Cargo format for solana target chain contract
language: "rust"
entry: cargo +nightly-2023-03-01 fmt --manifest-path ./target_chains/solana/Cargo.toml --all -- --config-path rustfmt.toml
entry: cargo +1.73.0 fmt --manifest-path ./target_chains/solana/Cargo.toml --all
pass_filenames: false
files: target_chains/solana
- id: cargo-clippy-pyth-solana-receiver
Expand Down
89 changes: 25 additions & 64 deletions apps/fortuna/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,27 @@
use {
crate::{
chain::reader::{
BlockNumber,
BlockStatus,
EntropyReader,
},
chain::reader::{BlockNumber, BlockStatus, EntropyReader},
state::HashChainState,
},
anyhow::Result,
axum::{
body::Body,
http::StatusCode,
response::{
IntoResponse,
Response,
},
response::{IntoResponse, Response},
routing::get,
Router,
},
ethers::core::types::Address,
prometheus_client::{
encoding::EncodeLabelSet,
metrics::{
counter::Counter,
family::Family,
},
metrics::{counter::Counter, family::Family},
registry::Registry,
},
std::{
collections::HashMap,
sync::Arc,
},
std::{collections::HashMap, sync::Arc},
tokio::sync::RwLock,
url::Url,
};
pub use {
chain_ids::*,
index::*,
live::*,
metrics::*,
ready::*,
revelation::*,
};
pub use {chain_ids::*, index::*, live::*, metrics::*, ready::*, revelation::*};

mod chain_ids;
mod index;
Expand Down Expand Up @@ -99,16 +79,16 @@ impl ApiState {
#[derive(Clone)]
pub struct BlockchainState {
/// The chain id for this blockchain, useful for logging
pub id: ChainId,
pub id: ChainId,
/// The hash chain(s) required to serve random numbers for this blockchain
pub state: Arc<HashChainState>,
pub state: Arc<HashChainState>,
/// The contract that the server is fulfilling requests for.
pub contract: Arc<dyn EntropyReader>,
pub contract: Arc<dyn EntropyReader>,
/// The address of the provider that this server is operating for.
pub provider_address: Address,
pub provider_address: Address,
/// The server will wait for this many block confirmations of a request before revealing
/// the random number.
pub reveal_delay_blocks: BlockNumber,
pub reveal_delay_blocks: BlockNumber,
/// The BlockStatus of the block that is considered to be confirmed on the blockchain.
/// For eg., Finalized, Safe
pub confirmed_block_status: BlockStatus,
Expand Down Expand Up @@ -194,35 +174,16 @@ pub fn get_register_uri(base_uri: &str, chain_id: &str) -> Result<String> {
mod test {
use {
crate::{
api::{
self,
ApiState,
BinaryEncoding,
Blob,
BlockchainState,
GetRandomValueResponse,
},
chain::reader::{
mock::MockEntropyReader,
BlockStatus,
},
state::{
HashChainState,
PebbleHashChain,
},
api::{self, ApiState, BinaryEncoding, Blob, BlockchainState, GetRandomValueResponse},
chain::reader::{mock::MockEntropyReader, BlockStatus},
state::{HashChainState, PebbleHashChain},
},
axum::http::StatusCode,
axum_test::{
TestResponse,
TestServer,
},
axum_test::{TestResponse, TestServer},
ethers::prelude::Address,
lazy_static::lazy_static,
prometheus_client::registry::Registry,
std::{
collections::HashMap,
sync::Arc,
},
std::{collections::HashMap, sync::Arc},
tokio::sync::RwLock,
};

Expand All @@ -245,11 +206,11 @@ mod test {
let eth_read = Arc::new(MockEntropyReader::with_requests(10, &[]));

let eth_state = BlockchainState {
id: "ethereum".into(),
state: ETH_CHAIN.clone(),
contract: eth_read.clone(),
provider_address: PROVIDER,
reveal_delay_blocks: 1,
id: "ethereum".into(),
state: ETH_CHAIN.clone(),
contract: eth_read.clone(),
provider_address: PROVIDER,
reveal_delay_blocks: 1,
confirmed_block_status: BlockStatus::Latest,
};

Expand All @@ -258,11 +219,11 @@ mod test {
let avax_read = Arc::new(MockEntropyReader::with_requests(10, &[]));

let avax_state = BlockchainState {
id: "avalanche".into(),
state: AVAX_CHAIN.clone(),
contract: avax_read.clone(),
provider_address: PROVIDER,
reveal_delay_blocks: 2,
id: "avalanche".into(),
state: AVAX_CHAIN.clone(),
contract: avax_read.clone(),
provider_address: PROVIDER,
reveal_delay_blocks: 2,
confirmed_block_status: BlockStatus::Latest,
};

Expand Down
10 changes: 2 additions & 8 deletions apps/fortuna/src/api/chain_ids.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
use {
crate::api::{
ChainId,
RestError,
},
crate::api::{ChainId, RestError},
anyhow::Result,
axum::{
extract::State,
Json,
},
axum::{extract::State, Json},
};

/// Get the list of supported chain ids
Expand Down
5 changes: 1 addition & 4 deletions apps/fortuna/src/api/index.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use axum::{
response::IntoResponse,
Json,
};
use axum::{response::IntoResponse, Json};

/// This is the index page for the REST service. It lists all the available endpoints.
///
Expand Down
5 changes: 1 addition & 4 deletions apps/fortuna/src/api/live.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use axum::{
http::StatusCode,
response::{
IntoResponse,
Response,
},
response::{IntoResponse, Response},
};

pub async fn live() -> Response {
Expand Down
5 changes: 1 addition & 4 deletions apps/fortuna/src/api/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Exposing prometheus metrics via HTTP in openmetrics format.

use {
axum::{
extract::State,
response::IntoResponse,
},
axum::{extract::State, response::IntoResponse},
prometheus_client::encoding::text::encode,
};

Expand Down
5 changes: 1 addition & 4 deletions apps/fortuna/src/api/ready.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use axum::{
http::StatusCode,
response::{
IntoResponse,
Response,
},
response::{IntoResponse, Response},
};

pub async fn ready() -> Response {
Expand Down
17 changes: 3 additions & 14 deletions apps/fortuna/src/api/revelation.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
use {
crate::api::{
ChainId,
RequestLabel,
RestError,
},
crate::api::{ChainId, RequestLabel, RestError},
anyhow::Result,
axum::{
extract::{
Path,
Query,
State,
},
extract::{Path, Query, State},
Json,
},
pythnet_sdk::wire::array,
serde_with::serde_as,
tokio::try_join,
utoipa::{
IntoParams,
ToSchema,
},
utoipa::{IntoParams, ToSchema},
};

/// Reveal the random value for a given sequence number and blockchain.
Expand Down
12 changes: 2 additions & 10 deletions apps/fortuna/src/chain/eth_gas_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ use {
axum::async_trait,
ethers::{
prelude::{
gas_oracle::{
GasOracleError,
Result,
},
gas_oracle::{GasOracleError, Result},
GasOracle,
},
providers::Middleware,
types::{
I256,
U256,
},
types::{I256, U256},
},
};

Expand All @@ -35,12 +29,10 @@ pub const SURGE_THRESHOLD_1: u64 = 40_000;
pub const SURGE_THRESHOLD_2: u64 = 100_000;
pub const SURGE_THRESHOLD_3: u64 = 200_000;


/// The threshold max change/difference (in %) at which we will ignore the fee history values
/// under it.
pub const EIP1559_FEE_ESTIMATION_THRESHOLD_MAX_CHANGE: i64 = 200;


/// Gas oracle from a [`Middleware`] implementation such as an
/// Ethereum RPC provider.
#[derive(Clone, Debug)]
Expand Down
Loading
Loading