Skip to content

Commit 2ef9ba7

Browse files
authored
Merge pull request #513 from hashgraph/sr/random-nodes-better
2 parents d33e80d + f1a8d00 commit 2ef9ba7

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/network/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,13 @@ impl NetworkData {
402402
}
403403

404404
pub(crate) fn random_node_ids(&self) -> Vec<AccountId> {
405-
let node_ids: Vec<_> = self.healthy_node_ids().collect();
405+
let mut node_ids: Vec<_> = self.healthy_node_ids().collect();
406+
407+
if node_ids.is_empty() {
408+
log::warn!("No healthy nodes, randomly picking some unhealthy ones");
409+
// hack, slowpath, don't care perf, fix this better later tho.
410+
node_ids = self.node_ids.to_vec();
411+
}
406412

407413
let node_sample_amount = (node_ids.len() + 2) / 3;
408414

src/transaction/mod.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,14 @@ impl<D> Transaction<D> {
221221
/// Defaults to the full list of nodes configured on the client.
222222
#[track_caller]
223223
pub fn node_account_ids(&mut self, ids: impl IntoIterator<Item = AccountId>) -> &mut Self {
224-
self.body_mut().node_account_ids = Some(ids.into_iter().collect());
224+
let nodes: Vec<_> = ids.into_iter().collect();
225+
226+
if nodes.is_empty() {
227+
log::warn!("Nodes list is empty, ignoring setter");
228+
} else {
229+
self.body_mut().node_account_ids = Some(nodes);
230+
}
231+
225232
self
226233
}
227234

@@ -388,9 +395,20 @@ impl<D: ValidateChecksums> Transaction<D> {
388395

389396
let node_account_ids = match &self.body.node_account_ids {
390397
// the clone here is the lesser of two evils.
391-
Some(it) => it.clone(),
398+
Some(it) => {
399+
assert!(!it.is_empty());
400+
it.clone()
401+
}
392402
None => {
393-
client.ok_or(Error::FreezeUnsetNodeAccountIds)?.net().0.load().random_node_ids()
403+
let nodes = client
404+
.ok_or(Error::FreezeUnsetNodeAccountIds)?
405+
.net()
406+
.0
407+
.load()
408+
.random_node_ids();
409+
assert!(!nodes.is_empty(), "BUG: Client didn't give any nodes (all unhealthy)");
410+
411+
nodes
394412
}
395413
};
396414

0 commit comments

Comments
 (0)