fix: format eth providers as set so they are never duplicated

This commit is contained in:
dr-frmr 2024-05-13 13:21:38 -06:00
parent 8643f8e6c8
commit ac408e6c2f
No known key found for this signature in database
5 changed files with 31 additions and 17 deletions

View File

@ -63,18 +63,26 @@ impl ActiveProviders {
kns_update,
use_as_provider,
} => {
self.nodes.push(NodeProvider {
trusted: new.trusted,
usable: use_as_provider,
kns_update,
});
self.remove_provider(&kns_update.name);
self.nodes.insert(
0,
NodeProvider {
trusted: new.trusted,
usable: use_as_provider,
kns_update,
},
);
}
NodeOrRpcUrl::RpcUrl(url) => {
self.urls.push(UrlProvider {
trusted: new.trusted,
url,
pubsub: None,
});
self.remove_provider(&url);
self.urls.insert(
0,
UrlProvider {
trusted: new.trusted,
url,
pubsub: None,
},
);
}
}
}

View File

@ -86,7 +86,7 @@ async fn main() {
Err(_) => serde_json::from_str(DEFAULT_ETH_PROVIDERS).unwrap(),
};
if let Some(rpc) = rpc {
eth_provider_config.push(lib::eth::ProviderConfig {
eth_provider_config.insert(lib::eth::ProviderConfig {
chain_id: CHAIN_ID,
trusted: true,
provider: lib::eth::NodeOrRpcUrl::RpcUrl(rpc.to_string()),

View File

@ -125,8 +125,13 @@ pub async fn register(
} else {
"wss://optimism-rpc.publicnode.com".to_string()
};
let connector = WsConnect { url, auth: None };
let Ok(client) = ClientBuilder::default().ws(connector).await else {
println!("Connecting to Optimism RPC at {url}");
// this fails occasionally in certain networking environments. i'm not sure why.
// frustratingly, the exact same call does not fail in the eth module. more investigation needed.
let Ok(client) = ClientBuilder::default()
.ws(WsConnect { url, auth: None })
.await
else {
panic!(
"Error: runtime could not connect to ETH RPC.\n\
This is necessary in order to verify node identity onchain.\n\
@ -134,6 +139,7 @@ pub async fn register(
the --rpc flag, and you are connected to the internet."
);
};
println!("Connected to Optimism RPC");
let provider = Arc::new(Provider::new_with_client(client));

View File

@ -1583,7 +1583,7 @@ pub enum NetResponse {
Verified(bool),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Hash, Eq, PartialEq)]
pub struct KnsUpdate {
pub name: String, // actual username / domain name
pub owner: String,

View File

@ -141,17 +141,17 @@ pub struct AccessSettings {
pub deny: HashSet<String>, // blacklist for access (always used)
}
pub type SavedConfigs = Vec<ProviderConfig>;
pub type SavedConfigs = HashSet<ProviderConfig>;
/// Provider config. Can currently be a node or a ws provider instance.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize, Hash, Eq, PartialEq)]
pub struct ProviderConfig {
pub chain_id: u64,
pub trusted: bool,
pub provider: NodeOrRpcUrl,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize, Hash, Eq, PartialEq)]
pub enum NodeOrRpcUrl {
Node {
kns_update: crate::core::KnsUpdate,