skip nodes that are syncing
This commit is contained in:
parent
eb4b487aae
commit
b8ac77a342
@ -69,7 +69,7 @@ impl SavedBlock {
|
||||
}
|
||||
|
||||
/// When the block was received, this node was still syncing
|
||||
pub fn was_syncing(&self) -> bool {
|
||||
pub fn syncing(&self) -> bool {
|
||||
// TODO: margin should come from a global config
|
||||
self.lag > 60
|
||||
}
|
||||
@ -85,7 +85,7 @@ impl Display for SavedBlock {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} ({})", self.number(), self.hash())?;
|
||||
|
||||
if self.was_syncing() {
|
||||
if self.syncing() {
|
||||
write!(f, " (behind by {} seconds)", self.lag)?;
|
||||
}
|
||||
|
||||
@ -307,7 +307,7 @@ impl Web3Connections {
|
||||
// we don't know if its on the heaviest chain yet
|
||||
self.save_block(&rpc_head_block.block, false).await?;
|
||||
|
||||
if rpc_head_block.was_syncing() {
|
||||
if rpc_head_block.syncing() {
|
||||
if connection_heads.remove(&rpc.name).is_some() {
|
||||
warn!("{} is behind by {} seconds", &rpc.name, rpc_head_block.lag);
|
||||
};
|
||||
@ -590,7 +590,7 @@ impl Web3Connections {
|
||||
}
|
||||
Ordering::Greater => {
|
||||
debug!(
|
||||
"new {}/{}/{} con head={} rpc_head={} rpc={}",
|
||||
"new {}/{}/{} con_head={} rpc_head={} rpc={}",
|
||||
num_consensus_rpcs,
|
||||
num_connection_heads,
|
||||
total_conns,
|
||||
|
@ -277,7 +277,15 @@ impl Web3Connection {
|
||||
pub fn has_block_data(&self, needed_block_num: &U64) -> bool {
|
||||
let head_block_num = match self.head_block.read().clone() {
|
||||
None => return false,
|
||||
Some(x) => x.number(),
|
||||
Some(x) => {
|
||||
if x.syncing() {
|
||||
// skip syncing nodes. even though they might be able to serve a query,
|
||||
// latency will be poor and
|
||||
return false;
|
||||
}
|
||||
|
||||
x.number()
|
||||
}
|
||||
};
|
||||
|
||||
// this rpc doesn't have that block yet. still syncing
|
||||
|
Loading…
Reference in New Issue
Block a user