add min_synced_rpcs to config

This commit is contained in:
Bryan Stitt 2022-08-27 00:33:45 +00:00
parent 4c0db2d4ff
commit 9fabb8e1e1
5 changed files with 15 additions and 4 deletions

@ -255,6 +255,7 @@ impl Web3ProxyApp {
redis_pool.clone(),
block_map.clone(),
Some(head_block_sender),
top_config.app.min_synced_rpcs,
Some(pending_tx_sender.clone()),
pending_transactions.clone(),
)
@ -276,6 +277,8 @@ impl Web3ProxyApp {
block_map,
// subscribing to new heads here won't work well. if they are fast, they might be ahead of balanced_rpcs
None,
// minimum doesn't really matter on private rpcs
1,
// TODO: subscribe to pending transactions on the private rpcs? they seem to have low rate limits
None,
pending_transactions.clone(),

@ -217,6 +217,7 @@ mod tests {
db_url: None,
invite_code: None,
redis_url: None,
min_synced_rpcs: 1,
public_rate_limit_per_minute: 0,
response_cache_max_bytes: 10_usize.pow(7),
redirect_public_url: "example.com/".to_string(),

@ -45,6 +45,8 @@ pub struct AppConfig {
pub chain_id: u64,
pub db_url: Option<String>,
pub invite_code: Option<String>,
#[serde(default = "default_min_synced_rpcs")]
pub min_synced_rpcs: usize,
pub redis_url: Option<String>,
#[serde(default = "default_public_rate_limit_per_minute")]
pub public_rate_limit_per_minute: u64,
@ -56,6 +58,10 @@ pub struct AppConfig {
pub redirect_user_url: String,
}
fn default_min_synced_rpcs() -> usize {
1
}
fn default_public_rate_limit_per_minute() -> u64 {
0
}

@ -366,16 +366,14 @@ impl Web3Connections {
drop(blockchain_guard);
let soft_limit_met = consensus_soft_limit >= min_sum_soft_limit;
let num_synced_rpcs = consensus_rpcs.len();
// TODO: put this in config
let min_synced_rpcs = 2;
let new_synced_connections = if soft_limit_met {
// we have a consensus large enough to serve traffic
let head_block_hash = highest_work_block.hash.unwrap();
let head_block_num = highest_work_block.number.unwrap();
let num_synced_rpcs = consensus_rpcs.len();
if num_synced_rpcs < min_synced_rpcs {
if num_synced_rpcs < self.min_synced_rpcs {
trace!(hash=%head_block_hash, num=?head_block_num, "not enough rpcs are synced to advance");
return Ok(());

@ -45,6 +45,7 @@ pub struct Web3Connections {
/// TODO: this map is going to grow forever unless we do some sort of pruning. maybe store pruned in redis?
/// TODO: what should we use for edges?
pub(super) blockchain_graphmap: RwLock<DiGraphMap<H256, u32>>,
pub(super) min_synced_rpcs: usize,
}
impl Web3Connections {
@ -57,6 +58,7 @@ impl Web3Connections {
redis_client_pool: Option<redis_rate_limit::RedisPool>,
block_map: BlockMap,
head_block_sender: Option<watch::Sender<Arc<Block<TxHash>>>>,
min_synced_rpcs: usize,
pending_tx_sender: Option<broadcast::Sender<TxStatus>>,
pending_transactions: Arc<DashMap<TxHash, TxStatus>>,
) -> anyhow::Result<(Arc<Self>, AnyhowJoinHandle<()>)> {
@ -169,6 +171,7 @@ impl Web3Connections {
pending_transactions,
block_map: Default::default(),
blockchain_graphmap: Default::default(),
min_synced_rpcs,
});
let handle = {