Skip to content

Commit

Permalink
Merge pull request #473 from skalenetwork/hotfix/SKALE-4942-incorrect…
Browse files Browse the repository at this point in the history
…-finish-ts-rotation

Hotfix/skale 4942 Fix incorrect finish_ts in rotation history
  • Loading branch information
dmytrotkk authored Feb 4, 2022
2 parents 8180bba + 2f6ad56 commit 56f777d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 14 additions & 1 deletion skale/contracts/manager/node_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# along with SKALE.py. If not, see <https://www.gnu.org/licenses/>.
""" NodeRotation.sol functions """

import logging
import functools
from dataclasses import dataclass

Expand All @@ -26,6 +27,9 @@
from web3.exceptions import ContractLogicError


logger = logging.getLogger(__name__)


NO_PREVIOUS_NODE_EXCEPTION_TEXT = 'No previous node'


Expand Down Expand Up @@ -75,8 +79,17 @@ def get_leaving_history(self, node_id):
def get_schain_finish_ts(self, node_id: int, schain_name: str) -> int:
raw_history = self.contract.functions.getLeavingHistory(node_id).call()
schain_id = self.skale.schains.name_to_id(schain_name)
return next(
finish_ts = next(
(schain[1] for schain in raw_history if '0x' + schain[0].hex() == schain_id), None)
if not finish_ts:
return None
exception = self.skale.schains_internal.check_exception(schain_name, node_id)
if exception:
rotation_delay = self.skale.constants_holder.get_rotation_delay()
logger.info(f'Node {node_id} in exceptions array for {schain_name}, \
adding {rotation_delay} to {finish_ts}.')
finish_ts += rotation_delay
return finish_ts

def is_rotation_in_progress(self, schain_name):
schain_id = self.schains.name_to_id(schain_name)
Expand Down
5 changes: 0 additions & 5 deletions skale/schain_config/rotation_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ def _add_previous_schain_rotations_state(
previous_node = skale.node_rotation.get_previous_node(schain_name, node_id)
if previous_node is not None:
finish_ts = skale.node_rotation.get_schain_finish_ts(previous_node, schain_name)
exception = skale.schains_internal.check_exception(schain_name, previous_node)
if exception:
logger.info(f'Node {previous_node} in exceptions array for {schain_name}, \
adding {rotation_delay} to {finish_ts}.')
finish_ts += rotation_delay
previous_nodes[node_id] = {
'finish_ts': finish_ts,
'previous_node_id': previous_node
Expand Down

0 comments on commit 56f777d

Please sign in to comment.