add min_synced_rpcs to config
This commit is contained in:
parent
4c0db2d4ff
commit
9fabb8e1e1
@ -255,6 +255,7 @@ impl Web3ProxyApp {
|
|||||||
redis_pool.clone(),
|
redis_pool.clone(),
|
||||||
block_map.clone(),
|
block_map.clone(),
|
||||||
Some(head_block_sender),
|
Some(head_block_sender),
|
||||||
|
top_config.app.min_synced_rpcs,
|
||||||
Some(pending_tx_sender.clone()),
|
Some(pending_tx_sender.clone()),
|
||||||
pending_transactions.clone(),
|
pending_transactions.clone(),
|
||||||
)
|
)
|
||||||
@ -276,6 +277,8 @@ impl Web3ProxyApp {
|
|||||||
block_map,
|
block_map,
|
||||||
// subscribing to new heads here won't work well. if they are fast, they might be ahead of balanced_rpcs
|
// subscribing to new heads here won't work well. if they are fast, they might be ahead of balanced_rpcs
|
||||||
None,
|
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
|
// TODO: subscribe to pending transactions on the private rpcs? they seem to have low rate limits
|
||||||
None,
|
None,
|
||||||
pending_transactions.clone(),
|
pending_transactions.clone(),
|
||||||
|
@ -217,6 +217,7 @@ mod tests {
|
|||||||
db_url: None,
|
db_url: None,
|
||||||
invite_code: None,
|
invite_code: None,
|
||||||
redis_url: None,
|
redis_url: None,
|
||||||
|
min_synced_rpcs: 1,
|
||||||
public_rate_limit_per_minute: 0,
|
public_rate_limit_per_minute: 0,
|
||||||
response_cache_max_bytes: 10_usize.pow(7),
|
response_cache_max_bytes: 10_usize.pow(7),
|
||||||
redirect_public_url: "example.com/".to_string(),
|
redirect_public_url: "example.com/".to_string(),
|
||||||
|
@ -45,6 +45,8 @@ pub struct AppConfig {
|
|||||||
pub chain_id: u64,
|
pub chain_id: u64,
|
||||||
pub db_url: Option<String>,
|
pub db_url: Option<String>,
|
||||||
pub invite_code: Option<String>,
|
pub invite_code: Option<String>,
|
||||||
|
#[serde(default = "default_min_synced_rpcs")]
|
||||||
|
pub min_synced_rpcs: usize,
|
||||||
pub redis_url: Option<String>,
|
pub redis_url: Option<String>,
|
||||||
#[serde(default = "default_public_rate_limit_per_minute")]
|
#[serde(default = "default_public_rate_limit_per_minute")]
|
||||||
pub public_rate_limit_per_minute: u64,
|
pub public_rate_limit_per_minute: u64,
|
||||||
@ -56,6 +58,10 @@ pub struct AppConfig {
|
|||||||
pub redirect_user_url: String,
|
pub redirect_user_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_min_synced_rpcs() -> usize {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
|
||||||
fn default_public_rate_limit_per_minute() -> u64 {
|
fn default_public_rate_limit_per_minute() -> u64 {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
@ -366,16 +366,14 @@ impl Web3Connections {
|
|||||||
drop(blockchain_guard);
|
drop(blockchain_guard);
|
||||||
|
|
||||||
let soft_limit_met = consensus_soft_limit >= min_sum_soft_limit;
|
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 {
|
let new_synced_connections = if soft_limit_met {
|
||||||
// we have a consensus large enough to serve traffic
|
// we have a consensus large enough to serve traffic
|
||||||
let head_block_hash = highest_work_block.hash.unwrap();
|
let head_block_hash = highest_work_block.hash.unwrap();
|
||||||
let head_block_num = highest_work_block.number.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");
|
trace!(hash=%head_block_hash, num=?head_block_num, "not enough rpcs are synced to advance");
|
||||||
|
|
||||||
return Ok(());
|
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: 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?
|
/// TODO: what should we use for edges?
|
||||||
pub(super) blockchain_graphmap: RwLock<DiGraphMap<H256, u32>>,
|
pub(super) blockchain_graphmap: RwLock<DiGraphMap<H256, u32>>,
|
||||||
|
pub(super) min_synced_rpcs: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Web3Connections {
|
impl Web3Connections {
|
||||||
@ -57,6 +58,7 @@ impl Web3Connections {
|
|||||||
redis_client_pool: Option<redis_rate_limit::RedisPool>,
|
redis_client_pool: Option<redis_rate_limit::RedisPool>,
|
||||||
block_map: BlockMap,
|
block_map: BlockMap,
|
||||||
head_block_sender: Option<watch::Sender<Arc<Block<TxHash>>>>,
|
head_block_sender: Option<watch::Sender<Arc<Block<TxHash>>>>,
|
||||||
|
min_synced_rpcs: usize,
|
||||||
pending_tx_sender: Option<broadcast::Sender<TxStatus>>,
|
pending_tx_sender: Option<broadcast::Sender<TxStatus>>,
|
||||||
pending_transactions: Arc<DashMap<TxHash, TxStatus>>,
|
pending_transactions: Arc<DashMap<TxHash, TxStatus>>,
|
||||||
) -> anyhow::Result<(Arc<Self>, AnyhowJoinHandle<()>)> {
|
) -> anyhow::Result<(Arc<Self>, AnyhowJoinHandle<()>)> {
|
||||||
@ -169,6 +171,7 @@ impl Web3Connections {
|
|||||||
pending_transactions,
|
pending_transactions,
|
||||||
block_map: Default::default(),
|
block_map: Default::default(),
|
||||||
blockchain_graphmap: Default::default(),
|
blockchain_graphmap: Default::default(),
|
||||||
|
min_synced_rpcs,
|
||||||
});
|
});
|
||||||
|
|
||||||
let handle = {
|
let handle = {
|
||||||
|
Loading…
Reference in New Issue
Block a user