From e7d93e6cc7cf1b92dd5a9e1966ce47d4078121eb Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 21 Feb 2023 12:11:14 +1100 Subject: [PATCH] Reduce big-O complexity of address change pruning I'm not sure this is *actually* useful, but it might come in handy if we see a ton of address changes at the fork boundary. I know the devops team have been testing with ~100k changes, so maybe this will help in that case. --- .../src/bls_to_execution_changes.rs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/beacon_node/operation_pool/src/bls_to_execution_changes.rs b/beacon_node/operation_pool/src/bls_to_execution_changes.rs index c73666e145..9978bd5a98 100644 --- a/beacon_node/operation_pool/src/bls_to_execution_changes.rs +++ b/beacon_node/operation_pool/src/bls_to_execution_changes.rs @@ -106,6 +106,16 @@ impl BlsToExecutionChanges { spec: &ChainSpec, ) { let mut validator_indices_pruned = vec![]; + let recently_changed_indices: HashSet = head_block + .message() + .body() + .bls_to_execution_changes() + .map_or(HashSet::default(), |recent_changes| { + recent_changes + .iter() + .map(|c| c.message.validator_index) + .collect() + }); self.queue.retain(|address_change| { let validator_index = address_change.as_inner().message.validator_index; @@ -114,15 +124,7 @@ impl BlsToExecutionChanges { .get(validator_index as usize) .map_or(true, |validator| { let prune = validator.has_eth1_withdrawal_credential(spec) - && head_block - .message() - .body() - .bls_to_execution_changes() - .map_or(true, |recent_changes| { - !recent_changes - .iter() - .any(|c| c.message.validator_index == validator_index) - }); + && !recently_changed_indices.contains(&validator_index); if prune { validator_indices_pruned.push(validator_index); }