Skip to content

Commit

Permalink
update: reputation_manager lowercase addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
sherifahmed990 committed Sep 9, 2024
1 parent d79255f commit fdb828a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
7 changes: 4 additions & 3 deletions voltaire_bundler/mempool/mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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."
Expand Down
34 changes: 17 additions & 17 deletions voltaire_bundler/mempool/reputation_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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:
Expand All @@ -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)

Expand Down

0 comments on commit fdb828a

Please sign in to comment.