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, kns_update,
use_as_provider, use_as_provider,
} => { } => {
self.nodes.push(NodeProvider { self.remove_provider(&kns_update.name);
trusted: new.trusted, self.nodes.insert(
usable: use_as_provider, 0,
kns_update, NodeProvider {
}); trusted: new.trusted,
usable: use_as_provider,
kns_update,
},
);
} }
NodeOrRpcUrl::RpcUrl(url) => { NodeOrRpcUrl::RpcUrl(url) => {
self.urls.push(UrlProvider { self.remove_provider(&url);
trusted: new.trusted, self.urls.insert(
url, 0,
pubsub: None, 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(), Err(_) => serde_json::from_str(DEFAULT_ETH_PROVIDERS).unwrap(),
}; };
if let Some(rpc) = rpc { if let Some(rpc) = rpc {
eth_provider_config.push(lib::eth::ProviderConfig { eth_provider_config.insert(lib::eth::ProviderConfig {
chain_id: CHAIN_ID, chain_id: CHAIN_ID,
trusted: true, trusted: true,
provider: lib::eth::NodeOrRpcUrl::RpcUrl(rpc.to_string()), provider: lib::eth::NodeOrRpcUrl::RpcUrl(rpc.to_string()),

View File

@ -125,8 +125,13 @@ pub async fn register(
} else { } else {
"wss://optimism-rpc.publicnode.com".to_string() "wss://optimism-rpc.publicnode.com".to_string()
}; };
let connector = WsConnect { url, auth: None }; println!("Connecting to Optimism RPC at {url}");
let Ok(client) = ClientBuilder::default().ws(connector).await else { // 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!( panic!(
"Error: runtime could not connect to ETH RPC.\n\ "Error: runtime could not connect to ETH RPC.\n\
This is necessary in order to verify node identity onchain.\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." the --rpc flag, and you are connected to the internet."
); );
}; };
println!("Connected to Optimism RPC");
let provider = Arc::new(Provider::new_with_client(client)); let provider = Arc::new(Provider::new_with_client(client));

View File

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

View File

@ -141,17 +141,17 @@ pub struct AccessSettings {
pub deny: HashSet<String>, // blacklist for access (always used) 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. /// 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 struct ProviderConfig {
pub chain_id: u64, pub chain_id: u64,
pub trusted: bool, pub trusted: bool,
pub provider: NodeOrRpcUrl, pub provider: NodeOrRpcUrl,
} }
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize, Hash, Eq, PartialEq)]
pub enum NodeOrRpcUrl { pub enum NodeOrRpcUrl {
Node { Node {
kns_update: crate::core::KnsUpdate, kns_update: crate::core::KnsUpdate,