Skip to content

Commit 8a38c48

Browse files
authored
feat: rustfmt config update (#188)
* chore: apply fmt, add rustfmt.toml * fix(ci): change fmt job toolchain to nightly
1 parent a496ec9 commit 8a38c48

File tree

18 files changed

+381
-704
lines changed

18 files changed

+381
-704
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
egress-policy: audit
5353

5454
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
55-
- uses: dtolnay/rust-toolchain@4305c38b25d97ef35a8ad1f985ccf2d2242004f2 # stable
55+
- uses: dtolnay/rust-toolchain@nightly
5656
with:
5757
components: rustfmt
5858
- run: cargo fmt --all -- --check

crates/flashblocks-rpc/src/pending_blocks.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use alloy_consensus::{Header, Sealed};
22
use alloy_eips::BlockNumberOrTag;
33
use alloy_primitives::{
4-
Address, B256, BlockNumber, TxHash, U256,
54
map::foldhash::{HashMap, HashMapExt},
5+
Address, BlockNumber, TxHash, B256, U256,
66
};
77
use alloy_provider::network::TransactionResponse;
8-
use alloy_rpc_types::{BlockTransactions, state::StateOverride};
8+
use alloy_rpc_types::{state::StateOverride, BlockTransactions};
99
use alloy_rpc_types_eth::{Filter, Header as RPCHeader, Log};
1010
use eyre::eyre;
1111
use op_alloy_network::Optimism;
@@ -60,8 +60,7 @@ impl PendingBlocksBuilder {
6060

6161
#[inline]
6262
pub(crate) fn with_transaction(&mut self, transaction: Transaction) -> &Self {
63-
self.transactions_by_hash
64-
.insert(transaction.tx_hash(), transaction.clone());
63+
self.transactions_by_hash.insert(transaction.tx_hash(), transaction.clone());
6564
self.transactions.push(transaction);
6665
self
6766
}
@@ -83,9 +82,7 @@ impl PendingBlocksBuilder {
8382
let zero = U256::from(0);
8483
let current_count = self.transaction_count.get(&sender).unwrap_or(&zero);
8584

86-
_ = self
87-
.transaction_count
88-
.insert(sender, *current_count + U256::from(1));
85+
_ = self.transaction_count.insert(sender, *current_count + U256::from(1));
8986
self
9087
}
9188

@@ -213,10 +210,7 @@ impl PendingBlocks {
213210
}
214211

215212
pub fn get_transaction_count(&self, address: Address) -> U256 {
216-
self.transaction_count
217-
.get(&address)
218-
.cloned()
219-
.unwrap_or(U256::from(0))
213+
self.transaction_count.get(&address).cloned().unwrap_or(U256::from(0))
220214
}
221215

222216
pub fn get_balance(&self, address: Address) -> Option<U256> {

crates/flashblocks-rpc/src/rpc.rs

Lines changed: 39 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
1-
use std::sync::Arc;
2-
use std::time::Duration;
1+
use std::{sync::Arc, time::Duration};
32

4-
use crate::metrics::Metrics;
5-
use crate::pending_blocks::PendingBlocks;
63
use alloy_eips::{BlockId, BlockNumberOrTag};
7-
use alloy_primitives::map::foldhash::{HashSet, HashSetExt};
8-
use alloy_primitives::{Address, TxHash, U256};
9-
use alloy_rpc_types::BlockOverrides;
10-
use alloy_rpc_types::simulate::{SimBlock, SimulatePayload, SimulatedBlock};
11-
use alloy_rpc_types::state::{EvmOverrides, StateOverride, StateOverridesBuilder};
4+
use alloy_primitives::{
5+
map::foldhash::{HashSet, HashSetExt},
6+
Address, TxHash, U256,
7+
};
8+
use alloy_rpc_types::{
9+
simulate::{SimBlock, SimulatePayload, SimulatedBlock},
10+
state::{EvmOverrides, StateOverride, StateOverridesBuilder},
11+
BlockOverrides,
12+
};
1213
use alloy_rpc_types_eth::{Filter, Log};
1314
use arc_swap::Guard;
1415
use jsonrpsee::{
15-
core::{RpcResult, async_trait},
16+
core::{async_trait, RpcResult},
1617
proc_macros::rpc,
1718
};
18-
use jsonrpsee_types::ErrorObjectOwned;
19-
use jsonrpsee_types::error::INVALID_PARAMS_CODE;
19+
use jsonrpsee_types::{error::INVALID_PARAMS_CODE, ErrorObjectOwned};
2020
use op_alloy_network::Optimism;
2121
use op_alloy_rpc_types::OpTransactionRequest;
22-
use reth::providers::CanonStateSubscriptions;
23-
use reth::rpc::eth::EthFilter;
24-
use reth::rpc::server_types::eth::EthApiError;
25-
use reth_rpc_eth_api::helpers::EthState;
26-
use reth_rpc_eth_api::helpers::EthTransactions;
27-
use reth_rpc_eth_api::helpers::{EthBlocks, EthCall};
28-
use reth_rpc_eth_api::{EthApiTypes, EthFilterApiServer, RpcBlock, helpers::FullEthApi};
29-
use reth_rpc_eth_api::{RpcReceipt, RpcTransaction};
30-
use tokio::sync::broadcast;
31-
use tokio::sync::broadcast::error::RecvError;
32-
use tokio::time;
33-
use tokio_stream::StreamExt;
34-
use tokio_stream::wrappers::BroadcastStream;
22+
use reth::{
23+
providers::CanonStateSubscriptions,
24+
rpc::{eth::EthFilter, server_types::eth::EthApiError},
25+
};
26+
use reth_rpc_eth_api::{
27+
helpers::{EthBlocks, EthCall, EthState, EthTransactions, FullEthApi},
28+
EthApiTypes, EthFilterApiServer, RpcBlock, RpcReceipt, RpcTransaction,
29+
};
30+
use tokio::{
31+
sync::{broadcast, broadcast::error::RecvError},
32+
time,
33+
};
34+
use tokio_stream::{wrappers::BroadcastStream, StreamExt};
3535
use tracing::{debug, trace, warn};
3636

37+
use crate::{metrics::Metrics, pending_blocks::PendingBlocks};
38+
3739
/// Max configured timeout for `eth_sendRawTransactionSync` in milliseconds.
3840
pub const MAX_TIMEOUT_SEND_RAW_TX_SYNC_MS: u64 = 6_000;
3941

@@ -89,7 +91,7 @@ pub trait EthApiOverride {
8991

9092
#[method(name = "getBalance")]
9193
async fn get_balance(&self, address: Address, block_number: Option<BlockId>)
92-
-> RpcResult<U256>;
94+
-> RpcResult<U256>;
9395

9496
#[method(name = "getTransactionCount")]
9597
async fn get_transaction_count(
@@ -149,12 +151,7 @@ pub struct EthApiExt<Eth: EthApiTypes, FB> {
149151

150152
impl<Eth: EthApiTypes, FB> EthApiExt<Eth, FB> {
151153
pub fn new(eth_api: Eth, eth_filter: EthFilter<Eth>, flashblocks_state: Arc<FB>) -> Self {
152-
Self {
153-
eth_api,
154-
eth_filter,
155-
flashblocks_state,
156-
metrics: Metrics::default(),
157-
}
154+
Self { eth_api, eth_filter, flashblocks_state, metrics: Metrics::default() }
158155
}
159156
}
160157

@@ -180,9 +177,7 @@ where
180177
let pending_blocks = self.flashblocks_state.get_pending_blocks();
181178
Ok(pending_blocks.get_block(full))
182179
} else {
183-
EthBlocks::rpc_block(&self.eth_api, number.into(), full)
184-
.await
185-
.map_err(Into::into)
180+
EthBlocks::rpc_block(&self.eth_api, number.into(), full).await.map_err(Into::into)
186181
}
187182
}
188183

@@ -201,9 +196,7 @@ where
201196
return Ok(Some(fb_receipt));
202197
}
203198

204-
EthTransactions::transaction_receipt(&self.eth_api, tx_hash)
205-
.await
206-
.map_err(Into::into)
199+
EthTransactions::transaction_receipt(&self.eth_api, tx_hash).await.map_err(Into::into)
207200
}
208201

209202
async fn get_balance(
@@ -224,9 +217,7 @@ where
224217
}
225218
}
226219

227-
EthState::balance(&self.eth_api, address, block_number)
228-
.await
229-
.map_err(Into::into)
220+
EthState::balance(&self.eth_api, address, block_number).await.map_err(Into::into)
230221
}
231222

