Skip to content

Commit 7a44923

Browse files
committed
chore: create root workspace and add lints
1 parent 3e24151 commit 7a44923

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+11664
-1126
lines changed

Cargo.lock

Lines changed: 11372 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
[workspace]
2+
resolver = "2"
3+
4+
members = [
5+
"apps/argus",
6+
"apps/fortuna",
7+
"apps/pyth-lazer-agent",
8+
"apps/quorum",
9+
"lazer/publisher_sdk/rust",
10+
"lazer/sdk/rust/client",
11+
"lazer/sdk/rust/protocol",
12+
"pythnet/pythnet_sdk",
13+
"target_chains/starknet/tools/test_vaas",
14+
]
15+
16+
exclude = [
17+
# Depends on pinned Solana version
18+
"apps/hermes/server",
19+
# Solana contract
20+
"governance/remote_executor",
21+
"governance/remote_executor/cli",
22+
"governance/remote_executor/programs/remote-executor",
23+
# Solana contract
24+
"lazer/contracts/solana",
25+
"lazer/contracts/solana/programs/pyth-lazer-solana-contract",
26+
# Solana contract
27+
"pythnet/message_buffer",
28+
"pythnet/message_buffer/programs/message_buffer",
29+
"pythnet/message_buffer/programs/mock-cpi-caller",
30+
# Solana contract
31+
"pythnet/stake_caps_parameters",
32+
"pythnet/stake_caps_parameters/cli",
33+
"pythnet/stake_caps_parameters/programs/stake_caps_parameters",
34+
# CosmWasm contract
35+
"target_chains/cosmwasm",
36+
"target_chains/cosmwasm/contracts/pyth",
37+
"target_chains/cosmwasm/examples/cw-contract",
38+
"target_chains/cosmwasm/sdk/rust",
39+
# Stylus contract
40+
"target_chains/ethereum/sdk/stylus",
41+
"target_chains/ethereum/sdk/stylus/benches",
42+
"target_chains/ethereum/sdk/stylus/contracts",
43+
"target_chains/ethereum/sdk/stylus/examples/extend-pyth-example",
44+
"target_chains/ethereum/sdk/stylus/examples/function-example",
45+
"target_chains/ethereum/sdk/stylus/examples/pyth-example",
46+
# Fuel contract
47+
"target_chains/fuel/contracts",
48+
# Near contract
49+
"target_chains/near/example",
50+
"target_chains/near/receiver",
51+
"target_chains/near/wormhole-stub",
52+
# Solana contracts
53+
"target_chains/solana",
54+
"target_chains/solana/cli",
55+
"target_chains/solana/common_test_utils",
56+
"target_chains/solana/program_simulator",
57+
"target_chains/solana/programs/pyth-price-store",
58+
"target_chains/solana/programs/pyth-price-store/target/package/pyth-price-publisher-0.1.0",
59+
"target_chains/solana/programs/pyth-push-oracle",
60+
"target_chains/solana/programs/pyth-solana-receiver",
61+
"target_chains/solana/pyth_solana_receiver_sdk",
62+
# Stylus contract
63+
"target_chains/stylus",
64+
"target_chains/stylus/contracts/pyth-receiver",
65+
"target_chains/stylus/contracts/wormhole",
66+
]
67+
68+
[workspace.lints.rust]
69+
unsafe_code = "deny"
70+
71+
[workspace.lints.clippy]
72+
# See https://github.com/pyth-network/pyth-crosschain/blob/main/doc/rust-code-guidelines.md
73+
74+
wildcard_dependencies = "deny"
75+
76+
collapsible_if = "allow"
77+
collapsible_else_if = "allow"
78+
79+
allow_attributes_without_reason = "warn"
80+
81+
# Panics
82+
expect_used = "warn"
83+
fallible_impl_from = "warn"
84+
indexing_slicing = "warn"
85+
panic = "warn"
86+
panic_in_result_fn = "warn"
87+
string_slice = "warn"
88+
todo = "warn"
89+
unchecked_duration_subtraction = "warn"
90+
unreachable = "warn"
91+
unwrap_in_result = "warn"
92+
unwrap_used = "warn"
93+
94+
# Correctness
95+
cast_lossless = "warn"
96+
cast_possible_truncation = "warn"
97+
cast_possible_wrap = "warn"
98+
cast_sign_loss = "warn"
99+
collection_is_never_read = "warn"
100+
match_wild_err_arm = "warn"
101+
path_buf_push_overwrite = "warn"
102+
read_zero_byte_vec = "warn"
103+
same_name_method = "warn"
104+
suspicious_operation_groupings = "warn"
105+
suspicious_xor_used_as_pow = "warn"
106+
unused_self = "warn"
107+
used_underscore_binding = "warn"
108+
while_float = "warn"

