From 7d1c6ef86d2913b5651fd15fc7da5a9fe308fa43 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 4 Sep 2024 18:07:06 +0200 Subject: [PATCH 1/4] fix: disable hash update --- operate/services/manage.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/operate/services/manage.py b/operate/services/manage.py index 42c3436d..83ccb84e 100644 --- a/operate/services/manage.py +++ b/operate/services/manage.py @@ -559,8 +559,9 @@ def _deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,to (not is_first_mint) and (on_chain_hash is not None) and ( - on_chain_hash != service.hash - or current_agent_id != staking_params["agent_ids"][0] + # TODO Discuss how to manage on-chain hash updates with staking programs. + # on_chain_hash != service.hash or # noqa + current_agent_id != staking_params["agent_ids"][0] or current_agent_bond != staking_params["min_staking_deposit"] ) ) From 5d2720db93adcb9158924ea7f838134c4807f27e Mon Sep 17 00:00:00 2001 From: truemiller Date: Wed, 4 Sep 2024 17:46:12 +0100 Subject: [PATCH 2/4] fix: migration countdown, and minimum duration fix from staging --- .../StakingContractSection/index.tsx | 77 ++++++++++++++++++- 1 file changed, 73 insertions(+), 4 deletions(-) diff --git a/frontend/components/ManageStakingPage/StakingContractSection/index.tsx b/frontend/components/ManageStakingPage/StakingContractSection/index.tsx index 801b4557..3818f49e 100644 --- a/frontend/components/ManageStakingPage/StakingContractSection/index.tsx +++ b/frontend/components/ManageStakingPage/StakingContractSection/index.tsx @@ -1,5 +1,6 @@ import { Button, Flex, Popover, theme, Typography } from 'antd'; import { useMemo, useState } from 'react'; +import { useInterval } from 'usehooks-ts'; import { Chain, DeploymentStatus } from '@/client'; import { OpenAddFundsSection } from '@/components/MainPage/sections/AddFundsSection'; @@ -18,6 +19,7 @@ import { useServiceTemplates } from '@/hooks/useServiceTemplates'; import { useStakingContractInfo } from '@/hooks/useStakingContractInfo'; import { useStakingProgram } from '@/hooks/useStakingProgram'; import { ServicesService } from '@/service/Services'; +import { StakingContractInfo } from '@/types/Autonolas'; import { getMinimumStakedAmountRequired } from '@/utils/service'; import { AlertInsufficientMigrationFunds, AlertNoSlots } from './alerts'; @@ -80,6 +82,9 @@ export const StakingContractSection = ({ const stakingContractInfoForStakingProgram = stakingContractInfoRecord?.[stakingProgram]; + const activeStakingContractInfo = + activeStakingProgram && stakingContractInfoRecord?.[activeStakingProgram]; + const activeStakingProgramMeta = activeStakingProgram && STAKING_PROGRAM_META[activeStakingProgram]; @@ -113,7 +118,8 @@ export const StakingContractSection = ({ const activeStakingContractSupportsMigration = !activeStakingProgram || - activeStakingProgramMeta?.canMigrateTo.includes(stakingProgram); + (activeStakingProgramMeta?.canMigrateTo.includes(stakingProgram) && + isServiceStakedForMinimumDuration); const canMigrate = // checks for both initial deployment and migration @@ -151,8 +157,12 @@ export const StakingContractSection = ({ return 'No available staking slots'; } - if (!isServiceStakedForMinimumDuration) { - return 'Service has not been staked for the minimum duration'; + if (!isServiceStakedForMinimumDuration && activeStakingContractInfo) { + return ( + + ); } if (!hasEnoughOlasToMigrate) { @@ -176,7 +186,8 @@ export const StakingContractSection = ({ return 'Pearl is currently stopping, please wait before switching'; } }, [ - activeStakingProgramMeta, + activeStakingContractInfo, + activeStakingProgramMeta?.canMigrateTo, hasEnoughOlasToMigrate, hasEnoughRewards, hasEnoughSlots, @@ -344,3 +355,61 @@ export const StakingContractSection = ({ ); }; + +const CountdownUntilMigration = ({ + activeStakingContractInfo, +}: { + activeStakingContractInfo: Partial; +}) => { + const [secondsUntilReady, setSecondsUntilMigration] = useState(); + + useInterval(() => { + if (!activeStakingContractInfo) return; + + const { serviceStakingStartTime, minimumStakingDuration } = + activeStakingContractInfo; + + if (!minimumStakingDuration) return; + if (!serviceStakingStartTime) return; + + const now = Math.round(Date.now() / 1000); + const timeSinceLastStaked = now - serviceStakingStartTime; + + const timeUntilMigration = minimumStakingDuration - timeSinceLastStaked; + + if (timeUntilMigration < 0) { + setSecondsUntilMigration(0); + return; + } + + setSecondsUntilMigration(timeUntilMigration); + }, 1000); + + if (!secondsUntilReady) return "You're ready to switch contracts!"; // Shouldn't happen, but just in case + + return ( + + Your agent must continuing staking for + {countdownDisplayFormat(secondsUntilReady)} + before it can switch to a new program! + + ); +}; + +const countdownDisplayFormat = (totalSeconds: number) => { + const days = Math.floor(totalSeconds / (24 * 3600)); + totalSeconds %= 24 * 3600; + + const hours = Math.floor(totalSeconds / 3600); + totalSeconds %= 3600; + + const minutes = Math.floor(totalSeconds / 60); + const seconds = totalSeconds % 60; + + // Ensure double digits for hours, minutes, and seconds + const formattedHours = String(hours).padStart(2, '0'); + const formattedMinutes = String(minutes).padStart(2, '0'); + const formattedSeconds = String(seconds).padStart(2, '0'); + + return `${days} days ${formattedHours} hours ${formattedMinutes} minutes ${formattedSeconds} seconds`; +}; From 8c1a4bd315773e50a766ce0935912860799cdfea Mon Sep 17 00:00:00 2001 From: truemiller Date: Wed, 4 Sep 2024 17:57:34 +0100 Subject: [PATCH 3/4] fix: typos --- .../ManageStakingPage/StakingContractSection/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/components/ManageStakingPage/StakingContractSection/index.tsx b/frontend/components/ManageStakingPage/StakingContractSection/index.tsx index 3818f49e..9a4c914f 100644 --- a/frontend/components/ManageStakingPage/StakingContractSection/index.tsx +++ b/frontend/components/ManageStakingPage/StakingContractSection/index.tsx @@ -389,9 +389,9 @@ const CountdownUntilMigration = ({ return ( - Your agent must continuing staking for + Your agent must continue staking for {countdownDisplayFormat(secondsUntilReady)} - before it can switch to a new program! + before it can switch to a new contract ); }; From 8f92be4633a52e2fe2651ba211144a025e362b08 Mon Sep 17 00:00:00 2001 From: truemiller Date: Wed, 4 Sep 2024 18:08:11 +0100 Subject: [PATCH 4/4] refactor: popover copy --- .../ManageStakingPage/StakingContractSection/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/components/ManageStakingPage/StakingContractSection/index.tsx b/frontend/components/ManageStakingPage/StakingContractSection/index.tsx index 9a4c914f..dee1864c 100644 --- a/frontend/components/ManageStakingPage/StakingContractSection/index.tsx +++ b/frontend/components/ManageStakingPage/StakingContractSection/index.tsx @@ -389,9 +389,10 @@ const CountdownUntilMigration = ({ return ( - Your agent must continue staking for + Can't switch because you unstaked too recently. + This may be because your agent was suspended. + Keep running your agent and you'll be able to switch in {countdownDisplayFormat(secondsUntilReady)} - before it can switch to a new contract ); };