232223
async fn get_transaction_count(
@@ -254,9 +245,7 @@ where
254245
return Ok(canon_count + fb_count);
255246
}
256247

257-
EthState::transaction_count(&self.eth_api, address, block_number)
258-
.await
259-
.map_err(Into::into)
248+
EthState::transaction_count(&self.eth_api, address, block_number).await.map_err(Into::into)
260249
}
261250

262251
async fn transaction_by_hash(
@@ -447,21 +436,13 @@ where
447436
state_overrides_builder.extend(sim_block.state_overrides.unwrap_or_default());
448437
let final_overrides = state_overrides_builder.build();
449438

450-
let block_state_call = SimBlock {
451-
state_overrides: Some(final_overrides),
452-
..sim_block
453-
};
439+
let block_state_call = SimBlock { state_overrides: Some(final_overrides), ..sim_block };
454440
block_state_calls.push(block_state_call);
455441
}
456442

457-
let payload = SimulatePayload {
458-
block_state_calls,
459-
..opts
460-
};
443+
let payload = SimulatePayload { block_state_calls, ..opts };
461444

462-
EthCall::simulate_v1(&self.eth_api, payload, Some(block_id))
463-
.await
464-
.map_err(Into::into)
445+
EthCall::simulate_v1(&self.eth_api, payload, Some(block_id)).await.map_err(Into::into)
465446
}
466447

467448
async fn get_logs(&self, filter: Filter) -> RpcResult<Vec<Log>> {
@@ -472,10 +453,9 @@ where
472453

473454
// Check if this is a mixed query (toBlock is pending)
474455
let (from_block, to_block) = match &filter.block_option {
475-
alloy_rpc_types_eth::FilterBlockOption::Range {
476-
from_block,
477-
to_block,
478-
} => (*from_block, *to_block),
456+
alloy_rpc_types_eth::FilterBlockOption::Range { from_block, to_block } => {
457+
(*from_block, *to_block)
458+
}
479459
_ => {
480460
// Block hash queries or other formats - delegate to eth API
481461
return self.eth_filter.logs(filter).await;

0 commit comments

Comments
 (0)