Skip to content

Commit 234a07e

Browse files
committed
chore(apps/fortuna): update to stable rust
1 parent 4ae66e1 commit 234a07e

File tree

16 files changed

+84
-72
lines changed

16 files changed

+84
-72
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ repos:
6666
entry: cargo +nightly-2023-07-23 fmt --manifest-path ./apps/fortuna/Cargo.toml --all -- --config-path rustfmt.toml
6767
pass_filenames: false
6868
files: apps/fortuna
69+
- id: cargo-clippy-fortuna
70+
name: Cargo clippy for Fortuna
71+
language: "rust"
72+
entry: cargo +1.82.0 clippy --manifest-path ./apps/fortuna/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
73+
pass_filenames: false
74+
files: apps/fortuna
6975
# Hooks for message buffer contract
7076
- id: cargo-fmt-message-buffer
7177
name: Cargo format for message buffer contract

apps/fortuna/Cargo.lock

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

apps/fortuna/Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
ARG RUST_VERSION=1.66.1
1+
ARG RUST_VERSION=1.82.0
22

33
FROM rust:${RUST_VERSION} AS build
44

5-
# Set default toolchain
6-
RUN rustup default nightly-2023-07-23
7-
85
# Build
96
WORKDIR /src
107
COPY apps/fortuna apps/fortuna

apps/fortuna/rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2023-07-23
1+
1.82.0

apps/fortuna/src/api/revelation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub async fn revelation(
5858
let state = state
5959
.chains
6060
.get(&chain_id)
61-
.ok_or_else(|| RestError::InvalidChainId)?;
61+
.ok_or(RestError::InvalidChainId)?;
6262

6363
let maybe_request_fut = state.contract.get_request(state.provider_address, sequence);
6464

@@ -85,7 +85,7 @@ pub async fn revelation(
8585
);
8686
RestError::Unknown
8787
})?;
88-
let encoded_value = Blob::new(encoding.unwrap_or(BinaryEncoding::Hex), value.clone());
88+
let encoded_value = Blob::new(encoding.unwrap_or(BinaryEncoding::Hex), *value);
8989

9090
Ok(Json(GetRandomValueResponse {
9191
value: encoded_value,

apps/fortuna/src/chain/ethereum.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ impl<T: JsonRpcClient + 'static + Clone> SignablePythContractInner<T> {
204204
if let PythRandomEvents::RequestedFilter(r) = PythRandomEvents::decode_log(&l)? {
205205
Ok(r.request.sequence_number)
206206
} else {
207-
Err(anyhow!("No log with sequence number").into())
207+
Err(anyhow!("No log with sequence number"))
208208
}
209209
} else {
210-
Err(anyhow!("Request failed").into())
210+
Err(anyhow!("Request failed"))
211211
}
212212
}
213213

@@ -238,10 +238,10 @@ impl<T: JsonRpcClient + 'static + Clone> SignablePythContractInner<T> {
238238
{
239239
Ok(r.random_number)
240240
} else {
241-
Err(anyhow!("No log with randomnumber").into())
241+
Err(anyhow!("No log with randomnumber"))
242242
}
243243
} else {
244-
Err(anyhow!("Request failed").into())
244+
Err(anyhow!("Request failed"))
245245
}
246246
}
247247

apps/fortuna/src/chain/reader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ pub enum BlockStatus {
2323
Safe,
2424
}
2525