apps/argus/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ethers = { version = "2.0.14", features = ["ws"] }
1313
fortuna = { path = "../fortuna" }
1414
futures = { version = "0.3.28" }
1515
hex = "0.4.3"
16-
prometheus-client = { version = "0.21.2" }
16+
prometheus-client = { version = "0.23.1" }
1717
pythnet-sdk = { path = "../../pythnet/pythnet_sdk", features = ["strum"] }
1818
rand = "0.8.5"
1919
reqwest = { version = "0.11.22", features = ["json", "blocking"] }
@@ -42,6 +42,8 @@ dashmap = "6.1.0"
4242
pyth-sdk = "0.8.0"
4343
humantime-serde = "1.1.1"
4444

45-
4645
[dev-dependencies]
4746
mockall = "0.13.1"
47+
48+
[lints]
49+
workspace = true

apps/argus/src/adapters/ethereum.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::same_name_method, reason = "generated code")]
2+
13
use {
24
crate::config::EthereumConfig,
35
crate::state::ChainName,
@@ -21,10 +23,7 @@ use {
2123

2224
// FIXME: When public scheduler interface is extracted out to an SDK,
2325
// get the ABI from the SDK package.
24-
abigen!(
25-
PythPulse,
26-
"../../target_chains/ethereum/contracts/out/IScheduler.sol/IScheduler.abi.json"
27-
);
26+
abigen!(PythPulse, "abi/IScheduler.abi.json");
2827

2928
pub type MiddlewaresWrapper<T> = LegacyTxMiddleware<
3029
GasOracleMiddleware<

apps/argus/src/api/metrics.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ pub async fn metrics(State(state): State<crate::api::ApiState>) -> impl IntoResp
99
let registry = state.metrics_registry.read().await;
1010
let mut buffer = String::new();
1111

12-
// Should not fail if the metrics are valid and there is memory available
13-
// to write to the buffer.
14-
encode(&mut buffer, &registry).unwrap();
12+
#[allow(
13+
clippy::expect_used,
14+
reason = "should not fail if the metrics are valid and there is memory available to write to the buffer"
15+
)]
16+
encode(&mut buffer, &registry).expect("metric encoding failed");
1517

1618
buffer
1719
}

apps/argus/src/command/run.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use {
1212
},
1313
state::ArgusState,
1414
},
15-
anyhow::{anyhow, Error, Result},
15+
anyhow::{anyhow, Context as _, Result},
1616
backoff::ExponentialBackoff,
1717
ethers::signers::Signer,
1818
fortuna::eth_utils::traced_client::RpcMetrics,
@@ -35,7 +35,7 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
3535
.keeper
3636
.private_key
3737
.load()?
38-
.expect("Keeper private key not found in config");
38+
.context("Keeper private key not found in config")?;
3939

