dynamic max_head_block_age

This commit is contained in:
Bryan Stitt 2023-10-24 21:53:41 -07:00
parent 4cf3142800
commit 16caf1d0fe
9 changed files with 23 additions and 10 deletions

1
Cargo.lock generated

@ -6678,7 +6678,6 @@ dependencies = [
"serde",
"serde_json",
"test-log",
"tokio",
"tokio-console",
"tracing",
"tracing-subscriber",

@ -133,10 +133,15 @@ impl Web3Rpcs {
// by_name starts empty. self.apply_server_configs will add to it
let by_name = RwLock::new(HashMap::new());
let max_head_block_lag = max_head_block_lag.unwrap_or(5.into());
let block_interval = average_block_interval(chain_id);
let max_head_block_age =
average_block_interval(chain_id).mul_f32((max_head_block_lag.as_u64() * 10) as f32);
// TODO: think about the max more for long block interval chains
let max_head_block_lag = max_head_block_lag.unwrap_or_else(|| {
U64::from(5.max((60f32 / block_interval.as_secs_f32()).round() as u64))
});
// TODO: think about the max more for long block interval chains
let max_head_block_age = block_interval.mul_f32((max_head_block_lag.as_u64() * 10) as f32);
let connections = Arc::new(Self {
block_and_rpc_sender,
@ -600,7 +605,7 @@ impl Serialize for Web3Rpcs {
where
S: Serializer,
{
let mut state = serializer.serialize_struct("Web3Rpcs", 5)?;
let mut state = serializer.serialize_struct("Web3Rpcs", 7)?;
{
let by_name = self.by_name.read();
@ -609,6 +614,13 @@ impl Serialize for Web3Rpcs {
state.serialize_field("conns", &rpcs)?;
}
state.serialize_field(
"max_head_block_age_ms",
&self.max_head_block_age.as_millis(),
)?;
state.serialize_field("max_head_block_lag", &self.max_head_block_lag)?;
{
let consensus_rpcs = self.watch_ranked_rpcs.borrow().clone();
// TODO: rename synced_connections to consensus_rpcs

@ -26,11 +26,8 @@ serde = { version = "1.0.189" }
serde_json = { version = "1.0.107", default-features = false, features = ["raw_value"] }
tokio-console = { version = "0.1.10", optional = true }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt"] }
[dev-dependencies]
env_logger = { version ="0.10", default-features = false, features = ["auto-color"] }
test-log = { version ="0.2.13", default-features = false, features = ["trace"] }
tokio = { version = "1.33.0", default-features = false, features = ["full", "test-util"] }
tracing = {version = "0.1", default-features = false }
tracing-subscriber = {version = "0.3", default-features = false, features = ["env-filter", "fmt"] }

@ -3,6 +3,7 @@ use std::time::Duration;
use tracing::info;
use web3_proxy::prelude::migration::sea_orm::prelude::Decimal;
use web3_proxy::prelude::reqwest;
use web3_proxy::prelude::tokio;
use web3_proxy::test_utils::mysql::TestMysql;
use web3_proxy::test_utils::TestAnvil;
use web3_proxy_cli::test_utils::admin_increases_balance::admin_increase_balance;

@ -5,6 +5,7 @@ use tracing::{info, warn};
use web3_proxy::prelude::futures::future::try_join_all;
use web3_proxy::prelude::reqwest;
use web3_proxy::prelude::rust_decimal::{Decimal, RoundingStrategy};
use web3_proxy::prelude::tokio;
use web3_proxy::prelude::tokio::time::sleep;
use web3_proxy::rpcs::blockchain::ArcBlock;
use web3_proxy::stats::FlushedStats;

@ -1,6 +1,5 @@
use serde_json::Value;
use std::{str::FromStr, time::Duration};
use tokio::{task::yield_now, time::sleep};
use tracing::{info, warn};
use web3_proxy::prelude::ethers::{
prelude::{Block, Transaction, TxHash, H256, U256, U64},
@ -9,6 +8,7 @@ use web3_proxy::prelude::ethers::{
};
use web3_proxy::prelude::http::StatusCode;
use web3_proxy::prelude::reqwest;
use web3_proxy::prelude::tokio::{self, task::yield_now, time::sleep};
use web3_proxy::rpcs::blockchain::ArcBlock;
use web3_proxy_cli::test_utils::{TestAnvil, TestApp, TestMysql};

@ -5,6 +5,7 @@ use tracing::{info, warn};
use web3_proxy::prelude::futures::future::try_join_all;
use web3_proxy::prelude::reqwest;
use web3_proxy::prelude::rust_decimal::{Decimal, RoundingStrategy};
use web3_proxy::prelude::tokio;
use web3_proxy::rpcs::blockchain::ArcBlock;
use web3_proxy_cli::test_utils::create_provider_with_rpc_key::create_provider_for_user;
use web3_proxy_cli::test_utils::rpc_key::user_get_first_rpc_key;

@ -4,6 +4,7 @@ use web3_proxy::balance::Balance;
use web3_proxy::prelude::ethers::prelude::U64;
use web3_proxy::prelude::migration::sea_orm::prelude::Decimal;
use web3_proxy::prelude::reqwest;
use web3_proxy::prelude::tokio;
use web3_proxy_cli::test_utils::{
admin_increases_balance::admin_increase_balance,
create_admin::create_user_as_admin,

@ -7,6 +7,7 @@ use web3_proxy::prelude::ethers::prelude::{Http, Provider};
use web3_proxy::prelude::ethers::{signers::Signer, types::Signature};
use web3_proxy::prelude::migration::sea_orm::prelude::Decimal;
use web3_proxy::prelude::reqwest;
use web3_proxy::prelude::tokio;
use web3_proxy::prelude::ulid::Ulid;
use web3_proxy::rpcs::blockchain::ArcBlock;
use web3_proxy_cli::test_utils::admin_deposits::get_admin_deposits;