diff --git a/contracts/interfaces/ISFC.sol b/contracts/interfaces/ISFC.sol index f507325..b8eea6f 100644 --- a/contracts/interfaces/ISFC.sol +++ b/contracts/interfaces/ISFC.sol @@ -175,7 +175,7 @@ interface ISFC { function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external; - function updateVoteBookAddress(address v) external; + function updateStakeSubscriberAddress(address v) external; function voteBookAddress() external view returns (address); diff --git a/contracts/sfc/SFC.sol b/contracts/sfc/SFC.sol index dc793f9..64675d5 100644 --- a/contracts/sfc/SFC.sol +++ b/contracts/sfc/SFC.sol @@ -102,8 +102,8 @@ contract SFC is Initializable, Ownable, Version { ConstantsManager internal c; - // the governance contract (to recalculate votes when the stake changes) - address public voteBookAddress; + // the contract subscribed to stake changes notifications + address public stakeSubscriberAddress; // address derived from the validator pubkey => validator id mapping(address pubkeyAddress => uint256 validatorID) public pubkeyAddressToValidatorID; @@ -161,8 +161,8 @@ contract SFC is Initializable, Ownable, Version { error TransfersNotAllowed(); error TransferFailed(); - // governance - error GovVotesRecountFailed(); + // stake changes subscriber + error StateSubscriberFailed(); // staking error InsufficientSelfStake(); @@ -369,18 +369,6 @@ contract SFC is Initializable, Ownable, Version { emit UpdatedSlashingRefundRatio(validatorID, refundRatio); } - /// Recount votes for a delegator and a validator. - /// Forces applying validators weights changes in governance voting. - function recountVotes(address delegator, address validatorAuth, bool strict, uint256 gas) external { - // solhint-disable-next-line avoid-low-level-calls - (bool success, ) = voteBookAddress.call{gas: gas}( - abi.encodeWithSignature("recountVotes(address,address)", delegator, validatorAuth) - ); - if (!success && strict) { - revert GovVotesRecountFailed(); - } - } - /// Delegate stake to a validator. function delegate(uint256 toValidatorID) external payable { _delegate(msg.sender, toValidatorID, msg.value); @@ -402,7 +390,7 @@ contract SFC is Initializable, Ownable, Version { _setValidatorDeactivated(validatorID, status); _syncValidator(validatorID, false); address validatorAddr = getValidator[validatorID].auth; - _recountVotes(validatorAddr, validatorAddr, false); + _notifyStakeSubscriber(validatorAddr, validatorAddr, false); } /// Stash rewards for a delegator. @@ -428,8 +416,8 @@ contract SFC is Initializable, Ownable, Version { } /// Update voteBook address. - function updateVoteBookAddress(address v) external onlyOwner { - voteBookAddress = v; + function updateStakeSubscriberAddress(address v) external onlyOwner { + stakeSubscriberAddress = v; } /// Get consts address. @@ -598,7 +586,7 @@ contract SFC is Initializable, Ownable, Version { emit Delegated(delegator, toValidatorID, amount); - _recountVotes(delegator, getValidator[toValidatorID].auth, strict); + _notifyStakeSubscriber(delegator, getValidator[toValidatorID].auth, strict); } /// Un-delegate stake from a validator. @@ -633,7 +621,7 @@ contract SFC is Initializable, Ownable, Version { _setValidatorDeactivated(toValidatorID, WITHDRAWN_BIT); } - _recountVotes(delegator, getValidator[toValidatorID].auth, strict); + _notifyStakeSubscriber(delegator, getValidator[toValidatorID].auth, strict); } /// Get slashing penalty for a stake. @@ -977,16 +965,16 @@ contract SFC is Initializable, Ownable, Version { /// Recount votes for a delegator and a validator. /// Force applying validators weights changes in governance voting. - function _recountVotes(address delegator, address validatorAuth, bool strict) internal { - if (voteBookAddress != address(0)) { + function _notifyStakeSubscriber(address delegator, address validatorAuth, bool strict) internal { + if (stakeSubscriberAddress != address(0)) { // Don't allow recountVotes to use up all the gas // solhint-disable-next-line avoid-low-level-calls - (bool success, ) = voteBookAddress.call{gas: 8000000}( - abi.encodeWithSignature("recountVotes(address,address)", delegator, validatorAuth) + (bool success, ) = stakeSubscriberAddress.call{gas: 8000000}( + abi.encodeWithSignature("announceStakeChange(address,address)", delegator, validatorAuth) ); - // Don't revert if recountVotes failed unless strict mode enabled + // Don't revert if announceStakeChange failed unless strict mode enabled if (!success && strict) { - revert GovVotesRecountFailed(); + revert StateSubscriberFailed(); } } }