BTreeMap instead of HashMap

This commit is contained in:
Bryan Stitt 2022-05-20 01:26:02 +00:00
parent 5d1e0a6178
commit c3d1d14f16
2 changed files with 9 additions and 19 deletions

View File

@ -3,9 +3,9 @@ use arc_swap::ArcSwap;
use derive_more::From;
use ethers::prelude::H256;
use futures::future::join_all;
use hashbrown::{HashMap, HashSet};
use hashbrown::HashMap;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};
use std::fmt;
use std::sync::Arc;
use tokio::task;
@ -14,21 +14,11 @@ use tracing::{info, info_span, instrument, warn};
use crate::connection::Web3Connection;
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
struct SyncedConnections {
head_block_num: u64,
head_block_hash: H256,
inner: HashSet<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),
}
}
inner: BTreeSet<usize>,
}
/// 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 {
inner: connections,
@ -142,7 +132,7 @@ impl Web3Connections {
let mut connection_states: HashMap<usize, (u64, H256)> =
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 {
// TODO: span with rpc in it, too

View File

@ -7,10 +7,10 @@ use futures::stream::FuturesUnordered;
use futures::StreamExt;
use governor::clock::{QuantaClock, QuantaInstant};
use governor::NotUntil;
use hashbrown::{HashMap, HashSet};
use hashbrown::HashMap;
use serde_json::value::RawValue;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};
use std::fmt;
use std::sync::Arc;
use tokio::task;
@ -24,7 +24,7 @@ use crate::connection::{ActiveRequestHandle, Web3Connection};
struct SyncedConnections {
head_block_num: u64,
head_block_hash: H256,
inner: HashSet<usize>,
inner: BTreeSet<usize>,
}
impl fmt::Debug for SyncedConnections {