4040
let chain_labels: Vec<String> = config.chains.keys().cloned().collect();
4141
let keeper_metrics = Arc::new(KeeperMetrics::new(metrics_registry.clone(), chain_labels).await);
@@ -47,27 +47,30 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
4747
// Spawn a task to listen for Ctrl+C so we can trigger a graceful shutdown
4848
spawn(async move {
4949
tracing::info!("Registered shutdown signal handler");
50-
tokio::signal::ctrl_c().await.unwrap();
51-
tracing::info!("Shutdown signal received, waiting for tasks to exit");
52-
// No need to handle error here, as this can only error if all of the
53-
// receivers have been dropped, which is what we want to do
54-
exit_tx.send(true)?;
55-
56-
Ok::<(), Error>(())
50+
match tokio::signal::ctrl_c().await {
51+
Ok(()) => {
52+
tracing::info!("Shutdown signal received, waiting for tasks to exit");
53+
// No need to handle error here, as this can only error if all of the
54+
// receivers have been dropped, which is what we want to do
55+
let _ = exit_tx.send(true);
56+
}
57+
Err(err) => {
58+
tracing::error!(?err, "Couldn't register shutdown signal handler");
59+
}
60+
}
5761
});
5862

5963
// Run keeper services for all chains
60-
let mut handles = Vec::new();
6164
for (chain_name, chain_config) in &config.chains {
62-
handles.push(spawn(run_keeper_for_chain(
65+
spawn(run_keeper_for_chain(
6366
keeper_private_key.clone(),
6467
chain_config.clone(),
6568
chain_name.clone(),
6669
keeper_metrics.clone(),
6770
rpc_metrics.clone(),
6871
exit_rx.clone(),
6972
config.clone(),
70-
)));
73+
));
7174
}
7275

7376
// Run API server for metrics and health checks
@@ -98,10 +101,11 @@ pub async fn run_keeper_for_chain(
98101
rpc_metrics.clone(),
99102
)
100103
.await
101-
.expect(&format!(
102-
"Failed to create InstrumentedSignablePythContract from config for chain {}",
103-
chain_name
104-
)),
104+
.with_context(|| {
105+
format!(
106+
"Failed to create InstrumentedSignablePythContract from config for chain {chain_name}"
107+
)
108+
})?,
105109
);
106110

107111
let keeper_address = contract.wallet().address();

apps/argus/src/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const DEFAULT_RPC_ADDR: &str = "127.0.0.1:7777";
2020
#[command(author = crate_authors!())]
2121
#[command(about = crate_description!())]
2222
#[command(version = crate_version!())]
23-
#[allow(clippy::large_enum_variant)]
2423
pub enum Options {
2524
/// Run the Argus keeper service.
2625
Run(RunOptions),

apps/argus/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(clippy::just_underscores_and_digits)]
21
pub mod adapters;
32
pub mod api;
43
pub mod command;

apps/argus/src/metrics.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,9 @@ impl Default for KeeperMetrics {
6868
gas_price_estimate: Family::default(),
6969
keeper_wallet_balance: Family::default(),
7070
price_update_latency_ms: Family::new_with_constructor(|| {
71-
Histogram::new(
72-
vec![
73-
100.0, 250.0, 500.0, 1000.0, 2500.0, 5000.0, 10000.0, 20000.0, 30000.0,
74-
60000.0,
75-
]
76-
.into_iter(),
77-
)
71+
Histogram::new(vec![
72+
100.0, 250.0, 500.0, 1000.0, 2500.0, 5000.0, 10000.0, 20000.0, 30000.0, 60000.0,
73+
])
7874
}),
7975
}
8076
}

apps/argus/src/services/chain_price_service.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ use crate::state::ChainName;
1919
use crate::state::ChainPriceState;
2020

2121
pub struct ChainPriceService {
22+
#[allow(dead_code, reason = "unknown")]
2223
chain_name: ChainName,
2324
name: String,
25+
#[allow(dead_code, reason = "unknown")]
2426
contract: Arc<dyn GetChainPrices + Send + Sync>,
2527
poll_interval: Duration,
2628
chain_price_state: Arc<ChainPriceState>,
@@ -35,7 +37,7 @@ impl ChainPriceService {
3537
) -> Self {
3638
Self {
3739
chain_name: chain_name.clone(),
38-
name: format!("ChainPriceService-{}", chain_name),
40+
name: format!("ChainPriceService-{chain_name}"),
3941
contract,
4042
poll_interval,
4143
chain_price_state,

0 commit comments

Comments
 (0)