mirror of https://github.com/nucypher/nucypher.git
Merge pull request #2688 from piotr-roslaniec/worker-shutdown#1515
Check for active stakes when starting worker and firing commitmentspull/2716/head
commit
5f91aeee03
|
@ -0,0 +1 @@
|
|||
Ursula will now check for active stakes on startup.
|
|
@ -1094,7 +1094,7 @@ class Worker(NucypherTokenActor):
|
|||
|
||||
if is_me:
|
||||
self.stakes = StakeList(registry=self.registry, checksum_address=self.checksum_address)
|
||||
self.work_tracker = work_tracker or WorkTracker(worker=self)
|
||||
self.work_tracker = work_tracker or WorkTracker(worker=self, stakes=self.stakes)
|
||||
|
||||
def block_until_ready(self, poll_rate: int = None, timeout: int = None, feedback_rate: int = None):
|
||||
"""
|
||||
|
|
|
@ -564,11 +564,12 @@ class WorkTracker:
|
|||
|
||||
ALLOWED_DEVIATION = 0.5 # i.e., up to +50% from the expected confirmation time
|
||||
|
||||
def __init__(self, worker, *args, **kwargs):
|
||||
def __init__(self, worker, stakes, *args, **kwargs):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
self.log = Logger('stake-tracker')
|
||||
self.worker = worker
|
||||
self.stakes = stakes
|
||||
self.staking_agent = self.worker.staking_agent
|
||||
self.client = self.staking_agent.blockchain.client
|
||||
|
||||
|
@ -801,6 +802,11 @@ class WorkTracker:
|
|||
# TODO: Follow-up actions for failed requirements
|
||||
return
|
||||
|
||||
self.stakes.refresh()
|
||||
if not self.stakes.has_active_substakes:
|
||||
self.log.warn(f'COMMIT PREVENTED - There are no active stakes.')
|
||||
return
|
||||
|
||||
txhash = self.__fire_commitment()
|
||||
self.__pending[current_block_number] = txhash
|
||||
|
||||
|
@ -902,3 +908,10 @@ class StakeList(UserList):
|
|||
|
||||
# Record most recent cache update
|
||||
self.__updated = maya.now()
|
||||
|
||||
@property
|
||||
def has_active_substakes(self) -> bool:
|
||||
current_period = self.staking_agent.get_current_period()
|
||||
for stake in self.data:
|
||||
if not stake.status(current_period=current_period).is_child(Stake.Status.INACTIVE):
|
||||
return True
|
||||
|
|
|
@ -1312,6 +1312,12 @@ class Ursula(Teacher, Character, Worker):
|
|||
self.block_until_ready()
|
||||
self.stakes.checksum_address = self.checksum_address
|
||||
self.stakes.refresh()
|
||||
if not self.stakes.has_active_substakes:
|
||||
msg = "No active stakes found for worker."
|
||||
if emitter:
|
||||
emitter.message(f"✗ {msg}", color='red')
|
||||
self.log.error(msg)
|
||||
return
|
||||
self.work_tracker.start(commit_now=True) # requirement_func=self._availability_tracker.status) # TODO: #2277
|
||||
if emitter:
|
||||
emitter.message(f"✓ Work Tracking", color='green')
|
||||
|
|
Loading…
Reference in New Issue