Skip to content

Commit

Permalink
[txn-emitter] Filter bad/stale clients (aptos-labs#3748)
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos authored Sep 3, 2022
1 parent ddff6a0 commit 8e1f094
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions crates/transaction-emitter-lib/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Cluster {
) -> Result<Self> {
let num_peers = peers.len();

let mut instances = Vec::new();
let mut instance_states = Vec::new();
let mut errors = Vec::new();
for url in &peers {
let instance = Instance::new(
Expand All @@ -54,7 +54,7 @@ impl Cluster {
None,
);
match instance.rest_client().get_ledger_information().await {
Ok(_) => instances.push(instance),
Ok(v) => instance_states.push((instance, v.into_inner())),
Err(err) => errors.push(err),
}
}
Expand All @@ -66,6 +66,32 @@ impl Cluster {
);
}

let mut instances = Vec::new();
let max_version = instance_states
.iter()
.map(|(_, s)| s.version)
.max()
.unwrap();

for (instance, state) in instance_states.into_iter() {
if state.chain_id != chain_id.id() {
warn!(
"Client {} running wrong chain {}",
instance.peer_name(),
state.chain_id
);
} else if state.version + 100000 < max_version {
warn!(
"Client {} too stale, {}, while chain at {}",
instance.peer_name(),
state.version,
max_version
);
} else {
instances.push(instance);
}
}

if instances.is_empty() {
return Err(anyhow!(
"None of the rest endpoints provided are reachable: {:?}",
Expand Down

0 comments on commit 8e1f094

Please sign in to comment.