From fdb828ad59079825399d216b463cfcca81e64e13 Mon Sep 17 00:00:00 2001 From: Sherif Abdelmoatty Date: Tue, 10 Sep 2024 00:08:51 +0300 Subject: [PATCH] update: reputation_manager lowercase addresses --- voltaire_bundler/mempool/mempool_manager.py | 7 ++-- .../mempool/reputation_manager.py | 34 +++++++++---------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/voltaire_bundler/mempool/mempool_manager.py b/voltaire_bundler/mempool/mempool_manager.py index 0089ebc..c632ed2 100644 --- a/voltaire_bundler/mempool/mempool_manager.py +++ b/voltaire_bundler/mempool/mempool_manager.py @@ -596,7 +596,7 @@ def _verify_banned_and_throttled_entity( entity_no_of_ops = self._get_entity_no_of_ops_in_mempool(entity) else: entity_no_of_ops = 0 - status = self.reputation_manager.get_status(entity) + status = self.reputation_manager.get_status(entity.lower()) if status == ReputationStatus.BANNED: raise ValidationException( ValidationExceptionCode.Reputation, @@ -761,10 +761,11 @@ def validate_staked_entity_can_include_more_user_operations( stake: int, unstake_delay: int ): - if self.reputation_manager.is_whitelisted(entity): + entity_lowercase = entity.lower() + if self.reputation_manager.is_whitelisted(entity_lowercase): return - if self.reputation_manager.get_status(entity) == ReputationStatus.BANNED: + if self.reputation_manager.get_status(entity_lowercase) == ReputationStatus.BANNED: raise ValidationException( ValidationExceptionCode.Reputation, f"{entity_title} {entity} is banned." diff --git a/voltaire_bundler/mempool/reputation_manager.py b/voltaire_bundler/mempool/reputation_manager.py index 0e5ee7d..57d8acc 100644 --- a/voltaire_bundler/mempool/reputation_manager.py +++ b/voltaire_bundler/mempool/reputation_manager.py @@ -79,32 +79,32 @@ def update_included_status(self, entity: str, modifier: int = 1) -> None: self.entities_reputation[entity_address].ops_included += modifier def ban_entity(self, entity: str) -> None: - if self.is_whitelisted(entity): + entity_lowercase = entity.lower() + if self.is_whitelisted(entity_lowercase): logging.warning( f"{entity} won't be banned because it is whitelisted.") else: - self.entities_reputation[entity.lower()] = ReputationEntry(10000, 0) + self.entities_reputation[entity_lowercase] = ReputationEntry(10000, 0) - def is_whitelisted(self, entity: str) -> bool: - return entity.lower() in self.whitelist + def is_whitelisted(self, entity_lowercase: str) -> bool: + return entity_lowercase in self.whitelist - def is_blacklisted(self, entity: str) -> bool: - return entity.lower() in self.blacklist + def is_blacklisted(self, entity_lowercase: str) -> bool: + return entity_lowercase in self.blacklist - def get_status(self, entity: str) -> ReputationStatus: - entity_address = entity.lower() + def get_status(self, entity_lowercase: str) -> ReputationStatus: if ( - self.is_blacklisted(entity) + self.is_blacklisted(entity_lowercase) ): return ReputationStatus.BANNED - + if ( - entity_address not in self.entities_reputation or - self.is_whitelisted(entity) + entity_lowercase not in self.entities_reputation or + self.is_whitelisted(entity_lowercase) ): return ReputationStatus.OK - reputation_entry = self.entities_reputation[entity_address] + reputation_entry = self.entities_reputation[entity_lowercase] min_expected_included = ( reputation_entry.ops_seen // MIN_INCLUSION_RATE_DENOMINATOR ) @@ -129,11 +129,11 @@ def set_reputation( def get_entities_reputation_json(self) -> list[dict[str, str]]: entities_reputation_json = [] - for entity_address in self.entities_reputation.keys(): + for entity_address_lowercase in self.entities_reputation.keys(): entry = entity_reputation_json = self.entities_reputation[ - entity_address] + entity_address_lowercase] - status = self.get_status(entity_address) + status = self.get_status(entity_address_lowercase) if status == ReputationStatus.OK: status_str = "ok" elif status == ReputationStatus.THROTTLED: @@ -145,7 +145,7 @@ def get_entities_reputation_json(self) -> list[dict[str, str]]: "opsSeen": entry.ops_seen, "opsIncluded": entry.ops_included, "status": status_str, - "address": entity_address + "address": entity_address_lowercase } entities_reputation_json.append(entity_reputation_json)