Merge pull request #2709 from fjarri/forever-young

Provide required info for nucypher-monitor without unnecessarily maturing sprouts
pull/2769/head
Derek Pierre 2021-06-07 12:24:26 -04:00 committed by GitHub
commit a9c76820ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 5 deletions

View File

@ -0,0 +1 @@
Fix a performance regression in ``FleetSensor`` where nodes were matured prematurely (pun not intended)

View File

@ -150,7 +150,6 @@ class FleetState:
nodes_to_add_dict = {node.checksum_address: node for node in nodes_to_add}
for checksum_address in diff.nodes_updated:
new_node = nodes_to_add_dict[checksum_address]
new_node.mature()
nodes[checksum_address] = new_node
for checksum_address in diff.nodes_removed:
del nodes[checksum_address]
@ -267,6 +266,12 @@ class FleetSensor:
def record_node(self, node: 'Ursula'):
if node.domain == self._domain:
# Replace the existing object with a newer object, even if they're equal
# (this object can be mutated externally).
# This behavior is supposed to be consistent with that of the node storage
# (where a newer object with the same `checksum_address` replaces an older one).
if node in self._nodes_to_add:
self._nodes_to_add.remove(node)
self._nodes_to_add.add(node)
if self._auto_update_state:

View File

@ -92,11 +92,15 @@ class NodeSprout(PartiallyKwargifiedBytes):
self._is_finishing = False
self._finishing_mutex = Queue()
def __eq__(self, other):
try:
other_stamp = other.stamp
except (AttributeError, NoSigningPower):
return False
return bytes(self.stamp) == bytes(other_stamp)
def __hash__(self):
if not self._hash:
self._hash = int.from_bytes(self.public_address,
byteorder="big") # stop-propagation logic (ie, only propagate verified, staked nodes) keeps this unique and BFT.
return self._hash
return int.from_bytes(bytes(self.stamp), byteorder="big")
def __repr__(self):
if not self._repr:
@ -133,6 +137,9 @@ class NodeSprout(PartiallyKwargifiedBytes):
self._nickname = Nickname.from_seed(self.checksum_address)
return self._nickname
def rest_url(self):
return self.rest_interface.uri
def mature(self):
if self._is_finishing:
return self._finishing_mutex.get()