BTreeMap instead of HashMap
This commit is contained in:
parent
5d1e0a6178
commit
c3d1d14f16
@ -3,9 +3,9 @@ use arc_swap::ArcSwap;
|
|||||||
use derive_more::From;
|
use derive_more::From;
|
||||||
use ethers::prelude::H256;
|
use ethers::prelude::H256;
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use hashbrown::{HashMap, HashSet};
|
use hashbrown::HashMap;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
@ -14,21 +14,11 @@ use tracing::{info, info_span, instrument, warn};
|
|||||||
|
|
||||||
use crate::connection::Web3Connection;
|
use crate::connection::Web3Connection;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, Default)]
|
||||||
struct SyncedConnections {
|
struct SyncedConnections {
|
||||||
head_block_num: u64,
|
head_block_num: u64,
|
||||||
head_block_hash: H256,
|
head_block_hash: H256,
|
||||||
inner: HashSet<usize>,
|
inner: BTreeSet<usize>,
|
||||||
}
|
|
||||||
|
|
||||||
impl SyncedConnections {
|
|
||||||
fn new(max_connections: usize) -> Self {
|
|
||||||
Self {
|
|
||||||
head_block_num: 0,
|
|
||||||
head_block_hash: Default::default(),
|
|
||||||
inner: HashSet::with_capacity(max_connections),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A collection of web3 connections. Sends requests either the current best server or all servers.
|
/// A collection of web3 connections. Sends requests either the current best server or all servers.
|
||||||
@ -72,7 +62,7 @@ impl Web3Connections {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let synced_connections = SyncedConnections::new(num_connections);
|
let synced_connections = SyncedConnections::default();
|
||||||
|
|
||||||
let connections = Arc::new(Self {
|
let connections = Arc::new(Self {
|
||||||
inner: connections,
|
inner: connections,
|
||||||
@ -142,7 +132,7 @@ impl Web3Connections {
|
|||||||
let mut connection_states: HashMap<usize, (u64, H256)> =
|
let mut connection_states: HashMap<usize, (u64, H256)> =
|
||||||
HashMap::with_capacity(max_connections);
|
HashMap::with_capacity(max_connections);
|
||||||
|
|
||||||
let mut pending_synced_connections = SyncedConnections::new(max_connections);
|
let mut pending_synced_connections = SyncedConnections::default();
|
||||||
|
|
||||||
while let Ok((new_block_num, new_block_hash, rpc_id)) = block_receiver.recv_async().await {
|
while let Ok((new_block_num, new_block_hash, rpc_id)) = block_receiver.recv_async().await {
|
||||||
// TODO: span with rpc in it, too
|
// TODO: span with rpc in it, too
|
||||||
|
@ -7,10 +7,10 @@ use futures::stream::FuturesUnordered;
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use governor::clock::{QuantaClock, QuantaInstant};
|
use governor::clock::{QuantaClock, QuantaInstant};
|
||||||
use governor::NotUntil;
|
use governor::NotUntil;
|
||||||
use hashbrown::{HashMap, HashSet};
|
use hashbrown::HashMap;
|
||||||
use serde_json::value::RawValue;
|
use serde_json::value::RawValue;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
@ -24,7 +24,7 @@ use crate::connection::{ActiveRequestHandle, Web3Connection};
|
|||||||
struct SyncedConnections {
|
struct SyncedConnections {
|
||||||
head_block_num: u64,
|
head_block_num: u64,
|
||||||
head_block_hash: H256,
|
head_block_hash: H256,
|
||||||
inner: HashSet<usize>,
|
inner: BTreeSet<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for SyncedConnections {
|
impl fmt::Debug for SyncedConnections {
|
||||||
|
Loading…
Reference in New Issue
Block a user