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

fix: removed free l1 endpoint rpc url #209

Merged
merged 2 commits into from
Jul 22, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- fix(l1): removed free l1 endpoint list
- fix(metrics): removed influx and added l2_state_size data
- fix: command to start the Madara client
- refactor: database error unification
Expand Down
56 changes: 0 additions & 56 deletions crates/client/sync/src/utils/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,3 @@ pub mod starknet_core_address {
}

pub const LOG_STATE_UPDTATE_TOPIC: &str = "0xd342ddf7a308dec111745b00315c14b7efb2bdae570a6856e088ed0c65a3576c";

// This a list of free RPC URLs for Ethereum mainnet.
//
// It is used whenever no --l1-endpoint is provided.
// It should be used only for testing purposes.
//
// The list comes from DefiLlama's chainlist repository:
// https://github.com/DefiLlama/chainlist
pub const L1_FREE_RPC_URLS: &[&str] = &[
"https://endpoints.omniatech.io/v1/eth/mainnet/public",
"https://rpc.ankr.com/eth",
"https://go.getblock.io/aefd01aa907c4805ba3c00a9e5b48c6b",
"https://eth-mainnet.nodereal.io/v1/1659dfb40aa24bbb8153a677b98064d7",
"https://ethereum-rpc.publicnode.com",
"wss://ethereum-rpc.publicnode.com",
"https://1rpc.io/eth",
"https://rpc.builder0x69.io/",
"https://rpc.mevblocker.io",
"https://rpc.flashbots.net/",
"https://cloudflare-eth.com/",
"https://eth-mainnet.public.blastapi.io",
"https://api.securerpc.com/v1",
"https://openapi.bitstack.com/v1/wNFxbiJyQsSeLrX8RRCHi7NpRxrlErZk/DjShIqLishPCTB9HiMkPHXjUM9CNM9Na/ETH/mainnet",
"https://eth-pokt.nodies.app",
"https://eth-mainnet-public.unifra.io",
"https://ethereum.blockpi.network/v1/rpc/public",
"https://rpc.payload.de",
"https://api.zmok.io/mainnet/oaen6dy8ff6hju9k",
"https://eth-mainnet.g.alchemy.com/v2/demo",
"https://eth.api.onfinality.io/public",
"https://core.gashawk.io/rpc",
"https://mainnet.eth.cloud.ava.do/",
"https://ethereumnodelight.app.runonflux.io",
"https://eth-mainnet.rpcfast.com?api_key=xbhWBI1Wkguk8SNMu1bvvLurPGLXmgwYeC4S6g2H7WdwFigZSmPWVZRxrskEQwIf",
"https://main-light.eth.linkpool.io",
"https://rpc.eth.gateway.fm",
"https://rpc.chain49.com/ethereum?api_key=14d1a8b86d8a4b4797938332394203dc",
"https://eth.meowrpc.com",
"https://eth.drpc.org",
"https://api.zan.top/node/v1/eth/mainnet/public",
"https://eth-mainnet.diamondswap.org/rpc",
"https://rpc.notadegen.com/eth",
"https://eth.merkle.io",
"https://rpc.lokibuilder.xyz/wallet",
"https://services.tokenview.io/vipapi/nodeservice/eth?apikey=qVHq2o6jpaakcw3lRstl",
"https://eth.nodeconnect.org/",
"https://api.stateless.solutions/ethereum/v1/demo",
"https://rpc.polysplit.cloud/v1/chain/1",
"https://public.stackup.sh/api/v1/node/ethereum-mainnet",
"https://api.tatum.io/v3/blockchain/node/ethereum-mainnet",
"https://eth.nownodes.io",
"https://rpc.nodifi.ai/api/rpc/free",
"https://ethereum.rpc.subquery.network/public",
"https://rpc.graffiti.farm",
"https://rpc.public.curie.radiumblock.co/http/ethereum",
];
65 changes: 0 additions & 65 deletions crates/client/sync/src/utils/utility.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
//! Utility functions for Deoxys.

use std::time::Instant;

use super::constant::L1_FREE_RPC_URLS;
use anyhow::{bail, Context};
use ethers::types::{I256, U256};
use rand::seq::SliceRandom;
use rand::thread_rng;
use reqwest::Client;
use serde_json::Value;
use starknet_api::hash::StarkFelt;
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -55,67 +51,6 @@ pub enum RpcError {
NoSuitableUrl,
}

struct RpcChecker {
client: Client,
urls: &'static [&'static str],
best_url: Option<&'static str>,
best_latency: u128,
}

impl RpcChecker {
fn new(urls: &'static [&'static str]) -> Self {
RpcChecker { client: Client::new(), urls, best_url: None, best_latency: u128::MAX }
}

async fn l1_free_rpc_check(&self, url: &str) -> Result<u128, RpcError> {
let start = Instant::now();
let response = self.client.get(url).send().await?;
if response.status().is_success() {
Ok(start.elapsed().as_millis())
} else {
Ok(u128::MAX)
}
}

async fn l1_free_rpc_best(&mut self) -> Result<&'static str, RpcError> {
log::warn!("Looking for the best available free Ethereum RPC endpoints online, as none has been provided.");
log::warn!("This should be for testing purposes only. We recommend providing your own L1 RPC endpoint using `--l1-endpoint <ETHEREUM RPC URL>`.");
for &url in self.urls.iter() {
match self.l1_free_rpc_check(url).await {
Ok(latency) if latency < self.best_latency => {
log::debug!("New best URL found: {} with latency {} ms", url, latency);
self.best_latency = latency;
self.best_url = Some(url);
}
Ok(latency) => {
log::debug!(
"URL {} has latency {} ms, which is not better than the current best {} ms",
url,
latency,
self.best_latency
);
}
Err(e) => {
log::debug!("Failed to check latency for URL {}: {:?}", url, e);
}
}
}

match self.best_url {
Some(best_url) => {
log::info!("🔗 Using best L1 free RPC url found: {}", best_url);
Ok(best_url)
}
None => Err(RpcError::NoSuitableUrl),
}
}
}

pub async fn l1_free_rpc_get() -> Result<&'static str, RpcError> {
let mut rpc_checker = RpcChecker::new(L1_FREE_RPC_URLS);
rpc_checker.l1_free_rpc_best().await
}

pub fn trim_hash(hash: &Felt) -> String {
let hash_str = format!("{:#x}", hash);
let hash_len = hash_str.len();
Expand Down
6 changes: 3 additions & 3 deletions crates/node/src/service/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use dc_db::{DatabaseService, DeoxysBackend};
use dc_metrics::MetricsRegistry;
use dc_sync::fetch::fetchers::FetchConfig;
use dc_sync::metrics::block_metrics::BlockMetrics;
use dc_sync::utility::l1_free_rpc_get;
use dc_telemetry::TelemetryHandle;
use primitive_types::H160;
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -47,8 +46,9 @@ impl SyncService {
if let Some(l1_rpc_url) = &config.l1_endpoint {
Some(l1_rpc_url.clone())
} else {
let l1_rpc_url = l1_free_rpc_get().await.expect("finding the best RPC URL");
Some(Url::parse(l1_rpc_url).expect("parsing the RPC URL"))
return Err(anyhow::anyhow!(
"❗ No L1 endpoint provided. You must provide one in order to verify the synced state."
));
}
} else {
None
Expand Down