rename head_block_id to head_block

This commit is contained in:
Bryan Stitt 2022-12-05 14:38:54 -08:00
parent 8d3046bebb
commit dc5c944545
5 changed files with 21 additions and 21 deletions

@ -882,7 +882,7 @@ impl Web3ProxyApp {
// TODO: if no servers synced, wait for them to be synced?
let head_block = self
.balanced_rpcs
.head_block_id()
.head_block()
.context("no servers synced")?;
// we do this check before checking caches because it might modify the request params

@ -509,7 +509,7 @@ impl Web3Connections {
let consensus_head_block: SavedBlock = maybe_head_block.into();
let new_synced_connections = SyncedConnections {
head_block_id: Some(consensus_head_block.clone()),
head_block: Some(consensus_head_block.clone()),
conns,
};
@ -518,7 +518,7 @@ impl Web3Connections {
.swap(Arc::new(new_synced_connections));
// TODO: if the rpc_head_block != consensus_head_block, log something?
match &old_synced_connections.head_block_id {
match &old_synced_connections.head_block {
None => {
debug!(
"first {}/{}/{} block={}, rpc={}",
@ -543,7 +543,7 @@ impl Web3Connections {
match consensus_head_block.number().cmp(&old_head_block.number()) {
Ordering::Equal => {
// TODO: if rpc_block_id != consensus_head_block_id, do a different log?
// TODO: if rpc_block_id != consensus_head_block, do a different log?
// multiple blocks with the same fork!
if consensus_head_block.hash() == old_head_block.hash() {

@ -7,7 +7,7 @@ use crate::config::BlockAndRpc;
use crate::frontend::authorization::Authorization;
use anyhow::Context;
use ethers::prelude::{Bytes, Middleware, ProviderError, TxHash, H256, U64};
use ethers::types::{Block, U256};
use ethers::types::U256;
use futures::future::try_join_all;
use futures::StreamExt;
use log::{debug, error, info, trace, warn, Level};
@ -499,15 +499,15 @@ impl Web3Connection {
let new_head_block = match new_head_block {
Ok(None) => {
{
let mut head_block_id = self.head_block.write();
let mut head_block = self.head_block.write();
if head_block_id.is_none() {
if head_block.is_none() {
// we previously sent a None. return early
return Ok(());
}
warn!("{} is not synced!", self);
*head_block_id = None;
*head_block = None;
}
None
@ -536,9 +536,9 @@ impl Web3Connection {
warn!("unable to get block from {}. err={:?}", self, err);
{
let mut head_block_id = self.head_block.write();
let mut head_block = self.head_block.write();
*head_block_id = None;
*head_block = None;
}
None
@ -1082,8 +1082,8 @@ impl Serialize for Web3Connection {
)?;
// TODO: rename to head_block (need to work with the frontend team)
let head_block_id = &*self.head_block.read();
state.serialize_field("head_block_id", head_block_id)?;
let head_block = &*self.head_block.read();
state.serialize_field("head_block", head_block)?;
state.end()
}

@ -8,7 +8,7 @@ use entities::revert_log;
use entities::sea_orm_active_enums::Method;
use ethers::providers::{HttpClientError, ProviderError, WsClientError};
use ethers::types::{Address, Bytes};
use log::{debug, error, info, trace, warn, Level};
use log::{debug, error, trace, warn, Level};
use metered::metered;
use metered::HitCount;
use metered::ResponseTime;

@ -11,7 +11,7 @@ use std::sync::Arc;
#[derive(Clone, Default, Serialize)]
pub struct SyncedConnections {
// TODO: store ArcBlock instead?
pub(super) head_block_id: Option<SavedBlock>,
pub(super) head_block: Option<SavedBlock>,
// TODO: this should be able to serialize, but it isn't
#[serde(skip_serializing)]
pub(super) conns: Vec<Arc<Web3Connection>>,
@ -22,31 +22,31 @@ impl fmt::Debug for SyncedConnections {
// TODO: the default formatter takes forever to write. this is too quiet though
// TODO: print the actual conns?
f.debug_struct("SyncedConnections")
.field("head_block_id", &self.head_block_id)
.field("head_block", &self.head_block)
.field("num_conns", &self.conns.len())
.finish_non_exhaustive()
}
}
impl Web3Connections {
pub fn head_block_id(&self) -> Option<SavedBlock> {
self.synced_connections.load().head_block_id.clone()
pub fn head_block(&self) -> Option<SavedBlock> {
self.synced_connections.load().head_block.clone()
}
pub fn head_block_hash(&self) -> Option<H256> {
self.synced_connections
.load()
.head_block_id
.head_block
.as_ref()
.map(|head_block_id| head_block_id.hash())
.map(|head_block| head_block.hash())
}
pub fn head_block_num(&self) -> Option<U64> {
self.synced_connections
.load()
.head_block_id
.head_block
.as_ref()
.map(|head_block_id| head_block_id.number())
.map(|head_block| head_block.number())
}
pub fn synced(&self) -> bool {