Skip to content

Commit

Permalink
[OZ][N-08] Inconsistent Naming Convention for Functions and Variables (
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-CZ authored Jan 31, 2025
1 parent 7944b6e commit 3025df3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
2 changes: 2 additions & 0 deletions contracts/interfaces/ISFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ interface ISFC {

function getEpochEndBlock(uint256 epoch) external view returns (uint256);

function epochEndTime(uint256 epoch) external view returns (uint256);

function rewardsStash(address delegator, uint256 validatorID) external view returns (uint256);

function createValidator(bytes calldata pubkey) external payable;
Expand Down
50 changes: 25 additions & 25 deletions contracts/sfc/SFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
event TreasuryFeesResolved(uint256 amount);

modifier onlyDriver() {
if (!isNode(msg.sender)) {
if (!_isNode(msg.sender)) {
revert NotDriverAuth();
}
_;
Expand Down Expand Up @@ -606,6 +606,11 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
return getEpochSnapshot[epoch].endBlock;
}

/// Get epoch end time.
function epochEndTime(uint256 epoch) public view returns (uint256) {
return getEpochSnapshot[epoch].endTime;
}

/// Check whether the given validator is slashed - the stake (or its part) cannot
/// be withdrawn because of misbehavior (double-sign) of the validator.
function isSlashed(uint256 validatorID) public view returns (bool) {
Expand All @@ -626,7 +631,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
}

/// Check if an address is the NodeDriverAuth contract.
function isNode(address addr) internal view virtual returns (bool) {
function _isNode(address addr) internal view virtual returns (bool) {
return addr == address(node);
}

Expand Down Expand Up @@ -703,7 +708,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
}

/// Get slashing penalty for a stake.
function getSlashingPenalty(
function _getSlashingPenalty(
uint256 amount,
bool isCheater,
uint256 refundRatio
Expand Down Expand Up @@ -747,7 +752,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {

uint256 amount = getWithdrawalRequest[delegator][toValidatorID][wrID].amount;
bool isCheater = isSlashed(toValidatorID);
uint256 penalty = getSlashingPenalty(amount, isCheater, slashingRefundRatio[toValidatorID]);
uint256 penalty = _getSlashingPenalty(amount, isCheater, slashingRefundRatio[toValidatorID]);
delete getWithdrawalRequest[delegator][toValidatorID][wrID];

if (amount <= penalty) {
Expand Down Expand Up @@ -835,11 +840,6 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
}
}

/// Get epoch end time.
function epochEndTime(uint256 epoch) internal view returns (uint256) {
return getEpochSnapshot[epoch].endTime;
}

/// Check if an address is redirected.
function _redirected(address addr) internal view returns (bool) {
return getRedirection[addr] != address(0);
Expand Down Expand Up @@ -1107,6 +1107,22 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
totalSupply = totalSupply + amount;
}

/// Sync validator with node.
function _syncValidator(uint256 validatorID, bool syncPubkey) internal {
if (!_validatorExists(validatorID)) {
revert ValidatorNotExists();
}
// emit special log for node
uint256 weight = getValidator[validatorID].receivedStake;
if (getValidator[validatorID].status != OK_STATUS) {
weight = 0;
}
node.updateValidatorWeight(validatorID, weight);
if (syncPubkey && weight != 0) {
node.updateValidatorPubkey(validatorID, getValidatorPubkey[validatorID]);
}
}

/// Notify stake subscriber about staking changes.
/// Used to recount votes from delegators in the governance contract.
function _notifyStakeSubscriber(address delegator, address validatorAuth, bool strict) internal {
Expand Down Expand Up @@ -1144,22 +1160,6 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
}
}

/// Sync validator with node.
function _syncValidator(uint256 validatorID, bool syncPubkey) public {
if (!_validatorExists(validatorID)) {
revert ValidatorNotExists();
}
// emit special log for node
uint256 weight = getValidator[validatorID].receivedStake;
if (getValidator[validatorID].status != OK_STATUS) {
weight = 0;
}
node.updateValidatorWeight(validatorID, weight);
if (syncPubkey && weight != 0) {
node.updateValidatorPubkey(validatorID, getValidatorPubkey[validatorID]);
}
}

/// Check if a validator exists.
function _validatorExists(uint256 validatorID) internal view returns (bool) {
return getValidator[validatorID].createdTime != 0;
Expand Down
8 changes: 6 additions & 2 deletions contracts/test/UnitTestSFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ contract UnitTestSFC is SFC {
return time;
}

function isNode(address addr) internal view override returns (bool) {
function _isNode(address addr) internal view override returns (bool) {
if (allowedNonNodeCalls) {
return true;
}
return SFC.isNode(addr);
return SFC._isNode(addr);
}

function syncValidator(uint256 validatorID, bool syncPubkey) public {
_syncValidator(validatorID, syncPubkey);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/SFC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('SFC', () => {
});

it('Should succeed and set genesis validator with bad status', async function () {
await this.sfc._syncValidator(1, false);
await this.sfc.syncValidator(1, false);
});

it('Should revert when sealEpoch not called by node', async function () {
Expand Down Expand Up @@ -1056,7 +1056,7 @@ describe('SFC', () => {
});

it('Should revert when syncing if validator does not exist', async function () {
await expect(this.sfc._syncValidator(33, false)).to.be.revertedWithCustomError(this.sfc, 'ValidatorNotExists');
await expect(this.sfc.syncValidator(33, false)).to.be.revertedWithCustomError(this.sfc, 'ValidatorNotExists');
});
});

Expand Down

0 comments on commit 3025df3

Please sign in to comment.