Skip to content

Commit

Permalink
fix: restake after eviction
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoreira-valory committed Jun 13, 2024
1 parent ec9699d commit f07b44e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,12 @@ def stake_service_on_chain(self, hash: str) -> None:
service.store()
return

if state == StakingState.EVICTED:
self.logger.info(f"{service.chain_data.token} has been evicted")
service.chain_data.staked = True
service.store()
self.unstake_service_on_chain(hash=hash)

self.logger.info(f"Staking service: {service.chain_data.token}")
ocm.stake(
service_id=service.chain_data.token,
Expand Down Expand Up @@ -714,6 +720,12 @@ def stake_service_on_chain_from_safe(self, hash: str) -> None:
service.store()
return

if state == StakingState.EVICTED:
self.logger.info(f"{service.chain_data.token} has been evicted")
service.chain_data.staked = True
service.store()
self.unstake_service_on_chain_from_safe(hash=hash)

self.logger.info(f"Approving staking: {service.chain_data.token}")
sftxb.new_tx().add(
sftxb.get_staking_approval_data(
Expand Down Expand Up @@ -751,7 +763,8 @@ def unstake_service_on_chain(self, hash: str) -> None:
service_id=service.chain_data.token,
staking_contract=STAKING[service.ledger_config.chain],
)
if state != StakingState.STAKED:
self.logger.info(f"Staking status for service {service.chain_data.token}: {state}")
if state not in {StakingState.STAKED, StakingState.EVICTED}:
self.logger.info("Cannot unstake service, it's not staked")
service.chain_data.staked = False
service.store()
Expand Down Expand Up @@ -781,8 +794,8 @@ def unstake_service_on_chain_from_safe(self, hash: str) -> None:
service_id=service.chain_data.token,
staking_contract=STAKING[service.ledger_config.chain],
)
self.logger.info(f"Checking staking status for: {service.chain_data.token}")
if state != StakingState.STAKED:
self.logger.info(f"Staking status for service {service.chain_data.token}: {state}")
if state not in {StakingState.STAKED, StakingState.EVICTED}:
self.logger.info("Cannot unstake service, it's not staked")
service.chain_data.staked = False
service.store()
Expand Down
4 changes: 2 additions & 2 deletions operate/services/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def check_staking_compatibility(
"""Check if service can be staked."""
status = self.status(service_id, staking_contract)
if status == StakingState.STAKED:
raise ValueError("Service already stacked")
raise ValueError("Service already staked")

if status == StakingState.EVICTED:
raise ValueError("Service is evicted")
Expand Down Expand Up @@ -330,7 +330,7 @@ def check_if_unstaking_possible(
"""Check unstaking availability"""
if (
self.status(service_id=service_id, staking_contract=staking_contract)
!= StakingState.STAKED
not in {StakingState.STAKED, StakingState.EVICTED}
):
raise ValueError("Service not staked.")

Expand Down

0 comments on commit f07b44e

Please sign in to comment.