Skip to content

Commit 9333418

Browse files
committed
all: Update Rust edition to 2024
1 parent f031138 commit 9333418

83 files changed

Lines changed: 655 additions & 766 deletions

Some content is hidden

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ members = [
2727

2828
[workspace.package]
2929
version = "0.42.1"
30-
edition = "2021"
30+
edition = "2024"
3131
authors = ["The Graph core developers & contributors"]
3232
readme = "README.md"
3333
homepage = "https://thegraph.com"

chain/common/tests/test-acme.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ fn check_repeated_type_ok() {
77
let types = parse_proto_file(PROTO_FILE).expect("Unable to read proto file!");
88

99
let array_types = types
10-
.iter()
11-
.flat_map(|(_, t)| t.fields.iter())
10+
.values()
11+
.flat_map(|t| t.fields.iter())
1212
.filter(|t| t.is_array)
1313
.map(|t| t.type_name.clone())
1414
.collect::<std::collections::HashSet<_>>();

chain/ethereum/src/call_helper.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,10 @@ pub fn interpret_eth_call_error(
9393
Ok(call::Retval::Null)
9494
}
9595

96-
if let RpcError::ErrorResp(rpc_error) = &err {
97-
if is_rpc_revert_message(&rpc_error.message) {
96+
if let RpcError::ErrorResp(rpc_error) = &err
97+
&& is_rpc_revert_message(&rpc_error.message) {
9898
return reverted(logger, &rpc_error.message);
9999
}
100-
}
101100

102101
if let RpcError::ErrorResp(rpc_error) = &err {
103102
let code = rpc_error.code;
@@ -106,13 +105,11 @@ pub fn interpret_eth_call_error(
106105
.as_ref()
107106
.and_then(|d| serde_json::from_str(d.get()).ok());
108107

109-
if code == PARITY_VM_EXECUTION_ERROR {
110-
if let Some(data) = data {
111-
if is_parity_revert(&data) {
108+
if code == PARITY_VM_EXECUTION_ERROR
109+
&& let Some(data) = data
110+
&& is_parity_revert(&data) {
112111
return reverted(logger, &parity_revert_reason(&data));
113112
}
114-
}
115-
}
116113
}
117114

118115
Err(ContractCallError::AlloyError(err))

chain/ethereum/src/chain.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,10 @@ where
396396
for _ in 0..offset {
397397
match parent_getter(current_ptr.clone()).await? {
398398
Some(parent) => {
399-
if let Some(root_hash) = &root {
400-
if parent.hash == *root_hash {
399+
if let Some(root_hash) = &root
400+
&& parent.hash == *root_hash {
401401
break;
402402
}
403-
}
404403
current_ptr = parent;
405404
}
406405
None => return Ok(None),
@@ -814,9 +813,7 @@ async fn fetch_unique_blocks_from_cache(
814813
.unwrap_or_default();
815814

816815
// Collect blocks and filter out ones with multiple entries
817-
let blocks: Vec<Arc<ExtendedBlockPtr>> = blocks_map
818-
.into_iter()
819-
.filter_map(|(_, values)| {
816+
let blocks: Vec<Arc<ExtendedBlockPtr>> = blocks_map.into_values().filter_map(|values| {
820817
if values.len() == 1 {
821818
Some(Arc::new(values[0].clone()))
822819
} else {

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,53 @@ use futures03::{future::BoxFuture, stream::FuturesUnordered};
33
use graph::abi;
44
use graph::abi::DynSolValueExt;
55
use graph::abi::FunctionExt;
6-
use graph::blockchain::client::ChainClient;
76
use graph::blockchain::BlockHash;
87
use graph::blockchain::ChainIdentifier;
98
use graph::blockchain::ExtendedBlockPtr;
9+
use graph::blockchain::client::ChainClient;
1010
use graph::components::ethereum::*;
1111
use graph::components::transaction_receipt::LightTransactionReceipt;
1212
use graph::data::store::ethereum::call;
1313
use graph::data::store::scalar;
14-
use graph::data::subgraph::UnifiedMappingApiVersion;
1514
use graph::data::subgraph::API_VERSION_0_0_7;
15+
use graph::data::subgraph::UnifiedMappingApiVersion;
1616
use graph::data_source::common::ContractCall;
1717
use graph::derive::CheapClone;
18-
use graph::futures01::stream;
1918
use graph::futures01::Future;
2019
use graph::futures01::Stream;
20+
use graph::futures01::stream;
2121
use graph::futures03::future::try_join_all;
2222
use graph::futures03::{
23-
self, compat::Future01CompatExt, FutureExt, StreamExt, TryFutureExt, TryStreamExt,
23+
self, FutureExt, StreamExt, TryFutureExt, TryStreamExt, compat::Future01CompatExt,
2424
};
2525
use graph::prelude::{
2626
alloy::{
2727
self,
2828
network::TransactionResponse,
2929
primitives::{Address, B256},
3030
providers::{
31+
Identity, Provider, RootProvider,
3132
ext::TraceApi,
3233
fillers::{
3334
BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller,
3435
},
35-
Identity, Provider, RootProvider,
3636
},
3737
rpc::types::{
38-
trace::{filter::TraceFilter as AlloyTraceFilter, parity::LocalizedTransactionTrace},
3938
TransactionInput, TransactionRequest,
39+
trace::{filter::TraceFilter as AlloyTraceFilter, parity::LocalizedTransactionTrace},
4040
},
4141
transports::{RpcError, TransportErrorKind},
4242
},
4343
tokio::try_join,
4444
};
4545
use graph::slog::o;
4646
use graph::{
47-
blockchain::{block_stream::BlockWithTriggers, BlockPtr, IngestorError},
47+
blockchain::{BlockPtr, IngestorError, block_stream::BlockWithTriggers},
4848
prelude::{
49-
anyhow::{self, anyhow, bail, ensure, Context},
50-
debug, error, hex, info, retry, trace, warn, BlockNumber, ChainStore, CheapClone,
51-
DynTryFuture, Error, EthereumCallCache, Logger, TimeoutError,
49+
BlockNumber, ChainStore, CheapClone, DynTryFuture, Error, EthereumCallCache, Logger,
50+
TimeoutError,
51+
anyhow::{self, Context, anyhow, bail, ensure},
52+
debug, error, hex, info, retry, trace, warn,
5253
},
5354
};
5455
use itertools::Itertools;
@@ -61,24 +62,24 @@ use std::time::{Duration, Instant};
6162
use tokio::sync::RwLock;
6263
use tokio::time::timeout;
6364

65+
use crate::Chain;
66+
use crate::NodeCapabilities;
67+
use crate::TriggerFilter;
6468
use crate::adapter::EthGetLogsFilter;
6569
use crate::adapter::EthereumRpcError;
6670
use crate::adapter::ProviderStatus;
6771
use crate::call_helper::interpret_eth_call_error;
6872
use crate::chain::BlockFinality;
6973
use crate::chain::ChainSettings;
7074
use crate::trigger::{LogPosition, LogRef};
71-
use crate::Chain;
72-
use crate::NodeCapabilities;
73-
use crate::TriggerFilter;
7475
use crate::{
76+
ENV_VARS,
7577
adapter::{
7678
ContractCallError, EthereumAdapter as EthereumAdapterTrait, EthereumBlockFilter,
7779
EthereumCallFilter, EthereumLogFilter, ProviderEthRpcMetrics, SubgraphEthRpcMetrics,
7880
},
7981
transport::Transport,
8082
trigger::{EthereumBlockTriggerType, EthereumTrigger},
81-
ENV_VARS,
8283
};
8384

8485
type AlloyProvider = FillProvider<
@@ -1014,7 +1015,8 @@ impl EthereumAdapter {
10141015
) -> Pin<
10151016
Box<
10161017
dyn std::future::Future<Output = Result<Vec<EthereumTrigger>, anyhow::Error>>
1017-
+ std::marker::Send,
1018+
+ std::marker::Send
1019+
+ '_,
10181020
>,
10191021
> {
10201022
// Create a HashMap of block numbers to Vec<EthereumBlockTriggerType>
@@ -1053,15 +1055,13 @@ impl EthereumAdapter {
10531055
let block_futures = blocks_matching_polling_filter.map(move |ptrs| {
10541056
ptrs.into_iter()
10551057
.flat_map(|ptr| {
1056-
let triggers = matching_blocks
1058+
matching_blocks
10571059
.get(&ptr.number)
10581060
// Safe to unwrap since we are iterating over ptrs which was created from
10591061
// the keys of matching_blocks
10601062
.unwrap()
10611063
.iter()
1062-
.map(move |trigger| EthereumTrigger::Block(ptr.clone(), trigger.clone()));
1063-
1064-
triggers
1064+
.map(move |trigger| EthereumTrigger::Block(ptr.clone(), trigger.clone()))
10651065
})
10661066
.collect::<Vec<_>>()
10671067
});
@@ -1126,7 +1126,7 @@ impl EthereumAdapter {
11261126
logger: Logger,
11271127
from: BlockNumber,
11281128
to: BlockNumber,
1129-
) -> Box<dyn Future<Item = Vec<BlockPtr>, Error = Error> + Send> {
1129+
) -> Box<dyn Future<Item = Vec<BlockPtr>, Error = Error> + Send + '_> {
11301130
// Currently we can't go to the DB for this because there might be duplicate entries for
11311131
// the same block number.
11321132
debug!(&logger, "Requesting hashes for blocks [{}, {}]", from, to);
@@ -1140,7 +1140,7 @@ impl EthereumAdapter {
11401140
&self,
11411141
logger: Logger,
11421142
blocks: Vec<BlockNumber>,
1143-
) -> Box<dyn Future<Item = Vec<BlockPtr>, Error = Error> + Send> {
1143+
) -> Box<dyn Future<Item = Vec<BlockPtr>, Error = Error> + Send + '_> {
11441144
// Currently we can't go to the DB for this because there might be duplicate entries for
11451145
// the same block number.
11461146
debug!(&logger, "Requesting hashes for blocks {:?}", blocks);
@@ -1587,15 +1587,26 @@ impl EthereumAdapterTrait for EthereumAdapter {
15871587

15881588
fn log_call_error(logger: &ProviderLogger, e: &ContractCallError, call: &ContractCall) {
15891589
match e {
1590-
ContractCallError::AlloyError(e) => error!(logger,
1590+
ContractCallError::AlloyError(e) => error!(
1591+
logger,
15911592
"Ethereum node returned an error when calling function \"{}\" of contract \"{}\": {}",
1592-
call.function.name, call.contract_name, e),
1593-
ContractCallError::Timeout => error!(logger,
1593+
call.function.name,
1594+
call.contract_name,
1595+
e
1596+
),
1597+
ContractCallError::Timeout => error!(
1598+
logger,
15941599
"Ethereum node did not respond when calling function \"{}\" of contract \"{}\"",
1595-
call.function.name, call.contract_name),
1596-
_ => error!(logger,
1600+
call.function.name,
1601+
call.contract_name
1602+
),
1603+
_ => error!(
1604+
logger,
15971605
"Failed to call function \"{}\" of contract \"{}\": {}",
1598-
call.function.name, call.contract_name, e),
1606+
call.function.name,
1607+
call.contract_name,
1608+
e
1609+
),
15991610
}
16001611
}
16011612

@@ -2125,7 +2136,7 @@ async fn filter_call_triggers_from_unsuccessful_transactions(
21252136
// And obtain all Transaction values for the calls in this block.
21262137
let transactions: Vec<&AnyTransaction> = {
21272138
match &block.block {
2128-
BlockFinality::Final(ref block) => block
2139+
BlockFinality::Final(block) => block
21292140
.transactions()
21302141
.ok_or_else(|| anyhow!("Block transactions not available"))?
21312142
.iter()
@@ -2696,15 +2707,15 @@ mod tests {
26962707
use crate::trigger::{EthereumBlockTriggerType, EthereumTrigger};
26972708

26982709
use super::{
2699-
check_block_receipt_support, parse_block_triggers, EthereumBlock, EthereumBlockFilter,
2700-
EthereumBlockWithCalls,
2710+
EthereumBlock, EthereumBlockFilter, EthereumBlockWithCalls, check_block_receipt_support,
2711+
parse_block_triggers,
27012712
};
27022713
use graph::blockchain::BlockPtr;
27032714
use graph::components::ethereum::AnyNetworkBare;
2704-
use graph::prelude::alloy::primitives::{Address, Bytes, B256};
2705-
use graph::prelude::alloy::providers::mock::Asserter;
2715+
use graph::prelude::alloy::primitives::{Address, B256, Bytes};
27062716
use graph::prelude::alloy::providers::ProviderBuilder;
2707-
use graph::prelude::{create_minimal_block_for_test, EthereumCall, LightEthereumBlock};
2717+
use graph::prelude::alloy::providers::mock::Asserter;
2718+
use graph::prelude::{EthereumCall, LightEthereumBlock, create_minimal_block_for_test};
27082719
use jsonrpc_core::serde_json::{self, Value};
27092720
use std::collections::HashSet;
27102721
use std::iter::FromIterator;

chain/ethereum/src/ingestor.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,10 @@ async fn on_poll_failure<A: crate::EthereumAdapterTrait>(
281281
// at the match level. If the current provider responds to eth_blockNumber, the
282282
// failure was not caused by provider unavailability — switching cannot help.
283283
let current = providers.iter().find(|p| p.provider() == current_name);
284-
if let Some(current) = current {
285-
if current.is_reachable().await {
284+
if let Some(current) = current
285+
&& current.is_reachable().await {
286286
return;
287287
}
288-
}
289288

290289
// Probe all alternatives in parallel; switch to the first that responds.
291290
let futs = providers

chain/ethereum/src/network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl EthereumNetworkAdapters {
118118

119119
let provider = ProviderManager::new(
120120
Logger::root(Discard, o!()),
121-
vec![(chain_id.clone(), adapters)].into_iter(),
121+
vec![(chain_id.clone(), adapters)],
122122
ProviderCheckStrategy::MarkAsValid,
123123
);
124124

chain/ethereum/src/polling_block_stream.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{anyhow, Error};
1+
use anyhow::{Error, anyhow};
22
use std::cmp;
33
use std::collections::VecDeque;
44
use std::pin::Pin;
@@ -7,13 +7,13 @@ use std::task::{Context, Poll};
77
use std::time::Duration;
88

99
use graph::blockchain::block_stream::{
10-
BlockStream, BlockStreamError, BlockStreamEvent, BlockWithTriggers, ChainHeadUpdateStream,
11-
FirehoseCursor, TriggersAdapterWrapper, BUFFERED_BLOCK_STREAM_SIZE,
10+
BUFFERED_BLOCK_STREAM_SIZE, BlockStream, BlockStreamError, BlockStreamEvent, BlockWithTriggers,
11+
ChainHeadUpdateStream, FirehoseCursor, TriggersAdapterWrapper,
1212
};
1313
use graph::blockchain::{Block, BlockPtr, TriggerFilterWrapper};
14-
use graph::futures03::{stream::Stream, Future, FutureExt};
15-
use graph::prelude::{DeploymentHash, BLOCK_NUMBER_MAX};
16-
use graph::slog::{info, trace, warn, Logger};
14+
use graph::futures03::{Future, FutureExt, stream::Stream};
15+
use graph::prelude::{BLOCK_NUMBER_MAX, DeploymentHash};
16+
use graph::slog::{Logger, info, trace, warn};
1717

1818
use graph::components::store::BlockNumber;
1919
use graph::data::subgraph::UnifiedMappingApiVersion;
@@ -182,7 +182,7 @@ impl PollingBlockStreamContext {
182182
return Ok(NextBlocks::Done);
183183
}
184184
ReconciliationStep::Revert(parent_ptr) => {
185-
return Ok(NextBlocks::Revert(parent_ptr))
185+
return Ok(NextBlocks::Revert(parent_ptr));
186186
}
187187
}
188188
}
@@ -224,11 +224,10 @@ impl PollingBlockStreamContext {
224224

225225
// Only continue if the subgraph block ptr is behind the head block ptr.
226226
// subgraph_ptr > head_ptr shouldn't happen, but if it does, it's safest to just stop.
227-
if let Some(ptr) = &subgraph_ptr {
228-
if ptr.number >= head_ptr.number {
227+
if let Some(ptr) = &subgraph_ptr
228+
&& ptr.number >= head_ptr.number {
229229
return Ok(ReconciliationStep::Done);
230230
}
231-
}
232231

233232
// Subgraph ptr is behind head ptr.
234233
// Let's try to move the subgraph ptr one step in the right direction.
@@ -569,7 +568,7 @@ impl Stream for PollingBlockStream {
569568
}
570569

571570
// Yielding blocks from reconciliation process
572-
BlockStreamState::YieldingBlocks(ref mut next_blocks) => {
571+
BlockStreamState::YieldingBlocks(next_blocks) => {
573572
match next_blocks.pop_front() {
574573
// Yield one block
575574
Some(next_block) => {
@@ -589,7 +588,7 @@ impl Stream for PollingBlockStream {
589588
}
590589

591590
// Pausing after an error, before looking for more blocks
592-
BlockStreamState::RetryAfterDelay(ref mut delay) => match delay.as_mut().poll(cx) {
591+
BlockStreamState::RetryAfterDelay(delay) => match delay.as_mut().poll(cx) {
593592
Poll::Ready(Ok(..)) | Poll::Ready(Err(_)) => {
594593
self.state = BlockStreamState::BeginReconciliation;
595594
}

chain/ethereum/src/transport.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,12 @@ impl Service<RequestPacket> for PatchingHttp {
265265
));
266266
}
267267

268-
if should_patch {
269-
if let Some(patched) = Self::patch_response(&body) {
268+
if should_patch
269+
&& let Some(patched) = Self::patch_response(&body) {
270270
return serde_json::from_slice(&patched).map_err(|err| {
271271
TransportError::deser_err(err, String::from_utf8_lossy(&patched))
272272
});
273273
}
274-
}
275274
serde_json::from_slice(&body)
276275
.map_err(|err| TransportError::deser_err(err, String::from_utf8_lossy(&body)))
277276
})

0 commit comments

Comments
 (0)