26-
impl Into<EthersBlockNumber> for BlockStatus {
27-
fn into(self) -> EthersBlockNumber {
28-
match self {
26+
impl From<BlockStatus> for EthersBlockNumber {
27+
fn from(val: BlockStatus) -> Self {
28+
match val {
2929
BlockStatus::Latest => EthersBlockNumber::Latest,
3030
BlockStatus::Finalized => EthersBlockNumber::Finalized,
3131
BlockStatus::Safe => EthersBlockNumber::Safe,

apps/fortuna/src/command/generate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub async fn generate(opts: &GenerateOptions) -> Result<()> {
5656
&provider,
5757
sequence_number,
5858
&user_randomness,
59-
&provider_randomness,
59+
provider_randomness,
6060
)
6161
.await?;
6262

apps/fortuna/src/command/register_provider.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub async fn register_provider_from_config(
5656

5757
// Initialize a Provider to interface with the EVM contract.
5858
let contract =
59-
Arc::new(SignablePythContract::from_config(&chain_config, &private_key_string).await?);
59+
Arc::new(SignablePythContract::from_config(chain_config, &private_key_string).await?);
6060
// Create a new random hash chain.
6161
let random = rand::random::<[u8; 32]>();
6262
let secret = provider_config
@@ -68,7 +68,7 @@ pub async fn register_provider_from_config(
6868
tracing::info!("Generating hash chain");
6969
let chain = PebbleHashChain::from_config(
7070
&secret,
71-
&chain_id,
71+
chain_id,
7272
&private_key_string.parse::<LocalWallet>()?.address(),
7373
&chain_config.contract_addr,
7474
&random,
@@ -86,7 +86,7 @@ pub async fn register_provider_from_config(
8686
seed: random,
8787
chain_length: commitment_length,
8888
};
89-
let uri = get_register_uri(&provider_config.uri, &chain_id)?;
89+
let uri = get_register_uri(&provider_config.uri, chain_id)?;
9090
let call = contract.register(
9191
fee_in_wei,
9292
commitment,
@@ -98,7 +98,7 @@ pub async fn register_provider_from_config(
9898
);
9999
let mut gas_estimate = call.estimate_gas().await?;
100100
let gas_multiplier = U256::from(2); //TODO: smarter gas estimation
101-
gas_estimate = gas_estimate * gas_multiplier;
101+
gas_estimate *= gas_multiplier;
102102
let call_with_gas = call.gas(gas_estimate);
103103
if let Some(r) = call_with_gas.send().await?.await? {
104104
tracing::info!("Registered provider: {:?}", r);

apps/fortuna/src/command/run.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
237237
rpc_metrics.clone(),
238238
));
239239

240-
run_api(opts.addr.clone(), chains, metrics_registry, rx_exit).await?;
240+
run_api(opts.addr, chains, metrics_registry, rx_exit).await?;
241241

242242
Ok(())
243243
}
@@ -251,11 +251,11 @@ async fn setup_chain_state(
251251
rpc_metrics: Arc<RpcMetrics>,
252252
) -> Result<BlockchainState> {
253253
let contract = Arc::new(InstrumentedPythContract::from_config(
254-
&chain_config,
254+
chain_config,
255255
chain_id.clone(),
256256
rpc_metrics,
257257
)?);
258-
let mut provider_commitments = chain_config.commitments.clone().unwrap_or(Vec::new());
258+
let mut provider_commitments = chain_config.commitments.clone().unwrap_or_default();
259259
provider_commitments.sort_by(|c1, c2| {
260260
c1.original_commitment_sequence_number
261261
.cmp(&c2.original_commitment_sequence_number)
@@ -301,9 +301,9 @@ async fn setup_chain_state(
301301
offsets.push(offset);
302302

303303
let pebble_hash_chain = PebbleHashChain::from_config(
304-
&secret,
305-
&chain_id,
306-
&provider,
304+
secret,
305+
chain_id,
306+
provider,
307307
&chain_config.contract_addr,
308308
&commitment.seed,
309309
commitment.chain_length,
@@ -321,7 +321,7 @@ async fn setup_chain_state(
321321
if chain_state.reveal(provider_info.original_commitment_sequence_number)?
322322
!= provider_info.original_commitment
323323
{
324-
return Err(anyhow!("The root of the generated hash chain for chain id {} does not match the commitment. Are the secret and chain length configured correctly?", &chain_id).into());
324+
return Err(anyhow!("The root of the generated hash chain for chain id {} does not match the commitment. Are the secret and chain length configured correctly?", &chain_id));
325325
} else {
326326
tracing::info!("Root of chain id {} matches commitment", &chain_id);
327327
}
@@ -330,7 +330,7 @@ async fn setup_chain_state(
330330
id: chain_id.clone(),
331331
state: Arc::new(chain_state),
332332
contract,
333-
provider_address: provider.clone(),
333+
provider_address: *provider,
334334
reveal_delay_blocks: chain_config.reveal_delay_blocks,
335335
confirmed_block_status: chain_config.confirmed_block_status,
336336
};

0 commit comments

Comments
 (0)