diff --git a/newsfragments/2688.feature.rst b/newsfragments/2688.feature.rst new file mode 100644 index 000000000..ff0b700e1 --- /dev/null +++ b/newsfragments/2688.feature.rst @@ -0,0 +1 @@ +Ursula will now check for active stakes on startup. diff --git a/nucypher/blockchain/eth/actors.py b/nucypher/blockchain/eth/actors.py index c1703c68e..d430d5aa9 100644 --- a/nucypher/blockchain/eth/actors.py +++ b/nucypher/blockchain/eth/actors.py @@ -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): """ diff --git a/nucypher/blockchain/eth/token.py b/nucypher/blockchain/eth/token.py index 85a060e11..4113ced30 100644 --- a/nucypher/blockchain/eth/token.py +++ b/nucypher/blockchain/eth/token.py @@ -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 diff --git a/nucypher/characters/lawful.py b/nucypher/characters/lawful.py index e993949e7..600f22732 100644 --- a/nucypher/characters/lawful.py +++ b/nucypher/characters/lawful.py @@ -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')