Skip to content

Commit

Permalink
Fix server nodes
Browse files Browse the repository at this point in the history
(if statement always false)
  • Loading branch information
SvineruS committed Nov 9, 2023
1 parent c82b557 commit cb97e09
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions contracts/staking/ServerNodes_Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,12 @@ contract ServerNodes_Manager is UUPSUpgradeable, IStakeManager, IOnBlockListener
function restake(address nodeAddress) public onlyNodeOwner(nodeAddress) whenNotPaused {
uint canceledAmount = lockKeeper.cancelLock(lockedWithdraws[nodeAddress]);

_addStake(nodeAddress, canceledAmount);

// re-register node if it was retired
if (stakes[nodeAddress].stake == 0) {
stakesList.push(nodeAddress);
onboardingWaitingList.push(nodeAddress);
}
_addStake(nodeAddress, canceledAmount);

emit StakeChanged(nodeAddress, msg.sender, int(canceledAmount));
}
Expand Down Expand Up @@ -156,6 +155,10 @@ contract ServerNodes_Manager is UUPSUpgradeable, IStakeManager, IOnBlockListener
return result;
}

function getOnboardingWaitingList() public view returns (address[] memory) {
return onboardingWaitingList;
}

// VALIDATOR SET METHODS

function reward(address nodeAddress, uint amount) external {
Expand Down Expand Up @@ -256,9 +259,10 @@ contract ServerNodes_Manager is UUPSUpgradeable, IStakeManager, IOnBlockListener
function _addStake(address nodeAddress, uint amount) internal {
stakes[nodeAddress].stake += amount;

// call validatorSet.stake() only when node already validator
if (validatorSet.getNodeStake(nodeAddress) > 0)
validatorSet.stake(nodeAddress, amount);
uint stakeInValidatorSet = validatorSet.getNodeStake(nodeAddress);
if (stakeInValidatorSet > 0)
// call validatorSet.stake() only when node is already validator
validatorSet.stake(nodeAddress, stakes[nodeAddress].stake - stakeInValidatorSet);
}

function _deleteStake(address nodeAddress) internal {
Expand Down Expand Up @@ -286,7 +290,7 @@ contract ServerNodes_Manager is UUPSUpgradeable, IStakeManager, IOnBlockListener
if (i != 0) i--;
}

// register node in validator set if onboarding delay passed
// register node in validator set if onboarding delay passed
else if (stakes[nodeAddress].timestampStake <= minTimestampForOnboarding) {
validatorSet.newStake(nodeAddress, stakes[nodeAddress].stake, false);

Expand All @@ -312,14 +316,15 @@ contract ServerNodes_Manager is UUPSUpgradeable, IStakeManager, IOnBlockListener
function _addressToString(address x) internal pure returns (string memory) {
bytes memory s = new bytes(40);
for (uint i = 0; i < 20; i++) {
uint8 b = uint8(uint(uint160(x)) / (2**(8*(19 - i))));
uint8 b = uint8(uint(uint160(x)) / (2 ** (8 * (19 - i))));
uint8 hi = (b / 16);
uint8 lo = (b - 16 * hi);
s[2*i] = _char(hi);
s[2*i+1] = _char(lo);
s[2 * i] = _char(hi);
s[2 * i + 1] = _char(lo);
}
return string(s);
}

function _char(uint8 b) internal pure returns (bytes1 c) {
return bytes1(b + (b < 10 ? 0x30 : 0x57));
}
Expand Down

0 comments on commit cb97e09

Please sign in to comment.